raylib-cpp
C++ object-oriented wrapper library for raylib.
Loading...
Searching...
No Matches
RenderTexture.hpp
1#ifndef RAYLIB_CPP_INCLUDE_RENDERTEXTURE_HPP_
2#define RAYLIB_CPP_INCLUDE_RENDERTEXTURE_HPP_
3
4#include "./TextureUnmanaged.hpp"
5#include "./raylib-cpp-utils.hpp"
6
7namespace raylib {
11class RenderTexture : public ::RenderTexture {
12public:
16 RenderTexture() = default;
17
18 RenderTexture(const ::RenderTexture& renderTexture)
19 : ::RenderTexture(renderTexture) {
20 // Nothing.
21 }
22
23 RenderTexture(unsigned int id, const ::Texture& texture, const ::Texture& depth)
24 : ::RenderTexture{id, texture, depth} {}
25
29 RenderTexture(int width, int height)
30 : ::RenderTexture(::LoadRenderTexture(width, height)) {
31 // Nothing.
32 }
33
34 RenderTexture(const RenderTexture&) = delete;
35
36 RenderTexture(RenderTexture&& other) noexcept
37 {
38 set(other);
39
40 other.id = 0;
41 other.texture = {};
42 other.depth = {};
43 }
44
45 GETTER(unsigned int, Id, id)
46
47
50 TextureUnmanaged GetTexture() { return texture; }
51
52 void SetTexture(const ::Texture& newTexture) { texture = newTexture; }
53
57 TextureUnmanaged GetDepth() { return depth; }
58
59 void SetDepth(const ::Texture& newDepth) { depth = newDepth; }
60
61 RenderTexture& operator=(const ::RenderTexture& texture) {
62 set(texture);
63 return *this;
64 }
65
66 RenderTexture& operator=(const RenderTexture&) = delete;
67
68 RenderTexture& operator=(RenderTexture&& other) noexcept {
69 if (this == &other) {
70 return *this;
71 }
72
73 Unload();
74 set(other);
75
76 other.id = 0;
77 other.texture = {};
78 other.depth = {};
79
80 return *this;
81 }
82
83 ~RenderTexture() { Unload(); }
84
85 void Unload() { UnloadRenderTexture(*this); }
86
91 ::BeginTextureMode(*this);
92 return *this;
93 }
94
99 ::EndTextureMode();
100 return *this;
101 }
102
106 static RenderTexture Load(int width, int height) { return ::LoadRenderTexture(width, height); }
107
111 [[nodiscard]] bool IsValid() const { return ::IsRenderTextureValid(*this); }
112protected:
113 void set(const ::RenderTexture& renderTexture) {
114 id = renderTexture.id;
115 texture = renderTexture.texture;
116 depth = renderTexture.depth;
117 }
118};
119
120using RenderTexture2D = RenderTexture;
121
122} // namespace raylib
123
126
127#endif // RAYLIB_CPP_INCLUDE_RENDERTEXTURE_HPP_
RenderTexture type, for texture rendering.
TextureUnmanaged GetTexture()
Get the color buffer attachment texture.
RenderTexture & BeginMode()
Initializes render texture for drawing.
RenderTexture & EndMode()
Ends drawing to render texture.
bool IsValid() const
Retrieves whether or not the render texture is ready.
TextureUnmanaged GetDepth()
Depth buffer attachment texture.
static RenderTexture Load(int width, int height)
Load texture for rendering (framebuffer)
RenderTexture()=default
Default constructor to build an empty RenderTexture.
RenderTexture(int width, int height)
Load texture for rendering (framebuffer)
A Texture that is not managed by C++ RAII.
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8