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()
79 VL_glGenFramebuffers( 1, (
unsigned int* )&mHandle );
VL_CHECK_OGL();
90 removeAllAttachments();
93 VL_glBindFramebuffer( GL_FRAMEBUFFER, 0 );
VL_CHECK_OGL();
109 Log::error(
"FramebufferObject::bindFramebuffer(): framebuffer object not supported.\n" );
113 if ( width() <= 0 || height() <= 0 )
115 Log::error(
Say(
"FramebufferObject::bindFramebuffer() called with illegal dimensions: width = %n, height = %n\n" ) << width() << height() );
119 if ( mFBOAttachments.empty() )
121 Log::error(
"FramebufferObject::bindFramebuffer() called with no attachment points!\n" );
127 Log::error(
"FramebufferObject::bindFramebuffer() called but handle() == NULL!\n" );
131 VL_glBindFramebuffer( target, handle() );
VL_CHECK_OGL()
133 #if defined(VL_OPENGL) 144 GLenum status = VL_glCheckFramebufferStatus( GL_FRAMEBUFFER );
VL_CHECK_OGL()
145 if ( status != GL_FRAMEBUFFER_COMPLETE )
147 VL_glBindFramebuffer( GL_FRAMEBUFFER, 0 );
VL_CHECK_OGL()
149 printFramebufferError( status );
162 Log::error(
"FramebufferObject::checkFramebufferStatus(): framebuffer object not supported.\n" );
166 if ( width() <= 0 || height() <= 0 )
168 Log::error(
Say(
"FramebufferObject::checkFramebufferStatus() called with illegal dimensions: width = %n, height = %n\n" ) << width() << height() );
172 if ( mFBOAttachments.empty() )
174 Log::error(
"FramebufferObject::checkFramebufferStatus() called with no attachment points!\n" );
180 Log::error(
"FramebufferObject::checkFramebufferStatus() called but handle() == NULL!\n" );
185 ScopedFBOBinding fbo_bind(
this );
188 GLenum status = VL_glCheckFramebufferStatus( GL_FRAMEBUFFER );
VL_CHECK_OGL()
192 printFramebufferError( status );
194 VL_CHECK( status == GL_FRAMEBUFFER_COMPLETE )
203 case GL_FRAMEBUFFER_COMPLETE:
205 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
206 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT\n" );
VL_TRAP()
208 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
209 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT\n" );
VL_TRAP()
211 case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
212 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT\n" );
VL_TRAP()
214 case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
215 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT\n" );
VL_TRAP()
217 case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
218 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER\n" );
VL_TRAP()
220 case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
221 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER\n" );
VL_TRAP()
223 case GL_FRAMEBUFFER_UNSUPPORTED:
224 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_UNSUPPORTED\n" );
VL_TRAP()
226 case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_ARB:
227 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_ARB\n" );
VL_TRAP()
229 case GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB:
230 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB\n" );
VL_TRAP()
232 case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
233 Log::bug(
"FramebufferObject::activate(): GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE\n" );
VL_TRAP()
244 removeAttachment( attach_point );
245 mFBOAttachments[attach_point] = attachment;
256 removeAttachment( attach_point );
257 mFBOAttachments[attach_point] = attachment;
301 std::vector<EAttachmentPoint> attachment_points;
302 std::map< EAttachmentPoint, ref<FBOAbstractAttachment> >::iterator it = mFBOAttachments.begin();
303 for( ; it != mFBOAttachments.end(); ++it )
304 if ( it->second == attachment )
305 attachment_points.push_back( it->first );
308 for(
unsigned i=0; i<attachment_points.size(); ++i )
309 removeAttachment( attachment_points[i] );
325 glGetIntegerv( GL_FRAMEBUFFER_BINDING, &fbo );
VL_CHECK_OGL()
327 VL_glBindFramebuffer( GL_FRAMEBUFFER, handle() );
VL_CHECK_OGL()
329 VL_glFramebufferRenderbuffer( GL_FRAMEBUFFER, attach_point, GL_RENDERBUFFER, 0 );
VL_CHECK_OGL()
331 VL_glBindFramebuffer( GL_FRAMEBUFFER, fbo );
VL_CHECK_OGL()
335 if ( fbo_attachment )
337 mFBOAttachments.erase( attach_point );
346 std::vector<EAttachmentPoint> attachment_points;
347 std::map< EAttachmentPoint, ref<FBOAbstractAttachment> >::iterator it = mFBOAttachments.begin();
348 for( ; it != mFBOAttachments.end(); ++it )
349 attachment_points.push_back( it->first );
352 for(
unsigned i=0; i<attachment_points.size(); ++i )
353 removeAttachment( attachment_points[i] );
364 VL_CHECK( texture()->dimension() == GL_TEXTURE_1D )
368 ScopedFBOBinding fbo_bind( fbo );
370 VL_glFramebufferTexture1D( GL_FRAMEBUFFER, attach_point, GL_TEXTURE_1D, texture()->handle(), mipmapLevel() );
VL_CHECK_OGL()
373 glBindTexture( texture()->dimension(), texture()->handle() );
VL_CHECK_OGL()
374 glTexParameteri( texture()->dimension(), GL_TEXTURE_MIN_FILTER, GL_LINEAR );
VL_CHECK_OGL()
375 glBindTexture( texture()->dimension(), 0 );
VL_CHECK_OGL()
391 ScopedFBOBinding fbo_bind( fbo );
393 int target = texture()->dimension() ==
TD_TEXTURE_CUBE_MAP ? ( int )textureTarget() : texture()->dimension();
395 if( !( texture()->dimension() ==
TD_TEXTURE_CUBE_MAP || (
int )textureTarget() == (
int )texture()->dimension() ) )
397 Log::bug(
"FBOTexture2DAttachment::init(): textureTarget() doens't match texture()->dimension().\n" );
401 VL_glFramebufferTexture2D( GL_FRAMEBUFFER, attach_point, target, texture()->handle(), mipmapLevel() );
VL_CHECK_OGL()
406 glBindTexture( texture()->dimension(), texture()->handle() );
VL_CHECK_OGL()
407 glTexParameteri( texture()->dimension(), GL_TEXTURE_MIN_FILTER, GL_LINEAR );
VL_CHECK_OGL()
408 glBindTexture( texture()->dimension(), 0 );
VL_CHECK_OGL()
420 ScopedFBOBinding fbo_bind( fbo );
422 VL_glFramebufferTexture( GL_FRAMEBUFFER, attach_point, texture()->handle(), mipmapLevel() );
VL_CHECK_OGL()
427 glBindTexture( texture()->dimension(), texture()->handle() );
VL_CHECK_OGL()
428 glTexParameteri( texture()->dimension(), GL_TEXTURE_MIN_FILTER, GL_LINEAR );
VL_CHECK_OGL()
429 glBindTexture( texture()->dimension(), 0 );
VL_CHECK_OGL()
443 VL_CHECK( layer() <= texture()->depth() );
444 VL_CHECK( texture()->dimension() == GL_TEXTURE_3D )
447 ScopedFBOBinding fbo_bind( fbo );
449 VL_glFramebufferTexture3D( GL_FRAMEBUFFER, attach_point, texture()->dimension(), texture()->handle(), mipmapLevel(), layer() );
VL_CHECK_OGL()
454 glBindTexture( texture()->dimension(), texture()->handle() );
VL_CHECK_OGL()
455 glTexParameteri( texture()->dimension(), GL_TEXTURE_MIN_FILTER, GL_LINEAR );
VL_CHECK_OGL()
456 glBindTexture( texture()->dimension(), 0 );
VL_CHECK_OGL()
471 VL_CHECK( texture()->dimension() == GL_TEXTURE_2D_ARRAY || texture()->dimension() == GL_TEXTURE_1D_ARRAY )
477 ScopedFBOBinding fbo_bind( fbo );
479 VL_glFramebufferTextureLayer( GL_FRAMEBUFFER, attach_point, texture()->handle(), mipmapLevel(), layer() );
VL_CHECK_OGL()
484 glBindTexture( texture()->dimension(), texture()->handle() );
VL_CHECK_OGL()
485 glTexParameteri( texture()->dimension(), GL_TEXTURE_MIN_FILTER, GL_LINEAR );
VL_CHECK_OGL()
486 glBindTexture( texture()->dimension(), 0 );
VL_CHECK_OGL()
492 std::set< ref<FramebufferObject> > fbos = fboFramebuffers();
494 it->get_writable()->removeAttachment(
this );
506 mReallocateRenderbuffer =
true;
526 mReallocateRenderbuffer =
true;
539 if ( w != width() || h != height() || samp != samples() || mReallocateRenderbuffer )
544 VL_glBindRenderbuffer( GL_RENDERBUFFER, handle() );
VL_CHECK_OGL()
547 VL_glRenderbufferStorageMultisample( GL_RENDERBUFFER, samples(), internalType(), width(), height() );
VL_CHECK_OGL()
553 Log::error(
"FBORenderbufferAttachment::initStorage() requesting multisampling storage but current OpenGL implementation does not support it!\n");
554 VL_glRenderbufferStorage( GL_RENDERBUFFER, internalType(), width(), height() );
VL_CHECK_OGL()
556 VL_glBindRenderbuffer( GL_RENDERBUFFER, 0 );
VL_CHECK_OGL()
557 mReallocateRenderbuffer =
false;
569 createRenderBuffer();
572 ScopedFBOBinding fbo_bind( fbo );
575 int actual_w = width() == 0 ? fbo->
width() : width();
576 int actual_h = height() == 0 ? fbo->
height() : height();
579 initStorage( actual_w, actual_h, samples() );
582 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).
int width() const
The width of a render target.
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)
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.
int height() const
The height of a render target.
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() ...
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.
virtual GLuint handle() const
The handle of the framebuffer object as returned by glGenFramebuffers.
VLCORE_EXPORT GlobalSettings * globalSettings()
Returns VisulizationLibrary's global settings.