From 2b28517228f191ff1f04425779d477247f3b924b Mon Sep 17 00:00:00 2001 From: Victor Cebollada Date: Tue, 7 Nov 2017 15:36:19 +0000 Subject: [PATCH 1/1] [4.0] Avoid calling glActiveTexture() unnecessarily. * glActiveTexture() is called before glBindTexture(). The context caches both calls but the Render::Texture was not using it. Change-Id: Idd6880f3c27ab180dbcb2bce8f219966039cc41d Signed-off-by: Victor Cebollada (cherry picked from commit 3ed1b4ee9d310989b3da67e51e31039c9e32714a) --- dali/internal/render/gl-resources/context.cpp | 2 +- dali/internal/render/gl-resources/context.h | 37 +++++------------------ dali/internal/render/renderers/render-texture.cpp | 3 +- 3 files changed, 9 insertions(+), 33 deletions(-) diff --git a/dali/internal/render/gl-resources/context.cpp b/dali/internal/render/gl-resources/context.cpp index 2d883bc..d3e0b56 100644 --- a/dali/internal/render/gl-resources/context.cpp +++ b/dali/internal/render/gl-resources/context.cpp @@ -241,7 +241,7 @@ void Context::InitializeGlState() memset( &mVertexAttributeCurrentState, 0, sizeof(mVertexAttributeCurrentState) ); //Initialize bound 2d texture cache - memset( &mBound2dTextureId, 0, sizeof(mBound2dTextureId) ); + memset( &mBoundTextureId, 0, sizeof(mBoundTextureId) ); mFrameBufferStateCache.Reset(); } diff --git a/dali/internal/render/gl-resources/context.h b/dali/internal/render/gl-resources/context.h index 59ed396..664c3a4 100644 --- a/dali/internal/render/gl-resources/context.h +++ b/dali/internal/render/gl-resources/context.h @@ -262,26 +262,12 @@ public: * @param textureunit to bind to * @param texture to bind */ - void BindTextureForUnit( TextureUnit textureunit, GLuint texture ) + void BindTextureForUnit( TextureUnit textureunit, int target, GLuint texture ) { - if( mBound2dTextureId[ textureunit ] != texture ) + if( mBoundTextureId[ textureunit ] != texture ) { ActiveTexture( textureunit ); - Bind2dTexture( texture ); - } - } - - /** - * Wrapper for OpenGL ES 2.0 glBindTexture(GL_TEXTURE_2D) - */ - void Bind2dTexture( GLuint texture ) - { - if (mBound2dTextureId[ mActiveTextureUnit ] != texture) - { - mBound2dTextureId[ mActiveTextureUnit ] = texture; - - LOG_GL("BindTexture GL_TEXTURE_2D %d\n", texture); - CHECK_GL( mGlAbstraction, mGlAbstraction.BindTexture(GL_TEXTURE_2D, texture) ); + BindTexture( target, texture ); } } @@ -290,9 +276,9 @@ public: */ void BindTexture( int target, GLuint texture ) { - if (mBound2dTextureId[ mActiveTextureUnit ] != texture) + if (mBoundTextureId[ mActiveTextureUnit ] != texture) { - mBound2dTextureId[ mActiveTextureUnit ] = texture; + mBoundTextureId[ mActiveTextureUnit ] = texture; LOG_GL("BindTexture target(%d) %d\n", target, texture); CHECK_GL( mGlAbstraction, mGlAbstraction.BindTexture(target, texture) ); @@ -300,15 +286,6 @@ public: } /** - * Wrapper for OpenGL ES 2.0 glBindTexture(GL_TEXTURE_CUBE_MAP) - */ - void BindCubeMapTexture( GLuint texture ) - { - LOG_GL("BindTexture GL_TEXTURE_CUBE_MAP %d\n", texture); - CHECK_GL( mGlAbstraction, mGlAbstraction.BindTexture(GL_TEXTURE_CUBE_MAP, texture) ); - } - - /** * Wrapper for OpenGL ES 2.0 glBlendColor() */ void SetDefaultBlendColor() @@ -669,7 +646,7 @@ public: // when creating new textures for( unsigned int i=0; i < MAX_TEXTURE_UNITS; ++i ) { - mBound2dTextureId[ i ] = 0; + mBoundTextureId[ i ] = 0; } } @@ -1734,7 +1711,7 @@ private: // Data // glBindTexture() state TextureUnit mActiveTextureUnit; - GLuint mBound2dTextureId[ MAX_TEXTURE_UNITS ]; ///< The ID passed to glBindTexture(GL_TEXTURE_2D) + GLuint mBoundTextureId[ MAX_TEXTURE_UNITS ]; ///< The ID passed to glBindTexture() // glBlendColor() state Vector4 mBlendColor; ///< Blend color diff --git a/dali/internal/render/renderers/render-texture.cpp b/dali/internal/render/renderers/render-texture.cpp index 7e0af70..7cb2f8e 100644 --- a/dali/internal/render/renderers/render-texture.cpp +++ b/dali/internal/render/renderers/render-texture.cpp @@ -860,8 +860,7 @@ bool Texture::Bind( Context& context, unsigned int textureUnit, Render::Sampler* if( mId != 0 ) { - context.ActiveTexture( static_cast(textureUnit) ); - context.BindTexture( mTarget, mId ); + context.BindTextureForUnit( static_cast( textureUnit ), mTarget, mId ); ApplySampler( context, sampler ); if( mNativeImage ) -- 2.7.4