0027354: Visualization: TKOpenGl - OpenGl_TextureBufferArb API should be extended
authorduv <duv@opencascade.com>
Tue, 5 Apr 2016 09:25:13 +0000 (12:25 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 8 Apr 2016 08:41:45 +0000 (11:41 +0300)
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
src/OpenGl/OpenGl_TextureBufferArb.cxx
src/OpenGl/OpenGl_TextureBufferArb.hxx

index 0dee006..ee8f344 100644 (file)
   #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
index 964a66b..b5e1d8b 100644 (file)
@@ -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  :
index 7b0a512..851640e 100644 (file)
@@ -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;