-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframebuffer.hpp
64 lines (51 loc) · 1.24 KB
/
framebuffer.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <stdint.h>
#include <cstdlib>
#include "color.hpp"
using namespace std;
struct PixelData
{
Color color;
//PixelData():color() {}
};
class Framebuffer
{
private:
uint32_t p_width;
uint32_t p_height;
uint32_t num_pixels;
PixelData* pixel_array;
public:
Framebuffer (uint32_t w, uint32_t h) : p_width(w), p_height(h), num_pixels(w * h)
{
pixel_array = new PixelData[num_pixels];
}
virtual ~Framebuffer()
{
delete[] pixel_array;
pixel_array = NULL;
p_width = p_height = num_pixels = 0;
}
Color& get_pixel_data(uint32_t row, uint32_t col)
{
return (pixel_array[row + col*p_width]).color;
}
void set_pixel_data(uint32_t row, uint32_t col, const Color& color)
{
if ((row < p_height) && (col < p_width))
{
pixel_array[row + col*p_width].color = color;
}
else
{
cerr << "Array out of bounds" << endl;
}
}
void clear_framebuffer()
{
//memset(pixel_array, Color(), sizeof(PixelData) * p_width * p_height);
for (int i=0; i<sizeof(PixelData);i++) {
pixel_array[i].color = Color();
}
}
};