]> OCCT Git - occt-copy.git/commitdiff
OpenGl_Texture API extended.
authorduv <duv@opencascade.com>
Fri, 25 Mar 2016 09:41:49 +0000 (12:41 +0300)
committerduv <duv@opencascade.com>
Fri, 25 Mar 2016 09:41:49 +0000 (12:41 +0300)
src/OpenGl/OpenGl_Texture.cxx
src/OpenGl/OpenGl_Texture.hxx
src/OpenGl/OpenGl_TextureBufferArb.cxx
src/OpenGl/OpenGl_TextureBufferArb.hxx

index a35e65384f85c84e20f915634bda5c78e1cb8208..7511909d6081aaf788fddc5e277f482a9accd60c 100644 (file)
@@ -919,3 +919,102 @@ bool OpenGl_Texture::Init3D (const Handle(OpenGl_Context)& theCtx,
   Unbind (theCtx);
   return true;
 }
+
+// =======================================================================
+// function : Init2D
+// purpose  :
+// =======================================================================
+bool OpenGl_Texture::Init2D (const Handle(OpenGl_Context)& theCtx,
+                             const GLint                   theTextFormat,
+                             const GLenum                  thePixelFormat,
+                             const GLenum                  theDataType,
+                             const Standard_Integer        theSizeX,
+                             const Standard_Integer        theSizeY,
+                             const void*                   thePixels)
+{
+  if (!Create(theCtx))
+  {
+    return false;
+  }
+
+  myTarget = GL_TEXTURE_2D;
+
+  const GLsizei aSizeX = Min (theCtx->MaxTextureSize(), theSizeX);
+  const GLsizei aSizeY = Min (theCtx->MaxTextureSize(), theSizeY);
+
+  Bind (theCtx);
+
+  if (theDataType == GL_FLOAT && !theCtx->arbTexFloat)
+  {
+    TCollection_ExtendedString aMsg ("Error: floating-point textures are not supported by hardware.");
+
+    theCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
+                         GL_DEBUG_TYPE_ERROR,
+                         0,
+                         GL_DEBUG_SEVERITY_HIGH,
+                         aMsg);
+
+    Release (theCtx.operator->());
+    Unbind (theCtx);
+    return false;
+  }
+
+  const GLint anIntFormat = theTextFormat;
+
+#if !defined (GL_ES_VERSION_2_0)
+  theCtx->core15fwd->glTexImage2D (GL_PROXY_TEXTURE_2D,
+                                   0,
+                                   anIntFormat,
+                                   aSizeX,
+                                   aSizeY,
+                                   0,
+                                   thePixelFormat,
+                                   theDataType,
+                                   NULL);
+
+  GLint aTestSizeX = 0;
+  GLint aTestSizeY = 0;
+
+  glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &aTestSizeX);
+  glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &aTestSizeY);
+
+  if (aTestSizeX == 0 || aTestSizeY == 0)
+  {
+    Unbind (theCtx);
+    Release (theCtx.operator->());
+    return false;
+  }
+#endif
+
+  const GLenum aWrapMode = myParams->IsRepeat() ? GL_REPEAT :  theCtx->TextureWrapClamp();
+  const GLenum aFilter   = (myParams->Filter() == Graphic3d_TOTF_NEAREST) ? GL_NEAREST : GL_LINEAR;
+
+  glTexParameteri (myTarget, GL_TEXTURE_WRAP_S, aWrapMode);
+  glTexParameteri (myTarget, GL_TEXTURE_WRAP_T, aWrapMode);
+
+  glTexParameteri (myTarget, GL_TEXTURE_MIN_FILTER, aFilter);
+  glTexParameteri (myTarget, GL_TEXTURE_MAG_FILTER, aFilter);
+
+  theCtx->core15fwd->glTexImage2D (myTarget,
+                                   0,
+                                   anIntFormat,
+                                   aSizeX,
+                                   aSizeY,
+                                   0,
+                                   thePixelFormat,
+                                   theDataType,
+                                   thePixels);
+
+  if (glGetError() != GL_NO_ERROR)
+  {
+    Unbind (theCtx);
+    Release (theCtx.operator->());
+    return false;
+  }
+
+  mySizeX = aSizeX;
+  mySizeY = aSizeY;
+
+  Unbind (theCtx);
+  return true;
+}
index c7242b062844b8feea57e25085a3dbaf87689d6e..7921dff0cb1842a0d562aa675579c471d816a1f1 100644 (file)
@@ -404,6 +404,15 @@ public:
                                const Standard_Integer        theSizeZ,
                                const void*                   thePixels);
 
+  //! Initializes 2D texture with specified format and size.
+  Standard_EXPORT bool Init2D (const Handle(OpenGl_Context)& theCtx,
+                               const GLint                   theTextFormat,
+                               const GLenum                  thePixelFormat,
+                               const GLenum                  theDataType,
+                               const Standard_Integer        theSizeX,
+                               const Standard_Integer        theSizeY,
+                               const void*                   thePixels);
+
   //! @return true if texture was generated within mipmaps
   Standard_EXPORT Standard_Boolean HasMipmaps() const;
 
index 964a66bee4f4b72612c52f6eb484638d781c4f14..6c3f552f47f11159e572942f5528937d8b172075 100644 (file)
@@ -181,6 +181,98 @@ 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 (theComponentsNb == 3
+       && !theGlCtx->arbTboRGB32)
+  {
+    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 (theComponentsNb == 3
+       && !theGlCtx->arbTboRGB32)
+  {
+    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 7b0a51256cd04b514e8756d5a31ef79d161261e8..d375f7b2c7d82eaa89081c6a5bc4502dcb0765bf 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;