Open CASCADE Technology  7.7.0
Public Member Functions | Static Public Member Functions | Static Public Attributes
OpenGl_Buffer Class Referenceabstract

Buffer Object - is a general storage object for arbitrary data (see sub-classes). More...

#include <OpenGl_Buffer.hxx>

Inheritance diagram for OpenGl_Buffer:
Inheritance graph
[legend]

Public Member Functions

 OpenGl_Buffer ()
 Create uninitialized buffer. More...
 
virtual ~OpenGl_Buffer ()
 Destroy object. More...
 
virtual unsigned int GetTarget () const =0
 Return buffer target. More...
 
virtual bool IsVirtual () const
 Return TRUE if this is a virtual (for backward compatibility) VBO object. More...
 
bool IsValid () const
 
unsigned int GetComponentsNb () const
 
Standard_Integer GetElemsNb () const
 
void SetElemsNb (Standard_Integer theNbElems)
 Overrides the number of vertex attributes / number of vertexes. It is up to user specifying this number correct (e.g. below initial value)! More...
 
unsigned int GetDataType () const
 
Standard_ByteGetDataOffset () const
 
virtual bool Create (const Handle< OpenGl_Context > &theGlCtx)
 Creates buffer object name (id) if not yet generated. Data should be initialized by another method. More...
 
virtual void Release (OpenGl_Context *theGlCtx) override
 Destroy object - will release GPU memory if any. More...
 
virtual void Bind (const Handle< OpenGl_Context > &theGlCtx) const
 Bind this buffer object. More...
 
virtual void Unbind (const Handle< OpenGl_Context > &theGlCtx) const
 Unbind this buffer object. More...
 
bool Init (const Handle< OpenGl_Context > &theGlCtx, const unsigned int theComponentsNb, const Standard_Integer theElemsNb, const float *theData)
 Notice that buffer object will be unbound after this call. More...
 
bool Init (const Handle< OpenGl_Context > &theGlCtx, const unsigned int theComponentsNb, const Standard_Integer theElemsNb, const unsigned int *theData)
 Notice that buffer object will be unbound after this call. More...
 
bool Init (const Handle< OpenGl_Context > &theGlCtx, const unsigned int theComponentsNb, const Standard_Integer theElemsNb, const unsigned short *theData)
 Notice that buffer object will be unbound after this call. More...
 
bool Init (const Handle< OpenGl_Context > &theGlCtx, const unsigned int theComponentsNb, const Standard_Integer theElemsNb, const Standard_Byte *theData)
 Notice that buffer object will be unbound after this call. More...
 
bool SubData (const Handle< OpenGl_Context > &theGlCtx, const Standard_Integer theElemFrom, const Standard_Integer theElemsNb, const float *theData)
 Notice that buffer object will be unbound after this call. Function replaces portion of data within this buffer object using glBufferSubData(). The buffer object should be initialized before call. More...
 
bool GetSubData (const Handle< OpenGl_Context > &theGlCtx, const Standard_Integer theElemFrom, const Standard_Integer theElemsNb, float *theData)
 Read back buffer sub-range. Notice that buffer object will be unbound after this call. Function reads portion of data from this buffer object using glGetBufferSubData(). More...
 
bool SubData (const Handle< OpenGl_Context > &theGlCtx, const Standard_Integer theElemFrom, const Standard_Integer theElemsNb, const unsigned int *theData)
 Notice that buffer object will be unbound after this call. Function replaces portion of data within this buffer object using glBufferSubData(). The buffer object should be initialized before call. More...
 
bool GetSubData (const Handle< OpenGl_Context > &theGlCtx, const Standard_Integer theElemFrom, const Standard_Integer theElemsNb, unsigned int *theData)
 Read back buffer sub-range. Notice that buffer object will be unbound after this call. Function reads portion of data from this buffer object using glGetBufferSubData(). More...
 
bool SubData (const Handle< OpenGl_Context > &theGlCtx, const Standard_Integer theElemFrom, const Standard_Integer theElemsNb, const unsigned short *theData)
 Notice that buffer object will be unbound after this call. Function replaces portion of data within this buffer object using glBufferSubData(). The buffer object should be initialized before call. More...
 
