
#ifndef RENDERTARGET_H
#define RENDERTARGET_H

#include "fastmath.hpp"
class Rendertarget {

  public:
    const int width;
    const int height;

    Rendertarget(int width, int height) : width(width), height(height) {
        pixels = new uint8_t[width * height * 3];
        depth = new decimal[width * height];
        for (int i = 0; i < width * height * 3; i++) {
            pixels[i] = 0;
        }
    }

    void set(int x, int y, vec3 val) {
        int start = (width * y + x) * 3;
        for (int i = 0; i < 3; i++) {
            pixels[start + i] = (uint8_t)(val[i].i >> SHIFT_AMOUNT);
        }
    }

    decimal getDepth(int x, int y) { return depth[width * y + x]; }
    void setDepth(int x, int y, decimal val) { depth[width * y + x] = val; }

    void clearDepth() {
        for (int i = 0; i < width * height; i++) {
            depth[i].i = std::numeric_limits<int32_t>::max();
        }
    }
    void clearTarget() {
        for (int i = 0; i < width * height * 3; i++) {
            pixels[i] = 0;
        }
    }

    uint8_t *pixels;
    decimal *depth;
};

#endif
