Open CASCADE Technology  7.4.0
Public Member Functions | Static Public Attributes

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:
Inheritance graph
[legend]

Public Member Functions

 OpenGl_VertexBuffer ()
 Create uninitialized VBO. More...
 
virtual ~OpenGl_VertexBuffer ()
 Destroy object. More...
 
virtual GLenum GetTarget () const
 
virtual bool IsVirtual () const
 Return TRUE if this is a virtual (for backward compatibility) VBO object. More...
 
bool IsValid () const
 
GLuint GetComponentsNb () const
 
GLsizei GetElemsNb () const
 
void SetElemsNb (GLsizei 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...
 
GLenum GetDataType () const
 
GLubyte * GetDataOffset () const
 
virtual bool Create (const Handle< OpenGl_Context > &theGlCtx)
 Creates VBO 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 VBO. More...
 
virtual void Unbind (const Handle< OpenGl_Context > &theGlCtx) const
 Unbind this VBO. More...
 
bool Init (const Handle< OpenGl_Context > &theGlCtx, const GLuint theComponentsNb, const GLsizei theElemsNb, const GLfloat *theData)
 Notice that VBO will be unbound after this call. More...
 
bool Init (const Handle< OpenGl_Context > &theGlCtx, const GLuint theComponentsNb, const GLsizei theElemsNb, const GLuint *theData)
 Notice that VBO will be unbound after this call. More...
 
bool Init (const Handle< OpenGl_Context > &theGlCtx, const GLuint theComponentsNb, const GLsizei theElemsNb, const GLushort *theData)
 Notice that VBO will be unbound after this call. More...
 
bool Init (const Handle< OpenGl_Context > &theGlCtx, const GLuint theComponentsNb, const GLsizei theElemsNb, const GLubyte *theData)
 Notice that VBO will be unbound after this call. More...
 
bool SubData (const Handle< OpenGl_Context > &theGlCtx, const GLsizei theElemFrom, const GLsizei theElemsNb, const GLfloat *theData)
 Notice that VBO will be unbound after this call. Function replaces portion of data within this VBO using glBufferSubData(). The VBO should be initialized before call. More...
 
bool SubData (const Handle< OpenGl_Context > &theGlCtx, const GLsizei theElemFrom, const GLsizei theElemsNb, const GLuint *theData)
 Notice that VBO will be unbound after this call. Function replaces portion of data within this VBO using glBufferSubData(). The VBO should be initialized before call. More...
 
bool SubData (const Handle< OpenGl_Context > &theGlCtx, const GLsizei theElemFrom, const GLsizei theElemsNb, const GLushort *theData)
 Notice that VBO will be unbound after this call. Function replaces portion of data within this VBO using glBufferSubData(). The VBO should be initialized before call. More...
 
bool SubData (const Handle< OpenGl_Context > &theGlCtx, const GLsizei theElemFrom, const GLsizei theElemsNb, const GLubyte *theData)
 Notice that VBO will be unbound after this call. Function replaces portion of data within this VBO using glBufferSubData(). The VBO should be initialized before call. More...
 
void BindVertexAttrib (const Handle< OpenGl_Context > &theGlCtx, const GLuint theAttribLoc) const
 Bind this VBO to active GLSL program. More...
 
void UnbindVertexAttrib (const Handle< OpenGl_Context > &theGlCtx, const GLuint theAttribLoc) const
 Unbind any VBO from active GLSL program. More...
 
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. More...
 
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. 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 Attributes

static const GLuint NO_BUFFER = 0
 Helpful constants. More...
 

advanced methods

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 GLuint theComponentsNb, const GLsizei theElemsNb, const void *theData, const GLenum theDataType, const GLsizei theStride)
 Initialize buffer with new data. More...
 
bool init (const Handle< OpenGl_Context > &theGlCtx, const GLuint theComponentsNb, const GLsizei theElemsNb, const void *theData, const GLenum theDataType)
 Initialize buffer with new data. More...
 
virtual bool subData (const Handle< OpenGl_Context > &theGlCtx, const GLsizei theElemFrom, const GLsizei theElemsNb, const void *theData, const GLenum theDataType)
 Update part of the buffer with new data. More...
 
static size_t sizeOfGlType (const GLenum theType)
 
