0032461: Visualization - expensive call of glGetTexEnviv/glTexEnvi in each render...
authorsshutina <sshutina@opencascade.com>
Wed, 15 Sep 2021 10:48:51 +0000 (13:48 +0300)
committersmoskvin <smoskvin@opencascade.com>
Wed, 15 Sep 2021 17:12:43 +0000 (20:12 +0300)
 - removed the call of glGetTexEnviv, glTexEnvi
 - replaced on the OpenGl_Sampler::applyGlobalTextureParams/resetGlobalTextureParams
 - added the method in OpenGl_Font returning first texture

src/OpenGl/OpenGl_Font.hxx
src/OpenGl/OpenGl_Sampler.hxx
src/OpenGl/OpenGl_Text.cxx

index 3373ac8..7797674 100755 (executable)
@@ -114,6 +114,12 @@ public:
                                     const Standard_Utf32Char      theUChar,
                                     Tile&                         theGlyph);
 
+  //! @return first texture.
+  const Handle(OpenGl_Texture)& Texture() const
+  {
+    return myTextures.First();
+  }
+
 protected:
 
   //! Render new glyph to the texture.
index bca6e44..9e3ac27 100644 (file)
@@ -27,6 +27,7 @@ class OpenGl_Sampler : public OpenGl_Resource
 {
   friend class OpenGl_Context;
   friend class OpenGl_Texture;
+  friend class OpenGl_Text;
   DEFINE_STANDARD_RTTIEXT(OpenGl_Sampler, OpenGl_Resource)
 public:
 
index 05c36af..f27d9d6 100644 (file)
@@ -16,6 +16,7 @@
 #include <OpenGl_Aspects.hxx>
 #include <OpenGl_GlCore11.hxx>
 #include <OpenGl_GraphicDriver.hxx>
+#include <OpenGl_Sampler.hxx>
 #include <OpenGl_ShaderManager.hxx>
 #include <OpenGl_ShaderProgram.hxx>
 #include <OpenGl_ShaderStates.hxx>
@@ -780,16 +781,10 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx,
   }
 #if !defined(GL_ES_VERSION_2_0)
   // activate texture unit
-  GLint aTexEnvParam = GL_REPLACE;
-  if (theCtx->core11ffp != NULL)
+  if (theCtx->core11ffp != NULL && theCtx->ActiveProgram().IsNull())
   {
-    theCtx->core11fwd->glDisable (GL_TEXTURE_1D);
-    theCtx->core11fwd->glEnable  (GL_TEXTURE_2D);
-    theCtx->core11ffp->glGetTexEnviv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &aTexEnvParam);
-    if (aTexEnvParam != GL_REPLACE)
-    {
-      theCtx->core11ffp->glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
-    }
+    const Handle(OpenGl_Texture)& aTexture = myFont->Texture();
+    OpenGl_Sampler::applyGlobalTextureParams (theCtx, *aTexture, aTexture->Sampler()->Parameters());
   }
 #endif
 
@@ -861,9 +856,10 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx,
   }
 
 #if !defined(GL_ES_VERSION_2_0)
-  if (theCtx->core11ffp != NULL)
+  if (theCtx->core11ffp != NULL && theCtx->ActiveProgram().IsNull())
   {
-    theCtx->core11ffp->glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, aTexEnvParam);
+    const Handle(OpenGl_Texture)& aTexture = myFont->Texture();
+    OpenGl_Sampler::resetGlobalTextureParams (theCtx, *aTexture, aTexture->Sampler()->Parameters());
   }
 #endif