Open CASCADE Technology  7.5.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes

OpenGl_FrameBuffer Class Reference

Class implements FrameBuffer Object (FBO) resource intended for off-screen rendering. More...

#include <OpenGl_FrameBuffer.hxx>

Inheritance diagram for OpenGl_FrameBuffer:
Inheritance graph
[legend]

Public Member Functions

 OpenGl_FrameBuffer ()
 Empty constructor. More...
 
virtual ~OpenGl_FrameBuffer ()
 Destructor. More...
 
virtual void Release (OpenGl_Context *theGlCtx) override
 Destroy object - will release GPU memory if any. More...
 
GLsizei NbSamples () const
 Number of multisampling samples. More...
 
GLsizei NbColorBuffers () const
 Number of color buffers. More...
 
bool HasColor () const
 Return true if FBO has been created with color attachment. More...
 
bool HasDepth () const
 Return true if FBO has been created with depth attachment. More...
 
GLsizei GetSizeX () const
 Textures width. More...
 
GLsizei GetSizeY () const
 Textures height. More...
 
GLsizei GetVPSizeX () const
 Viewport width. More...
 
GLsizei GetVPSizeY () const
 Viewport height. More...
 
GLsizei GetInitVPSizeX () const
 Viewport width. More...
 
GLsizei GetInitVPSizeY () const
 Viewport height. More...
 
Standard_Boolean IsValid () const
 Returns true if current object was initialized. More...
 
Standard_Boolean Init (const Handle< OpenGl_Context > &theGlCtx, const GLsizei theSizeX, const GLsizei theSizeY, const OpenGl_ColorFormats &theColorFormats, const Handle< OpenGl_Texture > &theDepthStencilTexture, const GLsizei theNbSamples=0)
 Initialize FBO for rendering into single/multiple color buffer and depth textures. More...
 
Standard_Boolean Init (const Handle< OpenGl_Context > &theGlCtx, const GLsizei theSizeX, const GLsizei theSizeY, const GLint theColorFormat, const GLint theDepthFormat, const GLsizei theNbSamples=0)
 Initialize FBO for rendering into textures. More...
 
Standard_Boolean Init (const Handle< OpenGl_Context > &theGlCtx, const GLsizei theSizeX, const GLsizei theSizeY, const OpenGl_ColorFormats &theColorFormats, const GLint theDepthFormat, const GLsizei theNbSamples=0)
 Initialize FBO for rendering into single/multiple color buffer and depth textures. More...
 
Standard_Boolean InitLazy (const Handle< OpenGl_Context > &theGlCtx, const GLsizei theViewportSizeX, const GLsizei theViewportSizeY, const GLint theColorFormat, const GLint theDepthFormat, const GLsizei theNbSamples=0)
 (Re-)initialize FBO with specified dimensions. More...
 
Standard_Boolean InitLazy (const Handle< OpenGl_Context > &theGlCtx, const GLsizei theViewportSizeX, const GLsizei theViewportSizeY, const OpenGl_ColorFormats &theColorFormats, const GLint theDepthFormat, const GLsizei theNbSamples=0)
 (Re-)initialize FBO with specified dimensions. More...
 
Standard_Boolean InitLazy (const Handle< OpenGl_Context > &theGlCtx, const OpenGl_FrameBuffer &theFbo)
 (Re-)initialize FBO with properties taken from another FBO. More...
 
Standard_Boolean InitWithRB (const Handle< OpenGl_Context > &theGlCtx, const GLsizei theSizeX, const GLsizei theSizeY, const GLint theColorFormat, const GLint theDepthFormat, const GLuint theColorRBufferFromWindow=0)
 (Re-)initialize FBO with specified dimensions. The Render Buffer Objects will be used for Color, Depth and Stencil attachments (as opposite to textures). More...
 
Standard_Boolean InitWrapper (const Handle< OpenGl_Context > &theGlCtx)
 Initialize class from currently bound FBO. Retrieved OpenGL objects will not be destroyed on Release. More...
 
void SetupViewport (const Handle< OpenGl_Context > &theGlCtx)
 Setup viewport to render into FBO. More...
 
void ChangeViewport (const GLsizei theVPSizeX, const GLsizei theVPSizeY)
 Override viewport settings. More...
 
virtual void BindBuffer (const Handle< OpenGl_Context > &theGlCtx)
 Bind frame buffer for drawing and reading (to render into the texture). More...
 
virtual void BindDrawBuffer (const Handle< OpenGl_Context > &theGlCtx)
 Bind frame buffer for drawing GL_DRAW_FRAMEBUFFER (to render into the texture). More...
 
