raylib-cpp
C++ object-oriented wrapper library for raylib.
RenderTexture.hpp
1 #ifndef RAYLIB_CPP_INCLUDE_RENDERTEXTURE_HPP_
2 #define RAYLIB_CPP_INCLUDE_RENDERTEXTURE_HPP_
3 
4 #include "./raylib.hpp"
5 #include "./raylib-cpp-utils.hpp"
6 #include "./RaylibException.hpp"
7 #include "./TextureUnmanaged.hpp"
8 
9 namespace raylib {
14  public:
19  id = 0;
20  }
21 
22  RenderTexture(const ::RenderTexture& renderTexture) {
23  set(renderTexture);
24  }
25 
26  RenderTexture(unsigned int id, const ::Texture& texture, const ::Texture& depth) :
27  ::RenderTexture{id, texture, depth} {}
28 
32  RenderTexture(int width, int height) {
33  set(::LoadRenderTexture(width, height));
34  }
35 
36  RenderTexture(const RenderTexture&) = delete;
37 
38  RenderTexture(RenderTexture&& other) {
39  set(other);
40 
41  other.id = 0;
42  other.texture = {};
43  other.depth = {};
44  }
45 
46  GETTERSETTER(unsigned int, Id, id)
47 
48 
52  return texture;
53  }
54 
55  inline void SetTexture(const ::Texture& newTexture) {
56  texture = newTexture;
57  }
58 
63  return depth;
64  }
65 
66  inline void SetDepth(const ::Texture& newDepth) {
67  depth = newDepth;
68  }
69 
70  RenderTexture& operator=(const ::RenderTexture& texture) {
71  set(texture);
72  return *this;
73  }
74 
75  RenderTexture& operator=(const RenderTexture&) = delete;
76 
77  RenderTexture& operator=(RenderTexture&& other) noexcept {
78  if (this == &other) {
79  return *this;
80  }
81 
82  Unload();
83  set(other);
84 
85  other.id = 0;
86  other.texture = {};
87  other.depth = {};
88 
89  return *this;
90  }
91 
92  ~RenderTexture() {
93  Unload();
94  }
95 
96  inline void Unload() {
97  UnloadRenderTexture(*this);
98  }
99 
104  ::BeginTextureMode(*this);
105  return *this;
106  }
107 
111  inline RenderTexture& EndMode() {
112  ::EndTextureMode();
113  return *this;
114  }
115 
119  static RenderTexture Load(int width, int height) {
120  return ::LoadRenderTexture(width, height);
121  }
122 
126  bool IsReady() const {
127  return id != 0;
128  }
129 
130  private:
131  void set(const ::RenderTexture& renderTexture) {
132  id = renderTexture.id;
133  texture = renderTexture.texture;
134  depth = renderTexture.depth;
135  }
136 };
137 typedef RenderTexture RenderTexture2D;
138 } // namespace raylib
139 
142 
143 #endif // RAYLIB_CPP_INCLUDE_RENDERTEXTURE_HPP_
RenderTexture type, for texture rendering.
TextureUnmanaged GetTexture()
Get the color buffer attachment texture.
RenderTexture & EndMode()
Ends drawing to render texture.
bool IsReady() const
Retrieves whether or not the render texture is ready.
RenderTexture & BeginMode()
Initializes render texture for drawing.
TextureUnmanaged GetDepth()
Depth buffer attachment texture.
RenderTexture()
Default constructor to build an empty RenderTexture.
static RenderTexture Load(int width, int height)
Load texture for rendering (framebuffer)
RenderTexture(int width, int height)
Load texture for rendering (framebuffer)
A Texture that is not managed by the C++ garbage collector.
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8