42 class ScopedFBOBinding
55 glGetIntegerv( GL_FRAMEBUFFER_BINDING, &mPrevFBO );
VL_CHECK_OGL()
58 VL_glBindFramebuffer( GL_FRAMEBUFFER, fbo->handle() );
VL_CHECK_OGL()
64 VL_glBindFramebuffer( GL_FRAMEBUFFER, mPrevFBO );
VL_CHECK_OGL()
73 std::map<int, const char*> fbo_attachments;
75 fbo_attachments[GL_NONE] =
"GL_NONE";
76 fbo_attachments[GL_BACK_LEFT] =
"GL_BACK_LEFT";
77 fbo_attachments[GL_BACK_RIGHT] =
"GL_BACK_RIGHT";
78 fbo_attachments[GL_FRONT_LEFT] =
"GL_FRONT_LEFT";
79 fbo_attachments[GL_FRONT_RIGHT] =
"GL_FRONT_RIGHT";
80 fbo_attachments[GL_AUX0] =
"GL_AUX0";
81 fbo_attachments[GL_AUX1] =
"GL_AUX1";
82 fbo_attachments[GL_AUX2] =
"GL_AUX2";
83 fbo_attachments[GL_AUX3] =
"GL_AUX3";
84 fbo_attachments[GL_COLOR_ATTACHMENT0] =
"GL_COLOR_ATTACHMENT0";
85 fbo_attachments[GL_COLOR_ATTACHMENT1] =
"GL_COLOR_ATTACHMENT1";
86 fbo_attachments[GL_COLOR_ATTACHMENT2] =
"GL_COLOR_ATTACHMENT2";
87 fbo_attachments[GL_COLOR_ATTACHMENT3] =
"GL_COLOR_ATTACHMENT3";
88 fbo_attachments[GL_COLOR_ATTACHMENT4] =
"GL_COLOR_ATTACHMENT4";
89 fbo_attachments[GL_COLOR_ATTACHMENT5] =
"GL_COLOR_ATTACHMENT5";
90 fbo_attachments[GL_COLOR_ATTACHMENT6] =
"GL_COLOR_ATTACHMENT6";
91 fbo_attachments[GL_COLOR_ATTACHMENT7] =
"GL_COLOR_ATTACHMENT7";
92 fbo_attachments[GL_COLOR_ATTACHMENT8] =
"GL_COLOR_ATTACHMENT8";
93 fbo_attachments[GL_COLOR_ATTACHMENT9] =
"GL_COLOR_ATTACHMENT9";
94 fbo_attachments[GL_COLOR_ATTACHMENT10] =
"GL_COLOR_ATTACHMENT10";
95 fbo_attachments[GL_COLOR_ATTACHMENT11] =
"GL_COLOR_ATTACHMENT11";
96 fbo_attachments[GL_COLOR_ATTACHMENT12] =
"GL_COLOR_ATTACHMENT12";
97 fbo_attachments[GL_COLOR_ATTACHMENT13] =
"GL_COLOR_ATTACHMENT13";
98 fbo_attachments[GL_COLOR_ATTACHMENT14] =
"GL_COLOR_ATTACHMENT14";
99 fbo_attachments[GL_COLOR_ATTACHMENT15] =
"GL_COLOR_ATTACHMENT15";
102 if (Has_GL_EXT_framebuffer_object||Has_GL_ARB_framebuffer_object)
103 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbo);
107 std::set<GLenum> legal;
108 legal.insert(GL_NONE);
109 legal.insert(GL_COLOR_ATTACHMENT0);
110 legal.insert(GL_COLOR_ATTACHMENT1);
111 legal.insert(GL_COLOR_ATTACHMENT2);
112 legal.insert(GL_COLOR_ATTACHMENT3);
113 legal.insert(GL_COLOR_ATTACHMENT4);
114 legal.insert(GL_COLOR_ATTACHMENT5);
115 legal.insert(GL_COLOR_ATTACHMENT6);
116 legal.insert(GL_COLOR_ATTACHMENT7);
117 legal.insert(GL_COLOR_ATTACHMENT8);
118 legal.insert(GL_COLOR_ATTACHMENT9);
119 legal.insert(GL_COLOR_ATTACHMENT10);
120 legal.insert(GL_COLOR_ATTACHMENT11);
121 legal.insert(GL_COLOR_ATTACHMENT12);
122 legal.insert(GL_COLOR_ATTACHMENT13);
123 legal.insert(GL_COLOR_ATTACHMENT14);
124 legal.insert(GL_COLOR_ATTACHMENT15);
125 for(
unsigned i=0; i<mDrawBuffers.size(); ++i)
127 if(legal.find(mDrawBuffers[i]) == legal.end())
129 Log::error(
Say(
"FBO bound but FramebufferObject::setDrawBuffers() called with non FBO compatible draw buffer '%s'.\n") << fbo_attachments[mDrawBuffers[i]]);
136 std::set<GLenum> legal;
137 legal.insert(GL_NONE);
138 legal.insert(GL_BACK_LEFT);
139 legal.insert(GL_BACK_RIGHT);
140 legal.insert(GL_FRONT_LEFT);
141 legal.insert(GL_FRONT_RIGHT);
142 legal.insert(GL_AUX0);
143 legal.insert(GL_AUX1);
144 legal.insert(GL_AUX2);
145 legal.insert(GL_AUX3);
146 for(
unsigned i=0; i<mDrawBuffers.size(); ++i)
148 if(legal.find(mDrawBuffers[i]) == legal.end())
150 Log::error(
Say(
"FBO not bound or not supported but FramebufferObject::setDrawBuffers() called with FBO specific draw buffer '%s'.\n") << fbo_attachments[mDrawBuffers[i]]);
170 glDrawBuffers( (GLsizei)mDrawBuffers.size(), (
const GLenum*)&mDrawBuffers[0] );
176 glDrawBuffer( mDrawBuffers[0] );
179 if ( mDrawBuffers.size() > 1 )
181 Log::error(
"FramebufferObject::bindDrawBuffers() error:\nglDrawBuffers() not supported by the current OpenGL driver. GL_ARB_draw_buffers or OpenGL 2.0 required.\n" );
190 glReadBuffer( readBuffer() );
203 VL_glGenFramebuffers( 1, (
unsigned int* )&mHandle );
VL_CHECK_OGL();
214 removeAllAttachments();
217 VL_glBindFramebuffer( GL_FRAMEBUFFER, 0 );
VL_CHECK_OGL();
231 if ( externallyManaged() ) {
237 Log::error(
"FramebufferObject::bindFramebuffer(): framebuffer object not supported.\n" );
241 if ( width() <= 0 || height() <= 0 )
243 Log::error(
Say(
"FramebufferObject::bindFramebuffer() called with illegal dimensions: width = %n, height = %n\n" ) << width() << height() );
248 if ( handle() != 0 && mFBOAttachments.empty() )
250 Log::error(
"FramebufferObject::bindFramebuffer() called with no attachment points!\n" );
262 VL_glBindFramebuffer( target, handle() );
VL_CHECK_OGL()
264 #if defined(VL_OPENGL) 281 GLenum status = VL_glCheckFramebufferStatus( GL_FRAMEBUFFER );
VL_CHECK_OGL()
282 if ( status != GL_FRAMEBUFFER_COMPLETE )
284 printFramebufferError( status );
285 VL_glBindFramebuffer( GL_FRAMEBUFFER, 0 );
VL_CHECK_OGL()
300 Log::error(
"FramebufferObject::checkFramebufferStatus(): framebuffer object not supported.\n" );
304 if ( width() <= 0 || height() <= 0 )
306 Log::error(
Say(
"FramebufferObject::checkFramebufferStatus() called with illegal dimensions: width = %n, height = %n\n" ) << width() << height() );
310 if ( mFBOAttachments.empty() )
312 Log::error(
"FramebufferObject::checkFramebufferStatus() called with no attachment points!\n" );
318 Log::error(
"FramebufferObject::checkFramebufferStatus() called but handle() == NULL!\n" );
323 ScopedFBOBinding fbo_bind(
this );
326 GLenum status = VL_glCheckFramebufferStatus( GL_FRAMEBUFFER );
VL_CHECK_OGL()
330 printFramebufferError( status );
332 VL_CHECK( status == GL_FRAMEBUFFER_COMPLETE )
341 case GL_FRAMEBUFFER_COMPLETE:
343 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
344 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT\n" );
VL_TRAP()
346 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
347 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT\n" );
VL_TRAP()
349 case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
350 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT\n" );
VL_TRAP()
352 case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
353 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT\n" );
VL_TRAP()
355 case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
356 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER\n" );
VL_TRAP()
358 case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
359 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER\n" );
VL_TRAP()
361 case GL_FRAMEBUFFER_UNSUPPORTED:
362 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_UNSUPPORTED\n" );
VL_TRAP()
364 case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_ARB:
365 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_ARB\n" );
VL_TRAP()
367 case GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB:
368 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB\n" );
VL_TRAP()
370 case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
371 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE\n" );
VL_TRAP()
382 removeAttachment( attach_point );
383 mFBOAttachments[attach_point] = attachment;
394 removeAttachment( attach_point );
395 mFBOAttachments[attach_point] = attachment;
439 std::vector<EAttachmentPoint> attachment_points;
440 std::map< EAttachmentPoint, ref<FBOAbstractAttachment> >::iterator it = mFBOAttachments.begin();
441 for( ; it != mFBOAttachments.end(); ++it )
442 if ( it->second == attachment )
443 attachment_points.push_back( it->first );
446 for(
unsigned i=0; i<attachment_points.size(); ++i )
447 removeAttachment( attachment_points[i] );
463 glGetIntegerv( GL_FRAMEBUFFER_BINDING, &fbo );
VL_CHECK_OGL()
465 VL_glBindFramebuffer( GL_FRAMEBUFFER, handle() );
VL_CHECK_OGL()
467 VL_glFramebufferRenderbuffer( GL_FRAMEBUFFER, attach_point, GL_RENDERBUFFER, 0 );
VL_CHECK_OGL()
469 VL_glBindFramebuffer( GL_FRAMEBUFFER, fbo );
VL_CHECK_OGL()
473 if ( fbo_attachment )
475 mFBOAttachments.erase( attach_point );
484 std::vector<EAttachmentPoint> attachment_points;
485 std::map< EAttachmentPoint, ref<FBOAbstractAttachment> >::iterator it = mFBOAttachments.begin();
486 for( ; it != mFBOAttachments.end(); ++it )
487 attachment_points.push_back( it->first );
490 for(
unsigned i=0; i<attachment_points.size(); ++i )
491 removeAttachment( attachment_points[i] );
502 VL_CHECK( texture()->dimension() == GL_TEXTURE_1D )
506 ScopedFBOBinding fbo_bind( fbo );
508 VL_glFramebufferTexture1D( GL_FRAMEBUFFER, attach_point, GL_TEXTURE_1D, texture()->handle(), mipmapLevel() );
VL_CHECK_OGL()
511 glBindTexture( texture()->dimension(), texture()->handle() );
VL_CHECK_OGL()
512 glTexParameteri( texture()->dimension(), GL_TEXTURE_MIN_FILTER, GL_LINEAR );
VL_CHECK_OGL()
513 glBindTexture( texture()->dimension(), 0 );
VL_CHECK_OGL()
529 ScopedFBOBinding fbo_bind( fbo );
531 int target = texture()->dimension() ==
TD_TEXTURE_CUBE_MAP ? ( int )textureTarget() : texture()->dimension();
533 if( !( texture()->dimension() ==
TD_TEXTURE_CUBE_MAP || (
int )textureTarget() == (
int )texture()->dimension() ) )
535 Log::bug(
"FBOTexture2DAttachment::init(): textureTarget() doens't match texture()->dimension().\n" );
539 VL_glFramebufferTexture2D( GL_FRAMEBUFFER, attach_point, target, texture()->handle(), mipmapLevel() );
VL_CHECK_OGL()
544 glBindTexture( texture()->dimension(), texture()->handle() );
VL_CHECK_OGL()
545 glTexParameteri( texture()->dimension(), GL_TEXTURE_MIN_FILTER, GL_LINEAR );
VL_CHECK_OGL()
546 glBindTexture( texture()->dimension(), 0 );
VL_CHECK_OGL()
558 ScopedFBOBinding fbo_bind( fbo );
560 VL_glFramebufferTexture( GL_FRAMEBUFFER, attach_point, texture()->handle(), mipmapLevel() );
VL_CHECK_OGL()
565 glBindTexture( texture()->dimension(), texture()->handle() );
VL_CHECK_OGL()
566 glTexParameteri( texture()->dimension(), GL_TEXTURE_MIN_FILTER, GL_LINEAR );
VL_CHECK_OGL()
567 glBindTexture( texture()->dimension(), 0 );
VL_CHECK_OGL()
581 VL_CHECK( layer() <= texture()->depth() );
582 VL_CHECK( texture()->dimension() == GL_TEXTURE_3D )
585 ScopedFBOBinding fbo_bind( fbo );
587 VL_glFramebufferTexture3D( GL_FRAMEBUFFER, attach_point, texture()->dimension(), texture()->handle(), mipmapLevel(), layer() );
VL_CHECK_OGL()
592 glBindTexture( texture()->dimension(), texture()->handle() );
VL_CHECK_OGL()
593 glTexParameteri( texture()->dimension(), GL_TEXTURE_MIN_FILTER, GL_LINEAR );
VL_CHECK_OGL()
594 glBindTexture( texture()->dimension(), 0 );
VL_CHECK_OGL()
609 VL_CHECK( texture()->dimension() == GL_TEXTURE_2D_ARRAY || texture()->dimension() == GL_TEXTURE_1D_ARRAY )
615 ScopedFBOBinding fbo_bind( fbo );
617 VL_glFramebufferTextureLayer( GL_FRAMEBUFFER, attach_point, texture()->handle(), mipmapLevel(), layer() );
VL_CHECK_OGL()
622 glBindTexture( texture()->dimension(), texture()->handle() );
VL_CHECK_OGL()
623 glTexParameteri( texture()->dimension(), GL_TEXTURE_MIN_FILTER, GL_LINEAR );
VL_CHECK_OGL()
624 glBindTexture( texture()->dimension(), 0 );
VL_CHECK_OGL()
630 std::set< ref<FramebufferObject> > fbos = fboFramebuffers();
632 it->get_writable()->removeAttachment(
this );
644 mReallocateRenderbuffer =
true;
664 mReallocateRenderbuffer =
true;
677 if ( w != width() || h != height() || samp != samples() || mReallocateRenderbuffer )
682 VL_glBindRenderbuffer( GL_RENDERBUFFER, handle() );
VL_CHECK_OGL()
685 VL_glRenderbufferStorageMultisample( GL_RENDERBUFFER, samples(), internalType(), width(), height() );
VL_CHECK_OGL()
691 Log::error(
"FBORenderbufferAttachment::initStorage() requesting multisampling storage but current OpenGL implementation does not support it!\n");
692 VL_glRenderbufferStorage( GL_RENDERBUFFER, internalType(), width(), height() );
VL_CHECK_OGL()
694 VL_glBindRenderbuffer( GL_RENDERBUFFER, 0 );
VL_CHECK_OGL()
695 mReallocateRenderbuffer =
false;
707 createRenderBuffer();
710 ScopedFBOBinding fbo_bind( fbo );
713 int actual_w = width() == 0 ? fbo->
width() : width();
714 int actual_h = height() == 0 ? fbo->
height() : height();
717 initStorage( actual_w, actual_h, samples() );
720 VL_glFramebufferRenderbuffer( GL_FRAMEBUFFER, attach_point, GL_RENDERBUFFER, handle() );
VL_CHECK_OGL()
virtual void bindAttachment(FramebufferObject *fbo, EAttachmentPoint attach_point)
virtual void bindAttachment(FramebufferObject *fbo, EAttachmentPoint attach_point)=0
A simple String formatting class.
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).
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
virtual void bindAttachment(FramebufferObject *fbo, EAttachmentPoint attach_point)
virtual void bindAttachment(FramebufferObject *fbo, EAttachmentPoint attach_point)
int width() const
The width of a render target.
bool checkDrawBuffers() const
Returns true if the draw buffers bound to this render target are legal for this render target type...
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...
void removeAttachment(FBOAbstractAttachment *attachment)
Unbinds the given attachments from a framebuffer object.
void removeAllAttachments()
Unbinds all attachments bound to a framebuffer object.
void addColorAttachment(EAttachmentPoint attach_point, FBOColorBufferAttachment *attachment)
Binds a color attachment to a framebuffer object.
void bindAttachment(FramebufferObject *fbo, EAttachmentPoint attach_point)
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() ...
void bindReadBuffer()
Binds to the currently active framebuffer object (including the 0 one) the read buffer specified by s...
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.
int height() const
The height of a render target.
void bindDrawBuffers() const
Binds to the currently active framebuffer object (including the 0 one) the draw buffers specified by ...
virtual GLuint handle() const
The handle of the framebuffer object as returned by glGenFramebuffers.
VLCORE_EXPORT GlobalSettings * globalSettings()
Returns VisulizationLibrary's global settings.