virtual void BindReadBuffer (const Handle< OpenGl_Context > &theGlCtx)
 Bind frame buffer for reading GL_READ_FRAMEBUFFER. More...
 
virtual void UnbindBuffer (const Handle< OpenGl_Context > &theGlCtx)
 Unbind frame buffer. More...
 
const Handle< OpenGl_Texture > & ColorTexture (const GLint theColorBufferIndex=0) const
 Returns the color texture for the given color buffer index. More...
 
const Handle< OpenGl_Texture > & DepthStencilTexture () const
 Returns the depth-stencil texture. More...
 
GLuint ColorRenderBuffer () const
 Returns the color Render Buffer. More...
 
GLuint DepthStencilRenderBuffer () const
 Returns the depth Render Buffer. More...
 
virtual Standard_Size EstimatedDataSize () const override
 Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules. More...
 
- Public Member Functions inherited from OpenGl_Resource
 OpenGl_Resource ()
 Empty constructor. More...
 
virtual ~OpenGl_Resource ()
 Destructor. Inheritors should call Clean (NULL) within it. More...
 
virtual void DumpJson (Standard_OStream &theOStream, Standard_Integer theDepth=-1) const
 Dumps the content of me into the stream. More...
 
- Public Member Functions inherited from Standard_Transient
 Standard_Transient ()
 Empty constructor. More...
 
 Standard_Transient (const Standard_Transient &)
 Copy constructor – does nothing. More...
 
Standard_Transientoperator= (const Standard_Transient &)
 Assignment operator, needed to avoid copying reference counter. More...
 
virtual ~Standard_Transient ()
 Destructor must be virtual. More...
 
virtual void Delete () const
 Memory deallocator for transient classes. More...
 
virtual const opencascade::handle< Standard_Type > & DynamicType () const
 Returns a type descriptor about this object. More...
 
Standard_Boolean IsInstance (const opencascade::handle< Standard_Type > &theType) const
 Returns a true value if this is an instance of Type. More...
 
Standard_Boolean IsInstance (const Standard_CString theTypeName) const
 Returns a true value if this is an instance of TypeName. More...
 
Standard_Boolean IsKind (const opencascade::handle< Standard_Type > &theType) const
 Returns true if this is an instance of Type or an instance of any class that inherits from Type. Note that multiple inheritance is not supported by OCCT RTTI mechanism. More...
 
Standard_Boolean IsKind (const Standard_CString theTypeName) const
 Returns true if this is an instance of TypeName or an instance of any class that inherits from TypeName. Note that multiple inheritance is not supported by OCCT RTTI mechanism. More...
 
Standard_TransientThis () const
 Returns non-const pointer to this object (like const_cast). For protection against creating handle to objects allocated in stack or call from constructor, it will raise exception Standard_ProgramError if reference counter is zero. More...
 
Standard_Integer GetRefCount () const
 Get the reference counter of this object. More...
 
void IncrementRefCounter () const
 Increments the reference counter of this object. More...
 
Standard_Integer DecrementRefCounter () const
 Decrements the reference counter of this object; returns the decremented value. More...
 

Static Public Member Functions

static Standard_Boolean BufferDump (const Handle< OpenGl_Context > &theGlCtx, const Handle< OpenGl_FrameBuffer > &theFbo, Image_PixMap &theImage, Graphic3d_BufferType theBufferType)
 Dump content into image. More...
 
- Static Public Member Functions inherited from Standard_Transient
static const char * get_type_name ()
 Returns a type descriptor about this object. More...
 
static const opencascade::handle< Standard_Type > & get_type_descriptor ()
 Returns type descriptor of Standard_Transient class. More...
 

Static Public Attributes

static const GLuint NO_FRAMEBUFFER = 0
 Helpful constants. More...
 
static const GLuint NO_RENDERBUFFER = 0
 

Protected Types

typedef NCollection_Vector< Handle< OpenGl_Texture > > OpenGl_TextureArray
 

Protected Member Functions

Standard_Boolean isValidFrameBuffer () const
 

Protected Attributes

GLsizei myInitVPSizeX
 viewport width specified during initialization (kept even on failure) More...
 
GLsizei myInitVPSizeY
 viewport height specified during initialization (kept even on failure) More...
 
GLsizei myVPSizeX
 viewport width (should be <= texture width) More...
 
GLsizei myVPSizeY
 viewport height (should be <= texture height) More...
 
GLsizei myNbSamples
 number of MSAA samples More...
 