bool GetSubData (const Handle< OpenGl_Context > &theGlCtx, const Standard_Integer theElemFrom, const Standard_Integer theElemsNb, unsigned short *theData)
 Read back buffer sub-range. Notice that buffer object will be unbound after this call. Function reads portion of data from this buffer object using glGetBufferSubData(). More...
 
bool SubData (const Handle< OpenGl_Context > &theGlCtx, const Standard_Integer theElemFrom, const Standard_Integer theElemsNb, const Standard_Byte *theData)
 Notice that buffer object will be unbound after this call. Function replaces portion of data within this buffer object using glBufferSubData(). The buffer object should be initialized before call. More...
 
bool GetSubData (const Handle< OpenGl_Context > &theGlCtx, const Standard_Integer theElemFrom, const Standard_Integer theElemsNb, Standard_Byte *theData)
 Read back buffer sub-range. Notice that buffer object will be unbound after this call. Function reads portion of data from this buffer object using glGetBufferSubData(). 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...
 
- 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 TCollection_AsciiString FormatTarget (unsigned int theTarget)
 Format VBO target enumeration value. 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 unsigned int NO_BUFFER = 0
 Helpful constants. More...
 

advanced methods

Standard_BytemyOffset
 offset to data More...
 
unsigned int myBufferId
 VBO name (index) More...
 
unsigned int myComponentsNb
 Number of components per generic vertex attribute, must be 1, 2, 3, or 4. More...
 
Standard_Integer myElemsNb
 Number of vertex attributes / number of vertices. More...
 
unsigned int myDataType
 Data type (GL_FLOAT, GL_UNSIGNED_INT, GL_UNSIGNED_BYTE etc.) More...
 
static size_t sizeOfGlType (unsigned int theType)
 
virtual Standard_Size EstimatedDataSize () const override
 Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules. More...
 
virtual bool init (const Handle< OpenGl_Context > &theGlCtx, const unsigned int theComponentsNb, const Standard_Integer theElemsNb, const void *theData, const unsigned int theDataType, const Standard_Integer theStride)
 Initialize buffer with new data. More...
 
bool init (const Handle< OpenGl_Context > &theGlCtx, const unsigned int theComponentsNb, const Standard_Integer theElemsNb, const void *theData, const unsigned int theDataType)
 Initialize buffer with new data. More...
 
virtual bool subData (const Handle< OpenGl_Context > &theGlCtx, const Standard_Integer theElemFrom, const Standard_Integer theElemsNb, const void *theData, const unsigned int theDataType)
 Update part of the buffer with new data. More...
 
virtual bool getSubData (const Handle< OpenGl_Context > &theGlCtx, const Standard_Integer theElemFrom, const Standard_Integer theElemsNb, void *theData, const unsigned int theDataType)
 Read back buffer sub-range. More...
 
virtual void DumpJson (Standard_OStream &theOStream, Standard_Integer theDepth=-1) const override
 Dumps the content of me into the stream. More...
 
void BindBufferBase (const Handle< OpenGl_Context > &theGlCtx, unsigned int theIndex)
 Binds a buffer object to an indexed buffer target. Wrapper for glBindBufferBase(). More...
 
void UnbindBufferBase (const Handle< OpenGl_Context > &theGlCtx, unsigned int theIndex)
 Unbinds a buffer object from an indexed buffer target. Wrapper for glBindBufferBase(). More...
 
void BindBufferRange (const Handle< OpenGl_Context > &theGlCtx, unsigned int theIndex, const intptr_t theOffset, const size_t theSize)
 Binds a buffer object to an indexed buffer target with specified offset and size. Wrapper for glBindBufferRange(). More...
 

Additional Inherited Members

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

Detailed Description

Buffer Object - is a general storage object for arbitrary data (see sub-classes).

Constructor & Destructor Documentation

◆ OpenGl_Buffer()

OpenGl_Buffer::OpenGl_Buffer ( )

Create uninitialized buffer.

◆ ~OpenGl_Buffer()

virtual OpenGl_Buffer::~OpenGl_Buffer ( )
virtual

Destroy object.

Member Function Documentation

◆ Bind()

virtual void OpenGl_Buffer::Bind ( const Handle< OpenGl_Context > &  theGlCtx) const
virtual

