TDME2  1.9.200
FrameBuffer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 
5 #include <tdme/tdme.h>
6 #include <tdme/engine/fwd-tdme.h>
9 
10 using std::string;
11 
13 
16 
17 /**
18  * Frame buffer class
19  * @author Andreas Drewke
20  */
22 {
23 
24 public:
25  static constexpr int32_t FRAMEBUFFER_DEPTHBUFFER { 1 };
26  static constexpr int32_t FRAMEBUFFER_COLORBUFFER { 2 };
27 
28  static constexpr int32_t TEXTUREID_NONE { 0 };
29 
30  static constexpr int32_t CUBEMAPTEXTUREINDEX_NONE { 0 };
31  static constexpr int32_t CUBEMAPTEXTUREINDEX_NEGATIVE_X { 1 };
32  static constexpr int32_t CUBEMAPTEXTUREINDEX_POSITIVE_X { 2 };
33  static constexpr int32_t CUBEMAPTEXTUREINDEX_POSITIVE_Y { 3 };
34  static constexpr int32_t CUBEMAPTEXTUREINDEX_NEGATIVE_Y { 4 };
35  static constexpr int32_t CUBEMAPTEXTUREINDEX_POSITIVE_Z { 5 };
36  static constexpr int32_t CUBEMAPTEXTUREINDEX_NEGATIVE_Z { 6 };
37 
38 private:
39  int32_t buffers;
40  int32_t width;
41  int32_t height;
42  int32_t frameBufferId;
49 
50  /**
51  * Render given depth texture and color buffer texture to screen
52  * @parma engine engine
53  * @param depthBufferTextureId depth buffer texture id
54  * @param colorBufferTextureId color buffer texture id
55  */
56  void renderToScreen(Engine* engine, int32_t depthBufferTextureId, int32_t colorBufferTextureId);
57 
58 public:
59  // forbid class copy
61 
62  /**
63  * Public constructor
64  * @param width width
65  * @param height height
66  * @param buffers buffers (see FrameBuffer::FRAMEBUFFER_*)
67  * @param cubeMapTextureId cube map texture id
68  * @param cubeMapTextureIndex cube map texture index
69  */
70  FrameBuffer(int32_t width, int32_t height, int32_t buffers, int32_t cubeMapTextureId = TEXTUREID_NONE, int32_t cubeMapTextureIndex = TEXTUREID_NONE);
71 
72  /**
73  * Destructor
74  */
75  virtual ~FrameBuffer();
76 
77  /**
78  * @return width
79  */
80  inline int32_t getWidth() {
81  return width;
82  }
83 
84  /**
85  * @return height
86  */
87  inline int32_t getHeight() {
88  return height;
89  }
90 
91  /**
92  * @return frame buffer id
93  */
94  inline int32_t getId() {
95  return frameBufferId;
96  }
97 
98  /**
99  * @return depth buffer texture id
100  */
101  inline int32_t getDepthBufferTextureId() {
102  return depthBufferTextureId;
103  }
104 
105  /**
106  * Set depth buffer texture id
107  * @param texture id depth buffer texture id
108  */
109  inline void setDepthBufferTextureId(int32_t textureId) {
110  depthBufferTextureId = textureId;
111  }
112 
113  /**
114  * @return color buffer texture id
115  */
116  inline int32_t getColorBufferTextureId() {
117  return colorBufferTextureId;
118  }
119 
120  /**
121  * Set color buffer texture id
122  * @param textureId color buffer texture id
123  */
124  inline void setColorBufferTextureId(int32_t textureId) {
125  colorBufferTextureId = textureId;
126  }
127 
128  /**
129  * Initialize the frame buffer
130  */
131  void initialize();
132 
133  /**
134  * Resize the frame buffer
135  * @param width width
136  * @param height height
137  */
138  void reshape(int32_t width, int32_t height);
139 
140  /**
141  * Disposes this frame buffer
142  */
143  void dispose();
144 
145  /**
146  * Enables this frame buffer to be rendered
147  */
148  void enableFrameBuffer();
149 
150  /**
151  * Switches back to non offscreen main frame buffer to be rendered
152  */
153  static void disableFrameBuffer();
154 
155  /**
156  * Bind depth texture
157  * @param contextIdx context index
158  */
159  void bindDepthBufferTexture(int contextIdx);
160 
161  /**
162  * Bind color texture
163  * @param contextIdx context index
164  */
165  void bindColorBufferTexture(int contextIdx);
166 
167  /**
168  * Render to screen or bound frame buffer
169  * @param engine engine
170  */
171  inline void renderToScreen(Engine* engine) {
173  }
174 
175  /**
176  * Render depth buffer to screen or bound frame buffer
177  * @param engine engine
178  */
179  inline void renderDepthBufferToScreen(Engine* engine) {
181  }
182 
183  /**
184  * Do post processing into target frame buffer (which can be screen as well when passing nullptr)
185  * @param engine engine
186  * @param source source frame buffer
187  * @param programId post processing shader id
188  * @param shaderId post processing shader id
189  * @param temporary bind additional temporary frame buffer
190  * @param blendToSource target = blendToSource + source
191  */
192  static void doPostProcessing(Engine* engine, FrameBuffer* target, FrameBuffer* source, const string& programId, const string& shaderId, FrameBuffer* temporary = nullptr, FrameBuffer* blendToSource = nullptr);
193 
194  // overridden methods
195  inline int32_t getColorTextureId() override {
196  return colorBufferTextureId;
197  }
198 
199 };
Engine main class.
Definition: Engine.h:131
Frame buffer class.
Definition: FrameBuffer.h:22
void bindColorBufferTexture(int contextIdx)
Bind color texture.
static constexpr int32_t CUBEMAPTEXTUREINDEX_NEGATIVE_Z
Definition: FrameBuffer.h:36
void reshape(int32_t width, int32_t height)
Resize the frame buffer.
Definition: FrameBuffer.cpp:70
void renderToScreen(Engine *engine, int32_t depthBufferTextureId, int32_t colorBufferTextureId)
Render given depth texture and color buffer texture to screen @parma engine engine.
void initialize()
Initialize the frame buffer.
Definition: FrameBuffer.cpp:38
virtual ~FrameBuffer()
Destructor.
Definition: FrameBuffer.cpp:35
static constexpr int32_t CUBEMAPTEXTUREINDEX_NEGATIVE_X
Definition: FrameBuffer.h:31
void renderDepthBufferToScreen(Engine *engine)
Render depth buffer to screen or bound frame buffer.
Definition: FrameBuffer.h:179
void setColorBufferTextureId(int32_t textureId)
Set color buffer texture id.
Definition: FrameBuffer.h:124
void setDepthBufferTextureId(int32_t textureId)
Set depth buffer texture id.
Definition: FrameBuffer.h:109
void renderToScreen(Engine *engine)
Render to screen or bound frame buffer.
Definition: FrameBuffer.h:171
static void disableFrameBuffer()
Switches back to non offscreen main frame buffer to be rendered.
void enableFrameBuffer()
Enables this frame buffer to be rendered.
Definition: FrameBuffer.cpp:93
static constexpr int32_t FRAMEBUFFER_COLORBUFFER
Definition: FrameBuffer.h:26
int32_t getColorBufferTextureId()
Definition: FrameBuffer.h:116
static constexpr int32_t CUBEMAPTEXTUREINDEX_NONE
Definition: FrameBuffer.h:30
static constexpr int32_t CUBEMAPTEXTUREINDEX_POSITIVE_X
Definition: FrameBuffer.h:32
static constexpr int32_t TEXTUREID_NONE
Definition: FrameBuffer.h:28
static void doPostProcessing(Engine *engine, FrameBuffer *target, FrameBuffer *source, const string &programId, const string &shaderId, FrameBuffer *temporary=nullptr, FrameBuffer *blendToSource=nullptr)
Do post processing into target frame buffer (which can be screen as well when passing nullptr)
static constexpr int32_t FRAMEBUFFER_DEPTHBUFFER
Definition: FrameBuffer.h:25
void dispose()
Disposes this frame buffer.
Definition: FrameBuffer.cpp:82
static constexpr int32_t CUBEMAPTEXTUREINDEX_NEGATIVE_Y
Definition: FrameBuffer.h:34
static constexpr int32_t CUBEMAPTEXTUREINDEX_POSITIVE_Y
Definition: FrameBuffer.h:33
static constexpr int32_t CUBEMAPTEXTUREINDEX_POSITIVE_Z
Definition: FrameBuffer.h:35
FrameBuffer(int32_t width, int32_t height, int32_t buffers, int32_t cubeMapTextureId=TEXTUREID_NONE, int32_t cubeMapTextureIndex=TEXTUREID_NONE)
Public constructor.
Definition: FrameBuffer.cpp:21
int32_t getDepthBufferTextureId()
Definition: FrameBuffer.h:101
int32_t getColorTextureId() override
Definition: FrameBuffer.h:195
void bindDepthBufferTexture(int contextIdx)
Bind depth texture.
Color texture interface.
Definition: ColorTexture.h:13
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6