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 "sTexture", // UNIFORM_SAMPLER
99 "sTextureRect", // UNIFORM_SAMPLER_RECT
100 "sEffect", // UNIFORM_EFFECT_SAMPLER
101 "uSize" // UNIFORM_SIZE
104 } // <unnamed> namespace
108 Program* Program::New( ProgramCache& cache, Internal::ShaderDataPtr shaderData, bool modifiesGeometry )
110 size_t shaderHash = shaderData->GetHashValue();
111 Program* program = cache.GetProgram( shaderHash );
113 if( NULL == program )
115 // program not found so create it
116 program = new Program( cache, shaderData, modifiesGeometry );
118 // we want to lazy load programs so dont do a Load yet, it gets done in Use()
120 cache.AddProgram( shaderHash, program );
135 if ( this != mCache.GetCurrentProgram() )
137 LOG_GL( "UseProgram(%d)\n", mProgramId );
138 CHECK_GL( mGlAbstraction, mGlAbstraction.UseProgram(mProgramId) );
140 mCache.SetCurrentProgram( this );
145 bool Program::IsUsed()
147 return ( this == mCache.GetCurrentProgram() );
150 GLint Program::GetAttribLocation( AttribType type )
152 DALI_ASSERT_DEBUG(type != ATTRIB_UNKNOWN);
154 return GetCustomAttributeLocation( type );
157 unsigned int Program::RegisterCustomAttribute( const std::string& name )
159 unsigned int index = 0;
160 // find the value from cache
161 for( ;index < mAttributeLocations.size(); ++index )
163 if( mAttributeLocations[ index ].first == name )
165 // name found so return index
169 // if we get here, index is one past end so push back the new name
170 mAttributeLocations.push_back( std::make_pair( name, ATTRIB_UNKNOWN ) );
174 GLint Program::GetCustomAttributeLocation( unsigned int attributeIndex )
176 // debug check that index is within name cache
177 DALI_ASSERT_DEBUG( mAttributeLocations.size() > attributeIndex );
179 // check if we have already queried the location of the attribute
180 GLint location = mAttributeLocations[ attributeIndex ].second;
182 if( location == ATTRIB_UNKNOWN )
184 location = CHECK_GL( mGlAbstraction, mGlAbstraction.GetAttribLocation( mProgramId, mAttributeLocations[ attributeIndex ].first.c_str() ) );
186 mAttributeLocations[ attributeIndex ].second = location;
187 LOG_GL( "GetAttributeLocation(program=%d,%s) = %d\n", mProgramId, mAttributeLocations[ attributeIndex ].first.c_str(), mAttributeLocations[ attributeIndex ].second );
194 unsigned int Program::RegisterUniform( const std::string& name )
196 unsigned int index = 0;
197 // find the value from cache
198 for( ;index < mUniformLocations.size(); ++index )
200 if( mUniformLocations[ index ].first == name )
202 // name found so return index
206 // if we get here, index is one past end so push back the new name
207 mUniformLocations.push_back( std::make_pair( name, UNIFORM_NOT_QUERIED ) );
211 GLint Program::GetUniformLocation( unsigned int uniformIndex )
213 // debug check that index is within name cache
214 DALI_ASSERT_DEBUG( mUniformLocations.size() > uniformIndex );
216 // check if we have already queried the location of the uniform
217 GLint location = mUniformLocations[ uniformIndex ].second;
219 if( location == UNIFORM_NOT_QUERIED )
221 location = CHECK_GL( mGlAbstraction, mGlAbstraction.GetUniformLocation( mProgramId, mUniformLocations[ uniformIndex ].first.c_str() ) );
223 mUniformLocations[ uniformIndex ].second = location;
224 LOG_GL( "GetUniformLocation(program=%d,%s) = %d\n", mProgramId, mUniformLocations[ uniformIndex ].first.c_str(), mUniformLocations[ uniformIndex ].second );
230 void Program::SetUniform1i( GLint location, GLint value0 )
232 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
234 if( UNIFORM_UNKNOWN == location )
236 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
237 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
238 // specified uniform variable will not be changed.following opengl silently do nothing
242 // check if uniform location fits the cache
243 if( location >= MAX_UNIFORM_CACHE_SIZE )
245 // not cached, make the gl call
246 LOG_GL( "Uniform1i(%d,%d)\n", location, value0 );
247 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform1i( location, value0 ) );
251 // check if the value is different from what's already been set
252 if( value0 != mUniformCacheInt[ location ] )
255 LOG_GL( "Uniform1i(%d,%d)\n", location, value0 );
256 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform1i( location, value0 ) );
258 mUniformCacheInt[ location ] = value0;
263 void Program::SetUniform4i( GLint location, GLint value0, GLint value1, GLint value2, GLint value3 )
265 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
267 if( UNIFORM_UNKNOWN == location )
269 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
270 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
271 // specified uniform variable will not be changed.following opengl silently do nothing
275 // Not caching these as based on current analysis this is not called that often by our shaders
276 LOG_GL( "Uniform4i(%d,%d,%d,%d,%d)\n", location, value0, value1, value2, value3 );
277 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform4i( location, value0, value1, value2, value3 ) );
280 void Program::SetUniform1f( GLint location, GLfloat value0 )
282 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
284 if( UNIFORM_UNKNOWN == location )
286 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
287 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
288 // specified uniform variable will not be changed.following opengl silently do nothing
292 // check if uniform location fits the cache
293 if( location >= MAX_UNIFORM_CACHE_SIZE )
295 // not cached, make the gl call
296 LOG_GL( "Uniform1f(%d,%f)\n", location, value0 );
297 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform1f( location, value0 ) );
301 // check if the same value has already been set, reset if it is different
302 if( ( fabsf(value0 - mUniformCacheFloat[ location ]) >= Math::MACHINE_EPSILON_1 ) )
305 LOG_GL( "Uniform1f(%d,%f)\n", location, value0 );
306 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform1f( location, value0 ) );
309 mUniformCacheFloat[ location ] = value0;
314 void Program::SetUniform2f( GLint location, GLfloat value0, GLfloat value1 )
316 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
318 if( UNIFORM_UNKNOWN == location )
320 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
321 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
322 // specified uniform variable will not be changed.following opengl silently do nothing
326 // Not caching these as based on current analysis this is not called that often by our shaders
327 LOG_GL( "Uniform2f(%d,%f,%f)\n", location, value0, value1 );
328 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform2f( location, value0, value1 ) );
331 void Program::SetSizeUniform3f( GLint location, GLfloat value0, GLfloat value1, GLfloat value2 )
333 if( ( fabsf(value0 - mSizeUniformCache.x) >= Math::MACHINE_EPSILON_1 )||
334 ( fabsf(value1 - mSizeUniformCache.y) >= Math::MACHINE_EPSILON_1 )||
335 ( fabsf(value2 - mSizeUniformCache.z) >= Math::MACHINE_EPSILON_1 ) )
337 mSizeUniformCache.x = value0;
338 mSizeUniformCache.y = value1;
339 mSizeUniformCache.z = value2;
340 SetUniform3f( location, value0, value1, value2 );
344 void Program::SetUniform3f( GLint location, GLfloat value0, GLfloat value1, GLfloat value2 )
346 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
348 if( UNIFORM_UNKNOWN == location )
350 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
351 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
352 // specified uniform variable will not be changed.following opengl silently do nothing
356 // Not caching these as based on current analysis this is not called that often by our shaders
357 LOG_GL( "Uniform3f(%d,%f,%f,%f)\n", location, value0, value1, value2 );
358 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform3f( location, value0, value1, value2 ) );
361 void Program::SetUniform4f( GLint location, GLfloat value0, GLfloat value1, GLfloat value2, GLfloat value3 )
363 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
365 if( UNIFORM_UNKNOWN == location )
367 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
368 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
369 // specified uniform variable will not be changed.following opengl silently do nothing
373 // check if uniform location fits the cache
374 if( location >= MAX_UNIFORM_CACHE_SIZE )
376 // not cached, make the gl call
377 LOG_GL( "Uniform4f(%d,%f,%f,%f,%f)\n", location, value0, value1, value2, value3 );
378 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform4f( location, value0, value1, value2, value3 ) );
382 // check if the same value has already been set, reset if any component is different
383 // checking index 3 first because we're often animating alpha (rgba)
384 if( ( fabsf(value3 - mUniformCacheFloat4[ location ][ 3 ]) >= Math::MACHINE_EPSILON_1 )||
385 ( fabsf(value0 - mUniformCacheFloat4[ location ][ 0 ]) >= Math::MACHINE_EPSILON_1 )||
386 ( fabsf(value1 - mUniformCacheFloat4[ location ][ 1 ]) >= Math::MACHINE_EPSILON_1 )||
387 ( fabsf(value2 - mUniformCacheFloat4[ location ][ 2 ]) >= Math::MACHINE_EPSILON_1 ) )
390 LOG_GL( "Uniform4f(%d,%f,%f,%f,%f)\n", location, value0, value1, value2, value3 );
391 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform4f( location, value0, value1, value2, value3 ) );
393 mUniformCacheFloat4[ location ][ 0 ] = value0;
394 mUniformCacheFloat4[ location ][ 1 ] = value1;
395 mUniformCacheFloat4[ location ][ 2 ] = value2;
396 mUniformCacheFloat4[ location ][ 3 ] = value3;
401 void Program::SetUniformMatrix4fv( GLint location, GLsizei count, const GLfloat* value )
403 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
405 if( UNIFORM_UNKNOWN == location )
407 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
408 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
409 // specified uniform variable will not be changed.following opengl silently do nothing
413 // Not caching these calls. Based on current analysis this is called very often
414 // but with different values (we're using this for MVP matrices)
415 // NOTE! we never want driver or GPU to transpose
416 LOG_GL( "UniformMatrix4fv(%d,%d,GL_FALSE,%x)\n", location, count, value );
417 CHECK_GL( mGlAbstraction, mGlAbstraction.UniformMatrix4fv( location, count, GL_FALSE, value ) );
420 void Program::SetUniformMatrix3fv( GLint location, GLsizei count, const GLfloat* value )
422 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
424 if( UNIFORM_UNKNOWN == location )
426 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
427 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
428 // specified uniform variable will not be changed.following opengl silently do nothing
433 // Not caching these calls. Based on current analysis this is called very often
434 // but with different values (we're using this for MVP matrices)
435 // NOTE! we never want driver or GPU to transpose
436 LOG_GL( "UniformMatrix3fv(%d,%d,GL_FALSE,%x)\n", location, count, value );
437 CHECK_GL( mGlAbstraction, mGlAbstraction.UniformMatrix3fv( location, count, GL_FALSE, value ) );
440 void Program::GlContextCreated()
444 void Program::GlContextDestroyed()
448 mFragmentShaderId = 0;
451 ResetAttribsUniformCache();
454 bool Program::ModifiesGeometry()
456 return mModifiesGeometry;
459 Program::Program( ProgramCache& cache, Internal::ShaderDataPtr shaderData, bool modifiesGeometry )
461 mGlAbstraction( mCache.GetGlAbstraction() ),
462 mProjectionMatrix( NULL ),
465 mVertexShaderId( 0 ),
466 mFragmentShaderId( 0 ),
468 mProgramData(shaderData),
469 mModifiesGeometry( modifiesGeometry )
471 // reserve space for standard attributes
472 mAttributeLocations.reserve( ATTRIB_TYPE_LAST );
473 for( int i=0; i<ATTRIB_TYPE_LAST; ++i )
475 RegisterCustomAttribute( gStdAttribs[i] );
478 // reserve space for standard uniforms
479 mUniformLocations.reserve( UNIFORM_TYPE_LAST );
480 // reset built in uniform names in cache
481 for( int i = 0; i < UNIFORM_TYPE_LAST; ++i )
483 RegisterUniform( gStdUniforms[ i ] );
486 ResetAttribsUniformCache();
496 DALI_ASSERT_ALWAYS( NULL != mProgramData.Get() && "Program data is not initialized" );
497 DALI_ASSERT_DEBUG( mProgramId == 0 && "mProgramId != 0, so about to leak a GL resource by overwriting it." );
499 LOG_GL( "CreateProgram()\n" );
500 mProgramId = CHECK_GL( mGlAbstraction, mGlAbstraction.CreateProgram() );
502 GLint linked = GL_FALSE;
504 const bool binariesSupported = mCache.IsBinarySupported();
506 // if shader binaries are supported and ShaderData contains compiled bytecode?
507 if( binariesSupported && mProgramData->HasBinary() )
509 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "Program::Load() - Using Compiled Shader, Size = %d\n", mProgramData->GetBufferSize());
511 CHECK_GL( mGlAbstraction, mGlAbstraction.ProgramBinary(mProgramId, mCache.ProgramBinaryFormat(), mProgramData->GetBufferData(), mProgramData->GetBufferSize()) );
513 CHECK_GL( mGlAbstraction, mGlAbstraction.ValidateProgram(mProgramId) );
516 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramiv( mProgramId, GL_VALIDATE_STATUS, &success ) );
518 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "ValidateProgram Status = %d\n", success);
520 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramiv( mProgramId, GL_LINK_STATUS, &linked ) );
522 if( GL_FALSE == linked )
524 DALI_LOG_ERROR("Failed to load program binary \n");
527 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramiv( mProgramId, GL_INFO_LOG_LENGTH, &nLength) );
530 Dali::Vector< char > szLog;
531 szLog.Reserve( nLength ); // Don't call Resize as we don't want to initialise the data, just reserve a buffer
532 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramInfoLog( mProgramId, nLength, &nLength, szLog.Begin() ) );
533 DALI_LOG_ERROR( "Program Link Error: %s\n", szLog.Begin() );
539 DALI_LOG_INFO( Debug::Filter::gShader, Debug::General, "Reused binary.\n" );
543 // Fall back to compiling and linking the vertex and fragment sources
544 if( GL_FALSE == linked )
546 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "Program::Load() - Runtime compilation\n");
547 if( CompileShader( GL_VERTEX_SHADER, mVertexShaderId, mProgramData->GetVertexShader() ) )
549 if( CompileShader( GL_FRAGMENT_SHADER, mFragmentShaderId, mProgramData->GetFragmentShader() ) )
553 if( binariesSupported && mLinked )
555 GLint binaryLength = 0;
557 DALI_LOG_INFO( Debug::Filter::gShader, Debug::General, "Compiled and linked.\n\nVS:\n%s\nFS:\n%s\n", mProgramData->GetVertexShader(), mProgramData->GetFragmentShader() );
559 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramiv(mProgramId, GL_PROGRAM_BINARY_LENGTH_OES, &binaryLength) );
560 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "Program::Load() - GL_PROGRAM_BINARY_LENGTH_OES: %d\n", binaryLength);
561 if( binaryLength > 0 )
563 // Allocate space for the bytecode in ShaderData
564 mProgramData->AllocateBuffer(binaryLength);
565 // Copy the bytecode to ShaderData
566 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramBinary(mProgramId, binaryLength, NULL, &binaryFormat, mProgramData->GetBufferData()) );
567 mCache.StoreBinary( mProgramData );
568 DALI_LOG_INFO( Debug::Filter::gShader, Debug::General, "Saved binary.\n" );
579 void Program::Unload()
583 if( this == mCache.GetCurrentProgram() )
585 CHECK_GL( mGlAbstraction, mGlAbstraction.UseProgram(0) );
587 mCache.SetCurrentProgram( NULL );
592 LOG_GL( "DeleteProgram(%d)\n", mProgramId );
593 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteProgram( mProgramId ) );
601 bool Program::CompileShader( GLenum shaderType, GLuint& shaderId, const char* src )
605 LOG_GL( "CreateShader(%d)\n", shaderType );
606 shaderId = CHECK_GL( mGlAbstraction, mGlAbstraction.CreateShader( shaderType ) );
607 LOG_GL( "AttachShader(%d,%d)\n", mProgramId, shaderId );
608 CHECK_GL( mGlAbstraction, mGlAbstraction.AttachShader( mProgramId, shaderId ) );
611 LOG_GL( "ShaderSource(%d)\n", shaderId );
612 CHECK_GL( mGlAbstraction, mGlAbstraction.ShaderSource(shaderId, 1, &src, NULL ) );
614 LOG_GL( "CompileShader(%d)\n", shaderId );
615 CHECK_GL( mGlAbstraction, mGlAbstraction.CompileShader( shaderId ) );
618 LOG_GL( "GetShaderiv(%d)\n", shaderId );
619 CHECK_GL( mGlAbstraction, mGlAbstraction.GetShaderiv( shaderId, GL_COMPILE_STATUS, &compiled ) );
621 if (compiled == GL_FALSE)
623 DALI_LOG_ERROR("Failed to compile shader\n");
624 LogWithLineNumbers(src);
627 mGlAbstraction.GetShaderiv( shaderId, GL_INFO_LOG_LENGTH, &nLength);
630 Dali::Vector< char > szLog;
631 szLog.Reserve( nLength ); // Don't call Resize as we don't want to initialise the data, just reserve a buffer
632 mGlAbstraction.GetShaderInfoLog( shaderId, nLength, &nLength, szLog.Begin() );
633 DALI_LOG_ERROR( "Shader Compiler Error: %s\n", szLog.Begin() );
636 DALI_ASSERT_ALWAYS( 0 && "Shader compilation failure" );
639 return compiled != 0;
644 LOG_GL( "LinkProgram(%d)\n", mProgramId );
645 CHECK_GL( mGlAbstraction, mGlAbstraction.LinkProgram( mProgramId ) );
648 LOG_GL( "GetProgramiv(%d)\n", mProgramId );
649 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramiv( mProgramId, GL_LINK_STATUS, &linked ) );
651 if (linked == GL_FALSE)
653 DALI_LOG_ERROR("Shader failed to link \n");
656 mGlAbstraction.GetProgramiv( mProgramId, GL_INFO_LOG_LENGTH, &nLength);
659 Dali::Vector< char > szLog;
660 szLog.Reserve( nLength ); // Don't call Resize as we don't want to initialise the data, just reserve a buffer
661 mGlAbstraction.GetProgramInfoLog( mProgramId, nLength, &nLength, szLog.Begin() );
662 DALI_LOG_ERROR( "Shader Link Error: %s\n", szLog.Begin() );
665 DALI_ASSERT_ALWAYS( 0 && "Shader linking failure" );
668 mLinked = linked != GL_FALSE;
671 void Program::FreeShaders()
675 LOG_GL( "DeleteShader(%d)\n", mVertexShaderId );
676 CHECK_GL( mGlAbstraction, mGlAbstraction.DetachShader( mProgramId, mVertexShaderId ) );
677 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteShader( mVertexShaderId ) );
681 if (mFragmentShaderId)
683 LOG_GL( "DeleteShader(%d)\n", mFragmentShaderId );
684 CHECK_GL( mGlAbstraction, mGlAbstraction.DetachShader( mProgramId, mFragmentShaderId ) );
685 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteShader( mFragmentShaderId ) );
686 mFragmentShaderId = 0;
690 void Program::ResetAttribsUniformCache()
692 // reset attribute locations
693 for( unsigned i = 0; i < mAttributeLocations.size() ; ++i )
695 mAttributeLocations[ i ].second = ATTRIB_UNKNOWN;
698 // reset all gl uniform locations
699 for( unsigned int i = 0; i < mUniformLocations.size(); ++i )
701 // reset gl program locations and names
702 mUniformLocations[ i ].second = UNIFORM_NOT_QUERIED;
705 // reset uniform caches
706 mSizeUniformCache.x = mSizeUniformCache.y = mSizeUniformCache.z = 0.f;
708 for( int i = 0; i < MAX_UNIFORM_CACHE_SIZE; ++i )
710 // GL initializes uniforms to 0
711 mUniformCacheInt[ i ] = 0;
712 mUniformCacheFloat[ i ] = 0.0f;
713 mUniformCacheFloat4[ i ][ 0 ] = 0.0f;
714 mUniformCacheFloat4[ i ][ 1 ] = 0.0f;
715 mUniformCacheFloat4[ i ][ 2 ] = 0.0f;
716 mUniformCacheFloat4[ i ][ 3 ] = 0.0f;
720 } // namespace Internal