Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef FramebufferObject_INCLUDE_ONCE
00033 #define FramebufferObject_INCLUDE_ONCE
00034
00035 #include <vlGraphics/Camera.hpp>
00036 #include <vlGraphics/Texture.hpp>
00037 #include <set>
00038 #include <map>
00039
00040 namespace vl
00041 {
00042 class FBORenderTarget;
00043
00044
00045
00049 class VLGRAPHICS_EXPORT FBOAbstractAttachment: public Object
00050 {
00051 friend class FBORenderTarget;
00052
00053 private:
00054
00055 FBOAbstractAttachment( const FBOAbstractAttachment& other ): Object( other ) {}
00056 void operator=( const FBOAbstractAttachment& ) {}
00057
00058 public:
00059 virtual const char* className() { return "vl::FBOAbstractAttachment"; }
00060
00062 FBOAbstractAttachment() {}
00063
00065 virtual ~FBOAbstractAttachment() { destroy(); }
00066
00068 virtual void destroy();
00069
00071 const std::set< ref<FBORenderTarget> >& fboRenderTargets() const { return mFBORenderTargets; }
00072
00073 protected:
00074 virtual void bindAttachment( FBORenderTarget* fbo, EAttachmentPoint attach_point ) = 0;
00075
00076 protected:
00077 std::set< ref<FBORenderTarget> > mFBORenderTargets;
00078 };
00079
00080
00081
00087 class VLGRAPHICS_EXPORT FBORenderbufferAttachment: public FBOAbstractAttachment
00088 {
00089 friend class FBORenderTarget;
00090
00091 public:
00092 virtual const char* className() { return "vl::FBORenderbufferAttachment"; }
00093
00095 FBORenderbufferAttachment(): mHandle( 0 ), mWidth( 0 ), mHeight( 0 ), mSamples( 0 ), mReallocateRenderbuffer( true ) {}
00096
00101 void create();
00102
00104 void destroy();
00105
00110 void setHandle( GLuint handle ) { if ( mHandle != handle ) { mHandle = handle; mReallocateRenderbuffer = false; } }
00111
00113 GLuint handle() const { return mHandle; }
00114
00122 void initStorage( int w, int h, int samples );
00123
00125 void initStorage() { initStorage( width(), height(), samples() ); }
00126
00132 int width() const { return mWidth; }
00133
00139 int height() const { return mHeight; }
00140
00146 int samples() const { return mSamples; }
00147
00152 void setWidth( int w ) { if ( w != mWidth ) mReallocateRenderbuffer = true; mWidth = w; }
00153
00158 void setHeight( int h ) { if ( h != mHeight ) mReallocateRenderbuffer = true; mHeight = h; }
00159
00163 void setSamples( int samples ) { if ( samples != mSamples ) mReallocateRenderbuffer = true; mSamples = samples; }
00164
00166 bool renderbufferStorageReady() const { return !mReallocateRenderbuffer; }
00167
00168 protected:
00169 void bindAttachment( FBORenderTarget* fbo, EAttachmentPoint attach_point );
00170 virtual int internalType() = 0;
00171
00172 protected:
00173 GLuint mHandle;
00174 int mWidth;
00175 int mHeight;
00176 int mSamples;
00177 bool mReallocateRenderbuffer;
00178 };
00179
00180
00181
00185 class VLGRAPHICS_EXPORT FBOColorBufferAttachment: public FBORenderbufferAttachment
00186 {
00187 public:
00188 virtual const char* className() { return "vl::FBOColorBufferAttachment"; }
00189
00191 FBOColorBufferAttachment( EColorBufferFormat type )
00192 {
00193 VL_DEBUG_SET_OBJECT_NAME()
00194 mType = type;
00195 }
00196
00198 void setType( EColorBufferFormat type ) { if ( type != mType ) mReallocateRenderbuffer = true; mType = type; }
00199
00201 EColorBufferFormat type() const { return mType; }
00202
00203 protected:
00204 virtual int internalType() { return type(); }
00205
00206 protected:
00207 EColorBufferFormat mType;
00208 };
00209
00210
00211
00215 class VLGRAPHICS_EXPORT FBODepthBufferAttachment: public FBORenderbufferAttachment
00216 {
00217 public:
00218 virtual const char* className() { return "vl::FBODepthBufferAttachment"; }
00219
00221 FBODepthBufferAttachment( EDepthBufferFormat type )
00222 {
00223 VL_DEBUG_SET_OBJECT_NAME()
00224 mType = type;
00225 }
00226
00228 void setType( EDepthBufferFormat type ) { if ( type != mType ) mReallocateRenderbuffer = true; mType = type; }
00229
00231 EDepthBufferFormat type() const { return mType; }
00232
00233 protected:
00234 virtual int internalType() { return type(); }
00235
00236 protected:
00237 EDepthBufferFormat mType;
00238 };
00239
00240
00241
00245 class VLGRAPHICS_EXPORT FBOStencilBufferAttachment: public FBORenderbufferAttachment
00246 {
00247 public:
00248 virtual const char* className() { return "vl::FBOStencilBufferAttachment"; }
00249
00251 FBOStencilBufferAttachment( EStencilBufferFormat type )
00252 {
00253 VL_DEBUG_SET_OBJECT_NAME()
00254 mType = type;
00255 }
00256
00258 void setType( EStencilBufferFormat type ) { if ( type != mType ) mReallocateRenderbuffer = true; mType = type; }
00259
00261 EStencilBufferFormat type() const { return mType; }
00262
00263 protected:
00264 virtual int internalType() { return type(); }
00265
00266 protected:
00267 EStencilBufferFormat mType;
00268 };
00269
00270
00271
00275 class VLGRAPHICS_EXPORT FBODepthStencilBufferAttachment: public FBORenderbufferAttachment
00276 {
00277 public:
00278 virtual const char* className() { return "vl::FBODepthStencilBufferAttachment"; }
00279
00281 FBODepthStencilBufferAttachment( EDepthStencilBufferFormat type )
00282 {
00283 VL_DEBUG_SET_OBJECT_NAME()
00284 mType = type;
00285 }
00286
00288 void setType( EDepthStencilBufferFormat type ) { if ( type != mType ) mReallocateRenderbuffer = true; mType = type; }
00289
00291 EDepthStencilBufferFormat type() const { return mType; }
00292
00293 protected:
00294 virtual int internalType() { return type(); }
00295
00296 protected:
00297 EDepthStencilBufferFormat mType;
00298 };
00299
00300
00301
00305 class VLGRAPHICS_EXPORT FBOAbstractTextureAttachment: public FBOAbstractAttachment
00306 {
00307 public:
00308 virtual const char* className() { return "vl::FBOAbstractTextureAttachment"; }
00309
00311 FBOAbstractTextureAttachment( Texture* texture, int mipmap_level ): mTexture(texture), mMipmapLevel(mipmap_level)
00312 {
00313 VL_DEBUG_SET_OBJECT_NAME()
00314 }
00315
00317 void setTexture( Texture* texture ) { mTexture = texture; }
00318
00320 Texture* texture() { return mTexture.get(); }
00321
00323 const Texture* texture() const { return mTexture.get(); }
00324
00326 void setMipmapLevel( int mipmap_level ) { mMipmapLevel = mipmap_level; }
00327
00329 int mipmapLevel() const { return mMipmapLevel; }
00330
00331 protected:
00332 ref<Texture> mTexture;
00333 int mMipmapLevel;
00334 };
00335
00336
00337
00342 class VLGRAPHICS_EXPORT FBOTexture1DAttachment: public FBOAbstractTextureAttachment
00343 {
00344 public:
00345 virtual const char* className() { return "vl::FBOTexture1DAttachment"; }
00346
00348 FBOTexture1DAttachment( Texture* texture, int mipmap_level ): FBOAbstractTextureAttachment( texture, mipmap_level )
00349 {
00350 VL_DEBUG_SET_OBJECT_NAME()
00351 }
00352
00353 protected:
00354 virtual void bindAttachment( FBORenderTarget* fbo, EAttachmentPoint attach_point );
00355 };
00356
00357
00358
00363 class VLGRAPHICS_EXPORT FBOTexture2DAttachment: public FBOAbstractTextureAttachment
00364 {
00365 public:
00366 virtual const char* className() { return "vl::FBOTexture2DAttachment"; }
00367
00369 FBOTexture2DAttachment( Texture* texture, int mipmap_level, ETex2DTarget target ): FBOAbstractTextureAttachment( texture, mipmap_level )
00370 {
00371 VL_DEBUG_SET_OBJECT_NAME()
00372 mTextureTarget = target;
00373 }
00374
00376 void setTextureTarget( ETex2DTarget target ) { mTextureTarget = target; }
00377
00379 ETex2DTarget textureTarget() const { return mTextureTarget; }
00380
00381 protected:
00382 virtual void bindAttachment( FBORenderTarget* fbo, EAttachmentPoint attach_point );
00383
00384 protected:
00385 ETex2DTarget mTextureTarget;
00386 };
00387
00388
00389
00394 class VLGRAPHICS_EXPORT FBOTextureAttachment: public FBOAbstractTextureAttachment
00395 {
00396 public:
00397 virtual const char* className() { return "vl::FBOTextureAttachment"; }
00398
00400 FBOTextureAttachment( Texture* texture, int mipmap_level ): FBOAbstractTextureAttachment( texture, mipmap_level )
00401 {
00402 VL_DEBUG_SET_OBJECT_NAME()
00403 }
00404
00405 protected:
00406 virtual void bindAttachment( FBORenderTarget* fbo, EAttachmentPoint attach_point );
00407
00408 };
00409
00410
00411
00416 class VLGRAPHICS_EXPORT FBOTexture3DAttachment: public FBOAbstractTextureAttachment
00417 {
00418 public:
00419 virtual const char* className() { return "vl::FBOTexture3DAttachment"; }
00420
00421 FBOTexture3DAttachment( Texture* texture, int mipmap_level, int layer ): FBOAbstractTextureAttachment( texture, mipmap_level )
00422 {
00423 VL_DEBUG_SET_OBJECT_NAME()
00424 mLayer = layer;
00425 }
00426
00428 void setLayer( int layer ) { mLayer = layer; }
00429
00431 int layer() const { return mLayer; }
00432
00433 protected:
00434 virtual void bindAttachment( FBORenderTarget* fbo, EAttachmentPoint attach_point );
00435
00436 protected:
00437 int mLayer;
00438 };
00439
00440
00441
00446 class VLGRAPHICS_EXPORT FBOTextureLayerAttachment: public FBOAbstractTextureAttachment
00447 {
00448 public:
00449 virtual const char* className() { return "vl::FBOTextureLayerAttachment"; }
00450
00452 FBOTextureLayerAttachment( Texture* texture, int mipmap_level, int layer ): FBOAbstractTextureAttachment( texture, mipmap_level )
00453 {
00454 VL_DEBUG_SET_OBJECT_NAME()
00455 mLayer = layer;
00456 }
00457
00459 int layer() const { return mLayer; }
00460
00462 void setLayer( int layer ) { mLayer = layer; }
00463
00464 protected:
00465 virtual void bindAttachment( FBORenderTarget* fbo, EAttachmentPoint attach_point );
00466
00467 protected:
00468 ref<Texture> mTexture;
00469 int mMipmapLevel;
00470 int mLayer;
00471 };
00472
00473
00474
00503 class VLGRAPHICS_EXPORT FBORenderTarget: public RenderTarget
00504 {
00505 friend class OpenGLContext;
00506
00507 private:
00508 FBORenderTarget( const FBORenderTarget& other ): RenderTarget( other ), mHandle( 0 ) {}
00509
00510 void operator=( const FBORenderTarget& ) {}
00511
00512 FBORenderTarget( OpenGLContext* ctx, int w, int h ): RenderTarget( ctx, w, h ), mHandle( 0 )
00513 {
00514 VL_DEBUG_SET_OBJECT_NAME()
00515 setDrawBuffer( RDB_COLOR_ATTACHMENT0 );
00516 setReadBuffer( RDB_COLOR_ATTACHMENT0 );
00517 }
00518
00519 public:
00520 virtual const char* className() { return "vl::FBORenderTarget"; }
00521
00523 ~FBORenderTarget() { if (openglContext()) destroy(); }
00524
00529 void create();
00530
00535 void destroy();
00536
00538 void setHandle( GLuint handle ) { mHandle = handle; }
00539
00541 virtual GLuint handle() const { return mHandle; }
00542
00548 virtual void bindFramebuffer( EFrameBufferBind target = FBB_FRAMEBUFFER );
00549
00551 GLenum checkFramebufferStatus();
00552
00554 void printFramebufferError( GLenum status ) const;
00555
00557 void addColorAttachment( EAttachmentPoint attach_point, FBOColorBufferAttachment* attachment );
00558
00560 void addTextureAttachment( EAttachmentPoint attach_point, FBOAbstractTextureAttachment* attachment );
00561
00566 void addDepthAttachment( FBOAbstractAttachment* attachment );
00567
00572 void addStencilAttachment( FBOAbstractAttachment* attachment );
00573
00575 void addDepthStencilAttachment( FBOAbstractAttachment* attachment );
00576
00578 void removeAttachment( FBOAbstractAttachment* attachment );
00579
00581 void removeAttachment( EAttachmentPoint attach_point );
00582
00584 void removeAllAttachments();
00585
00587 const std::map< EAttachmentPoint, ref<FBOAbstractAttachment> >& fboAttachments() const { return mFBOAttachments; }
00588
00589 public:
00590 std::map< EAttachmentPoint, ref<FBOAbstractAttachment> > mFBOAttachments;
00591 GLuint mHandle;
00592 };
00593 }
00594
00595 #endif