2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/render/shaders/program.h>
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/common/dali-vector.h>
27 #include <dali/public-api/common/constants.h>
28 #include <dali/integration-api/debug.h>
29 #include <dali/internal/common/shader-data.h>
30 #include <dali/integration-api/gl-defines.h>
31 #include <dali/internal/render/common/performance-monitor.h>
32 #include <dali/internal/render/shaders/program-cache.h>
33 #include <dali/internal/render/gl-resources/gl-call-debug.h>
37 void LogWithLineNumbers( const char * source )
39 unsigned int lineNumber = 0u;
40 const char *prev = source;
41 const char *ptr = prev;
49 // seek the next end of line or end of text
50 while( *ptr!='\n' && *ptr != '\0' )
55 std::string line( prev, ptr-prev );
56 Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugError, "%4d %s\n", lineNumber, line.c_str());
79 const char* gStdAttribs[ Program::ATTRIB_TYPE_LAST ] =
81 "aPosition", // ATTRIB_POSITION
82 "aNormal", // ATTRIB_NORMAL
83 "aTexCoord", // ATTRIB_TEXCOORD
84 "aColor", // ATTRIB_COLOR
85 "aBoneWeights", // ATTRIB_BONE_WEIGHTS
86 "aBoneIndices" // ATTRIB_BONE_INDICES
89 const char* gStdUniforms[ Program::UNIFORM_TYPE_LAST ] =
91 "uMvpMatrix", // UNIFORM_MVP_MATRIX
92 "uModelView", // UNIFORM_MODELVIEW_MATRIX
93 "uProjection", // UNIFORM_PROJECTION_MATRIX
94 "uModelMatrix", // UNIFORM_MODEL_MATRIX,
95 "uViewMatrix", // UNIFORM_VIEW_MATRIX,
96 "uNormalMatrix", // UNIFORM_NORMAL_MATRIX
97 "uColor", // UNIFORM_COLOR
98 "uCustomTextureCoords", // UNIFORM_CUSTOM_TEXTURE_COORDS
99 "sTexture", // UNIFORM_SAMPLER
100 "sTextureRect", // UNIFORM_SAMPLER_RECT
101 "sEffect", // UNIFORM_EFFECT_SAMPLER
102 "sEffectRect", // UNIFORM_EFFECT_SAMPLER_RECT
103 "uTimeDelta", // UNIFORM_TIME_DELTA
104 "sOpacityTexture", // UNIFORM_SAMPLER_OPACITY
105 "sNormalMapTexture", // UNIFORM_SAMPLER_NORMAL_MAP
106 "uSize" // UNIFORM_SIZE
109 } // <unnamed> namespace
113 Program* Program::New( ProgramCache& cache, Internal::ShaderDataPtr shaderData, bool modifiesGeometry )
115 size_t shaderHash = shaderData->GetHashValue();
116 Program* program = cache.GetProgram( shaderHash );
118 if( NULL == program )
120 // program not found so create it
121 program = new Program( cache, shaderData, modifiesGeometry );
123 // we want to lazy load programs so dont do a Load yet, it gets done in Use()
125 cache.AddProgram( shaderHash, program );
140 if ( this != mCache.GetCurrentProgram() )
142 LOG_GL( "UseProgram(%d)\n", mProgramId );
143 CHECK_GL( mGlAbstraction, mGlAbstraction.UseProgram(mProgramId) );
145 mCache.SetCurrentProgram( this );
150 bool Program::IsUsed()
152 return ( this == mCache.GetCurrentProgram() );
155 GLint Program::GetAttribLocation( AttribType type )
157 DALI_ASSERT_DEBUG(type != ATTRIB_UNKNOWN);
159 return GetCustomAttributeLocation( type );
162 unsigned int Program::RegisterCustomAttribute( const std::string& name )
164 unsigned int index = 0;
165 // find the value from cache
166 for( ;index < mAttributeLocations.size(); ++index )
168 if( mAttributeLocations[ index ].first == name )
170 // name found so return index
174 // if we get here, index is one past end so push back the new name
175 mAttributeLocations.push_back( std::make_pair( name, ATTRIB_UNKNOWN ) );
179 GLint Program::GetCustomAttributeLocation( unsigned int attributeIndex )
181 // debug check that index is within name cache
182 DALI_ASSERT_DEBUG( mAttributeLocations.size() > attributeIndex );
184 // check if we have already queried the location of the attribute
185 GLint location = mAttributeLocations[ attributeIndex ].second;
187 if( location == ATTRIB_UNKNOWN )
189 location = CHECK_GL( mGlAbstraction, mGlAbstraction.GetAttribLocation( mProgramId, mAttributeLocations[ attributeIndex ].first.c_str() ) );
191 mAttributeLocations[ attributeIndex ].second = location;
192 LOG_GL( "GetAttributeLocation(program=%d,%s) = %d\n", mProgramId, mAttributeLocations[ attributeIndex ].first.c_str(), mAttributeLocations[ attributeIndex ].second );
199 unsigned int Program::RegisterUniform( const std::string& name )
201 unsigned int index = 0;
202 // find the value from cache
203 for( ;index < mUniformLocations.size(); ++index )
205 if( mUniformLocations[ index ].first == name )
207 // name found so return index
211 // if we get here, index is one past end so push back the new name
212 mUniformLocations.push_back( std::make_pair( name, UNIFORM_NOT_QUERIED ) );
216 GLint Program::GetUniformLocation( unsigned int uniformIndex )
218 // debug check that index is within name cache
219 DALI_ASSERT_DEBUG( mUniformLocations.size() > uniformIndex );
221 // check if we have already queried the location of the uniform
222 GLint location = mUniformLocations[ uniformIndex ].second;
224 if( location == UNIFORM_NOT_QUERIED )
226 location = CHECK_GL( mGlAbstraction, mGlAbstraction.GetUniformLocation( mProgramId, mUniformLocations[ uniformIndex ].first.c_str() ) );
228 mUniformLocations[ uniformIndex ].second = location;
229 LOG_GL( "GetUniformLocation(program=%d,%s) = %d\n", mProgramId, mUniformLocations[ uniformIndex ].first.c_str(), mUniformLocations[ uniformIndex ].second );
235 void Program::SetUniform1i( GLint location, GLint value0 )
237 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
239 if( UNIFORM_UNKNOWN == location )
241 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
242 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
243 // specified uniform variable will not be changed.following opengl silently do nothing
247 // check if uniform location fits the cache
248 if( location >= MAX_UNIFORM_CACHE_SIZE )
250 // not cached, make the gl call
251 LOG_GL( "Uniform1i(%d,%d)\n", location, value0 );
252 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform1i( location, value0 ) );
256 // check if the value is different from what's already been set
257 if( value0 != mUniformCacheInt[ location ] )
260 LOG_GL( "Uniform1i(%d,%d)\n", location, value0 );
261 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform1i( location, value0 ) );
263 mUniformCacheInt[ location ] = value0;
268 void Program::SetUniform4i( GLint location, GLint value0, GLint value1, GLint value2, GLint value3 )
270 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
272 if( UNIFORM_UNKNOWN == location )
274 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
275 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
276 // specified uniform variable will not be changed.following opengl silently do nothing
280 // Not caching these as based on current analysis this is not called that often by our shaders
281 LOG_GL( "Uniform4i(%d,%d,%d,%d,%d)\n", location, value0, value1, value2, value3 );
282 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform4i( location, value0, value1, value2, value3 ) );
285 void Program::SetUniform1f( GLint location, GLfloat value0 )
287 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
289 if( UNIFORM_UNKNOWN == location )
291 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
292 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
293 // specified uniform variable will not be changed.following opengl silently do nothing
297 // check if uniform location fits the cache
298 if( location >= MAX_UNIFORM_CACHE_SIZE )
300 // not cached, make the gl call
301 LOG_GL( "Uniform1f(%d,%f)\n", location, value0 );
302 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform1f( location, value0 ) );
306 // check if the same value has already been set, reset if it is different
307 if( ( fabsf(value0 - mUniformCacheFloat[ location ]) >= Math::MACHINE_EPSILON_1 ) )
310 LOG_GL( "Uniform1f(%d,%f)\n", location, value0 );
311 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform1f( location, value0 ) );
314 mUniformCacheFloat[ location ] = value0;
319 void Program::SetUniform2f( GLint location, GLfloat value0, GLfloat value1 )
321 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
323 if( UNIFORM_UNKNOWN == location )
325 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
326 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
327 // specified uniform variable will not be changed.following opengl silently do nothing
331 // Not caching these as based on current analysis this is not called that often by our shaders
332 LOG_GL( "Uniform2f(%d,%f,%f)\n", location, value0, value1 );
333 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform2f( location, value0, value1 ) );
336 void Program::SetSizeUniform3f( GLint location, GLfloat value0, GLfloat value1, GLfloat value2 )
338 if( ( fabsf(value0 - mSizeUniformCache.x) >= Math::MACHINE_EPSILON_1 )||
339 ( fabsf(value1 - mSizeUniformCache.y) >= Math::MACHINE_EPSILON_1 )||
340 ( fabsf(value2 - mSizeUniformCache.z) >= Math::MACHINE_EPSILON_1 ) )
342 mSizeUniformCache.x = value0;
343 mSizeUniformCache.y = value1;
344 mSizeUniformCache.z = value2;
345 SetUniform3f( location, value0, value1, value2 );
349 void Program::SetUniform3f( GLint location, GLfloat value0, GLfloat value1, GLfloat value2 )
351 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
353 if( UNIFORM_UNKNOWN == location )
355 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
356 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
357 // specified uniform variable will not be changed.following opengl silently do nothing
361 // Not caching these as based on current analysis this is not called that often by our shaders
362 LOG_GL( "Uniform3f(%d,%f,%f,%f)\n", location, value0, value1, value2 );
363 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform3f( location, value0, value1, value2 ) );
366 void Program::SetUniform4f( GLint location, GLfloat value0, GLfloat value1, GLfloat value2, GLfloat value3 )
368 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
370 if( UNIFORM_UNKNOWN == location )
372 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
373 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
374 // specified uniform variable will not be changed.following opengl silently do nothing
378 // check if uniform location fits the cache
379 if( location >= MAX_UNIFORM_CACHE_SIZE )
381 // not cached, make the gl call
382 LOG_GL( "Uniform4f(%d,%f,%f,%f,%f)\n", location, value0, value1, value2, value3 );
383 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform4f( location, value0, value1, value2, value3 ) );
387 // check if the same value has already been set, reset if any component is different
388 // checking index 3 first because we're often animating alpha (rgba)
389 if( ( fabsf(value3 - mUniformCacheFloat4[ location ][ 3 ]) >= Math::MACHINE_EPSILON_1 )||
390 ( fabsf(value0 - mUniformCacheFloat4[ location ][ 0 ]) >= Math::MACHINE_EPSILON_1 )||
391 ( fabsf(value1 - mUniformCacheFloat4[ location ][ 1 ]) >= Math::MACHINE_EPSILON_1 )||
392 ( fabsf(value2 - mUniformCacheFloat4[ location ][ 2 ]) >= Math::MACHINE_EPSILON_1 ) )
395 LOG_GL( "Uniform4f(%d,%f,%f,%f,%f)\n", location, value0, value1, value2, value3 );
396 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform4f( location, value0, value1, value2, value3 ) );
398 mUniformCacheFloat4[ location ][ 0 ] = value0;
399 mUniformCacheFloat4[ location ][ 1 ] = value1;
400 mUniformCacheFloat4[ location ][ 2 ] = value2;
401 mUniformCacheFloat4[ location ][ 3 ] = value3;
406 void Program::SetUniformMatrix4fv( GLint location, GLsizei count, const GLfloat* value )
408 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
410 if( UNIFORM_UNKNOWN == location )
412 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
413 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
414 // specified uniform variable will not be changed.following opengl silently do nothing
418 // Not caching these calls. Based on current analysis this is called very often
419 // but with different values (we're using this for MVP matrices)
420 // NOTE! we never want driver or GPU to transpose
421 LOG_GL( "UniformMatrix4fv(%d,%d,GL_FALSE,%x)\n", location, count, value );
422 CHECK_GL( mGlAbstraction, mGlAbstraction.UniformMatrix4fv( location, count, GL_FALSE, value ) );
425 void Program::SetUniformMatrix3fv( GLint location, GLsizei count, const GLfloat* value )
427 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
429 if( UNIFORM_UNKNOWN == location )
431 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
432 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
433 // specified uniform variable will not be changed.following opengl silently do nothing
438 // Not caching these calls. Based on current analysis this is called very often
439 // but with different values (we're using this for MVP matrices)
440 // NOTE! we never want driver or GPU to transpose
441 LOG_GL( "UniformMatrix3fv(%d,%d,GL_FALSE,%x)\n", location, count, value );
442 CHECK_GL( mGlAbstraction, mGlAbstraction.UniformMatrix3fv( location, count, GL_FALSE, value ) );
445 void Program::GlContextCreated()
449 void Program::GlContextDestroyed()
453 mFragmentShaderId = 0;
456 ResetAttribsUniformCache();
459 bool Program::ModifiesGeometry()
461 return mModifiesGeometry;
464 Program::Program( ProgramCache& cache, Internal::ShaderDataPtr shaderData, bool modifiesGeometry )
466 mGlAbstraction( mCache.GetGlAbstraction() ),
467 mProjectionMatrix( NULL ),
470 mVertexShaderId( 0 ),
471 mFragmentShaderId( 0 ),
473 mProgramData(shaderData),
474 mModifiesGeometry( modifiesGeometry )
476 // reserve space for standard attributes
477 mAttributeLocations.reserve( ATTRIB_TYPE_LAST );
478 for( int i=0; i<ATTRIB_TYPE_LAST; ++i )
480 RegisterCustomAttribute( gStdAttribs[i] );
483 // reserve space for standard uniforms
484 mUniformLocations.reserve( UNIFORM_TYPE_LAST );
485 // reset built in uniform names in cache
486 for( int i = 0; i < UNIFORM_TYPE_LAST; ++i )
488 RegisterUniform( gStdUniforms[ i ] );
491 ResetAttribsUniformCache();
501 DALI_ASSERT_ALWAYS( NULL != mProgramData.Get() && "Program data is not initialized" );
502 DALI_ASSERT_DEBUG( mProgramId == 0 && "mProgramId != 0, so about to leak a GL resource by overwriting it." );
504 LOG_GL( "CreateProgram()\n" );
505 mProgramId = CHECK_GL( mGlAbstraction, mGlAbstraction.CreateProgram() );
507 GLint linked = GL_FALSE;
509 const bool binariesSupported = mCache.IsBinarySupported();
511 // if shader binaries are supported and ShaderData contains compiled bytecode?
512 if( binariesSupported && mProgramData->HasBinary() )
514 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "Program::Load() - Using Compiled Shader, Size = %d\n", mProgramData->GetBufferSize());
516 CHECK_GL( mGlAbstraction, mGlAbstraction.ProgramBinary(mProgramId, mCache.ProgramBinaryFormat(), mProgramData->GetBufferData(), mProgramData->GetBufferSize()) );
518 CHECK_GL( mGlAbstraction, mGlAbstraction.ValidateProgram(mProgramId) );
521 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramiv( mProgramId, GL_VALIDATE_STATUS, &success ) );
523 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "ValidateProgram Status = %d\n", success);
525 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramiv( mProgramId, GL_LINK_STATUS, &linked ) );
527 if( GL_FALSE == linked )
529 DALI_LOG_ERROR("Failed to load program binary \n");
532 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramiv( mProgramId, GL_INFO_LOG_LENGTH, &nLength) );
535 Dali::Vector< char > szLog;
536 szLog.Reserve( nLength ); // Don't call Resize as we don't want to initialise the data, just reserve a buffer
537 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramInfoLog( mProgramId, nLength, &nLength, szLog.Begin() ) );
538 DALI_LOG_ERROR( "Program Link Error: %s\n", szLog.Begin() );
544 DALI_LOG_INFO( Debug::Filter::gShader, Debug::General, "Reused binary.\n" );
548 // Fall back to compiling and linking the vertex and fragment sources
549 if( GL_FALSE == linked )
551 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "Program::Load() - Runtime compilation\n");
552 if( CompileShader( GL_VERTEX_SHADER, mVertexShaderId, mProgramData->GetVertexShader() ) )
554 if( CompileShader( GL_FRAGMENT_SHADER, mFragmentShaderId, mProgramData->GetFragmentShader() ) )
558 if( binariesSupported && mLinked )
560 GLint binaryLength = 0;
562 DALI_LOG_INFO( Debug::Filter::gShader, Debug::General, "Compiled and linked.\n\nVS:\n%s\nFS:\n%s\n", mProgramData->GetVertexShader(), mProgramData->GetFragmentShader() );
564 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramiv(mProgramId, GL_PROGRAM_BINARY_LENGTH_OES, &binaryLength) );
565 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "Program::Load() - GL_PROGRAM_BINARY_LENGTH_OES: %d\n", binaryLength);
566 if( binaryLength > 0 )
568 // Allocate space for the bytecode in ShaderData
569 mProgramData->AllocateBuffer(binaryLength);
570 // Copy the bytecode to ShaderData
571 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramBinary(mProgramId, binaryLength, NULL, &binaryFormat, mProgramData->GetBufferData()) );
572 mCache.StoreBinary( mProgramData );
573 DALI_LOG_INFO( Debug::Filter::gShader, Debug::General, "Saved binary.\n" );
584 void Program::Unload()
588 if( this == mCache.GetCurrentProgram() )
590 CHECK_GL( mGlAbstraction, mGlAbstraction.UseProgram(0) );
592 mCache.SetCurrentProgram( NULL );
597 LOG_GL( "DeleteProgram(%d)\n", mProgramId );
598 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteProgram( mProgramId ) );
606 bool Program::CompileShader( GLenum shaderType, GLuint& shaderId, const char* src )
610 LOG_GL( "CreateShader(%d)\n", shaderType );
611 shaderId = CHECK_GL( mGlAbstraction, mGlAbstraction.CreateShader( shaderType ) );
612 LOG_GL( "AttachShader(%d,%d)\n", mProgramId, shaderId );
613 CHECK_GL( mGlAbstraction, mGlAbstraction.AttachShader( mProgramId, shaderId ) );
616 LOG_GL( "ShaderSource(%d)\n", shaderId );
617 CHECK_GL( mGlAbstraction, mGlAbstraction.ShaderSource(shaderId, 1, &src, NULL ) );
619 LOG_GL( "CompileShader(%d)\n", shaderId );
620 CHECK_GL( mGlAbstraction, mGlAbstraction.CompileShader( shaderId ) );
623 LOG_GL( "GetShaderiv(%d)\n", shaderId );
624 CHECK_GL( mGlAbstraction, mGlAbstraction.GetShaderiv( shaderId, GL_COMPILE_STATUS, &compiled ) );
626 if (compiled == GL_FALSE)
628 DALI_LOG_ERROR("Failed to compile shader\n");
629 LogWithLineNumbers(src);
632 mGlAbstraction.GetShaderiv( shaderId, GL_INFO_LOG_LENGTH, &nLength);
635 Dali::Vector< char > szLog;
636 szLog.Reserve( nLength ); // Don't call Resize as we don't want to initialise the data, just reserve a buffer
637 mGlAbstraction.GetShaderInfoLog( shaderId, nLength, &nLength, szLog.Begin() );
638 DALI_LOG_ERROR( "Shader Compiler Error: %s\n", szLog.Begin() );
641 DALI_ASSERT_ALWAYS( 0 && "Shader compilation failure" );
644 return compiled != 0;
649 LOG_GL( "LinkProgram(%d)\n", mProgramId );
650 CHECK_GL( mGlAbstraction, mGlAbstraction.LinkProgram( mProgramId ) );
653 LOG_GL( "GetProgramiv(%d)\n", mProgramId );
654 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramiv( mProgramId, GL_LINK_STATUS, &linked ) );
656 if (linked == GL_FALSE)
658 DALI_LOG_ERROR("Shader failed to link \n");
661 mGlAbstraction.GetProgramiv( mProgramId, GL_INFO_LOG_LENGTH, &nLength);
664 Dali::Vector< char > szLog;
665 szLog.Reserve( nLength ); // Don't call Resize as we don't want to initialise the data, just reserve a buffer
666 mGlAbstraction.GetProgramInfoLog( mProgramId, nLength, &nLength, szLog.Begin() );
667 DALI_LOG_ERROR( "Shader Link Error: %s\n", szLog.Begin() );
670 DALI_ASSERT_ALWAYS( 0 && "Shader linking failure" );
673 mLinked = linked != GL_FALSE;
676 void Program::FreeShaders()
680 LOG_GL( "DeleteShader(%d)\n", mVertexShaderId );
681 CHECK_GL( mGlAbstraction, mGlAbstraction.DetachShader( mProgramId, mVertexShaderId ) );
682 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteShader( mVertexShaderId ) );
686 if (mFragmentShaderId)
688 LOG_GL( "DeleteShader(%d)\n", mFragmentShaderId );
689 CHECK_GL( mGlAbstraction, mGlAbstraction.DetachShader( mProgramId, mFragmentShaderId ) );
690 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteShader( mFragmentShaderId ) );
691 mFragmentShaderId = 0;
695 void Program::ResetAttribsUniformCache()
697 // reset attribute locations
698 for( unsigned i = 0; i < mAttributeLocations.size() ; ++i )
700 mAttributeLocations[ i ].second = ATTRIB_UNKNOWN;
703 // reset all gl uniform locations
704 for( unsigned int i = 0; i < mUniformLocations.size(); ++i )
706 // reset gl program locations and names
707 mUniformLocations[ i ].second = UNIFORM_NOT_QUERIED;
710 // reset uniform caches
711 mSizeUniformCache.x = mSizeUniformCache.y = mSizeUniformCache.z = 0.f;
713 for( int i = 0; i < MAX_UNIFORM_CACHE_SIZE; ++i )
715 // GL initializes uniforms to 0
716 mUniformCacheInt[ i ] = 0;
717 mUniformCacheFloat[ i ] = 0.0f;
718 mUniformCacheFloat4[ i ][ 0 ] = 0.0f;
719 mUniformCacheFloat4[ i ][ 1 ] = 0.0f;
720 mUniformCacheFloat4[ i ][ 2 ] = 0.0f;
721 mUniformCacheFloat4[ i ][ 3 ] = 0.0f;
725 } // namespace Internal