Bind this buffer object.

◆ BindBufferBase()

void OpenGl_Buffer::BindBufferBase ( const Handle< OpenGl_Context > &  theGlCtx,
unsigned int  theIndex 
)
protected

Binds a buffer object to an indexed buffer target. Wrapper for glBindBufferBase().

Parameters
theGlCtx[in] active OpenGL context
theIndex[in] index to bind

◆ BindBufferRange()

void OpenGl_Buffer::BindBufferRange ( const Handle< OpenGl_Context > &  theGlCtx,
unsigned int  theIndex,
const intptr_t  theOffset,
const size_t  theSize 
)
protected

Binds a buffer object to an indexed buffer target with specified offset and size. Wrapper for glBindBufferRange().

Parameters
theGlCtx[in] active OpenGL context
theIndex[in] index to bind (
See also
GL_MAX_UNIFORM_BUFFER_BINDINGS in case of uniform buffer)
Parameters
theOffset[in] offset within the buffer (
See also
GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT in case of uniform buffer)
Parameters
theSize[in] sub-section length starting from offset

◆ Create()

virtual bool OpenGl_Buffer::Create ( const Handle< OpenGl_Context > &  theGlCtx)
virtual

Creates buffer object name (id) if not yet generated. Data should be initialized by another method.

Reimplemented in OpenGl_TextureBuffer.

◆ DumpJson()

virtual void OpenGl_Buffer::DumpJson ( Standard_OStream theOStream,
Standard_Integer  theDepth = -1 
) const
overridevirtual

Dumps the content of me into the stream.

Reimplemented from OpenGl_Resource.

Reimplemented in OpenGl_IndexBuffer.

◆ EstimatedDataSize()

virtual Standard_Size OpenGl_Buffer::EstimatedDataSize ( ) const
inlineoverridevirtual

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

Implements OpenGl_Resource.

◆ FormatTarget()

static TCollection_AsciiString OpenGl_Buffer::FormatTarget ( unsigned int  theTarget)
static

Format VBO target enumeration value.

◆ GetComponentsNb()

unsigned int OpenGl_Buffer::GetComponentsNb ( ) const
inline
Returns
the number of components per generic vertex attribute.

◆ GetDataOffset()

Standard_Byte* OpenGl_Buffer::GetDataOffset ( ) const
inline
Returns
offset to data, NULL by default

◆ GetDataType()

unsigned int OpenGl_Buffer::GetDataType ( ) const
inline
Returns
data type of each component in the array.

◆ GetElemsNb()

Standard_Integer OpenGl_Buffer::GetElemsNb ( ) const
inline
Returns
number of vertex attributes / number of vertices specified within ::Init()

◆ GetSubData() [1/4]

bool OpenGl_Buffer::GetSubData ( const Handle< OpenGl_Context > &  theGlCtx,
const Standard_Integer  theElemFrom,
const Standard_Integer  theElemsNb,
float *  theData 
)

Read back buffer sub-range. Notice that buffer object will be unbound after this call. Function reads portion of data from this buffer object using glGetBufferSubData().

