Carna Version 3.3.3
Loading...
Searching...
No Matches
Framebuffer.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 - 2015 Leonid Kostrykin
3 *
4 * Chair of Medical Engineering (mediTEC)
5 * RWTH Aachen University
6 * Pauwelsstr. 20
7 * 52074 Aachen
8 * Germany
9 *
10 */
11
12#ifndef FRAMEBUFFER_H_6014714286
13#define FRAMEBUFFER_H_6014714286
14
19#include <Carna/Carna.h>
21#include <Carna/base/math.h>
22#include <stack>
23#include <set>
24
25namespace Carna
26{
27
28namespace base
29{
30
31
32
33// ----------------------------------------------------------------------------------
34// Framebuffer
35// ----------------------------------------------------------------------------------
36
49class CARNA_LIB Framebuffer
50{
51
53
54 math::Vector2ui size;
55
56public:
57
61 const static unsigned int MAXIMUM_ALLOWED_COLOR_COMPONENTS = 8;
62
68 Framebuffer( unsigned int width, unsigned int height, Texture< 2 >& renderTexture );
69
77
82
86 bool hasRenderTexture( unsigned int location ) const;
87
92 const Texture< 2 >& renderTexture( unsigned int location ) const;
93
97 const unsigned int id;
98
104 static void copyDepthAttachment( unsigned int srcId, unsigned int dstId, const Viewport& src, const Viewport& dst );
105
113 ( unsigned int srcId, unsigned int dstId
114 , const Viewport& src, const Viewport& dst
115 , unsigned int srcColorAttachment, unsigned int dstColorAttachment );
116
121 static unsigned int currentId();
122
126 void resize( const math::Vector2ui& size );
127
130 void resize( unsigned int width, unsigned int height );
131
135 inline unsigned int width() const
136 {
137 return size.x();
138 }
139
143 inline unsigned int height() const
144 {
145 return size.y();
146 }
147
148 // ------------------------------------------------------------------------------
149 // Framebuffer :: MinimalBinding
150 // ------------------------------------------------------------------------------
151
162 class CARNA_LIB MinimalBinding
163 {
164
166
167 public:
168
172 explicit MinimalBinding( Framebuffer& fbo );
173
178
188 void setColorComponent( Texture< 2 >& renderTexture, unsigned int location = 0 );
189
195 void removeColorComponent( unsigned int location );
196
203 Color readPixel( unsigned int x, unsigned int y, unsigned int location = 0 ) const;
204
208 const Framebuffer& framebuffer() const;
209
217 virtual void refresh() const;
218
219 private:
220
224 void bindFBO() const;
225
226 protected:
227
232
233 }; // Framebuffer :: MinimalBinding
234
235 // ------------------------------------------------------------------------------
236 // Framebuffer :: Binding
237 // ------------------------------------------------------------------------------
238
246 class CARNA_LIB Binding : public MinimalBinding
247 {
248
249 public:
250
257 explicit Binding( Framebuffer& );
258
259 protected:
260
263 virtual void refresh();
264
265 }; // Framebuffer :: Binding
266
267 // ------------------------------------------------------------------------------
268
269private:
270
271 Texture< 2 >* renderTextures[ MAXIMUM_ALLOWED_COLOR_COMPONENTS ];
272 const unsigned int depthBuffer;
273 std::set< unsigned int > boundColorBuffers;
274 class BindingStack;
275
276 static void copy
277 ( unsigned int srcId, unsigned int dstId
278 , const Viewport& src, const Viewport& dst
279 , unsigned int flags
280 , unsigned int srcColorAttachment, unsigned int dstColorAttachment );
281
282 static void copy
283 ( unsigned int srcId, unsigned int dstId
284 , unsigned int srcX0, unsigned int srcY0
285 , unsigned int dstX0, unsigned int dstY0
286 , unsigned int srcWidth, unsigned int srcHeight
287 , unsigned int dstWidth, unsigned int dstHeight
288 , unsigned int flags
289 , unsigned int srcColorAttachment, unsigned int dstColorAttachment );
290
291}; // Framebuffer
292
293
294
295// ----------------------------------------------------------------------------------
296// CARNA_RENDER_TO_FRAMEBUFFER_EX
297// ----------------------------------------------------------------------------------
298
303#define CARNA_RENDER_TO_FRAMEBUFFER_EX( fbo, binding, instructions ) \
304 { \
305 Carna::base::Framebuffer::Binding binding( fbo ); \
306 instructions; \
307 }
308
309
310
311// ----------------------------------------------------------------------------------
312// CARNA_RENDER_TO_FRAMEBUFFER
313// ----------------------------------------------------------------------------------
314
317#define CARNA_RENDER_TO_FRAMEBUFFER( fbo, instructions ) \
318 CARNA_RENDER_TO_FRAMEBUFFER_EX( fbo, fboBinding##__COUNTER__, instructions )
319
320
321
322} // namespace Carna :: base
323
324} // namespace Carna
325
326#endif // FRAMEBUFFER_H_6014714286
Represents an association.
Definition Association.h:45
Represents a color. Objects from this class are copyable and assignable.
Definition Color.h:42
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.
virtual void refresh() const
Re-performs this binding. This is useful if the currently bound framebuffer has been changed through ...
virtual ~MinimalBinding()
Retracts this binding and restores the previous one.
const Framebuffer & framebuffer() const
References the bound framebuffer.
void removeColorComponent(unsigned int location)
Removes color component at location from bound framebuffer object.
MinimalBinding(Framebuffer &fbo)
Binds fbo as the current framebuffer.
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.
Framebuffer & fbo
References the bound framebuffer.
Maintains a framebuffer object that supports up to 8 color components simultaneously.
Definition Framebuffer.h:50
unsigned int width() const
Returns the framebuffer's width.
void resize(const math::Vector2ui &size)
Resizes depth buffer and color components to size.
void resize(unsigned int width, unsigned int height)
const unsigned int id
Identifies the maintained framebuffer object.
Definition Framebuffer.h:97
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...
bool hasRenderTexture(unsigned int location) const
Tells whether a color component exists at location.
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 ...
const Texture< 2 > & renderTexture(unsigned int location) const
References the render texture at location.
Framebuffer(unsigned int width, unsigned int height, Texture< 2 > &renderTexture)
Acquires framebuffer object with depth buffer and attaches renderTexture as the first color attachmen...
static Texture< 2 > * createRenderTexture(bool floatingPoint=false)
Creates render texture.
unsigned int height() const
Returns the framebuffer's height.
static unsigned int currentId()
Tells the ID of the currently bound framebuffer. This is 0 for the main framebuffer.
~Framebuffer()
Deletes the maintained framebuffer object and its depth buffer.
Defines a rendering viewport. The viewport is a property of the current OpenGL context.
Definition Viewport.h:49
Defines Carna::base::math namespace and CARNA_FOR_VECTOR3UI.
Eigen::Matrix< unsigned int, 2, 1 > Vector2ui
Defines vector.
Definition math.h:200
#define NON_COPYABLE
Features class it is placed in as non-copyable.