OpenGl_ColorFormats myColorFormats
 sized format for color texture, GL_RGBA8 by default More...
 
GLint myDepthFormat
 sized format for depth-stencil texture, GL_DEPTH24_STENCIL8 by default More...
 
GLuint myGlFBufferId
 FBO object ID. More...
 
GLuint myGlColorRBufferId
 color Render Buffer object (alternative to myColorTexture) More...
 
GLuint myGlDepthRBufferId
 depth-stencil Render Buffer object (alternative to myDepthStencilTexture) More...
 
bool myIsOwnBuffer
 flag indicating that FBO should be deallocated by this class More...
 
bool myIsOwnDepth
 flag indicating that FBO should be deallocated by this class More...
 
OpenGl_TextureArray myColorTextures
 color texture objects More...
 
Handle< OpenGl_TexturemyDepthStencilTexture
 depth-stencil texture object More...
 

Additional Inherited Members

- Public Types inherited from Standard_Transient
typedef void base_type
 Returns a type descriptor about this object. More...
 

Detailed Description

Class implements FrameBuffer Object (FBO) resource intended for off-screen rendering.

Member Typedef Documentation

◆ OpenGl_TextureArray

Constructor & Destructor Documentation

◆ OpenGl_FrameBuffer()

OpenGl_FrameBuffer::OpenGl_FrameBuffer ( )

Empty constructor.

◆ ~OpenGl_FrameBuffer()

virtual OpenGl_FrameBuffer::~OpenGl_FrameBuffer ( )
virtual

Destructor.

Member Function Documentation

◆ BindBuffer()

virtual void OpenGl_FrameBuffer::BindBuffer ( const Handle< OpenGl_Context > &  theGlCtx)
virtual

Bind frame buffer for drawing and reading (to render into the texture).

◆ BindDrawBuffer()

virtual void OpenGl_FrameBuffer::BindDrawBuffer ( const Handle< OpenGl_Context > &  theGlCtx)
virtual

Bind frame buffer for drawing GL_DRAW_FRAMEBUFFER (to render into the texture).

◆ BindReadBuffer()

virtual void OpenGl_FrameBuffer::BindReadBuffer ( const Handle< OpenGl_Context > &  theGlCtx)
virtual

Bind frame buffer for reading GL_READ_FRAMEBUFFER.

◆ BufferDump()

static Standard_Boolean OpenGl_FrameBuffer::BufferDump ( const Handle< OpenGl_Context > &  theGlCtx,
const Handle< OpenGl_FrameBuffer > &  theFbo,
Image_PixMap theImage,
Graphic3d_BufferType  theBufferType 
)
static

Dump content into image.

Parameters
theGlCtxbound OpenGL context
theFboFBO to dump (or window buffer, if NULL)
theImagetarget image
theBufferTypebuffer type (attachment) to dump
Returns
TRUE on success

◆ ChangeViewport()

void OpenGl_FrameBuffer::ChangeViewport ( const GLsizei  theVPSizeX,
const GLsizei  theVPSizeY 
)

Override viewport settings.

◆ ColorRenderBuffer()

GLuint OpenGl_FrameBuffer::ColorRenderBuffer ( ) const
inline

Returns the color Render Buffer.

◆ ColorTexture()

const Handle< OpenGl_Texture >& OpenGl_FrameBuffer::ColorTexture ( const GLint  theColorBufferIndex = 0) const
inline

Returns the color texture for the given color buffer index.

◆ DepthStencilRenderBuffer()

GLuint OpenGl_FrameBuffer::DepthStencilRenderBuffer ( ) const
inline

Returns the depth Render Buffer.

◆ DepthStencilTexture()

const Handle< OpenGl_Texture >& OpenGl_FrameBuffer::DepthStencilTexture ( ) const
inline

Returns the depth-stencil texture.

◆ EstimatedDataSize()

virtual Standard_Size OpenGl_FrameBuffer::EstimatedDataSize ( ) const
overridevirtual

Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules.

Implements OpenGl_Resource.

◆ GetInitVPSizeX()

GLsizei OpenGl_FrameBuffer::GetInitVPSizeX ( ) const
inline

Viewport width.

◆ GetInitVPSizeY()

GLsizei OpenGl_FrameBuffer::GetInitVPSizeY ( ) const
inline

Viewport height.

◆ GetSizeX()

GLsizei OpenGl_FrameBuffer::GetSizeX ( ) const
inline

Textures width.

◆ GetSizeY()

GLsizei OpenGl_FrameBuffer::GetSizeY ( ) const
inline