static void bindAttribute (const Handle< OpenGl_Context > &theGlCtx, const Graphic3d_TypeOfAttribute theMode, const GLint theNbComp, const GLenum theDataType, const GLsizei theStride, const GLvoid *theOffset)
 Setup array pointer - either for active GLSL program OpenGl_Context::ActiveProgram() or for FFP using bindFixed() when no program bound. More...
 
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. More...
 

methods for interleaved attributes array

GLubyte * myOffset
 offset to data More...
 
GLuint myBufferId
 VBO name (index) More...
 
GLuint myComponentsNb
 Number of components per generic vertex attribute, must be 1, 2, 3, or 4. More...
 
GLsizei myElemsNb
 Number of vertex attributes / number of vertices. More...
 
GLenum myDataType
 Data type (GL_FLOAT, GL_UNSIGNED_INT, GL_UNSIGNED_BYTE etc.) More...
 
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. More...
 
virtual void BindPositionAttribute (const Handle< OpenGl_Context > &theGlCtx) const
 Bind vertex position attribute only. Default implementation does nothing. More...
 
virtual void UnbindAllAttributes (const Handle< OpenGl_Context > &theGlCtx) const
 Unbind all vertex attributes. Default implementation does nothing. More...
 

Additional Inherited Members

- Public Types inherited from Standard_Transient
typedef void base_type
 Returns a type descriptor about this object. 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...
 

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

◆ Bind()

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

Bind this VBO.

Reimplemented in OpenGl_VertexBufferCompat.

◆ 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 GLint  theNbComp,
const GLenum  theDataType,
const GLsizei  theStride,
const GLvoid *  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 GLuint  theAttribLoc 
) const

Bind this VBO to active GLSL program.

◆ Create()

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

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

Reimplemented in OpenGl_TextureBufferArb, and OpenGl_VertexBufferCompat.

◆ EstimatedDataSize()

virtual Standard_Size OpenGl_VertexBuffer::EstimatedDataSize ( ) const
inlineoverridevirtual

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

Implements OpenGl_Resource.

◆ GetComponentsNb()

GLuint OpenGl_VertexBuffer::GetComponentsNb ( ) const
inline
Returns
the number of components per generic vertex attribute.

◆ GetDataOffset()

GLubyte* OpenGl_VertexBuffer::GetDataOffset ( ) const
inline
Returns
offset to data, NULL by default

◆ GetDataType()

GLenum OpenGl_VertexBuffer::GetDataType ( ) const
inline
Returns
data type of each component in the array.

◆ GetElemsNb()

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

◆ GetTarget()

virtual GLenum OpenGl_VertexBuffer::GetTarget ( ) const
virtual

◆ 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

◆ Init() [1/4]

bool OpenGl_VertexBuffer::Init ( const Handle< OpenGl_Context > &  theGlCtx,
const GLuint  theComponentsNb,
const GLsizei  theElemsNb,
const GLfloat *  theData 
)
inline

Notice that VBO will be unbound after this call.

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

◆ Init() [2/4]

bool OpenGl_VertexBuffer::Init ( const Handle< OpenGl_Context > &  theGlCtx,
const GLuint  theComponentsNb,
const GLsizei  theElemsNb,
const GLuint *  theData 
)
inline

Notice that VBO will be unbound after this call.

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

◆ Init() [3/4]

bool OpenGl_VertexBuffer::Init ( const Handle< OpenGl_Context > &  theGlCtx,
const GLuint  theComponentsNb,
const GLsizei  theElemsNb,
const GLushort *  theData 
)
inline

Notice that VBO will be unbound after this call.

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

◆ Init() [4/4]

bool OpenGl_VertexBuffer::Init ( const Handle< OpenGl_Context > &  theGlCtx,
const GLuint  theComponentsNb,
const GLsizei  theElemsNb,
const GLubyte *  theData 
)
inline

Notice that VBO will be unbound after this call.

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

◆ init() [1/2]

virtual bool OpenGl_VertexBuffer::init ( const Handle< OpenGl_Context > &  theGlCtx,
const GLuint  theComponentsNb,
const GLsizei  theElemsNb,
const void *  theData,
const GLenum  theDataType,
const GLsizei  theStride 
)
virtual

