X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Frender%2Fshaders%2Fprogram.cpp;h=451de0bb6c7083eeccb9bf7e90e73e82b30a29c9;hb=649ec06daecb510fb84fe4642a6af957f127e7ab;hp=c707aa9fc28dc6a1c5abdfe83e4a011de2933786;hpb=dcbe581a107fdda950cca57f70dd759f01b74762;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/render/shaders/program.cpp b/dali/internal/render/shaders/program.cpp index c707aa9..451de0b 100644 --- a/dali/internal/render/shaders/program.cpp +++ b/dali/internal/render/shaders/program.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ // EXTERNAL INCLUDES #include +#include // INTERNAL INCLUDES #include @@ -110,8 +111,7 @@ Program* Program::New( ProgramCache& cache, Internal::ShaderDataPtr shaderData, { // program not found so create it program = new Program( cache, shaderData, modifiesGeometry ); - - // we want to lazy load programs so dont do a Load yet, it gets done in Use() + program->Load(); cache.AddProgram( shaderHash, program ); } @@ -120,11 +120,6 @@ Program* Program::New( ProgramCache& cache, Internal::ShaderDataPtr shaderData, void Program::Use() { - if ( !mLinked ) - { - Load(); - } - if ( mLinked ) { if ( this != mCache.GetCurrentProgram() ) @@ -231,16 +226,16 @@ namespace struct LocationPosition { 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) + int position; ///< the position of the uniform declaration + LocationPosition( GLint uniformLocation, int position ) + : uniformLocation(uniformLocation), position(position) { } }; bool sortByPosition( LocationPosition a, LocationPosition b ) { - return a.characterPosition < b.characterPosition; + return a.position < b.position; } } @@ -263,36 +258,65 @@ void Program::GetActiveSamplerUniforms() for( int i=0; i( i ), uniformMaxNameLength, &nameLength, &number, &type, name ); - if( type == GL_SAMPLER_2D ) /// Is there a native sampler type? + if( type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || type == GL_SAMPLER_EXTERNAL_OES ) { GLuint location = mGlAbstraction.GetUniformLocation( mProgramId, name ); samplerNames.push_back(name); - samplerUniformLocations.push_back(LocationPosition(location, 0u)); + samplerUniformLocations.push_back(LocationPosition(location, -1)); } } } - if( samplerUniformLocations.size() > 1 ) + //Determine declaration order of each sampler + char* fragShader = strdup( mProgramData->GetFragmentShader() ); + char* nextPtr = NULL; + const char* token = strtok_r( fragShader, " ;\n", &nextPtr ); + int samplerPosition = 0; + while( token ) { - // Now, re-order according to declaration order in the fragment source. - std::string fragShader( mProgramData->GetFragmentShader() ); - for( unsigned int i=0; i 1 ) + { std::sort( samplerUniformLocations.begin(), samplerUniformLocations.end(), sortByPosition); } - for( unsigned int i=0; i