From df45f8db5f8ce5e455767d093128479d6a2dee63 Mon Sep 17 00:00:00 2001 From: duv Date: Tue, 5 Apr 2016 12:25:13 +0300 Subject: [PATCH] 0027354: Visualization: TKOpenGl - OpenGl_TextureBufferArb API should be extended All variants of Init function of OpenGl_VertexBuffer are now also supported by OpenGl_TextureBufferArb. Missing texture formats added to OpenGl_GlFunctions.hxx. --- src/OpenGl/OpenGl_GlFunctions.hxx | 22 ++++++- src/OpenGl/OpenGl_TextureBufferArb.cxx | 82 ++++++++++++++++++++++++++ src/OpenGl/OpenGl_TextureBufferArb.hxx | 14 +++++ 3 files changed, 117 insertions(+), 1 deletion(-) diff --git a/src/OpenGl/OpenGl_GlFunctions.hxx b/src/OpenGl/OpenGl_GlFunctions.hxx index 0dee006154..ee8f34483c 100644 --- a/src/OpenGl/OpenGl_GlFunctions.hxx +++ b/src/OpenGl/OpenGl_GlFunctions.hxx @@ -106,10 +106,30 @@ #define GL_RG16F 0x822F #define GL_RG32F 0x8230 + #define GL_R8I 0x8231 + #define GL_R8UI 0x8232 + #define GL_R16I 0x8233 + #define GL_R16UI 0x8234 #define GL_R32I 0x8235 + #define GL_R32UI 0x8236 + #define GL_RG8I 0x8237 + #define GL_RG8UI 0x8238 + #define GL_RG16I 0x8239 + #define GL_RG16UI 0x823A #define GL_RG32I 0x823B - #define GL_RGB32I 0x8D83 + #define GL_RG32UI 0x823C + #define GL_RGBA32UI 0x8D70 + #define GL_RGB32UI 0x8D71 + #define GL_RGBA16UI 0x8D76 + #define GL_RGB16UI 0x8D77 + #define GL_RGBA8UI 0x8D7C + #define GL_RGB8UI 0x8D7D #define GL_RGBA32I 0x8D82 + #define GL_RGB32I 0x8D83 + #define GL_RGBA16I 0x8D88 + #define GL_RGB16I 0x8D89 + #define GL_RGBA8I 0x8D8E + #define GL_RGB8I 0x8D8F // GL_OES_packed_depth_stencil #define GL_DEPTH_STENCIL 0x84F9 diff --git a/src/OpenGl/OpenGl_TextureBufferArb.cxx b/src/OpenGl/OpenGl_TextureBufferArb.cxx index 964a66bee4..b5e1d8bf79 100644 --- a/src/OpenGl/OpenGl_TextureBufferArb.cxx +++ b/src/OpenGl/OpenGl_TextureBufferArb.cxx @@ -181,6 +181,88 @@ bool OpenGl_TextureBufferArb::Init (const Handle(OpenGl_Context)& theGlCtx, return true; } +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +bool OpenGl_TextureBufferArb::Init (const Handle(OpenGl_Context)& theGlCtx, + const GLuint theComponentsNb, + const GLsizei theElemsNb, + const GLushort* theData) +{ + if (theGlCtx->arbTBO == NULL) + { + return false; + } + else if (theComponentsNb < 1 + || theComponentsNb > 4) + { + // unsupported format + return false; + } + else if (!Create (theGlCtx) + || !OpenGl_VertexBuffer::Init (theGlCtx, theComponentsNb, theElemsNb, theData)) + { + return false; + } + + switch (theComponentsNb) + { + case 1: myTexFormat = GL_R16I; break; + case 2: myTexFormat = GL_RG16I; break; + case 3: myTexFormat = GL_RGB16I; break; + case 4: myTexFormat = GL_RGBA16I; break; + } + + Bind (theGlCtx); + BindTexture (theGlCtx); + theGlCtx->arbTBO->glTexBuffer (GetTarget(), myTexFormat, myBufferId); + UnbindTexture (theGlCtx); + Unbind (theGlCtx); + return true; +} + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +bool OpenGl_TextureBufferArb::Init (const Handle(OpenGl_Context)& theGlCtx, + const GLuint theComponentsNb, + const GLsizei theElemsNb, + const GLubyte* theData) +{ + if (theGlCtx->arbTBO == NULL) + { + return false; + } + else if (theComponentsNb < 1 + || theComponentsNb > 4) + { + // unsupported format + return false; + } + else if (!Create (theGlCtx) + || !OpenGl_VertexBuffer::Init (theGlCtx, theComponentsNb, theElemsNb, theData)) + { + return false; + } + + switch (theComponentsNb) + { + case 1: myTexFormat = GL_R8; break; + case 2: myTexFormat = GL_RG8; break; + case 3: myTexFormat = GL_RGB8; break; + case 4: myTexFormat = GL_RGBA8; break; + } + + Bind (theGlCtx); + BindTexture (theGlCtx); + theGlCtx->arbTBO->glTexBuffer (GetTarget(), myTexFormat, myBufferId); + UnbindTexture (theGlCtx); + Unbind (theGlCtx); + return true; +} + // ======================================================================= // function : BindTexture // purpose : diff --git a/src/OpenGl/OpenGl_TextureBufferArb.hxx b/src/OpenGl/OpenGl_TextureBufferArb.hxx index 7b0a51256c..851640ed8c 100644 --- a/src/OpenGl/OpenGl_TextureBufferArb.hxx +++ b/src/OpenGl/OpenGl_TextureBufferArb.hxx @@ -76,6 +76,20 @@ public: const GLsizei theElemsNb, const GLuint* theData); + //! Perform TBO initialization with specified data. + //! Existing data will be deleted. + Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx, + const GLuint theComponentsNb, + const GLsizei theElemsNb, + const GLushort* theData); + + //! Perform TBO initialization with specified data. + //! Existing data will be deleted. + Standard_EXPORT bool Init (const Handle(OpenGl_Context)& theGlCtx, + const GLuint theComponentsNb, + const GLsizei theElemsNb, + const GLubyte* theData); + //! Bind TBO to specified Texture Unit. Standard_EXPORT void BindTexture (const Handle(OpenGl_Context)& theGlCtx, const GLenum theTextureUnit = GL_TEXTURE0) const; -- 2.20.1