From 5ec86b45081ff6dd2f3b2555f465b10c9d64a697 Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Mon, 4 Apr 2016 06:59:08 -0700 Subject: [PATCH] Revert "Removed need for sampler uniform names" This reverts commit 9f94da7375ab73f889c82d60639434e72543c826. Change-Id: I444e4aba29a14bc14daac0127f287a63c5e30776 --- dali/internal/render/renderers/render-renderer.cpp | 53 ++++++------ dali/internal/render/shaders/program.cpp | 95 ++++------------------ dali/internal/render/shaders/program.h | 23 ++---- 3 files changed, 54 insertions(+), 117 deletions(-) diff --git a/dali/internal/render/renderers/render-renderer.cpp b/dali/internal/render/renderers/render-renderer.cpp index 8d666b7..2a93574 100644 --- a/dali/internal/render/renderers/render-renderer.cpp +++ b/dali/internal/render/renderers/render-renderer.cpp @@ -367,34 +367,39 @@ bool Renderer::BindTextures( SceneGraph::TextureCache& textureCache, Program& pr if( result ) { - GLint uniformLocation; - - bool result = program.GetSamplerUniformLocation( i, uniformLocation ); - if( result && Program::UNIFORM_UNKNOWN != uniformLocation ) + Render::Texture& textureMapping = textures[i]; + // Set sampler uniform location for the texture + int32_t uniqueIndex = textureMapping.GetUniformUniqueIndex(); + if( Render::Texture::NOT_INITIALIZED == uniqueIndex ) + { + uniqueIndex = mUniformNameCache->GetSamplerUniformUniqueIndex( textureMapping.GetUniformName() ); + textureMapping.SetUniformUniqueIndex( uniqueIndex ); + } + GLint uniformLocation = program.GetSamplerUniformLocation( uniqueIndex, textureMapping.GetUniformName() ); + if( Program::UNIFORM_UNKNOWN != uniformLocation ) { program.SetUniform1i( uniformLocation, textureUnit ); + } - unsigned int samplerBitfield(0); - Render::Texture& textureMapping = textures[i]; - const Render::Sampler* sampler( textureMapping.GetSampler() ); - if( sampler ) - { - samplerBitfield = ImageSampler::PackBitfield( - static_cast< FilterMode::Type >(sampler->GetMinifyFilterMode()), - static_cast< FilterMode::Type >(sampler->GetMagnifyFilterMode()), - static_cast< WrapMode::Type >(sampler->GetUWrapMode()), - static_cast< WrapMode::Type >(sampler->GetVWrapMode()) - ); - } - else - { - samplerBitfield = ImageSampler::DEFAULT_BITFIELD; - } - - texture->ApplySampler( (TextureUnit)textureUnit, samplerBitfield ); - - ++textureUnit; + unsigned int samplerBitfield(0); + const Render::Sampler* sampler( textureMapping.GetSampler() ); + if( sampler ) + { + samplerBitfield = ImageSampler::PackBitfield( + static_cast< FilterMode::Type >(sampler->GetMinifyFilterMode()), + static_cast< FilterMode::Type >(sampler->GetMagnifyFilterMode()), + static_cast< WrapMode::Type >(sampler->GetUWrapMode()), + static_cast< WrapMode::Type >(sampler->GetVWrapMode()) + ); } + else + { + samplerBitfield = ImageSampler::DEFAULT_BITFIELD; + } + + texture->ApplySampler( (TextureUnit)textureUnit, samplerBitfield ); + + ++textureUnit; } } } diff --git a/dali/internal/render/shaders/program.cpp b/dali/internal/render/shaders/program.cpp index c707aa9..a2367f6 100644 --- a/dali/internal/render/shaders/program.cpp +++ b/dali/internal/render/shaders/program.cpp @@ -222,89 +222,29 @@ GLint Program::GetUniformLocation( unsigned int uniformIndex ) return location; } -namespace -{ -/** - * This struct is used to record the position of a uniform declaration - * within the fragment shader source code. - */ -struct LocationPosition +GLint Program::GetSamplerUniformLocation( int32_t uniqueIndex, const std::string& samplerName ) { - GLint uniformLocation; ///< The location of the uniform (used as an identifier) - int characterPosition; ///< the position of the uniform declaration - LocationPosition( GLint uniformLocation, int characterPosition ) - : uniformLocation(uniformLocation), characterPosition(characterPosition) - { - } -}; - -bool sortByPosition( LocationPosition a, LocationPosition b ) -{ - return a.characterPosition < b.characterPosition; -} -} - -void Program::GetActiveSamplerUniforms() -{ - GLint numberOfActiveUniforms = -1; - GLint uniformMaxNameLength=-1; - - mGlAbstraction.GetProgramiv( mProgramId, GL_ACTIVE_UNIFORMS, &numberOfActiveUniforms ); - mGlAbstraction.GetProgramiv( mProgramId, GL_ACTIVE_UNIFORM_MAX_LENGTH, &uniformMaxNameLength ); - - std::vector samplerNames; - char name[uniformMaxNameLength+1]; // Allow for null terminator - std::vector< LocationPosition > samplerUniformLocations; - - { - int nameLength = -1; - int number = -1; - GLenum type = GL_ZERO; - - for( int i=0; i 1 ) + if( index < mSamplerUniformLocations.Size() ) { - // Now, re-order according to declaration order in the fragment source. - std::string fragShader( mProgramData->GetFragmentShader() ); - for( unsigned int i=0; i NameLocationPair; - typedef std::vector< NameLocationPair > Locations; - - Locations mAttributeLocations; ///< attribute location cache - Locations mUniformLocations; ///< uniform location cache - std::vector mSamplerUniformLocations; ///< sampler uniform location cache + std::vector< std::pair< std::string, GLint > > mAttributeLocations; ///< attribute location cache + std::vector< std::pair< std::string, GLint > > mUniformLocations; ///< uniform location cache + Dali::Vector< GLint > mSamplerUniformLocations; ///< sampler uniform location cache // uniform value caching GLint mUniformCacheInt[ MAX_UNIFORM_CACHE_SIZE ]; ///< Value cache for uniforms of single int -- 2.7.4