OCCT3D OCCT 8.0.1
OCCT documentation

Search guides and API reference

Enter at least two characters.

    Open CASCADE Technology Reference Manual 8.0.1
    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:

    Public Member Functions

     OpenGl_Buffer ()
     Create uninitialized buffer.
     ~OpenGl_Buffer () override
     Destroy object.
    virtual unsigned int GetTarget () const =0
     Return buffer target.
    virtual bool IsVirtual () const
     Return TRUE if this is a virtual (for backward compatibility) VBO object.
    bool IsValid () const
    unsigned int GetComponentsNb () const
    int GetElemsNb () const
    void SetElemsNb (int 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
    uint8_t * GetDataOffset () const
    virtual bool Create (const occ::handle< OpenGl_Context > &theGlCtx)
     Creates buffer object name (id) if not yet generated. Data should be initialized by another method.
    void Release (OpenGl_Context *theGlCtx) override
     Destroy object - will release GPU memory if any.
    virtual void Bind (const occ::handle< OpenGl_Context > &theGlCtx) const
     Bind this buffer object.
    virtual void Unbind (const occ::handle< OpenGl_Context > &theGlCtx) const
     Unbind this buffer object.
    bool Init (const occ::handle< OpenGl_Context > &theGlCtx, const unsigned int theComponentsNb, const int theElemsNb, const float *theData)
     Notice that buffer object will be unbound after this call.
    bool Init (const occ::handle< OpenGl_Context > &theGlCtx, const unsigned int theComponentsNb, const int theElemsNb, const unsigned int *theData)
     Notice that buffer object will be unbound after this call.
    bool Init (const occ::handle< OpenGl_Context > &theGlCtx, const unsigned int theComponentsNb, const int theElemsNb, const unsigned short *theData)
     Notice that buffer object will be unbound after this call.
    bool Init (const occ::handle< OpenGl_Context > &theGlCtx, const unsigned int theComponentsNb, const int theElemsNb, const uint8_t *theData)
     Notice that buffer object will be unbound after this call.
    bool SubData (const occ::handle< OpenGl_Context > &theGlCtx, const int theElemFrom, const int 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 occ::handle< OpenGl_Context > &theGlCtx, const int theElemFrom, const int 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 occ::handle< OpenGl_Context > &theGlCtx, const int theElemFrom, const int 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 occ::handle< OpenGl_Context > &theGlCtx, const int theElemFrom, const int 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 occ::handle< OpenGl_Context > &theGlCtx, const int theElemFrom, const int 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 occ::handle< OpenGl_Context > &theGlCtx, const int theElemFrom, const int 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 occ::handle< OpenGl_Context > &theGlCtx, const int theElemFrom, const int theElemsNb, const uint8_t *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 occ::handle< OpenGl_Context > &theGlCtx, const int theElemFrom, const int theElemsNb, uint8_t *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().
    Public Member Functions inherited from OpenGl_Resource
     OpenGl_Resource ()
     Empty constructor.
     ~OpenGl_Resource () override
     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 ()=default
     Destructor must be virtual.
    virtual const opencascade::handle< Standard_Type > & DynamicType () const
     Returns a type descriptor about this object.
    bool IsInstance (const opencascade::handle< Standard_Type > &theType) const
     Returns a true value if this is an instance of Type.
    bool IsInstance (const char *const theTypeName) const
     Returns a true value if this is an instance of TypeName.
    bool 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.
    bool IsKind (const char *const 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.
    int GetRefCount () const noexcept
     Get the reference counter of this object.
    void IncrementRefCounter () noexcept
     Increments the reference counter of this object. Uses relaxed memory ordering since incrementing only requires atomicity, not synchronization with other memory operations.
    int DecrementRefCounter () noexcept
     Decrements the reference counter of this object; returns the decremented value. Uses release ordering for the decrement to ensure all writes to the object are visible before the count reaches zero. An acquire fence is added only when the count reaches zero, ensuring proper synchronization before deletion. This is more efficient than using acq_rel for every decrement.
    virtual void Delete () const
     Memory deallocator for transient classes.

    Static Public Member Functions

    static TCollection_AsciiString FormatTarget (unsigned int theTarget)
     Format VBO target enumeration value.
    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

    static const unsigned int NO_BUFFER = 0
     Helpful constants.

    advanced methods

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

    uint8_t * myOffset
     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.
    int myElemsNb
     Number of vertex attributes / number of vertices.
    unsigned int myDataType
     Data type (GL_FLOAT, GL_UNSIGNED_INT, GL_UNSIGNED_BYTE etc.).
    static size_t sizeOfGlType (unsigned int theType)
    size_t EstimatedDataSize () const override
     offset to data
    virtual bool init (const occ::handle< OpenGl_Context > &theGlCtx, const unsigned int theComponentsNb, const int theElemsNb, const void *theData, const unsigned int theDataType, const int theStride)
     Initialize buffer with new data.
    bool init (const occ::handle< OpenGl_Context > &theGlCtx, const unsigned int theComponentsNb, const int theElemsNb, const void *theData, const unsigned int theDataType)
     Initialize buffer with new data.
    virtual bool subData (const occ::handle< OpenGl_Context > &theGlCtx, const int theElemFrom, const int theElemsNb, const void *theData, const unsigned int theDataType)
     Update part of the buffer with new data.
    virtual bool getSubData (const occ::handle< OpenGl_Context > &theGlCtx, const int theElemFrom, const int theElemsNb, void *theData, const unsigned int theDataType)
     Read back buffer sub-range.
    void DumpJson (Standard_OStream &theOStream, int theDepth=-1) const override
     Dumps the content of me into the stream.
    void BindBufferBase (const occ::handle< OpenGl_Context > &theGlCtx, unsigned int theIndex)
     Binds a buffer object to an indexed buffer target. Wrapper for glBindBufferBase().
    void UnbindBufferBase (const occ::handle< OpenGl_Context > &theGlCtx, unsigned int theIndex)
     Unbinds a buffer object from an indexed buffer target. Wrapper for glBindBufferBase().
    void BindBufferRange (const occ::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().

    Additional Inherited Members

    typedef void base_type
     Returns a type descriptor about this object.

    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()

    OpenGl_Buffer::~OpenGl_Buffer ( )
    override

    Destroy object.

    Member Function Documentation

    ◆ Bind()

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

    ◆ BindBufferBase()

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

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

    Parameters
    [in]theGlCtxactive OpenGL context
    [in]theIndexindex to bind

    ◆ BindBufferRange()

    void OpenGl_Buffer::BindBufferRange ( const occ::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
    [in]theGlCtxactive OpenGL context
    [in]theIndexindex to bind (
    See also
    GL_MAX_UNIFORM_BUFFER_BINDINGS in case of uniform buffer)
    Parameters
    [in]theOffsetoffset within the buffer (
    See also
    GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT in case of uniform buffer)
    Parameters
    [in]theSizesub-section length starting from offset

    ◆ Create()

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

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

    Reimplemented in OpenGl_BufferCompatT< OpenGl_IndexBuffer >, OpenGl_BufferCompatT< OpenGl_VertexBuffer >, and OpenGl_TextureBuffer.

    ◆ DumpJson()

    void OpenGl_Buffer::DumpJson ( Standard_OStream & theOStream,
    int theDepth = -1 ) const
    overridevirtual

    Dumps the content of me into the stream.

    Reimplemented from OpenGl_Resource.

    Reimplemented in OpenGl_IndexBuffer.

    ◆ EstimatedDataSize()

    size_t OpenGl_Buffer::EstimatedDataSize ( ) const
    inlineoverridevirtual

    offset to data

    Implements OpenGl_Resource.

    ◆ FormatTarget()

    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()

    uint8_t * 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()

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

    ◆ GetSubData() [1/4]

    bool OpenGl_Buffer::GetSubData ( const occ::handle< OpenGl_Context > & theGlCtx,
    const int theElemFrom,
    const int 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
    [in]theElemFromelement id from which replace buffer data (>=0);
    [in]theElemsNbelements count (theElemFrom + theElemsNb <= GetElemsNb());
    [out]theDatadestination pointer to float data.

    ◆ GetSubData() [2/4]

    bool OpenGl_Buffer::GetSubData ( const occ::handle< OpenGl_Context > & theGlCtx,
    const int theElemFrom,
    const int theElemsNb,
    uint8_t * 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
    [in]theElemFromelement id from which replace buffer data (>=0);
    [in]theElemsNbelements count (theElemFrom + theElemsNb <= GetElemsNb());
    [out]theDatadestination pointer to uint8_t data.

    ◆ GetSubData() [3/4]

    bool OpenGl_Buffer::GetSubData ( const occ::handle< OpenGl_Context > & theGlCtx,
    const int theElemFrom,
    const int 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
    [in]theElemFromelement id from which replace buffer data (>=0);
    [in]theElemsNbelements count (theElemFrom + theElemsNb <= GetElemsNb());
    [out]theDatadestination pointer to unsigned int data.

    ◆ GetSubData() [4/4]

    bool OpenGl_Buffer::GetSubData ( const occ::handle< OpenGl_Context > & theGlCtx,
    const int theElemFrom,
    const int 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
    [in]theElemFromelement id from which replace buffer data (>=0);
    [in]theElemsNbelements count (theElemFrom + theElemsNb <= GetElemsNb());
    [out]theDatadestination pointer to unsigned short data.

    ◆ getSubData()

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

    ◆ GetTarget()

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

    ◆ Init() [1/4]

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

    Notice that buffer object will be unbound after this call.

    Parameters
    [in]theComponentsNbspecifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
    [in]theElemsNbelements count;
    [in]theDatapointer to float data (vertices/normals etc.).

    ◆ Init() [2/4]

    bool OpenGl_Buffer::Init ( const occ::handle< OpenGl_Context > & theGlCtx,
    const unsigned int theComponentsNb,
    const int theElemsNb,
    const uint8_t * theData )

    Notice that buffer object will be unbound after this call.

    Parameters
    [in]theComponentsNbspecifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
    [in]theElemsNbelements count;
    [in]theDatapointer to uint8_t data (indices/colors etc.).

    ◆ Init() [3/4]

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

    Notice that buffer object will be unbound after this call.

    Parameters
    [in]theComponentsNbspecifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
    [in]theElemsNbelements count;
    [in]theDatapointer to unsigned int data (indices etc.).

    ◆ Init() [4/4]

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

    Notice that buffer object will be unbound after this call.

    Parameters
    [in]theComponentsNbspecifies the number of components per generic vertex attribute; must be 1, 2, 3, or 4;
    [in]theElemsNbelements count;
    [in]theDatapointer to unsigned short data (indices etc.).

    ◆ init() [1/2]

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

    Initialize buffer with new data.

    ◆ init() [2/2]

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

    Initialize buffer with new data.

    Reimplemented in OpenGl_BufferCompatT< OpenGl_IndexBuffer >, and OpenGl_BufferCompatT< OpenGl_VertexBuffer >.

    ◆ 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.

    Reimplemented in OpenGl_BufferCompatT< OpenGl_IndexBuffer >, and OpenGl_BufferCompatT< OpenGl_VertexBuffer >.

    ◆ Release()

    void OpenGl_Buffer::Release ( OpenGl_Context * theGlCtx)
    overridevirtual

    Destroy object - will release GPU memory if any.

    Implements OpenGl_Resource.

    Reimplemented in OpenGl_BufferCompatT< OpenGl_IndexBuffer >, OpenGl_BufferCompatT< OpenGl_VertexBuffer >, and OpenGl_TextureBuffer.

    ◆ SetElemsNb()

    void OpenGl_Buffer::SetElemsNb ( int 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()

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

    ◆ SubData() [1/4]

    bool OpenGl_Buffer::SubData ( const occ::handle< OpenGl_Context > & theGlCtx,
    const int theElemFrom,
    const int 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
    [in]theElemFromelement id from which replace buffer data (>=0);
    [in]theElemsNbelements count (theElemFrom + theElemsNb <= GetElemsNb());
    [in]theDatapointer to float data.

    ◆ SubData() [2/4]

    bool OpenGl_Buffer::SubData ( const occ::handle< OpenGl_Context > & theGlCtx,
    const int theElemFrom,
    const int theElemsNb,
    const uint8_t * 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
    [in]theElemFromelement id from which replace buffer data (>=0);
    [in]theElemsNbelements count (theElemFrom + theElemsNb <= GetElemsNb());
    [in]theDatapointer to uint8_t data.

    ◆ SubData() [3/4]

    bool OpenGl_Buffer::SubData ( const occ::handle< OpenGl_Context > & theGlCtx,
    const int theElemFrom,
    const int 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
    [in]theElemFromelement id from which replace buffer data (>=0);
    [in]theElemsNbelements count (theElemFrom + theElemsNb <= GetElemsNb());
    [in]theDatapointer to unsigned int data.

    ◆ SubData() [4/4]

    bool OpenGl_Buffer::SubData ( const occ::handle< OpenGl_Context > & theGlCtx,
    const int theElemFrom,
    const int 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
    [in]theElemFromelement id from which replace buffer data (>=0);
    [in]theElemsNbelements count (theElemFrom + theElemsNb <= GetElemsNb());
    [in]theDatapointer to unsigned short data.

    ◆ subData()

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

    Update part of the buffer with new data.

    Reimplemented in OpenGl_BufferCompatT< OpenGl_IndexBuffer >, and OpenGl_BufferCompatT< OpenGl_VertexBuffer >.

    ◆ Unbind()

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

    ◆ UnbindBufferBase()

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

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

    Parameters
    [in]theGlCtxactive OpenGL context
    [in]theIndexindex 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

    int OpenGl_Buffer::myElemsNb
    protected

    Number of vertex attributes / number of vertices.

    ◆ myOffset

    uint8_t* 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: