t
Loading...
Searching...
No Matches
RenderTarget.hpp
1#include "primitives/Texture.hpp"
2
3#ifndef RENDERTARGET_HPP
4#define RENDERTARGET_HPP
5
6namespace t {
7
8template <typename BufferType> class RenderTarget {
9public:
10 int width;
11 int height;
12 Texture<BufferType> texture;
13
14 RenderTarget(int _width, int _height, TextureFormat _format)
15 : width(_width), height(_height), texture(_width, _height, _format) {}
16
17 Color read(int x, int y) {
18 switch (this->texture.format) {
20 return Color(texture.image[x * 3 + y * width * 3],
21 texture.image[x * 3 + y * width * 3 + 1],
22 texture.image[x * 3 + y * width * 3 + 2]);
23
25 const auto depth = texture.image[x + y * width];
26 return Color(depth, depth, depth);
27 }
28
29 return Color(0, 0, 0);
30 }
31
32 void write(int x, int y, Color color) {
33 switch (this->texture.format) {
35 texture.image[x * 3 + y * width * 3] = color.x;
36 texture.image[x * 3 + y * width * 3 + 1] = color.y;
37 texture.image[x * 3 + y * width * 3 + 2] = color.z;
38 break;
39
41 texture.image[x + y * width] = color.x;
42 break;
43 }
44 }
45};
46
47} // namespace t
48
49#endif // RENDERTARGET_HPP
The color class.
Definition Color.hpp:18
Definition RenderTarget.hpp:8
The 2D texture class.
Definition Texture.hpp:17
std::vector< BufferType > image
The image data of the texture.
Definition Texture.hpp:22
TextureFormat format
The format of the texture.
Definition Texture.hpp:21
double z
The z component of this 3D vector.
Definition Vector3.hpp:24
double y
The y component of this 3D vector.
Definition Vector3.hpp:23
double x
The x component of this 3D vector.
Definition Vector3.hpp:22
The t software 3D graphics library namespace.
Definition algorithms.hpp:12
TextureFormat
The texture format.
Definition constants.hpp:28
@ Depth
Stores the depth in normalized floating-point values.
@ RgbDouble
Stores RGB values in normalized floating-point values.