From: kgv Date: Thu, 22 Aug 2013 07:25:38 +0000 (+0400) Subject: 0024113: Provide missing OpenGl_VertexBuffer::SubData() specializations X-Git-Tag: V6_7_0_beta~166 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=99d99a6db2edd9aeac3b629aa0ef7bc7ef076a1c 0024113: Provide missing OpenGl_VertexBuffer::SubData() specializations remark on doxygen documentation --- diff --git a/src/OpenGl/OpenGl_VertexBuffer.cxx b/src/OpenGl/OpenGl_VertexBuffer.cxx index 436e67d35c..1a9878ca4b 100644 --- a/src/OpenGl/OpenGl_VertexBuffer.cxx +++ b/src/OpenGl/OpenGl_VertexBuffer.cxx @@ -179,6 +179,31 @@ bool OpenGl_VertexBuffer::Init (const Handle(OpenGl_Context)& theGlCtx, return isDone; } +// ======================================================================= +// function : SubData +// purpose : +// ======================================================================= +bool OpenGl_VertexBuffer::SubData (const Handle(OpenGl_Context)& theGlCtx, + const GLsizei theElemFrom, + const GLsizei theElemsNb, + const GLuint* theData) +{ + if (!IsValid() || myDataType != GL_UNSIGNED_INT + || theElemFrom < 0 || ((theElemFrom + theElemsNb) > myElemsNb)) + { + return false; + } + + Bind (theGlCtx); + theGlCtx->core15->glBufferSubData (GetTarget(), + GLintptr(theElemFrom) * GLintptr(myComponentsNb) * sizeof(GLuint), // offset in bytes + GLsizeiptr(theElemsNb) * GLsizeiptr(myComponentsNb) * sizeof(GLuint), // size in bytes + theData); + bool isDone = (glGetError() == GL_NO_ERROR); // GL_OUT_OF_MEMORY + Unbind (theGlCtx); + return isDone; +} + // ======================================================================= // function : Init // purpose : @@ -203,6 +228,31 @@ bool OpenGl_VertexBuffer::Init (const Handle(OpenGl_Context)& theGlCtx, return isDone; } +// ======================================================================= +// function : SubData +// purpose : +// ======================================================================= +bool OpenGl_VertexBuffer::SubData (const Handle(OpenGl_Context)& theGlCtx, + const GLsizei theElemFrom, + const GLsizei theElemsNb, + const GLubyte* theData) +{ + if (!IsValid() || myDataType != GL_UNSIGNED_BYTE + || theElemFrom < 0 || ((theElemFrom + theElemsNb) > myElemsNb)) + { + return false; + } + + Bind (theGlCtx); + theGlCtx->core15->glBufferSubData (GetTarget(), + GLintptr(theElemFrom) * GLintptr(myComponentsNb) * sizeof(GLubyte), // offset in bytes + GLsizeiptr(theElemsNb) * GLsizeiptr(myComponentsNb) * sizeof(GLubyte), // size in bytes + theData); + bool isDone = (glGetError() == GL_NO_ERROR); // GL_OUT_OF_MEMORY + Unbind (theGlCtx); + return isDone; +} + // ======================================================================= // function : BindVertexAttrib // purpose : diff --git a/src/OpenGl/OpenGl_VertexBuffer.hxx b/src/OpenGl/OpenGl_VertexBuffer.hxx index d6916159b7..564bddd7d7 100644 --- a/src/OpenGl/OpenGl_VertexBuffer.hxx +++ b/src/OpenGl/OpenGl_VertexBuffer.hxx @@ -113,13 +113,35 @@ public: //! Function replaces portion of data within this VBO using glBufferSubData(). //! The VBO should be initialized before call. //! @param theElemFrom - element id from which replace buffer data (>=0); - //! @param theElemsNb - elements count (theElemFrom + theElemsNb < GetElemsNb()); + //! @param theElemsNb - elements count (theElemFrom + theElemsNb <= GetElemsNb()); //! @param theData - pointer to GLfloat data. Standard_EXPORT 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. + //! @param theElemFrom element id from which replace buffer data (>=0); + //! @param theElemsNb elements count (theElemFrom + theElemsNb <= GetElemsNb()); + //! @param theData pointer to GLuint data. + Standard_EXPORT 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. + //! @param theElemFrom element id from which replace buffer data (>=0); + //! @param theElemsNb elements count (theElemFrom + theElemsNb <= GetElemsNb()); + //! @param theData pointer to GLubyte data. + Standard_EXPORT bool SubData (const Handle(OpenGl_Context)& theGlCtx, + const GLsizei theElemFrom, + const GLsizei theElemsNb, + const GLubyte* theData); + //! Bind this VBO to active GLSL program. Standard_EXPORT void BindVertexAttrib (const Handle(OpenGl_Context)& theGlCtx, const GLuint theAttribLoc) const; diff --git a/src/OpenGl/OpenGl_VertexBufferEditor.hxx b/src/OpenGl/OpenGl_VertexBufferEditor.hxx index eacf1417ad..b953e741fd 100644 --- a/src/OpenGl/OpenGl_VertexBufferEditor.hxx +++ b/src/OpenGl/OpenGl_VertexBufferEditor.hxx @@ -111,6 +111,12 @@ public: return Standard_True; } + //! @return assigned VBO + inline const Handle(OpenGl_VertexBuffer)& GetVBO() const + { + return myVbo; + } + private: Handle(OpenGl_Context) myGlCtx; //!< handle to current OpenGL context