From 5c225e8e077074d0f1fc3309ce148d13225ec023 Mon Sep 17 00:00:00 2001 From: iko Date: Thu, 12 Sep 2019 16:07:30 +0300 Subject: [PATCH] 0030963: Visualization, TKOpenGl - texture unit error during FFP global texture's parameters processing The texture units used in FFP texture functions are correct now. --- src/OpenGl/OpenGl_Context.cxx | 22 ++++++++++++---------- src/OpenGl/OpenGl_Context.hxx | 6 ++++++ src/OpenGl/OpenGl_Sampler.cxx | 3 ++- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/OpenGl/OpenGl_Context.cxx b/src/OpenGl/OpenGl_Context.cxx index d22993dc01..702ed31aaf 100644 --- a/src/OpenGl/OpenGl_Context.cxx +++ b/src/OpenGl/OpenGl_Context.cxx @@ -162,6 +162,7 @@ OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps) myTexClamp (GL_CLAMP_TO_EDGE), myMaxTexDim (1024), myMaxTexCombined (1), + myMaxTexUnitsFFP (1), myMaxDumpSizeX (1024), myMaxDumpSizeY (1024), myMaxClipPlanes (6), @@ -1557,18 +1558,19 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile) } glGetIntegerv (GL_MAX_TEXTURE_SIZE, &myMaxTexDim); +#if !defined(GL_ES_VERSION_2_0) + if (IsGlGreaterEqual (1, 3) && core11 != NULL) + { + // this is a maximum of texture units for FFP functionality, + // usually smaller than combined texture units available for GLSL + glGetIntegerv (GL_MAX_TEXTURE_UNITS, &myMaxTexUnitsFFP); + myMaxTexCombined = myMaxTexUnitsFFP; + } +#endif if (IsGlGreaterEqual (2, 0)) { glGetIntegerv (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &myMaxTexCombined); } -#if !defined(GL_ES_VERSION_2_0) - else if (IsGlGreaterEqual (1, 3)) - { - // this is a maximum of texture units for FFP functionality, - // dramatically smaller than combined texture units available for GLSL - glGetIntegerv (GL_MAX_TEXTURE_UNITS, &myMaxTexCombined); - } -#endif mySpriteTexUnit = myMaxTexCombined >= 2 ? Graphic3d_TextureUnit_1 : Graphic3d_TextureUnit_0; @@ -3233,13 +3235,13 @@ Handle(OpenGl_TextureSet) OpenGl_Context::BindTextures (const Handle(OpenGl_Text { if (const Handle(OpenGl_Texture)& aTextureOld = aTextureIterOld.Value()) { + aTextureOld->Unbind(aThisCtx); #if !defined(GL_ES_VERSION_2_0) if (core11 != NULL) { OpenGl_Sampler::resetGlobalTextureParams (aThisCtx, *aTextureOld, aTextureOld->Sampler()->Parameters()); } #endif - aTextureOld->Unbind (aThisCtx); } } break; @@ -3260,13 +3262,13 @@ Handle(OpenGl_TextureSet) OpenGl_Context::BindTextures (const Handle(OpenGl_Text { if (!aTextureOld.IsNull()) { + aTextureOld->Unbind(aThisCtx); #if !defined(GL_ES_VERSION_2_0) if (core11 != NULL) { OpenGl_Sampler::resetGlobalTextureParams (aThisCtx, *aTextureOld, aTextureOld->Sampler()->Parameters()); } #endif - aTextureOld->Unbind (aThisCtx); } aTextureIterNew.Next(); diff --git a/src/OpenGl/OpenGl_Context.hxx b/src/OpenGl/OpenGl_Context.hxx index 187416bedc..6c7f256a11 100644 --- a/src/OpenGl/OpenGl_Context.hxx +++ b/src/OpenGl/OpenGl_Context.hxx @@ -497,6 +497,11 @@ public: //! @return value for GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS Standard_Integer MaxCombinedTextureUnits() const { return myMaxTexCombined; } + //! This method returns the multi-texture limit for obsolete fixed-function pipeline. + //! Use MaxCombinedTextureUnits() instead for limits for using programmable pipeline. + //! @return value for GL_MAX_TEXTURE_UNITS + Standard_Integer MaxTextureUnitsFFP() const { return myMaxTexUnitsFFP; } + //! @return texture unit to be used for sprites Graphic3d_TextureUnit SpriteTextureUnit() const { return mySpriteTexUnit; } @@ -965,6 +970,7 @@ private: // context info Standard_Integer myTexClamp; //!< either GL_CLAMP_TO_EDGE (1.2+) or GL_CLAMP (1.1) Standard_Integer myMaxTexDim; //!< value for GL_MAX_TEXTURE_SIZE Standard_Integer myMaxTexCombined; //!< value for GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS + Standard_Integer myMaxTexUnitsFFP; //!< value for GL_MAX_TEXTURE_UNITS (fixed-function pipeline only) Standard_Integer myMaxDumpSizeX; //!< maximum FBO width for image dump Standard_Integer myMaxDumpSizeY; //!< maximum FBO height for image dump Standard_Integer myMaxClipPlanes; //!< value for GL_MAX_CLIP_PLANES diff --git a/src/OpenGl/OpenGl_Sampler.cxx b/src/OpenGl/OpenGl_Sampler.cxx index 4ee9e5b576..24b69b65fa 100644 --- a/src/OpenGl/OpenGl_Sampler.cxx +++ b/src/OpenGl/OpenGl_Sampler.cxx @@ -276,7 +276,8 @@ void OpenGl_Sampler::applyGlobalTextureParams (const Handle(OpenGl_Context)& the (void )theTexture; (void )theParams; #else - if (theCtx->core11 == NULL) + if (theCtx->core11 == NULL + || theParams->TextureUnit() >= theCtx->MaxTextureUnitsFFP()) { return; }