-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRenderTarget.h
More file actions
124 lines (98 loc) · 3.3 KB
/
RenderTarget.h
File metadata and controls
124 lines (98 loc) · 3.3 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#ifndef RENDERTARGET_H
#define RENDERTARGET_H
#include "Config.h"
namespace P3D
{
class RenderTarget
{
public:
explicit RenderTarget(unsigned int width, unsigned int height, pixel* buffer = nullptr, unsigned int y_pitch = 0)
{
AttachColorBuffer(width, height, buffer, y_pitch);
}
RenderTarget(const RenderTarget&) = delete;
RenderTarget& operator=(const RenderTarget&) = delete;
RenderTarget(RenderTarget&&) = delete;
RenderTarget& operator=(RenderTarget&&) = delete;
~RenderTarget()
{
RemoveColorBuffer();
RemoveZBuffer();
}
bool AttachColorBuffer(unsigned int width, unsigned int height, pixel* buffer = nullptr, unsigned int y_pitch = 0)
{
RemoveColorBuffer();
if(!width || !height)
return false;
if(y_pitch == 0)
y_pitch = width;
if(y_pitch < width)
return false;
color_buffer_y_pitch = y_pitch;
this->width = width;
this->height = height;
if(buffer)
{
color_buffer = buffer;
}
else
{
color_buffer = new pixel[width * height];
owned_color_buffer = true;
}
return true;
}
bool AttachZBuffer(z_val* buffer = nullptr, unsigned int y_pitch = 0)
{
RemoveZBuffer();
if(!width || !height)
return false;
if(y_pitch == 0)
y_pitch = width;
if(y_pitch < width)
return false;
if(buffer)
{
z_buffer = buffer;
z_buffer_y_pitch = y_pitch;
}
else
{
z_buffer = new z_val[width * height];
z_buffer_y_pitch = width;
owned_z_buffer = true;
}
return true;
}
void RemoveZBuffer()
{
if(owned_z_buffer)
delete[] z_buffer;
z_buffer = nullptr;
z_buffer_y_pitch = 0;
}
unsigned int GetWidth() const {return width;}
unsigned int GetHeight() const {return height;}
unsigned int GetColorBufferYPitch() const {return color_buffer_y_pitch;}
pixel* GetColorBuffer() const {return color_buffer;}
z_val* GetZBuffer() const {return z_buffer;}
unsigned int GetZBufferYPitch() const {return z_buffer_y_pitch;}
private:
void RemoveColorBuffer()
{
if(owned_color_buffer)
delete[] color_buffer;
color_buffer = nullptr;
owned_color_buffer = false;
}
pixel* color_buffer = nullptr;
unsigned int width = 0;
unsigned int height = 0;
unsigned int color_buffer_y_pitch = 0;
z_val* z_buffer = nullptr;
unsigned int z_buffer_y_pitch = 0;
bool owned_color_buffer = false;
bool owned_z_buffer = false;
};
};
#endif // RENDERTARGET_H