Open CASCADE Technology 7.8.2.dev
OpenGl_VertexBuffer Class Reference

Vertex Buffer Object - is a general storage object for vertex attributes (position, normal, color). Notice that you should use OpenGl_IndexBuffer specialization for array of indices. More...

#include <OpenGl_VertexBuffer.hxx>

Inheritance diagram for OpenGl_VertexBuffer:

Public Member Functions

 OpenGl_VertexBuffer ()
 Create uninitialized VBO.
 
virtual ~OpenGl_VertexBuffer ()
 Destroy object.
 
virtual unsigned int GetTarget () const override
 Return buffer target GL_ARRAY_BUFFER.
 
void BindVertexAttrib (const Handle< OpenGl_Context > &theGlCtx, const unsigned int theAttribLoc) const
 Bind this VBO to active GLSL program.
 
void UnbindVertexAttrib (const Handle< OpenGl_Context > &theGlCtx, const unsigned int theAttribLoc) const
 Unbind any VBO from active GLSL program.
 
void BindAttribute (const Handle< OpenGl_Context > &theCtx, const Graphic3d_TypeOfAttribute theMode) const
 Bind this VBO and enable specified attribute in OpenGl_Context::ActiveProgram() or FFP.
 
void UnbindAttribute (const Handle< OpenGl_Context > &theCtx, const Graphic3d_TypeOfAttribute theMode) const
 Unbind this VBO and disable specified attribute in OpenGl_Context::ActiveProgram() or FFP.
 
methods for interleaved attributes array
virtual bool HasColorAttribute () const
 
virtual bool HasNormalAttribute () const
 
virtual void BindAllAttributes (const Handle< OpenGl_Context > &theGlCtx) const
 Bind all vertex attributes to active program OpenGl_Context::ActiveProgram() or for FFP. Default implementation does nothing.
 
virtual void BindPositionAttribute (const Handle< OpenGl_Context > &theGlCtx) const
 Bind vertex position attribute only. Default implementation does nothing.
 
virtual void UnbindAllAttributes (const Handle< OpenGl_Context > &theGlCtx) const
 Unbind all vertex attributes. Default implementation does nothing.
 
- Public Member Functions inherited from OpenGl_Buffer
 OpenGl_Buffer ()
 Create uninitialized buffer.
 
virtual ~OpenGl_Buffer ()
 Destroy object.
 
virtual bool IsVirtual () const
 Return TRUE if this is a virtual (for backward compatibility) VBO object.
 
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)!
 
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.
 
virtual void Release (OpenGl_Context *theGlCtx) override
 Destroy object - will release GPU memory if any.
 
virtual void Bind (const Handle< OpenGl_Context > &theGlCtx) const
 Bind this buffer object.
 
virtual void Unbind (const Handle< OpenGl_Context > &theGlCtx) const
 Unbind this buffer object.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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().
 
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.
 
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().
 
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.
 
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().
 
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.
 
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().
 
virtual Standard_Size EstimatedDataSize () const override
 Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules.
 
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.
 
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.
 
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.
 
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.
 
virtual void DumpJson (Standard_OStream &theOStream, Standard_Integer theDepth=-1) const override
 Dumps the content of me into the stream.
 
- Public Member Functions inherited from OpenGl_Resource
 OpenGl_Resource ()
 Empty constructor.
 
virtual ~OpenGl_Resource ()
 Destructor. Inheritors should call Clean (NULL) within it.
 
- Public Member Functions inherited from Standard_Transient
 Standard_Transient ()
 Empty constructor.
 
 Standard_Transient (const Standard_Transient &)
 Copy constructor – does nothing.
 
Standard_Transientoperator= (const Standard_Transient &)
 Assignment operator, needed to avoid copying reference counter.
 
virtual ~Standard_Transient ()
 Destructor must be virtual.
 
virtual const opencascade::handle< Standard_Type > & DynamicType () const
 Returns a type descriptor about this object.
 
Standard_Boolean IsInstance (const opencascade::handle< Standard_Type > &theType) const
 Returns a true value if this is an instance of Type.
 
Standard_Boolean IsInstance (const Standard_CString theTypeName) const
 Returns a true value if this is an instance of TypeName.
 
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.
 
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.
 
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.
 
Standard_Integer GetRefCount () const noexcept
 Get the reference counter of this object.
 
void IncrementRefCounter () noexcept
 Increments the reference counter of this object.
 
Standard_Integer DecrementRefCounter () noexcept
 Decrements the reference counter of this object; returns the decremented value.
 
virtual void Delete () const
 Memory deallocator for transient classes.
 

advanced methods

static void bindAttribute (const Handle< OpenGl_Context > &theGlCtx, const Graphic3d_TypeOfAttribute theMode, const Standard_Integer theNbComp, const unsigned int theDataType, const Standard_Integer theStride, const void *theOffset)
 Setup array pointer - either for active GLSL program OpenGl_Context::ActiveProgram() or for FFP using bindFixed() when no program bound.
 
static void unbindAttribute (const Handle< OpenGl_Context > &theGlCtx, const Graphic3d_TypeOfAttribute theMode)
 Disable GLSL array pointer - either for active GLSL program OpenGl_Context::ActiveProgram() or for FFP using unbindFixed() when no program bound.
 

Additional Inherited Members

- Public Types inherited from Standard_Transient
typedef void base_type
 Returns a type descriptor about this object.
 
- Static Public Member Functions inherited from OpenGl_Buffer
static TCollection_AsciiString FormatTarget (unsigned int theTarget)
 Format VBO target enumeration value.
 
static size_t sizeOfGlType (unsigned int theType)
 