Initialize buffer with new data.

Reimplemented in OpenGl_VertexBufferCompat.

◆ init() [2/2]

bool OpenGl_VertexBuffer::init ( const Handle< OpenGl_Context > &  theGlCtx,
const GLuint  theComponentsNb,
const GLsizei  theElemsNb,
const void *  theData,
const GLenum  theDataType 
)
inline

Initialize buffer with new data.

◆ IsValid()

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

◆ IsVirtual()

virtual bool OpenGl_VertexBuffer::IsVirtual ( ) const
inlinevirtual

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

Reimplemented in OpenGl_VertexBufferCompat.

◆ Release()

virtual void OpenGl_VertexBuffer::Release ( OpenGl_Context theGlCtx)
overridevirtual

Destroy object - will release GPU memory if any.

Implements OpenGl_Resource.

Reimplemented in OpenGl_TextureBufferArb, and OpenGl_VertexBufferCompat.

◆ SetElemsNb()

void OpenGl_VertexBuffer::SetElemsNb ( GLsizei  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_VertexBuffer::sizeOfGlType ( const GLenum  theType)
inlinestatic
Returns
size of specified GL type

◆ SubData() [1/4]

bool OpenGl_VertexBuffer::SubData ( const Handle< OpenGl_Context > &  theGlCtx,
const GLsizei  theElemFrom,
const GLsizei  theElemsNb,
const GLfloat *  theData 
)
inline

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

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

◆ SubData() [2/4]

bool OpenGl_VertexBuffer::SubData ( const Handle< OpenGl_Context > &  theGlCtx,
const GLsizei  theElemFrom,
const GLsizei  theElemsNb,
const GLuint *  theData 
)
inline

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

Parameters
theElemFromelement id from which replace buffer data (>=0);
theElemsNbelements count (theElemFrom + theElemsNb <= GetElemsNb());
theDatapointer to GLuint data.

◆ SubData() [3/4]

bool OpenGl_VertexBuffer::SubData ( const Handle< OpenGl_Context > &  theGlCtx,
const GLsizei  theElemFrom,
const GLsizei  theElemsNb,
const GLushort *  theData 
)
inline

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

Parameters
theElemFromelement id from which replace buffer data (>=0);
theElemsNbelements count (theElemFrom + theElemsNb <= GetElemsNb());
theDatapointer to GLushort data.

◆ SubData() [4/4]

bool OpenGl_VertexBuffer::SubData ( const Handle< OpenGl_Context > &  theGlCtx,
const GLsizei  theElemFrom,
const GLsizei  theElemsNb,
const GLubyte *  theData 
)
inline

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

Parameters
theElemFromelement id from which replace buffer data (>=0);
theElemsNbelements count (theElemFrom + theElemsNb <= GetElemsNb());
theDatapointer to GLubyte data.

◆ subData()

virtual bool OpenGl_VertexBuffer::subData ( const Handle< OpenGl_Context > &  theGlCtx,
const GLsizei  theElemFrom,
const GLsizei  theElemsNb,
const void *  theData,
const GLenum  theDataType 
)
virtual

Update part of the buffer with new data.

Reimplemented in OpenGl_VertexBufferCompat.

◆ Unbind()

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

Unbind this VBO.

Reimplemented in OpenGl_VertexBufferCompat.

◆ 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 GLuint  theAttribLoc 
) const

Unbind any VBO from active GLSL program.

Field Documentation

◆ myBufferId

GLuint OpenGl_VertexBuffer::myBufferId
protected

VBO name (index)

◆ myComponentsNb

GLuint OpenGl_VertexBuffer::myComponentsNb
protected

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

◆ myDataType

GLenum OpenGl_VertexBuffer::myDataType
protected

Data type (GL_FLOAT, GL_UNSIGNED_INT, GL_UNSIGNED_BYTE etc.)

◆ myElemsNb

GLsizei OpenGl_VertexBuffer::myElemsNb
protected

Number of vertex attributes / number of vertices.

◆ myOffset

GLubyte* OpenGl_VertexBuffer::myOffset
protected

offset to data

◆ NO_BUFFER

const GLuint OpenGl_VertexBuffer::NO_BUFFER = 0
static

Helpful constants.


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