LibCarna Version 3.4.0
Loading...
Searching...
No Matches
Framebuffer.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 - 2016 Leonid Kostrykin
3 *
4 * Chair of Medical Engineering (mediTEC)
5 * RWTH Aachen University
6 * Pauwelsstr. 20
7 * 52074 Aachen
8 * Germany
9 *
10 *
11 * Copyright (C) 2021 - 2025 Leonid Kostrykin
12 *
13 */
14
15#ifndef FRAMEBUFFER_H_6014714286
16#define FRAMEBUFFER_H_6014714286
17
23#include <LibCarna/LibCarna.hpp>
26#include <stack>
27#include <set>
28
29namespace LibCarna
30{
31
32namespace base
33{
34
35
36
37// ----------------------------------------------------------------------------------
38// Framebuffer
39// ----------------------------------------------------------------------------------
40
52class LIBCARNA Framebuffer
53{
54
56
57 math::Vector2ui size;
58
59public:
60
64 const static unsigned int MAXIMUM_ALLOWED_COLOR_COMPONENTS = 8;
65
71 Framebuffer( unsigned int width, unsigned int height, Texture< 2 >& renderTexture );
72
80
85
89 bool hasRenderTexture( unsigned int location ) const;
90
95 const Texture< 2 >& renderTexture( unsigned int location ) const;
96
100 const unsigned int id;
101
107 static void copyDepthAttachment( unsigned int srcId, unsigned int dstId, const Viewport& src, const Viewport& dst );
108
116 ( unsigned int srcId, unsigned int dstId
117 , const Viewport& src, const Viewport& dst
118 , unsigned int srcColorAttachment, unsigned int dstColorAttachment );
119
124 static unsigned int currentId();
125
129 void resize( const math::Vector2ui& size );
130
133 void resize( unsigned int width, unsigned int height );
134
138 inline unsigned int width() const
139 {
140 return size.x();
141 }
142
146 inline unsigned int height() const
147 {
148 return size.y();
149 }
150
151 // ------------------------------------------------------------------------------
152 // Framebuffer :: MinimalBinding
153 // ------------------------------------------------------------------------------
154
164 class LIBCARNA MinimalBinding
165 {
166
168
169 public:
170
174 explicit MinimalBinding( Framebuffer& fbo );
175
180
190 void setColorComponent( Texture< 2 >& renderTexture, unsigned int location = 0 );
191
197 void removeColorComponent( unsigned int location );
198
205 Color readPixel( unsigned int x, unsigned int y, unsigned int location = 0 ) const;
206
210 const Framebuffer& framebuffer() const;
211
219 virtual void refresh() const;
220
221 private:
222
226 void bindFBO() const;
227
228 protected:
229
234
235 }; // Framebuffer :: MinimalBinding
236
237 // ------------------------------------------------------------------------------
238 // Framebuffer :: Binding
239 // ------------------------------------------------------------------------------
240
247 class LIBCARNA Binding : public MinimalBinding
248 {
249
250 public:
251
258 explicit Binding( Framebuffer& );
259
260 protected:
261
264 virtual void refresh();
265
266 }; // Framebuffer :: Binding
267
268 // ------------------------------------------------------------------------------
269
270private:
271
272 Texture< 2 >* renderTextures[ MAXIMUM_ALLOWED_COLOR_COMPONENTS ];
273 const unsigned int depthBuffer;
274 std::set< unsigned int > boundColorBuffers;
275 class BindingStack;
276
277 static void copy
278 ( unsigned int srcId, unsigned int dstId
279 , const Viewport& src, const Viewport& dst
280 , unsigned int flags
281 , unsigned int srcColorAttachment, unsigned int dstColorAttachment );
282
283 static void copy
284 ( unsigned int srcId, unsigned int dstId
285 , unsigned int srcX0, unsigned int srcY0
286 , unsigned int dstX0, unsigned int dstY0
287 , unsigned int srcWidth, unsigned int srcHeight
288 , unsigned int dstWidth, unsigned int dstHeight
289 , unsigned int flags
290 , unsigned int srcColorAttachment, unsigned int dstColorAttachment );
291
292}; // Framebuffer
293
294
295
296// ----------------------------------------------------------------------------------
297// LIBCARNA_RENDER_TO_FRAMEBUFFER_EX
298// ----------------------------------------------------------------------------------
299
304#define LIBCARNA_RENDER_TO_FRAMEBUFFER_EX( fbo, binding, instructions ) \
305 { \
306 LibCarna::base::Framebuffer::Binding binding( fbo ); \
307 instructions; \
308 }
309
310
311
312// ----------------------------------------------------------------------------------
313// LIBCARNA_RENDER_TO_FRAMEBUFFER
314// ----------------------------------------------------------------------------------
315
318#define LIBCARNA_RENDER_TO_FRAMEBUFFER( fbo, instructions ) \
319 LIBCARNA_RENDER_TO_FRAMEBUFFER_EX( fbo, fboBinding##__COUNTER__, instructions )
320
321
322
323} // namespace LibCarna :: base
324
325} // namespace LibCarna
326
327#endif // FRAMEBUFFER_H_6014714286
Contains forward-declarations.
Represents an association.
Represents a color. Objects from this class are copyable and assignable.
Definition Color.hpp:45
Acts like MinimalBinding, but checks the bound framebuffer for validity and allows rendering.
Binding(Framebuffer &)
Binds fbo as the current framebuffer.
virtual void refresh()
Re-performs the binding.
Maintains the binding of a Framebuffer in a RAII-manner.
MinimalBinding(Framebuffer &fbo)
Binds fbo as the current framebuffer.
void removeColorComponent(unsigned int location)
Removes color component at location from bound framebuffer object.
virtual ~MinimalBinding()
Retracts this binding and restores the previous one.
const Framebuffer & framebuffer() const
References the bound framebuffer.
Framebuffer & fbo
References the bound framebuffer.
virtual void refresh() const
Re-performs this binding. This is useful if the currently bound framebuffer has been changed through ...
void setColorComponent(Texture< 2 > &renderTexture, unsigned int location=0)
Attaches renderTexture as the color component at location of the bound framebuffer object.
Color readPixel(unsigned int x, unsigned int y, unsigned int location=0) const
Reads the color of the pixel located at x and y within the color attachment at location.
Maintains a framebuffer object that supports up to 8 color components simultaneously.
unsigned int width() const
Returns the framebuffer's width.
const Texture< 2 > & renderTexture(unsigned int location) const
References the render texture at location.
~Framebuffer()
Deletes the maintained framebuffer object and its depth buffer.
static void copyDepthAttachment(unsigned int srcId, unsigned int dstId, const Viewport &src, const Viewport &dst)
Copies data from the depth attachment of the framebuffer identified by srcId to the depth attachment ...
static Texture< 2 > * createRenderTexture(bool floatingPoint=false)
Creates render texture.
void resize(unsigned int width, unsigned int height)
unsigned int height() const
Returns the framebuffer's height.
const unsigned int id
Identifies the maintained framebuffer object.
Framebuffer(unsigned int width, unsigned int height, Texture< 2 > &renderTexture)
Acquires framebuffer object with depth buffer and attaches renderTexture as the first color attachmen...
void resize(const math::Vector2ui &size)
Resizes depth buffer and color components to size.
bool hasRenderTexture(unsigned int location) const
Tells whether a color component exists at location.
static unsigned int currentId()
Tells the ID of the currently bound framebuffer. This is 0 for the main framebuffer.
static void copyColorAttachment(unsigned int srcId, unsigned int dstId, const Viewport &src, const Viewport &dst, unsigned int srcColorAttachment, unsigned int dstColorAttachment)
Copies data from the color attachment srcColorAttachment of the framebuffer identified by srcId to th...
Defines a rendering viewport. The viewport is a property of the current OpenGL context.
Definition Viewport.hpp:52
Defines LibCarna::base::math namespace and LIBCARNA_FOR_VECTOR3UI.
Eigen::Matrix< unsigned int, 2, 1 > Vector2ui
Defines vector.
Definition math.hpp:204
Defines LibCarna::base::noncopyable and NON_COPYABLE.
#define NON_COPYABLE
Marks the class that it is placed in as non-copyable.