From 58f2990bc5423f527655e136948cbd4eb859e954 Mon Sep 17 00:00:00 2001 From: sshutina Date: Wed, 15 Sep 2021 13:48:51 +0300 Subject: [PATCH] 0032461: Visualization - expensive call of glGetTexEnviv/glTexEnvi in each render of OpenGl_Text - 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 | 6 ++++++ src/OpenGl/OpenGl_Sampler.hxx | 1 + src/OpenGl/OpenGl_Text.cxx | 18 +++++++----------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/OpenGl/OpenGl_Font.hxx b/src/OpenGl/OpenGl_Font.hxx index 3373ac8918..7797674824 100755 --- a/src/OpenGl/OpenGl_Font.hxx +++ b/src/OpenGl/OpenGl_Font.hxx @@ -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. diff --git a/src/OpenGl/OpenGl_Sampler.hxx b/src/OpenGl/OpenGl_Sampler.hxx index bca6e4416e..9e3ac27b32 100644 --- a/src/OpenGl/OpenGl_Sampler.hxx +++ b/src/OpenGl/OpenGl_Sampler.hxx @@ -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: diff --git a/src/OpenGl/OpenGl_Text.cxx b/src/OpenGl/OpenGl_Text.cxx index 05c36af339..f27d9d6c7e 100644 --- a/src/OpenGl/OpenGl_Text.cxx +++ b/src/OpenGl/OpenGl_Text.cxx @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -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