Visualization Library 2.0.0-b3

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
FramebufferObject.cpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2011, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
36 #include <vlCore/Say.hpp>
37 #include <vlCore/Log.hpp>
38 
39 using namespace vl;
40 
41 namespace
42 {
43  class ScopedFBOBinding
44  {
45  GLint mPrevFBO;
46  public:
47  ScopedFBOBinding( FramebufferObject* fbo )
48  {
49  VL_CHECK( fbo );
50  VL_CHECK( fbo->handle() );
51  /*if ( !fbo->handle() )
52  fbo->create();*/
53 
54  // saves current FBO
55  mPrevFBO = 0;
56  glGetIntegerv( GL_FRAMEBUFFER_BINDING, &mPrevFBO ); VL_CHECK_OGL()
57 
58  // binds this FBO
59  VL_glBindFramebuffer( GL_FRAMEBUFFER, fbo->handle() ); VL_CHECK_OGL()
60  }
61 
62  ~ScopedFBOBinding()
63  {
64  // restore the FBO
65  VL_glBindFramebuffer( GL_FRAMEBUFFER, mPrevFBO ); VL_CHECK_OGL()
66  }
67  };
68 }
69 //-----------------------------------------------------------------------------
70 // FramebufferObject
71 //-----------------------------------------------------------------------------
73 {
74  VL_CHECK_OGL();
75  VL_CHECK(openglContext());
76  openglContext()->makeCurrent(); VL_CHECK_OGL();
77 
78  if ( !mHandle )
79  {
80  VL_glGenFramebuffers( 1, ( unsigned int* )&mHandle ); VL_CHECK_OGL();
81  }
82  VL_CHECK( mHandle )
83 }
84 //-----------------------------------------------------------------------------
86 {
87  VL_CHECK_OGL();
88  VL_CHECK(openglContext());
89  openglContext()->makeCurrent(); VL_CHECK_OGL();
90 
91  removeAllAttachments();
92  if ( handle() )
93  {
94  VL_glBindFramebuffer( GL_FRAMEBUFFER, 0 ); VL_CHECK_OGL();
95  VL_glDeleteFramebuffers( 1, &mHandle ); VL_CHECK_OGL();
96  mHandle = 0;
97  }
98  setWidth( 0 );
99  setHeight( 0 );
100 }
101 //-----------------------------------------------------------------------------
103 {
104  VL_CHECK_OGL();
105  VL_CHECK(openglContext());
106  openglContext()->makeCurrent(); VL_CHECK_OGL();
107 
108  if ( !Has_FBO )
109  {
110  Log::error( "FramebufferObject::bindFramebuffer(): framebuffer object not supported.\n" );
111  return;
112  }
113 
114  if ( width() <= 0 || height() <= 0 )
115  {
116  Log::error( Say( "FramebufferObject::bindFramebuffer() called with illegal dimensions: width = %n, height = %n\n" ) << width() << height() );
117  VL_TRAP()
118  }
119 
120  if ( mFBOAttachments.empty() )
121  {
122  Log::error( "FramebufferObject::bindFramebuffer() called with no attachment points!\n" );
123  VL_TRAP()
124  }
125 
126  if ( !handle() )
127  {
128  Log::error( "FramebufferObject::bindFramebuffer() called but handle() == NULL!\n" );
129  VL_TRAP()
130  }
131 
132  VL_glBindFramebuffer( target, handle() ); VL_CHECK_OGL()
133 
134 #if defined(VL_OPENGL)
135  // bind draw buffers
136  if (target == FBB_FRAMEBUFFER || target == FBB_DRAW_FRAMEBUFFER)
137  bindDrawBuffers();
138 
139  // bind read buffer
140  if (target == FBB_FRAMEBUFFER || target == FBB_READ_FRAMEBUFFER)
141  bindReadBuffer();
142 #endif
143 
144  #ifndef NDEBUG
145  GLenum status = VL_glCheckFramebufferStatus( GL_FRAMEBUFFER ); VL_CHECK_OGL()
146  if ( status != GL_FRAMEBUFFER_COMPLETE )
147  {
148  VL_glBindFramebuffer( GL_FRAMEBUFFER, 0 ); VL_CHECK_OGL()
149  }
150  printFramebufferError( status );
151  #endif
152 }
153 //-----------------------------------------------------------------------------
156 {
157  VL_CHECK_OGL();
158  VL_CHECK(openglContext());
159  openglContext()->makeCurrent(); VL_CHECK_OGL();
160 
161  if ( !Has_FBO )
162  {
163  Log::error( "FramebufferObject::checkFramebufferStatus(): framebuffer object not supported.\n" );
164  return 0;
165  }
166 
167  if ( width() <= 0 || height() <= 0 )
168  {
169  Log::error( Say( "FramebufferObject::checkFramebufferStatus() called with illegal dimensions: width = %n, height = %n\n" ) << width() << height() );
170  return 0;
171  }
172 
173  if ( mFBOAttachments.empty() )
174  {
175  Log::error( "FramebufferObject::checkFramebufferStatus() called with no attachment points!\n" );
176  return 0;
177  }
178 
179  if ( !handle() )
180  {
181  Log::error( "FramebufferObject::checkFramebufferStatus() called but handle() == NULL!\n" );
182  return 0;
183  }
184 
185  // binds the FBO for this function call
186  ScopedFBOBinding fbo_bind( this );
187 
188  // checks error
189  GLenum status = VL_glCheckFramebufferStatus( GL_FRAMEBUFFER ); VL_CHECK_OGL()
190 
191  // restore the FBO
192  if ( globalSettings()->verbosityLevel() >= vl::VEL_VERBOSITY_NORMAL )
193  printFramebufferError( status );
194 
195  VL_CHECK( status == GL_FRAMEBUFFER_COMPLETE )
196 
197  return status;
198 }
199 //-----------------------------------------------------------------------------
200 void FramebufferObject::printFramebufferError( GLenum status ) const
201 {
202  switch( status )
203  {
204  case GL_FRAMEBUFFER_COMPLETE:
205  break;
206  case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
207  Log::bug( "FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT\n" ); VL_TRAP()
208  break;
209  case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
210  Log::bug( "FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT\n" ); VL_TRAP()
211  break;
212  case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
213  Log::bug( "FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT\n" ); VL_TRAP()
214  break;
215  case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
216  Log::bug( "FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT\n" ); VL_TRAP()
217  break;
218  case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
219  Log::bug( "FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER\n" ); VL_TRAP()
220  break;
221  case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
222  Log::bug( "FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER\n" ); VL_TRAP()
223  break;
224  case GL_FRAMEBUFFER_UNSUPPORTED:
225  Log::bug( "FramebufferObject::activate(): GL_FRAMEBUFFER_UNSUPPORTED\n" ); VL_TRAP()
226  break;
227  case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_ARB:
228  Log::bug( "FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_ARB\n" ); VL_TRAP()
229  break;
230  case GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB:
231  Log::bug( "FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB\n" ); VL_TRAP()
232  break;
233  case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
234  Log::bug( "FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE\n" ); VL_TRAP()
235  break;
236  }
237 }
238 //-----------------------------------------------------------------------------
240 {
241  VL_CHECK( attach_point >= AP_COLOR_ATTACHMENT0 && attach_point <= AP_COLOR_ATTACHMENT15 );
242  VL_CHECK( Has_FBO )
243  if( !Has_FBO )
244  return;
245  removeAttachment( attach_point );
246  mFBOAttachments[attach_point] = attachment;
247  attachment->mFramebufferObjects.insert( this );
248  attachment->bindAttachment( this, attach_point );
249 }
250 //-----------------------------------------------------------------------------
252 {
253  VL_CHECK( attach_point >= AP_COLOR_ATTACHMENT0 && attach_point <= AP_COLOR_ATTACHMENT15 );
254  VL_CHECK( Has_FBO )
255  if( !Has_FBO )
256  return;
257  removeAttachment( attach_point );
258  mFBOAttachments[attach_point] = attachment;
259  attachment->mFramebufferObjects.insert( this );
260  attachment->bindAttachment( this, attach_point );
261 }
262 //-----------------------------------------------------------------------------
264 {
265  VL_CHECK( Has_FBO )
266  if( !Has_FBO )
267  return;
268  removeAttachment( AP_DEPTH_ATTACHMENT );
269  mFBOAttachments[AP_DEPTH_ATTACHMENT] = attachment;
270  attachment->mFramebufferObjects.insert( this );
271  attachment->bindAttachment( this, AP_DEPTH_ATTACHMENT );
272 }
273 //-----------------------------------------------------------------------------
275 {
276  VL_CHECK( Has_FBO )
277  if( !Has_FBO )
278  return;
279  removeAttachment( AP_STENCIL_ATTACHMENT );
280  mFBOAttachments[AP_STENCIL_ATTACHMENT] = attachment;
281  attachment->mFramebufferObjects.insert( this );
282  attachment->bindAttachment( this, AP_STENCIL_ATTACHMENT );
283 }
284 //-----------------------------------------------------------------------------
286 {
287  VL_CHECK( Has_FBO )
288  if( !Has_FBO )
289  return;
290  removeAttachment( AP_DEPTH_STENCIL_ATTACHMENT );
291  mFBOAttachments[AP_DEPTH_STENCIL_ATTACHMENT] = attachment;
292  attachment->mFramebufferObjects.insert( this );
293  attachment->bindAttachment( this, AP_DEPTH_STENCIL_ATTACHMENT );
294 }
295 //-----------------------------------------------------------------------------
297 {
298  VL_CHECK( Has_FBO )
299  if( !Has_FBO )
300  return;
301  // collect for all the attachment points
302  std::vector<EAttachmentPoint> attachment_points;
303  std::map< EAttachmentPoint, ref<FBOAbstractAttachment> >::iterator it = mFBOAttachments.begin();
304  for( ; it != mFBOAttachments.end(); ++it )
305  if ( it->second == attachment )
306  attachment_points.push_back( it->first );
307 
308  // remove it from all the attachment points
309  for( unsigned i=0; i<attachment_points.size(); ++i )
310  removeAttachment( attachment_points[i] );
311 }
312 //-----------------------------------------------------------------------------
314 {
316 
317  VL_CHECK_OGL();
318  VL_CHECK(openglContext());
319  openglContext()->makeCurrent(); VL_CHECK_OGL();
320 
321  VL_CHECK( Has_FBO )
322  if( !Has_FBO )
323  return;
324  if ( handle() )
325  {
326  // save current fbo
327  int fbo = -1;
328  glGetIntegerv( GL_FRAMEBUFFER_BINDING, &fbo ); VL_CHECK_OGL()
329  // bind this fbo
330  VL_glBindFramebuffer( GL_FRAMEBUFFER, handle() ); VL_CHECK_OGL()
331  // detach should work for any kind of buffer and texture
332  VL_glFramebufferRenderbuffer( GL_FRAMEBUFFER, attach_point, GL_RENDERBUFFER, 0 ); VL_CHECK_OGL()
333  // restore fbo
334  VL_glBindFramebuffer( GL_FRAMEBUFFER, fbo ); VL_CHECK_OGL()
335  }
336  // remove FramebufferObject from FBOAbstractAttachment
337  FBOAbstractAttachment* fbo_attachment = /* mFBOAttachments.find( attachment ) != mFBOAttachments.end() ? */ mFBOAttachments[attach_point].get() /* : NULL */;
338  if ( fbo_attachment )
339  fbo_attachment->mFramebufferObjects.erase( this );
340  mFBOAttachments.erase( attach_point );
341 }
342 //-----------------------------------------------------------------------------
344 {
345  VL_CHECK( Has_FBO )
346  if( !Has_FBO )
347  return;
348  // look for all the attachment points
349  std::vector<EAttachmentPoint> attachment_points;
350  std::map< EAttachmentPoint, ref<FBOAbstractAttachment> >::iterator it = mFBOAttachments.begin();
351  for( ; it != mFBOAttachments.end(); ++it )
352  attachment_points.push_back( it->first );
353 
354  // remove attachment points
355  for( unsigned i=0; i<attachment_points.size(); ++i )
356  removeAttachment( attachment_points[i] );
357 }
358 //-----------------------------------------------------------------------------
360 {
361  VL_CHECK_OGL()
362  VL_CHECK( Has_FBO )
363  if( !Has_FBO )
364  return;
365  VL_CHECK( texture() )
366  VL_CHECK( texture()->handle() )
367  VL_CHECK( texture()->dimension() == GL_TEXTURE_1D )
368  VL_CHECK( fbo->width() == texture()->width() );
369 
370  // binds the FBO for this function call
371  ScopedFBOBinding fbo_bind( fbo );
372 
373  VL_glFramebufferTexture1D( GL_FRAMEBUFFER, attach_point, GL_TEXTURE_1D, texture()->handle(), mipmapLevel() ); VL_CHECK_OGL()
374 
375  // needed to make non-mipmapped textures work with FBO, see framebuffer_object.txt line 442
376  glBindTexture( texture()->dimension(), texture()->handle() ); VL_CHECK_OGL()
377  glTexParameteri( texture()->dimension(), GL_TEXTURE_MIN_FILTER, GL_LINEAR ); VL_CHECK_OGL()
378  glBindTexture( texture()->dimension(), 0 ); VL_CHECK_OGL()
379 }
380 //-----------------------------------------------------------------------------
382 {
383  VL_CHECK_OGL()
384  VL_CHECK( Has_FBO )
385  if( !Has_FBO )
386  return;
387  VL_CHECK( texture() )
388  VL_CHECK( texture()->handle() )
389  // VL_CHECK( texture()->dimension() == GL_TEXTURE_2D )
390  VL_CHECK( fbo->width() <= texture()->width() );
391  VL_CHECK( fbo->height() <= texture()->height() );
392 
393  // binds the FBO for this function call
394  ScopedFBOBinding fbo_bind( fbo );
395 
396  int target = texture()->dimension() == TD_TEXTURE_CUBE_MAP ? ( int )textureTarget() : texture()->dimension();
397  #ifndef NDEBUG
398  if( !( texture()->dimension() == TD_TEXTURE_CUBE_MAP || ( int )textureTarget() == ( int )texture()->dimension() ) )
399  {
400  Log::bug( "FBOTexture2DAttachment::init(): textureTarget() doens't match texture()->dimension().\n" );
401  }
402  #endif
403 
404  VL_glFramebufferTexture2D( GL_FRAMEBUFFER, attach_point, target, texture()->handle(), mipmapLevel() ); VL_CHECK_OGL()
405 
406  // needed to make non-mipmapped textures work with FBO, see framebuffer_object.txt line 442
407  if ( texture()->dimension() != TD_TEXTURE_2D_MULTISAMPLE )
408  {
409  glBindTexture( texture()->dimension(), texture()->handle() ); VL_CHECK_OGL()
410  glTexParameteri( texture()->dimension(), GL_TEXTURE_MIN_FILTER, GL_LINEAR ); VL_CHECK_OGL()
411  glBindTexture( texture()->dimension(), 0 ); VL_CHECK_OGL()
412  }
413 }
414 //-----------------------------------------------------------------------------
416 {
417  VL_CHECK_OGL()
418  VL_CHECK( Has_GL_NV_geometry_shader4||Has_GL_EXT_geometry_shader4||Has_GL_ARB_geometry_shader4||Has_GL_Version_3_2||Has_GL_Version_4_0 )
419  VL_CHECK( texture() )
420  VL_CHECK( texture()->handle() )
421 
422  // binds the FBO for this function call
423  ScopedFBOBinding fbo_bind( fbo );
424 
425  VL_glFramebufferTexture( GL_FRAMEBUFFER, attach_point, texture()->handle(), mipmapLevel() ); VL_CHECK_OGL()
426 
427  // needed to make non-mipmapped textures work with FBO, see framebuffer_object.txt line 442
428  if ( texture()->dimension() != TD_TEXTURE_2D_MULTISAMPLE )
429  {
430  glBindTexture( texture()->dimension(), texture()->handle() ); VL_CHECK_OGL()
431  glTexParameteri( texture()->dimension(), GL_TEXTURE_MIN_FILTER, GL_LINEAR ); VL_CHECK_OGL()
432  glBindTexture( texture()->dimension(), 0 ); VL_CHECK_OGL()
433  }
434 }
435 //-----------------------------------------------------------------------------
437 {
438  VL_CHECK_OGL()
439  VL_CHECK( Has_FBO )
440  if( !Has_FBO )
441  return;
442  VL_CHECK( texture() )
443  VL_CHECK( texture()->handle() )
444  VL_CHECK( fbo->width() <= texture()->width() );
445  VL_CHECK( fbo->height() <= texture()->height() );
446  VL_CHECK( layer() <= texture()->depth() );
447  VL_CHECK( texture()->dimension() == GL_TEXTURE_3D )
448 
449  // binds the FBO for this function call
450  ScopedFBOBinding fbo_bind( fbo );
451 
452  VL_glFramebufferTexture3D( GL_FRAMEBUFFER, attach_point, texture()->dimension(), texture()->handle(), mipmapLevel(), layer() ); VL_CHECK_OGL()
453 
454  // needed to make non-mipmapped textures work with FBO, see framebuffer_object.txt line 442
455  if ( texture()->dimension() != TD_TEXTURE_2D_MULTISAMPLE_ARRAY )
456  {
457  glBindTexture( texture()->dimension(), texture()->handle() ); VL_CHECK_OGL()
458  glTexParameteri( texture()->dimension(), GL_TEXTURE_MIN_FILTER, GL_LINEAR ); VL_CHECK_OGL()
459  glBindTexture( texture()->dimension(), 0 ); VL_CHECK_OGL()
460  }
461 }
462 //-----------------------------------------------------------------------------
464 {
465  VL_CHECK_OGL()
466  VL_CHECK( Has_FBO )
467  VL_CHECK( Has_GL_EXT_texture_array||Has_GL_NV_geometry_shader4||Has_GL_ARB_geometry_shader4||Has_GL_EXT_geometry_shader4||Has_GL_Version_3_2||Has_GL_Version_4_0 )
468  if( !Has_FBO )
469  return;
470  if( !( Has_GL_EXT_texture_array||Has_GL_NV_geometry_shader4||Has_GL_ARB_geometry_shader4||Has_GL_EXT_geometry_shader4||Has_GL_Version_3_2||Has_GL_Version_4_0 ) )
471  return;
472  VL_CHECK( texture() )
473  VL_CHECK( texture()->handle() )
474  VL_CHECK( texture()->dimension() == GL_TEXTURE_2D_ARRAY || texture()->dimension() == GL_TEXTURE_1D_ARRAY )
475  VL_CHECK( fbo->width() <= texture()->width() );
476  VL_CHECK( fbo->height() <= texture()->height() );
477  // VL_CHECK( layer() <= texture()->depth() );
478 
479  // binds the FBO for this function call
480  ScopedFBOBinding fbo_bind( fbo );
481 
482  VL_glFramebufferTextureLayer( GL_FRAMEBUFFER, attach_point, texture()->handle(), mipmapLevel(), layer() ); VL_CHECK_OGL()
483 
484  // needed to make non-mipmapped textures work with FBO, see framebuffer_object.txt line 442
485  if ( texture()->dimension() != TD_TEXTURE_2D_MULTISAMPLE_ARRAY )
486  {
487  glBindTexture( texture()->dimension(), texture()->handle() ); VL_CHECK_OGL()
488  glTexParameteri( texture()->dimension(), GL_TEXTURE_MIN_FILTER, GL_LINEAR ); VL_CHECK_OGL()
489  glBindTexture( texture()->dimension(), 0 ); VL_CHECK_OGL()
490  }
491 }
492 //-----------------------------------------------------------------------------
494 {
495  std::set< ref<FramebufferObject> > fbos = fboFramebuffers();
496  for( std::set< ref<FramebufferObject> >::iterator it = fbos.begin(); it != fbos.end(); ++it )
497  it->get_writable()->removeAttachment( this );
498 }
499 //-----------------------------------------------------------------------------
501 {
502  VL_CHECK_OGL()
503  VL_CHECK( Has_FBO )
504  if( !Has_FBO )
505  return;
506  if ( !mHandle )
507  {
508  VL_glGenRenderbuffers( 1, &mHandle ); VL_CHECK_OGL()
509  mReallocateRenderbuffer = true;
510  }
511  VL_CHECK( mHandle )
512 }
513 //-----------------------------------------------------------------------------
515 {
516  VL_CHECK_OGL()
517  VL_CHECK( Has_FBO )
518  if( !Has_FBO )
519  return;
520 
521  unbindFromAllFBO();
522 
523  mWidth = 0;
524  mHeight = 0;
525  if ( mHandle )
526  {
527  VL_glDeleteRenderbuffers( 1, &mHandle ); VL_CHECK_OGL()
528  mHandle = 0;
529  mReallocateRenderbuffer = true;
530  }
531 }
532 //-----------------------------------------------------------------------------
533 void FBORenderbufferAttachment::initStorage( int w, int h, int samp )
534 {
535  VL_CHECK_OGL()
536  VL_CHECK( handle() );
537  VL_CHECK( w>0 && h>0 );
538  VL_CHECK( Has_FBO )
539  if( !Has_FBO )
540  return;
541 
542  if ( w != width() || h != height() || samp != samples() || mReallocateRenderbuffer )
543  {
544  mWidth = w;
545  mHeight = h;
546  mSamples = samp;
547  VL_glBindRenderbuffer( GL_RENDERBUFFER, handle() ); VL_CHECK_OGL()
548  if ( Has_FBO_Multisample )
549  {
550  VL_glRenderbufferStorageMultisample( GL_RENDERBUFFER, samples(), internalType(), width(), height() ); VL_CHECK_OGL()
551  }
552  else
553  {
554  VL_CHECK(samples() == 0)
555  if (samples())
556  Log::error("FBORenderbufferAttachment::initStorage() requesting multisampling storage but current OpenGL implementation does not support it!\n");
557  VL_glRenderbufferStorage( GL_RENDERBUFFER, internalType(), width(), height() ); VL_CHECK_OGL()
558  }
559  VL_glBindRenderbuffer( GL_RENDERBUFFER, 0 ); VL_CHECK_OGL()
560  mReallocateRenderbuffer = false;
561  }
562 }
563 //-----------------------------------------------------------------------------
565 {
566  VL_CHECK_OGL()
567  VL_CHECK( Has_FBO )
568  if( !Has_FBO )
569  return;
570 
571  if (!handle())
572  createRenderBuffer();
573 
574  // binds the FBO for this function call
575  ScopedFBOBinding fbo_bind( fbo );
576 
577  // choose the maximum dimension
578  int actual_w = width() == 0 ? fbo->width() : width();
579  int actual_h = height() == 0 ? fbo->height() : height();
580  VL_CHECK( actual_w >= fbo->width() );
581  VL_CHECK( actual_h >= fbo->height() );
582  initStorage( actual_w, actual_h, samples() );
583 
584  // attach the renderbuffer to the framebuffer's attachment point
585  VL_glFramebufferRenderbuffer( GL_FRAMEBUFFER, attach_point, GL_RENDERBUFFER, handle() ); VL_CHECK_OGL()
586 }
587 //-----------------------------------------------------------------------------
virtual void bindAttachment(FramebufferObject *fbo, EAttachmentPoint attach_point)
EAttachmentPoint
virtual void bindAttachment(FramebufferObject *fbo, EAttachmentPoint attach_point)=0
A simple String formatting class.
Definition: Say.hpp:124
Abstract class that represents a framebuffer object attachment to be used with FramebufferObject.
virtual void bindAttachment(FramebufferObject *fbo, EAttachmentPoint attach_point)
Base class for all the framebuffer texture attachments (see also FramebufferObject).
int width() const
The width of a render target.
Definition: Framebuffer.hpp:72
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
Definition: Log.cpp:164
virtual void bindAttachment(FramebufferObject *fbo, EAttachmentPoint attach_point)
bool Has_GL_Version_4_0
Definition: OpenGL.cpp:60
virtual void bindAttachment(FramebufferObject *fbo, EAttachmentPoint attach_point)
void createRenderBuffer()
Creates a renderbuffer object calling glGenRenderbuffers().
< Outputs normal information messages, plus all error messages.
void deleteRenderBuffer()
Deletes the renderbuffer object created with the createRenderBuffer() method.
virtual void unbindFromAllFBO()
Removes the FBO attachment from all bound FBO render targets.
void addDepthAttachment(FBOAbstractAttachment *attachment)
Binds a depth attachment to a framebuffer object.
Visualization Library main namespace.
void addDepthStencilAttachment(FBOAbstractAttachment *attachment)
Binds a depth-stencil attachment to a framebuffer object.
void addTextureAttachment(EAttachmentPoint attach_point, FBOAbstractTextureAttachment *attachment)
Binds a texture attachment to a framebuffer object.
static void bug(const String &message)
Use this function to provide information about programming errors: wrong parameter initialization...
Definition: Log.cpp:174
#define VL_TRAP()
Definition: checks.hpp:70
static VLGRAPHICS_EXPORT bool isGraphicsInitialized()
Returns true if VLGraphics library is initialized and shutdown has not been called.
void removeAttachment(FBOAbstractAttachment *attachment)
Unbinds the given attachments from a framebuffer object.
void removeAllAttachments()
Unbinds all attachments bound to a framebuffer object.
int height() const
The height of a render target.
Definition: Framebuffer.hpp:75
void addColorAttachment(EAttachmentPoint attach_point, FBOColorBufferAttachment *attachment)
Binds a color attachment to a framebuffer object.
void bindAttachment(FramebufferObject *fbo, EAttachmentPoint attach_point)
bool Has_GL_Version_3_2
Definition: OpenGL.cpp:58
A color renderbuffer to be attached to a FramebufferObject.
void createFBO()
Creates a framebuffer object by calling glGenFramebuffers().
void deleteFBO()
Deletes a framebuffer object by calling glDeleteFramebuffers().
void initStorage()
The same as calling initStorage( width(), height() )
void addStencilAttachment(FBOAbstractAttachment *attachment)
Binds a stencil attachment to a framebuffer object.
void printFramebufferError(GLenum status) const
Prints a human readable description of the error code as returned by glCheckFramebufferStatus() ...
EFramebufferBind
#define VL_CHECK_OGL()
Definition: OpenGL.hpp:156
virtual void bindFramebuffer(EFramebufferBind target=FBB_FRAMEBUFFER)
Makes the framebuffer the current rendering target calling glBindFramebuffer( GL_FRAMEBUFFER, FramebufferObject::handle() ) and initializes all the previously defined attachment points.
Implements a framebuffer object to be used as a rendering target as specified by the ARB_framebuffer_...
GLenum checkFramebufferStatus()
Checks the framebuffer status and returns the value of glCheckFramebufferStatus() ...
virtual void bindAttachment(FramebufferObject *fbo, EAttachmentPoint attach_point)
std::set< ref< FramebufferObject > > mFramebufferObjects
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
bool Has_FBO
Definition: OpenGL.cpp:83
#define VL_CHECK(expr)
Definition: checks.hpp:73
bool Has_FBO_Multisample
Definition: OpenGL.cpp:85
virtual GLuint handle() const
The handle of the framebuffer object as returned by glGenFramebuffers.
VLCORE_EXPORT GlobalSettings * globalSettings()
Returns VisulizationLibrary&#39;s global settings.
Definition: init_core.cpp:112