- Static Public Member Functions inherited from Standard_Transient
static constexpr const char * get_type_name ()
 Returns a type descriptor about this object.
 
static const opencascade::handle< Standard_Type > & get_type_descriptor ()
 Returns type descriptor of Standard_Transient class.
 
- Static Public Attributes inherited from OpenGl_Buffer
static const unsigned int NO_BUFFER = 0
 Helpful constants.
 
- Protected Member Functions inherited from OpenGl_Buffer
void BindBufferBase (const Handle< OpenGl_Context > &theGlCtx, unsigned int theIndex)
 Binds a buffer object to an indexed buffer target. Wrapper for glBindBufferBase().
 
void UnbindBufferBase (const Handle< OpenGl_Context > &theGlCtx, unsigned int theIndex)
 Unbinds a buffer object from an indexed buffer target. Wrapper for glBindBufferBase().
 
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().
 
- Protected Attributes inherited from OpenGl_Buffer
Standard_BytemyOffset
 offset to data
 
unsigned int myBufferId
 VBO name (index)
 
unsigned int myComponentsNb
 Number of components per generic vertex attribute, must be 1, 2, 3, or 4.
 
Standard_Integer myElemsNb
 Number of vertex attributes / number of vertices.
 
unsigned int myDataType
 Data type (GL_FLOAT, GL_UNSIGNED_INT, GL_UNSIGNED_BYTE etc.)
 

Detailed Description

Vertex Buffer Object - is a general storage object for vertex attributes (position, normal, color). Notice that you should use OpenGl_IndexBuffer specialization for array of indices.

Constructor & Destructor Documentation

◆ OpenGl_VertexBuffer()

OpenGl_VertexBuffer::OpenGl_VertexBuffer ( )

Create uninitialized VBO.

◆ ~OpenGl_VertexBuffer()

virtual OpenGl_VertexBuffer::~OpenGl_VertexBuffer ( )
virtual

Destroy object.

Member Function Documentation

◆ BindAllAttributes()

virtual void OpenGl_VertexBuffer::BindAllAttributes ( const Handle< OpenGl_Context > & theGlCtx) const
virtual

Bind all vertex attributes to active program OpenGl_Context::ActiveProgram() or for FFP. Default implementation does nothing.

◆ BindAttribute()

void OpenGl_VertexBuffer::BindAttribute ( const Handle< OpenGl_Context > & theCtx,
const Graphic3d_TypeOfAttribute theMode ) const
inline

Bind this VBO and enable specified attribute in OpenGl_Context::ActiveProgram() or FFP.

Parameters
theGlCtx- handle to bound GL context;
theMode- array mode (GL_VERTEX_ARRAY, GL_NORMAL_ARRAY, GL_COLOR_ARRAY, GL_INDEX_ARRAY, GL_TEXTURE_COORD_ARRAY).

◆ bindAttribute()

static void OpenGl_VertexBuffer::bindAttribute ( const Handle< OpenGl_Context > & theGlCtx,
const Graphic3d_TypeOfAttribute theMode,
const Standard_Integer theNbComp,
const unsigned int theDataType,
const Standard_Integer theStride,
const void * theOffset )
static

Setup array pointer - either for active GLSL program OpenGl_Context::ActiveProgram() or for FFP using bindFixed() when no program bound.

◆ BindPositionAttribute()

virtual void OpenGl_VertexBuffer::BindPositionAttribute ( const Handle< OpenGl_Context > & theGlCtx) const
virtual

Bind vertex position attribute only. Default implementation does nothing.

◆ BindVertexAttrib()

void OpenGl_VertexBuffer::BindVertexAttrib ( const Handle< OpenGl_Context > & theGlCtx,
const unsigned int theAttribLoc ) const

Bind this VBO to active GLSL program.

◆ GetTarget()

virtual unsigned int OpenGl_VertexBuffer::GetTarget ( ) const
overridevirtual

Return buffer target GL_ARRAY_BUFFER.

Implements OpenGl_Buffer.

◆ HasColorAttribute()

virtual bool OpenGl_VertexBuffer::HasColorAttribute ( ) const
virtual
Returns
true if buffer contains per-vertex color attribute

◆ HasNormalAttribute()

virtual bool OpenGl_VertexBuffer::HasNormalAttribute ( ) const
virtual
Returns
true if buffer contains per-vertex normal attribute

◆ UnbindAllAttributes()

virtual void OpenGl_VertexBuffer::UnbindAllAttributes ( const Handle< OpenGl_Context > & theGlCtx) const
virtual

Unbind all vertex attributes. Default implementation does nothing.

◆ UnbindAttribute()

void OpenGl_VertexBuffer::UnbindAttribute ( const Handle< OpenGl_Context > & theCtx,
const Graphic3d_TypeOfAttribute theMode ) const
inline

Unbind this VBO and disable specified attribute in OpenGl_Context::ActiveProgram() or FFP.

Parameters
theCtxhandle to bound GL context
theModearray mode

◆ unbindAttribute()

static void OpenGl_VertexBuffer::unbindAttribute ( const Handle< OpenGl_Context > & theGlCtx,
const Graphic3d_TypeOfAttribute theMode )
static

Disable GLSL array pointer - either for active GLSL program OpenGl_Context::ActiveProgram() or for FFP using unbindFixed() when no program bound.

◆ UnbindVertexAttrib()

void OpenGl_VertexBuffer::UnbindVertexAttrib ( const Handle< OpenGl_Context > & theGlCtx,
const unsigned int theAttribLoc ) const

Unbind any VBO from active GLSL program.


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