Parameters
theElemFrom[in] element id from which replace buffer data (>=0);
theElemsNb[in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
theData[out] destination pointer to float data.

◆ GetSubData() [2/4]

bool OpenGl_Buffer::GetSubData ( const Handle< OpenGl_Context > &  theGlCtx,
const Standard_Integer  theElemFrom,
const Standard_Integer  theElemsNb,
unsigned int *  theData 
)

Read back buffer sub-range. Notice that buffer object will be unbound after this call. Function reads portion of data from this buffer object using glGetBufferSubData().

Parameters
theElemFrom[in] element id from which replace buffer data (>=0);
theElemsNb[in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
theData[out] destination pointer to unsigned int data.

◆ GetSubData() [3/4]

bool OpenGl_Buffer::GetSubData ( const Handle< OpenGl_Context > &  theGlCtx,
const Standard_Integer  theElemFrom,
const Standard_Integer  theElemsNb,
unsigned short *  theData 
)

Read back buffer sub-range. Notice that buffer object will be unbound after this call. Function reads portion of data from this buffer object using glGetBufferSubData().

Parameters
theElemFrom[in] element id from which replace buffer data (>=0);
theElemsNb[in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
theData[out] destination pointer to unsigned short data.

◆ GetSubData() [4/4]

bool OpenGl_Buffer::GetSubData ( const Handle< OpenGl_Context > &  theGlCtx,
const Standard_Integer  theElemFrom,
const Standard_Integer  theElemsNb,
Standard_Byte theData 
)

Read back buffer sub-range. Notice that buffer object will be unbound after this call. Function reads portion of data from this buffer object using glGetBufferSubData().

Parameters
theElemFrom[in] element id from which replace buffer data (>=0);
theElemsNb[in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
theData[out] destination pointer to Standard_Byte data.

◆ getSubData()

virtual bool OpenGl_Buffer::getSubData ( const Handle< OpenGl_Context > &  theGlCtx,
const Standard_Integer  theElemFrom,
const Standard_Integer  theElemsNb,
void *  theData,
const unsigned int  theDataType 
)
virtual

Read back buffer sub-range.

◆ GetTarget()

virtual unsigned int OpenGl_Buffer::GetTarget ( ) const
pure virtual

◆ Init() [1/4]

bool OpenGl_Buffer::Init ( const Handle< OpenGl_Context > &  theGlCtx,
const unsigned int  theComponentsNb,
const Standard_Integer  theElemsNb,
const float *  theData 
)

Notice that buffer object will be unbound after this call.

Parameters
theComponentsNb[in] specifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
theElemsNb[in] elements count;
theData[in] pointer to float data (vertices/normals etc.).

◆ Init() [2/4]

bool OpenGl_Buffer::Init ( const Handle< OpenGl_Context > &  theGlCtx,
const unsigned int  theComponentsNb,
const Standard_Integer  theElemsNb,
const unsigned int *  theData 
)

Notice that buffer object will be unbound after this call.

Parameters
theComponentsNb[in] specifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
theElemsNb[in] elements count;
theData[in] pointer to unsigned int data (indices etc.).

◆ Init() [3/4]

bool OpenGl_Buffer::Init ( const Handle< OpenGl_Context > &  theGlCtx,
const unsigned int  theComponentsNb,
const Standard_Integer  theElemsNb,
const unsigned short *  theData 
)

Notice that buffer object will be unbound after this call.

Parameters
theComponentsNb[in] specifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
theElemsNb[in] elements count;
theData[in] pointer to unsigned short data (indices etc.).

◆ Init() [4/4]

bool OpenGl_Buffer::Init ( const Handle< OpenGl_Context > &  theGlCtx,
const unsigned int  theComponentsNb,
const Standard_Integer  theElemsNb,
const Standard_Byte theData 
)

Notice that buffer object will be unbound after this call.

Parameters
theComponentsNb[in] specifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
theElemsNb[in] elements count;
theData[in] pointer to Standard_Byte data (indices/colors etc.).

◆ init() [1/2]

virtual bool OpenGl_Buffer::init ( const Handle< OpenGl_Context > &  theGlCtx,
const unsigned int  theComponentsNb,
const Standard_Integer  theElemsNb,
const void *  theData,
const unsigned int  theDataType,
const Standard_Integer  theStride 
)
virtual

Initialize buffer with new data.

◆ init() [2/2]

bool OpenGl_Buffer::init ( const Handle< OpenGl_Context > &  theGlCtx,
const unsigned int  theComponentsNb,
const Standard_Integer  theElemsNb,
const void *  theData,
const unsigned int  theDataType 
)
inline

Initialize buffer with new data.

◆ IsValid()

bool OpenGl_Buffer::IsValid ( ) const
inline
Returns
true if current object was initialized

◆ IsVirtual()

virtual bool OpenGl_Buffer::IsVirtual ( ) const
inlinevirtual

Return TRUE if this is a virtual (for backward compatibility) VBO object.

◆ Release()

virtual void OpenGl_Buffer::Release ( OpenGl_Context theGlCtx)
overridevirtual

Destroy object - will release GPU memory if any.

Implements OpenGl_Resource.

Reimplemented in OpenGl_TextureBuffer.

◆ SetElemsNb()

void OpenGl_Buffer::SetElemsNb ( Standard_Integer  theNbElems)
inline

Overrides the number of vertex attributes / number of vertexes. It is up to user specifying this number correct (e.g. below initial value)!

◆ sizeOfGlType()

static size_t OpenGl_Buffer::sizeOfGlType ( unsigned int  theType)
static
Returns
size of specified GL type

◆ SubData() [1/4]

bool OpenGl_Buffer::SubData ( const Handle< OpenGl_Context > &  theGlCtx,
const Standard_Integer  theElemFrom,
const Standard_Integer  theElemsNb,
const float *  theData 
)

Notice that buffer object will be unbound after this call. Function replaces portion of data within this buffer object using glBufferSubData(). The buffer object should be initialized before call.

Parameters
theElemFrom[in] element id from which replace buffer data (>=0);
theElemsNb[in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
theData[in] pointer to float data.

◆ SubData() [2/4]

bool OpenGl_Buffer::SubData ( const Handle< OpenGl_Context > &  theGlCtx,
const Standard_Integer  theElemFrom,
const Standard_Integer  theElemsNb,
const unsigned int *  theData 
)

Notice that buffer object will be unbound after this call. Function replaces portion of data within this buffer object using glBufferSubData(). The buffer object should be initialized before call.

Parameters
theElemFrom[in] element id from which replace buffer data (>=0);
theElemsNb[in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
theData[in] pointer to unsigned int data.

◆ SubData() [3/4]

bool OpenGl_Buffer::SubData ( const Handle< OpenGl_Context > &  theGlCtx,
const Standard_Integer  theElemFrom,
const Standard_Integer  theElemsNb,
const unsigned short *  theData 
)

Notice that buffer object will be unbound after this call. Function replaces portion of data within this buffer object using glBufferSubData(). The buffer object should be initialized before call.

Parameters
theElemFrom[in] element id from which replace buffer data (>=0);
theElemsNb[in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
theData[in] pointer to unsigned short data.

◆ SubData() [4/4]

bool OpenGl_Buffer::SubData ( const Handle< OpenGl_Context > &  theGlCtx,
const Standard_Integer  theElemFrom,
const Standard_Integer  theElemsNb,
const Standard_Byte theData 
)

Notice that buffer object will be unbound after this call. Function replaces portion of data within this buffer object using glBufferSubData(). The buffer object should be initialized before call.

Parameters
theElemFrom[in] element id from which replace buffer data (>=0);
theElemsNb[in] elements count (theElemFrom + theElemsNb <= GetElemsNb());
theData[in] pointer to Standard_Byte data.

◆ subData()

virtual bool OpenGl_Buffer::subData ( const Handle< OpenGl_Context > &  theGlCtx,
const Standard_Integer  theElemFrom,
const Standard_Integer  theElemsNb,
const void *  theData,
const unsigned int  theDataType 
)
virtual

Update part of the buffer with new data.

◆ Unbind()

virtual void OpenGl_Buffer::Unbind ( const Handle< OpenGl_Context > &  theGlCtx) const
virtual

Unbind this buffer object.

◆ UnbindBufferBase()

void OpenGl_Buffer::UnbindBufferBase ( const Handle< OpenGl_Context > &  theGlCtx,
unsigned int  theIndex 
)
protected

Unbinds a buffer object from an indexed buffer target. Wrapper for glBindBufferBase().

Parameters
theGlCtx[in] active OpenGL context
theIndex[in] index to bind

Field Documentation

◆ myBufferId

unsigned int OpenGl_Buffer::myBufferId
protected

VBO name (index)

◆ myComponentsNb

unsigned int OpenGl_Buffer::myComponentsNb
protected

Number of components per generic vertex attribute, must be 1, 2, 3, or 4.

◆ myDataType

unsigned int OpenGl_Buffer::myDataType
protected

Data type (GL_FLOAT, GL_UNSIGNED_INT, GL_UNSIGNED_BYTE etc.)

◆ myElemsNb

Standard_Integer OpenGl_Buffer::myElemsNb
protected

Number of vertex attributes / number of vertices.

◆ myOffset

Standard_Byte* OpenGl_Buffer::myOffset
protected

offset to data

◆ NO_BUFFER

const unsigned int OpenGl_Buffer::NO_BUFFER = 0
static

Helpful constants.


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