Textures height.

◆ GetVPSizeX()

GLsizei OpenGl_FrameBuffer::GetVPSizeX ( ) const
inline

Viewport width.

◆ GetVPSizeY()

GLsizei OpenGl_FrameBuffer::GetVPSizeY ( ) const
inline

Viewport height.

◆ HasColor()

bool OpenGl_FrameBuffer::HasColor ( ) const
inline

Return true if FBO has been created with color attachment.

◆ HasDepth()

bool OpenGl_FrameBuffer::HasDepth ( ) const
inline

Return true if FBO has been created with depth attachment.

◆ Init() [1/3]

Standard_Boolean OpenGl_FrameBuffer::Init ( const Handle< OpenGl_Context > &  theGlCtx,
const GLsizei  theSizeX,
const GLsizei  theSizeY,
const OpenGl_ColorFormats theColorFormats,
const Handle< OpenGl_Texture > &  theDepthStencilTexture,
const GLsizei  theNbSamples = 0 
)

Initialize FBO for rendering into single/multiple color buffer and depth textures.

Parameters
theGlCtxcurrently bound OpenGL context
theSizeXtexture width
theSizeYtexture height
theColorFormatslist of color texture sized format (0 means no color attachment), e.g. GL_RGBA8
theDepthStencilTexturedepth-stencil texture
theNbSamplesMSAA number of samples (0 means normal texture)
Returns
true on success

◆ Init() [2/3]

Standard_Boolean OpenGl_FrameBuffer::Init ( const Handle< OpenGl_Context > &  theGlCtx,
const GLsizei  theSizeX,
const GLsizei  theSizeY,
const GLint  theColorFormat,
const GLint  theDepthFormat,
const GLsizei  theNbSamples = 0 
)

Initialize FBO for rendering into textures.

Parameters
theGlCtxcurrently bound OpenGL context
theSizeXtexture width
theSizeYtexture height
theColorFormatcolor texture sized format (0 means no color attachment), e.g. GL_RGBA8
theDepthFormatdepth-stencil texture sized format (0 means no depth attachment), e.g. GL_DEPTH24_STENCIL8
theNbSamplesMSAA number of samples (0 means normal texture)
Returns
true on success

◆ Init() [3/3]

Standard_Boolean OpenGl_FrameBuffer::Init ( const Handle< OpenGl_Context > &  theGlCtx,
const GLsizei  theSizeX,
const GLsizei  theSizeY,
const OpenGl_ColorFormats theColorFormats,
const GLint  theDepthFormat,
const GLsizei  theNbSamples = 0 
)

Initialize FBO for rendering into single/multiple color buffer and depth textures.

Parameters
theGlCtxcurrently bound OpenGL context
theSizeXtexture width
theSizeYtexture height
theColorFormatslist of color texture sized format (0 means no color attachment), e.g. GL_RGBA8
theDepthFormatdepth-stencil texture sized format (0 means no depth attachment), e.g. GL_DEPTH24_STENCIL8
theNbSamplesMSAA number of samples (0 means normal texture)
Returns
true on success

◆ InitLazy() [1/3]

Standard_Boolean OpenGl_FrameBuffer::InitLazy ( const Handle< OpenGl_Context > &  theGlCtx,
const GLsizei  theViewportSizeX,
const GLsizei  theViewportSizeY,
const GLint  theColorFormat,
const GLint  theDepthFormat,
const GLsizei  theNbSamples = 0 
)

(Re-)initialize FBO with specified dimensions.

◆ InitLazy() [2/3]

Standard_Boolean OpenGl_FrameBuffer::InitLazy ( const Handle< OpenGl_Context > &  theGlCtx,
const GLsizei  theViewportSizeX,
const GLsizei  theViewportSizeY,
const OpenGl_ColorFormats theColorFormats,
const GLint  theDepthFormat,
const GLsizei  theNbSamples = 0 
)

(Re-)initialize FBO with specified dimensions.

◆ InitLazy() [3/3]

Standard_Boolean OpenGl_FrameBuffer::InitLazy ( const Handle< OpenGl_Context > &  theGlCtx,
const OpenGl_FrameBuffer theFbo 
)
inline

(Re-)initialize FBO with properties taken from another FBO.

◆ InitWithRB()

Standard_Boolean OpenGl_FrameBuffer::InitWithRB ( const Handle< OpenGl_Context > &  theGlCtx,
const GLsizei  theSizeX,
const GLsizei  theSizeY,
const GLint  theColorFormat,
const GLint  theDepthFormat,
const GLuint  theColorRBufferFromWindow = 0 
)

