@ -46,9 +46,9 @@ Renderbuffer depthStencil;
// configure the textures and allocate texture memory...
framebuffer . attachTexture2D ( Framebuffer : : Target : : Draw , 0 , & color ) ;
framebuffer . attachTexture2D ( Framebuffer : : Target : : Draw , 1 , & normal ) ;
framebuffer . attachRenderbuffer ( Framebuffer : : Target : : Draw , Framebuffer : : DepthStencilAttachment : : DepthStencil , & depthStencil ) ;
framebuffer . attachTexture2D ( 0 , & color ) ;
framebuffer . attachTexture2D ( 1 , & normal ) ;
framebuffer . attachRenderbuffer ( Framebuffer : : DepthStencilAttachment : : DepthStencil , & depthStencil ) ;
@ endcode
Then you need to map outputs of your shader to color attachments in the
@ -75,9 +75,21 @@ void drawEvent() {
}
@ endcode
@ section Framebuffer - performance - optimization Performance optimizations
See also @ ref AbstractFramebuffer - performance - optimization " relevant section in AbstractFramebuffer " .
If extension @ extension { EXT , direct_state_access } is available , functions
mapForDraw ( ) , mapForRead ( ) , attachRenderbuffer ( ) , attachTexture1D ( ) ,
attachTexture2D ( ) , attachCubeMapTexture ( ) and attachTexture3D ( ) use DSA
to avoid unnecessary calls to @ fn_gl { BindFramebuffer } . See their respective
documentation for more information .
@ requires_gl30 % Extension @ extension { EXT , framebuffer_object }
*/
class MAGNUM_EXPORT Framebuffer : public AbstractFramebuffer {
friend class Context ;
public :
/**
* @ brief Constructor
@ -106,7 +118,12 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer {
* framebuffer . mapForDraw ( { { MyShader : : ColorOutput , 0 } ,
* { MyShader : : NormalOutput , 1 } } ) ;
* @ endcode
* @ see mapForRead ( ) , @ fn_gl { BindFramebuffer } , @ fn_gl { DrawBuffers }
*
* If @ extension { EXT , direct_state_access } is not available and the
* framebufferbuffer is not currently bound , it is bound before the
* operation .
* @ see mapForRead ( ) , @ fn_gl { BindFramebuffer } , @ fn_gl { DrawBuffers } or
* @ fn_gl_extension { FramebufferDrawBuffers , EXT , direct_state_access }
* @ requires_gles30 % Extension @ es_extension2 { NV , draw_buffers , GL_NV_draw_buffers }
*/
void mapForDraw ( std : : initializer_list < std : : pair < GLuint , std : : int8_t > > attachments ) ;
@ -117,19 +134,32 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer {
*
* Similar to above function , can be used in cases when shader has
* only one ( unnamed ) output .
* @ see mapForRead ( ) , @ fn_gl { BindFramebuffer } , @ fn_gl { DrawBuffer }
*
* If @ extension { EXT , direct_state_access } is not available and the
* framebufferbuffer is not currently bound , it is bound before the
* operation .
* @ see mapForRead ( ) , @ fn_gl { BindFramebuffer } , @ fn_gl { DrawBuffer } or
* @ fn_gl_extension { FramebufferDrawBuffer , EXT , direct_state_access }
* @ requires_gles30 % Extension @ es_extension2 { NV , draw_buffers , GL_NV_draw_buffers }
*/
void mapForDraw ( std : : int8_t attachment ) ;
inline void mapForDraw ( std : : int8_t attachment ) {
( this - > * drawBufferImplementation ) ( static_cast < GLenum > ( GL_COLOR_ATTACHMENT0 + attachment ) ) ;
}
/**
* @ brief Map given color attachment for reading
* @ param attachment Color attachment ID
*
* @ see mapForDraw ( ) , @ fn_gl { BindFramebuffer } , @ fn_gl { ReadBuffer }
* If @ extension { EXT , direct_state_access } is not available and the
* framebufferbuffer is not currently bound , it is bound before the
* operation .
* @ see mapForDraw ( ) , @ fn_gl { BindFramebuffer } , @ fn_gl { ReadBuffer } or
* @ fn_gl_extension { FramebufferReadBuffer , EXT , direct_state_access }
* @ requires_gles30 % Extension @ es_extension2 { NV , read_buffer , GL_NV_read_buffer }
*/
void mapForRead ( std : : uint8_t attachment ) ;
inline void mapForRead ( std : : uint8_t attachment ) {
( this - > * readBufferImplementation ) ( GL_COLOR_ATTACHMENT0 + attachment ) ;
}
/**
* @ brief Attachment for depth / stencil part of fragment shader output
@ -155,127 +185,204 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer {
/**
* @ brief Attach renderbuffer to given framebuffer depth / stencil attachment
* @ param target % Target
* @ param depthStencilAttachment Depth / stencil attachment
* @ param renderbuffer % Renderbuffer
*
* @ see @ fn_gl { BindFramebuffer } , @ fn_gl { FramebufferRenderbuffer }
* If @ extension { EXT , direct_state_access } is not available and the
* framebufferbuffer is not currently bound , it is bound before the
* operation .
* @ see @ fn_gl { BindFramebuffer } , @ fn_gl { FramebufferRenderbuffer } or
* @ fn_gl_extension { NamedFramebufferRenderbuffer , EXT , direct_state_access }
*/
void attachRenderbuffer ( Target target , DepthStencilAttachment depthStencilAttachment , Renderbuffer * renderbuffer ) ;
inline void attachRenderbuffer ( DepthStencilAttachment depthStencilAttachment , Renderbuffer * renderbuffer ) {
( this - > * renderbufferImplementation ) ( GLenum ( depthStencilAttachment ) , renderbuffer ) ;
}
/**
* @ brief Attach renderbuffer to given framebuffer color attachment
* @ param target % Target
* @ param colorAttachment Color attachment ID ( number between 0 and 15 )
* @ param renderbuffer % Renderbuffer
*
* @ see @ fn_gl { BindFramebuffer } , @ fn_gl { FramebufferRenderbuffer }
* If @ extension { EXT , direct_state_access } is not available and the
* framebufferbuffer is not currently bound , it is bound before the
* operation .
* @ see @ fn_gl { BindFramebuffer } , @ fn_gl { FramebufferRenderbuffer } or
* @ fn_gl_extension { NamedFramebufferRenderbuffer , EXT , direct_state_access }
*/
void attachRenderbuffer ( Target target , std : : uint8_t colorAttachment , Renderbuffer * renderbuffer ) ;
inline void attachRenderbuffer ( std : : uint8_t colorAttachment , Renderbuffer * renderbuffer ) {
( this - > * renderbufferImplementation ) ( GL_COLOR_ATTACHMENT0 + colorAttachment , renderbuffer ) ;
}
# ifndef MAGNUM_TARGET_GLES
/**
* @ brief Attach 1 D texture to given framebuffer depth / stencil attachment
* @ param target % Target
* @ param depthStencilAttachment Depth / stencil attachment
* @ param texture 1 D texture
* @ param mipLevel Mip level
*
* @ see @ fn_gl { BindFramebuffer } , @ fn_gl { FramebufferTexture }
* If @ extension { EXT , direct_state_access } is not available and the
* framebufferbuffer is not currently bound , it is bound before the
* operation .
* @ see @ fn_gl { BindFramebuffer } , @ fn_gl { FramebufferTexture } or
* @ fn_gl_extension { NamedFramebufferTexture1D , EXT , direct_state_access }
* @ requires_gl Only 2 D and 3 D textures are available in OpenGL ES .
*/
void attachTexture1D ( Target target , DepthStencilAttachment depthStencilAttachment , Texture1D * texture , GLint mipLevel ) ;
inline void attachTexture1D ( DepthStencilAttachment depthStencilAttachment , Texture1D * texture , GLint mipLevel ) {
/** @todo Check for texture target compatibility */
( this - > * texture1DImplementation ) ( GLenum ( depthStencilAttachment ) , texture , mipLevel ) ;
}
/**
* @ brief Attach 1 D texture to given framebuffer color attachment
* @ param target % Target
* @ param colorAttachment Color attachment ID ( number between 0 and 15 )
* @ param texture 1 D texture
* @ param mipLevel Mip level
*
* @ see @ fn_gl { BindFramebuffer } , @ fn_gl { FramebufferTexture }
* If @ extension { EXT , direct_state_access } is not available and the
* framebufferbuffer is not currently bound , it is bound before the
* operation .
* @ see @ fn_gl { BindFramebuffer } , @ fn_gl { FramebufferTexture } or
* @ fn_gl_extension { NamedFramebufferTexture1D , EXT , direct_state_access }
* @ requires_gl Only 2 D and 3 D textures are available in OpenGL ES .
*/
void attachTexture1D ( Target target , std : : uint8_t colorAttachment , Texture1D * texture , GLint mipLevel ) ;
inline void attachTexture1D ( std : : uint8_t colorAttachment , Texture1D * texture , GLint mipLevel ) {
/** @todo Check for texture target compatibility */
( this - > * texture1DImplementation ) ( GL_COLOR_ATTACHMENT0 + colorAttachment , texture , mipLevel ) ;
}
# endif
/**
* @ brief Attach 2 D texture to given framebuffer depth / stencil attachment
* @ param target % Target
* @ param depthStencilAttachment Depth / stencil attachment
* @ param texture 2 D texture
* @ param mipLevel Mip level . For rectangle textures it
* should be always 0.
*
* @ see attachCubeMapTexture ( ) , @ fn_gl { BindFramebuffer } ,
* @ fn_gl { FramebufferTexture }
* If @ extension { EXT , direct_state_access } is not available and the
* framebufferbuffer is not currently bound , it is bound before the
* operation .
* @ see attachCubeMapTexture ( ) , @ fn_gl { BindFramebuffer } , @ fn_gl { FramebufferTexture }
* or @ fn_gl_extension { NamedFramebufferTexture2D , EXT , direct_state_access }
*/
void attachTexture2D ( Target target , DepthStencilAttachment depthStencilAttachment , Texture2D * texture , GLint mipLevel ) ;
void attachTexture2D ( DepthStencilAttachment depthStencilAttachment , Texture2D * texture , GLint mipLevel ) ;
/**
* @ brief Attach 2 D texture to given framebuffer color attachment
* @ param target % Target
* @ param colorAttachment Color attachment ID ( number between 0 and 15 )
* @ param texture 2 D texture
* @ param mipLevel Mip level . For rectangle textures it
* should be always 0.
*
* @ see attachCubeMapTexture ( ) , @ fn_gl { BindFramebuffer } ,
* @ fn_gl { FramebufferTexture }
* If @ extension { EXT , direct_state_access } is not available and the
* framebufferbuffer is not currently bound , it is bound before the
* operation .
* @ see attachCubeMapTexture ( ) , @ fn_gl { BindFramebuffer } , @ fn_gl { FramebufferTexture }
* or @ fn_gl_extension { NamedFramebufferTexture2D , EXT , direct_state_access }
*/
void attachTexture2D ( Target target , std : : uint8_t colorAttachment , Texture2D * texture , GLint mipLevel ) ;
void attachTexture2D ( std : : uint8_t colorAttachment , Texture2D * texture , GLint mipLevel ) ;
/**
* @ brief Attach cube map texture to given framebuffer depth / stencil attachment
* @ param target % Target
* @ param depthStencilAttachment Depth / stencil attachment
* @ param texture Cube map texture
* @ param coordinate Cube map coordinate
* @ param mipLevel Mip level
*
* @ see attachTexture2D ( ) , @ fn_gl { BindFramebuffer } ,
* @ fn_gl { FramebufferTexture }
* If @ extension { EXT , direct_state_access } is not available and the
* framebufferbuffer is not currently bound , it is bound before the
* operation .
* @ see attachTexture2D ( ) , @ fn_gl { BindFramebuffer } , @ fn_gl { FramebufferTexture }
* or @ fn_gl_extension { NamedFramebufferTexture2D , EXT , direct_state_access }
*/
void attachCubeMapTexture ( Target target , DepthStencilAttachment depthStencilAttachment , CubeMapTexture * texture , CubeMapTexture : : Coordinate coordinate , GLint mipLevel ) ;
inline void attachCubeMapTexture ( DepthStencilAttachment depthStencilAttachment , CubeMapTexture * texture , CubeMapTexture : : Coordinate coordinate , GLint mipLevel ) {
( this - > * texture2DImplementation ) ( GLenum ( depthStencilAttachment ) , GLenum ( coordinate ) , texture - > id ( ) , mipLevel ) ;
}
/**
* @ brief Attach cube map texture to given framebuffer color attachment
* @ param target % Target
* @ param colorAttachment Color attachment ID ( number between 0 and 15 )
* @ param texture Cube map texture
* @ param coordinate Cube map coordinate
* @ param mipLevel Mip level
*
* @ see attachTexture2D ( ) , @ fn_gl { BindFramebuffer } ,
* @ fn_gl { FramebufferTexture }
* If @ extension { EXT , direct_state_access } is not available and the
* framebufferbuffer is not currently bound , it is bound before the
* operation .
* @ see attachTexture2D ( ) , @ fn_gl { BindFramebuffer } , @ fn_gl { FramebufferTexture }
* or @ fn_gl_extension { NamedFramebufferTexture2D , EXT , direct_state_access }
*/
void attachCubeMapTexture ( Target target , std : : uint8_t colorAttachment , CubeMapTexture * texture , CubeMapTexture : : Coordinate coordinate , GLint mipLevel ) ;
inline void attachCubeMapTexture ( std : : uint8_t colorAttachment , CubeMapTexture * texture , CubeMapTexture : : Coordinate coordinate , GLint mipLevel ) {
( this - > * texture2DImplementation ) ( GL_COLOR_ATTACHMENT0 + colorAttachment , GLenum ( coordinate ) , texture - > id ( ) , mipLevel ) ;
}
/**
* @ brief Attach 3 D texture to given framebuffer depth / stencil attachment
* @ param target % Target
* @ param depthStencilAttachment Depth / stencil attachment
* @ param texture 3 D texture
* @ param mipLevel Mip level
* @ param layer Layer of 2 D image within a 3 D texture
*
* @ see @ fn_gl { BindFramebuffer } , @ fn_gl { FramebufferTexture }
* If @ extension { EXT , direct_state_access } is not available and the
* framebufferbuffer is not currently bound , it is bound before the
* operation .
* @ see @ fn_gl { BindFramebuffer } , @ fn_gl { FramebufferTexture } or
* @ fn_gl_extension { NamedFramebufferTexture3D , EXT , direct_state_access }
* @ requires_es_extension % Extension @ es_extension { OES , texture_3D }
*/
void attachTexture3D ( Target target , DepthStencilAttachment depthStencilAttachment , Texture3D * texture , GLint mipLevel , GLint layer ) ;
inline void attachTexture3D ( DepthStencilAttachment depthStencilAttachment , Texture3D * texture , GLint mipLevel , GLint layer ) {
/** @todo Check for texture target compatibility */
( this - > * texture3DImplementation ) ( GLenum ( depthStencilAttachment ) , texture , mipLevel , layer ) ;
}
/**
* @ brief Attach 3 D texture to given framebuffer color attachment
* @ param target % Target
* @ param colorAttachment Color attachment ID ( number between 0 and 15 )
* @ param texture 3 D texture
* @ param mipLevel Mip level
* @ param layer Layer of 2 D image within a 3 D texture .
*
* @ see @ fn_gl { BindFramebuffer } , @ fn_gl { FramebufferTexture }
* If @ extension { EXT , direct_state_access } is not available and the
* framebufferbuffer is not currently bound , it is bound before the
* operation .
* @ see @ fn_gl { BindFramebuffer } , @ fn_gl { FramebufferTexture } or
* @ fn_gl_extension { NamedFramebufferTexture3D , EXT , direct_state_access }
* @ requires_es_extension % Extension @ es_extension { OES , texture_3D }
*/
void attachTexture3D ( Target target , std : : uint8_t colorAttachment , Texture3D * texture , GLint mipLevel , GLint layer ) ;
inline void attachTexture3D ( std : : uint8_t colorAttachment , Texture3D * texture , GLint mipLevel , GLint layer ) {
/** @todo Check for texture target compatibility */
( this - > * texture3DImplementation ) ( GL_COLOR_ATTACHMENT0 + colorAttachment , texture , mipLevel , layer ) ;
}
private :
static void MAGNUM_LOCAL initializeContextBasedFunctionality ( Context * context ) ;
typedef void ( Framebuffer : : * RenderbufferImplementation ) ( GLenum , Renderbuffer * ) ;
void MAGNUM_LOCAL renderbufferImplementationDefault ( GLenum attachment , Renderbuffer * renderbuffer ) ;
# ifndef MAGNUM_TARGET_GLES
void MAGNUM_LOCAL renderbufferImplementationDSA ( GLenum attachment , Renderbuffer * renderbuffer ) ;
# endif
static RenderbufferImplementation renderbufferImplementation ;
# ifndef MAGNUM_TARGET_GLES
typedef void ( Framebuffer : : * Texture1DImplementation ) ( GLenum , Texture1D * , GLint ) ;
void MAGNUM_LOCAL texture1DImplementationDefault ( GLenum attachment , Texture1D * texture , GLint mipLevel ) ;
void MAGNUM_LOCAL texture1DImplementationDSA ( GLenum attachment , Texture1D * texture , GLint mipLevel ) ;
static Texture1DImplementation texture1DImplementation ;
# endif
typedef void ( Framebuffer : : * Texture2DImplementation ) ( GLenum , GLenum , GLuint , GLint ) ;
void MAGNUM_LOCAL texture2DImplementationDefault ( GLenum attachment , GLenum textureTarget , GLuint textureId , GLint mipLevel ) ;
# ifndef MAGNUM_TARGET_GLES
void MAGNUM_LOCAL texture2DImplementationDSA ( GLenum attachment , GLenum textureTarget , GLuint textureId , GLint mipLevel ) ;
# endif
static MAGNUM_LOCAL Texture2DImplementation texture2DImplementation ;
typedef void ( Framebuffer : : * Texture3DImplementation ) ( GLenum , Texture3D * , GLint , GLint ) ;
void MAGNUM_LOCAL texture3DImplementationDefault ( GLenum attachment , Texture3D * texture , GLint mipLevel , GLint layer ) ;
# ifndef MAGNUM_TARGET_GLES
void MAGNUM_LOCAL texture3DImplementationDSA ( GLenum attachment , Texture3D * texture , GLint mipLevel , GLint layer ) ;
# endif
static Texture3DImplementation texture3DImplementation ;
} ;
}