(Re-)initialize FBO with specified dimensions. The Render Buffer Objects will be used for Color, Depth and Stencil attachments (as opposite to textures).

Parameters
theGlCtxcurrently bound OpenGL context
theSizeXrender buffer width
theSizeYrender buffer height
theColorFormatcolor render buffer sized format, e.g. GL_RGBA8
theDepthFormatdepth-stencil render buffer sized format, e.g. GL_DEPTH24_STENCIL8
theColorRBufferFromWindowwhen specified - should be ID of already initialized RB object, which will be released within this class

◆ InitWrapper()

Standard_Boolean OpenGl_FrameBuffer::InitWrapper ( const Handle< OpenGl_Context > &  theGlCtx)

Initialize class from currently bound FBO. Retrieved OpenGL objects will not be destroyed on Release.

◆ IsValid()

Standard_Boolean OpenGl_FrameBuffer::IsValid ( ) const
inline

Returns true if current object was initialized.

◆ isValidFrameBuffer()

Standard_Boolean OpenGl_FrameBuffer::isValidFrameBuffer ( ) const
inlineprotected

◆ NbColorBuffers()

GLsizei OpenGl_FrameBuffer::NbColorBuffers ( ) const
inline

Number of color buffers.

◆ NbSamples()

GLsizei OpenGl_FrameBuffer::NbSamples ( ) const
inline

Number of multisampling samples.

◆ Release()

virtual void OpenGl_FrameBuffer::Release ( OpenGl_Context theGlCtx)
overridevirtual

Destroy object - will release GPU memory if any.

Implements OpenGl_Resource.

◆ SetupViewport()

void OpenGl_FrameBuffer::SetupViewport ( const Handle< OpenGl_Context > &  theGlCtx)

Setup viewport to render into FBO.

◆ UnbindBuffer()

virtual void OpenGl_FrameBuffer::UnbindBuffer ( const Handle< OpenGl_Context > &  theGlCtx)
virtual

Unbind frame buffer.

Field Documentation

◆ myColorFormats

OpenGl_ColorFormats OpenGl_FrameBuffer::myColorFormats
protected

sized format for color texture, GL_RGBA8 by default

◆ myColorTextures

OpenGl_TextureArray OpenGl_FrameBuffer::myColorTextures
protected

color texture objects

◆ myDepthFormat

GLint OpenGl_FrameBuffer::myDepthFormat
protected

sized format for depth-stencil texture, GL_DEPTH24_STENCIL8 by default

◆ myDepthStencilTexture

Handle< OpenGl_Texture > OpenGl_FrameBuffer::myDepthStencilTexture
protected

depth-stencil texture object

◆ myGlColorRBufferId

GLuint OpenGl_FrameBuffer::myGlColorRBufferId
protected

color Render Buffer object (alternative to myColorTexture)

◆ myGlDepthRBufferId

GLuint OpenGl_FrameBuffer::myGlDepthRBufferId
protected

depth-stencil Render Buffer object (alternative to myDepthStencilTexture)

◆ myGlFBufferId

GLuint OpenGl_FrameBuffer::myGlFBufferId
protected

FBO object ID.

◆ myInitVPSizeX

GLsizei OpenGl_FrameBuffer::myInitVPSizeX
protected

viewport width specified during initialization (kept even on failure)

◆ myInitVPSizeY

GLsizei OpenGl_FrameBuffer::myInitVPSizeY
protected

viewport height specified during initialization (kept even on failure)

◆ myIsOwnBuffer

bool OpenGl_FrameBuffer::myIsOwnBuffer
protected

flag indicating that FBO should be deallocated by this class

◆ myIsOwnDepth

bool OpenGl_FrameBuffer::myIsOwnDepth
protected

flag indicating that FBO should be deallocated by this class

◆ myNbSamples

GLsizei OpenGl_FrameBuffer::myNbSamples
protected

number of MSAA samples

◆ myVPSizeX

GLsizei OpenGl_FrameBuffer::myVPSizeX
protected

viewport width (should be <= texture width)

◆ myVPSizeY

GLsizei OpenGl_FrameBuffer::myVPSizeY
protected

viewport height (should be <= texture height)

◆ NO_FRAMEBUFFER

const GLuint OpenGl_FrameBuffer::NO_FRAMEBUFFER = 0
static

Helpful constants.

◆ NO_RENDERBUFFER

const GLuint OpenGl_FrameBuffer::NO_RENDERBUFFER = 0
static

The documentation for this class was generated from the following file: