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 "aTexCoord", // ATTRIB_TEXCOORD
85 const char* gStdUniforms[ Program::UNIFORM_TYPE_LAST ] =
87 "uMvpMatrix", // UNIFORM_MVP_MATRIX
88 "uModelView", // UNIFORM_MODELVIEW_MATRIX
89 "uProjection", // UNIFORM_PROJECTION_MATRIX
90 "uModelMatrix", // UNIFORM_MODEL_MATRIX,
91 "uViewMatrix", // UNIFORM_VIEW_MATRIX,
92 "uNormalMatrix", // UNIFORM_NORMAL_MATRIX
93 "uColor", // UNIFORM_COLOR
94 "sTexture", // UNIFORM_SAMPLER
95 "sTextureRect", // UNIFORM_SAMPLER_RECT
96 "sEffect", // UNIFORM_EFFECT_SAMPLER
97 "uSize" // UNIFORM_SIZE
100 } // <unnamed> namespace
104 Program* Program::New( ProgramCache& cache, Internal::ShaderDataPtr shaderData, bool modifiesGeometry )
106 size_t shaderHash = shaderData->GetHashValue();
107 Program* program = cache.GetProgram( shaderHash );
109 if( NULL == program )
111 // program not found so create it
112 program = new Program( cache, shaderData, modifiesGeometry );
114 // we want to lazy load programs so dont do a Load yet, it gets done in Use()
116 cache.AddProgram( shaderHash, program );
131 if ( this != mCache.GetCurrentProgram() )
133 LOG_GL( "UseProgram(%d)\n", mProgramId );
134 CHECK_GL( mGlAbstraction, mGlAbstraction.UseProgram(mProgramId) );
136 mCache.SetCurrentProgram( this );
141 bool Program::IsUsed()
143 return ( this == mCache.GetCurrentProgram() );
146 GLint Program::GetAttribLocation( AttribType type )
148 DALI_ASSERT_DEBUG(type != ATTRIB_UNKNOWN);
150 return GetCustomAttributeLocation( type );
153 unsigned int Program::RegisterCustomAttribute( const std::string& name )
155 unsigned int index = 0;
156 // find the value from cache
157 for( ;index < mAttributeLocations.size(); ++index )
159 if( mAttributeLocations[ index ].first == name )
161 // name found so return index
165 // if we get here, index is one past end so push back the new name
166 mAttributeLocations.push_back( std::make_pair( name, ATTRIB_UNKNOWN ) );
170 GLint Program::GetCustomAttributeLocation( unsigned int attributeIndex )
172 // debug check that index is within name cache
173 DALI_ASSERT_DEBUG( mAttributeLocations.size() > attributeIndex );
175 // check if we have already queried the location of the attribute
176 GLint location = mAttributeLocations[ attributeIndex ].second;
178 if( location == ATTRIB_UNKNOWN )
180 location = CHECK_GL( mGlAbstraction, mGlAbstraction.GetAttribLocation( mProgramId, mAttributeLocations[ attributeIndex ].first.c_str() ) );
182 mAttributeLocations[ attributeIndex ].second = location;
183 LOG_GL( "GetAttributeLocation(program=%d,%s) = %d\n", mProgramId, mAttributeLocations[ attributeIndex ].first.c_str(), mAttributeLocations[ attributeIndex ].second );
190 unsigned int Program::RegisterUniform( const std::string& name )
192 unsigned int index = 0;
193 // find the value from cache
194 for( ;index < mUniformLocations.size(); ++index )
196 if( mUniformLocations[ index ].first == name )
198 // name found so return index
202 // if we get here, index is one past end so push back the new name
203 mUniformLocations.push_back( std::make_pair( name, UNIFORM_NOT_QUERIED ) );
207 GLint Program::GetUniformLocation( unsigned int uniformIndex )
209 // debug check that index is within name cache
210 DALI_ASSERT_DEBUG( mUniformLocations.size() > uniformIndex );
212 // check if we have already queried the location of the uniform
213 GLint location = mUniformLocations[ uniformIndex ].second;
215 if( location == UNIFORM_NOT_QUERIED )
217 location = CHECK_GL( mGlAbstraction, mGlAbstraction.GetUniformLocation( mProgramId, mUniformLocations[ uniformIndex ].first.c_str() ) );
219 mUniformLocations[ uniformIndex ].second = location;
220 LOG_GL( "GetUniformLocation(program=%d,%s) = %d\n", mProgramId, mUniformLocations[ uniformIndex ].first.c_str(), mUniformLocations[ uniformIndex ].second );
226 void Program::SetUniform1i( GLint location, GLint value0 )
228 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
230 if( UNIFORM_UNKNOWN == location )
232 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
233 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
234 // specified uniform variable will not be changed.following opengl silently do nothing
238 // check if uniform location fits the cache
239 if( location >= MAX_UNIFORM_CACHE_SIZE )
241 // not cached, make the gl call
242 LOG_GL( "Uniform1i(%d,%d)\n", location, value0 );
243 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform1i( location, value0 ) );
247 // check if the value is different from what's already been set
248 if( value0 != mUniformCacheInt[ location ] )
251 LOG_GL( "Uniform1i(%d,%d)\n", location, value0 );
252 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform1i( location, value0 ) );
254 mUniformCacheInt[ location ] = value0;
259 void Program::SetUniform4i( GLint location, GLint value0, GLint value1, GLint value2, GLint value3 )
261 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
263 if( UNIFORM_UNKNOWN == location )
265 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
266 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
267 // specified uniform variable will not be changed.following opengl silently do nothing
271 // Not caching these as based on current analysis this is not called that often by our shaders
272 LOG_GL( "Uniform4i(%d,%d,%d,%d,%d)\n", location, value0, value1, value2, value3 );
273 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform4i( location, value0, value1, value2, value3 ) );
276 void Program::SetUniform1f( GLint location, GLfloat value0 )
278 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
280 if( UNIFORM_UNKNOWN == location )
282 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
283 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
284 // specified uniform variable will not be changed.following opengl silently do nothing
288 // check if uniform location fits the cache
289 if( location >= MAX_UNIFORM_CACHE_SIZE )
291 // not cached, make the gl call
292 LOG_GL( "Uniform1f(%d,%f)\n", location, value0 );
293 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform1f( location, value0 ) );
297 // check if the same value has already been set, reset if it is different
298 if( ( fabsf(value0 - mUniformCacheFloat[ location ]) >= Math::MACHINE_EPSILON_1 ) )
301 LOG_GL( "Uniform1f(%d,%f)\n", location, value0 );
302 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform1f( location, value0 ) );
305 mUniformCacheFloat[ location ] = value0;
310 void Program::SetUniform2f( GLint location, GLfloat value0, GLfloat value1 )
312 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
314 if( UNIFORM_UNKNOWN == location )
316 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
317 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
318 // specified uniform variable will not be changed.following opengl silently do nothing
322 // check if uniform location fits the cache
323 if( location >= MAX_UNIFORM_CACHE_SIZE )
325 // not cached, make the gl call
326 LOG_GL( "Uniform2f(%d,%f,%f)\n", location, value0, value1 );
327 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform2f( location, value0, value1 ) );
331 // check if the same value has already been set, reset if it is different
332 if( ( fabsf(value0 - mUniformCacheFloat2[ location ][ 0 ]) >= Math::MACHINE_EPSILON_1 )||
333 ( fabsf(value1 - mUniformCacheFloat2[ location ][ 1 ]) >= Math::MACHINE_EPSILON_1 ) )
336 LOG_GL( "Uniform2f(%d,%f,%f)\n", location, value0, value1 );
337 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform2f( location, value0, value1 ) );
340 mUniformCacheFloat2[ location ][ 0 ] = value0;
341 mUniformCacheFloat2[ location ][ 1 ] = value1;
346 void Program::SetSizeUniform3f( GLint location, GLfloat value0, GLfloat value1, GLfloat value2 )
348 if( ( fabsf(value0 - mSizeUniformCache.x) >= Math::MACHINE_EPSILON_1 )||
349 ( fabsf(value1 - mSizeUniformCache.y) >= Math::MACHINE_EPSILON_1 )||
350 ( fabsf(value2 - mSizeUniformCache.z) >= Math::MACHINE_EPSILON_1 ) )
352 mSizeUniformCache.x = value0;
353 mSizeUniformCache.y = value1;
354 mSizeUniformCache.z = value2;
355 SetUniform3f( location, value0, value1, value2 );
359 void Program::SetUniform3f( GLint location, GLfloat value0, GLfloat value1, GLfloat value2 )
361 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
363 if( UNIFORM_UNKNOWN == location )
365 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
366 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
367 // specified uniform variable will not be changed.following opengl silently do nothing
371 // Not caching these as based on current analysis this is not called that often by our shaders
372 LOG_GL( "Uniform3f(%d,%f,%f,%f)\n", location, value0, value1, value2 );
373 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform3f( location, value0, value1, value2 ) );
376 void Program::SetUniform4f( GLint location, GLfloat value0, GLfloat value1, GLfloat value2, GLfloat value3 )
378 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
380 if( UNIFORM_UNKNOWN == location )
382 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
383 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
384 // specified uniform variable will not be changed.following opengl silently do nothing
388 // check if uniform location fits the cache
389 if( location >= MAX_UNIFORM_CACHE_SIZE )
391 // not cached, make the gl call
392 LOG_GL( "Uniform4f(%d,%f,%f,%f,%f)\n", location, value0, value1, value2, value3 );
393 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform4f( location, value0, value1, value2, value3 ) );
397 // check if the same value has already been set, reset if any component is different
398 // checking index 3 first because we're often animating alpha (rgba)
399 if( ( fabsf(value3 - mUniformCacheFloat4[ location ][ 3 ]) >= Math::MACHINE_EPSILON_1 )||
400 ( fabsf(value0 - mUniformCacheFloat4[ location ][ 0 ]) >= Math::MACHINE_EPSILON_1 )||
401 ( fabsf(value1 - mUniformCacheFloat4[ location ][ 1 ]) >= Math::MACHINE_EPSILON_1 )||
402 ( fabsf(value2 - mUniformCacheFloat4[ location ][ 2 ]) >= Math::MACHINE_EPSILON_1 ) )
405 LOG_GL( "Uniform4f(%d,%f,%f,%f,%f)\n", location, value0, value1, value2, value3 );
406 CHECK_GL( mGlAbstraction, mGlAbstraction.Uniform4f( location, value0, value1, value2, value3 ) );
408 mUniformCacheFloat4[ location ][ 0 ] = value0;
409 mUniformCacheFloat4[ location ][ 1 ] = value1;
410 mUniformCacheFloat4[ location ][ 2 ] = value2;
411 mUniformCacheFloat4[ location ][ 3 ] = value3;
416 void Program::SetUniformMatrix4fv( GLint location, GLsizei count, const GLfloat* value )
418 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
420 if( UNIFORM_UNKNOWN == location )
422 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
423 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
424 // specified uniform variable will not be changed.following opengl silently do nothing
428 // Not caching these calls. Based on current analysis this is called very often
429 // but with different values (we're using this for MVP matrices)
430 // NOTE! we never want driver or GPU to transpose
431 LOG_GL( "UniformMatrix4fv(%d,%d,GL_FALSE,%x)\n", location, count, value );
432 CHECK_GL( mGlAbstraction, mGlAbstraction.UniformMatrix4fv( location, count, GL_FALSE, value ) );
435 void Program::SetUniformMatrix3fv( GLint location, GLsizei count, const GLfloat* value )
437 DALI_ASSERT_DEBUG( IsUsed() ); // should not call this if this program is not used
439 if( UNIFORM_UNKNOWN == location )
441 // From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml : Notes
442 // If location is equal to UNIFORM_UNKNOWN, the data passed in will be silently ignored and the
443 // specified uniform variable will not be changed.following opengl silently do nothing
448 // Not caching these calls. Based on current analysis this is called very often
449 // but with different values (we're using this for MVP matrices)
450 // NOTE! we never want driver or GPU to transpose
451 LOG_GL( "UniformMatrix3fv(%d,%d,GL_FALSE,%x)\n", location, count, value );
452 CHECK_GL( mGlAbstraction, mGlAbstraction.UniformMatrix3fv( location, count, GL_FALSE, value ) );
455 void Program::GlContextCreated()
459 void Program::GlContextDestroyed()
463 mFragmentShaderId = 0;
466 ResetAttribsUniformCache();
469 bool Program::ModifiesGeometry()
471 return mModifiesGeometry;
474 Program::Program( ProgramCache& cache, Internal::ShaderDataPtr shaderData, bool modifiesGeometry )
476 mGlAbstraction( mCache.GetGlAbstraction() ),
477 mProjectionMatrix( NULL ),
480 mVertexShaderId( 0 ),
481 mFragmentShaderId( 0 ),
483 mProgramData(shaderData),
484 mModifiesGeometry( modifiesGeometry )
486 // reserve space for standard attributes
487 mAttributeLocations.reserve( ATTRIB_TYPE_LAST );
488 for( int i=0; i<ATTRIB_TYPE_LAST; ++i )
490 RegisterCustomAttribute( gStdAttribs[i] );
493 // reserve space for standard uniforms
494 mUniformLocations.reserve( UNIFORM_TYPE_LAST );
495 // reset built in uniform names in cache
496 for( int i = 0; i < UNIFORM_TYPE_LAST; ++i )
498 RegisterUniform( gStdUniforms[ i ] );
501 ResetAttribsUniformCache();
511 DALI_ASSERT_ALWAYS( NULL != mProgramData.Get() && "Program data is not initialized" );
512 DALI_ASSERT_DEBUG( mProgramId == 0 && "mProgramId != 0, so about to leak a GL resource by overwriting it." );
514 LOG_GL( "CreateProgram()\n" );
515 mProgramId = CHECK_GL( mGlAbstraction, mGlAbstraction.CreateProgram() );
517 GLint linked = GL_FALSE;
519 const bool binariesSupported = mCache.IsBinarySupported();
521 // if shader binaries are supported and ShaderData contains compiled bytecode?
522 if( binariesSupported && mProgramData->HasBinary() )
524 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "Program::Load() - Using Compiled Shader, Size = %d\n", mProgramData->GetBufferSize());
526 CHECK_GL( mGlAbstraction, mGlAbstraction.ProgramBinary(mProgramId, mCache.ProgramBinaryFormat(), mProgramData->GetBufferData(), mProgramData->GetBufferSize()) );
528 CHECK_GL( mGlAbstraction, mGlAbstraction.ValidateProgram(mProgramId) );
531 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramiv( mProgramId, GL_VALIDATE_STATUS, &success ) );
533 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "ValidateProgram Status = %d\n", success);
535 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramiv( mProgramId, GL_LINK_STATUS, &linked ) );
537 if( GL_FALSE == linked )
539 DALI_LOG_ERROR("Failed to load program binary \n");
542 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramiv( mProgramId, GL_INFO_LOG_LENGTH, &nLength) );
545 Dali::Vector< char > szLog;
546 szLog.Reserve( nLength ); // Don't call Resize as we don't want to initialise the data, just reserve a buffer
547 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramInfoLog( mProgramId, nLength, &nLength, szLog.Begin() ) );
548 DALI_LOG_ERROR( "Program Link Error: %s\n", szLog.Begin() );
554 DALI_LOG_INFO( Debug::Filter::gShader, Debug::General, "Reused binary.\n" );
558 // Fall back to compiling and linking the vertex and fragment sources
559 if( GL_FALSE == linked )
561 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "Program::Load() - Runtime compilation\n");
562 if( CompileShader( GL_VERTEX_SHADER, mVertexShaderId, mProgramData->GetVertexShader() ) )
564 if( CompileShader( GL_FRAGMENT_SHADER, mFragmentShaderId, mProgramData->GetFragmentShader() ) )
568 if( binariesSupported && mLinked )
570 GLint binaryLength = 0;
572 DALI_LOG_INFO( Debug::Filter::gShader, Debug::General, "Compiled and linked.\n\nVS:\n%s\nFS:\n%s\n", mProgramData->GetVertexShader(), mProgramData->GetFragmentShader() );
574 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramiv(mProgramId, GL_PROGRAM_BINARY_LENGTH_OES, &binaryLength) );
575 DALI_LOG_INFO(Debug::Filter::gShader, Debug::General, "Program::Load() - GL_PROGRAM_BINARY_LENGTH_OES: %d\n", binaryLength);
576 if( binaryLength > 0 )
578 // Allocate space for the bytecode in ShaderData
579 mProgramData->AllocateBuffer(binaryLength);
580 // Copy the bytecode to ShaderData
581 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramBinary(mProgramId, binaryLength, NULL, &binaryFormat, mProgramData->GetBufferData()) );
582 mCache.StoreBinary( mProgramData );
583 DALI_LOG_INFO( Debug::Filter::gShader, Debug::General, "Saved binary.\n" );
594 void Program::Unload()
598 if( this == mCache.GetCurrentProgram() )
600 CHECK_GL( mGlAbstraction, mGlAbstraction.UseProgram(0) );
602 mCache.SetCurrentProgram( NULL );
607 LOG_GL( "DeleteProgram(%d)\n", mProgramId );
608 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteProgram( mProgramId ) );
616 bool Program::CompileShader( GLenum shaderType, GLuint& shaderId, const char* src )
620 LOG_GL( "CreateShader(%d)\n", shaderType );
621 shaderId = CHECK_GL( mGlAbstraction, mGlAbstraction.CreateShader( shaderType ) );
622 LOG_GL( "AttachShader(%d,%d)\n", mProgramId, shaderId );
623 CHECK_GL( mGlAbstraction, mGlAbstraction.AttachShader( mProgramId, shaderId ) );
626 LOG_GL( "ShaderSource(%d)\n", shaderId );
627 CHECK_GL( mGlAbstraction, mGlAbstraction.ShaderSource(shaderId, 1, &src, NULL ) );
629 LOG_GL( "CompileShader(%d)\n", shaderId );
630 CHECK_GL( mGlAbstraction, mGlAbstraction.CompileShader( shaderId ) );
633 LOG_GL( "GetShaderiv(%d)\n", shaderId );
634 CHECK_GL( mGlAbstraction, mGlAbstraction.GetShaderiv( shaderId, GL_COMPILE_STATUS, &compiled ) );
636 if (compiled == GL_FALSE)
638 DALI_LOG_ERROR("Failed to compile shader\n");
639 LogWithLineNumbers(src);
642 mGlAbstraction.GetShaderiv( shaderId, GL_INFO_LOG_LENGTH, &nLength);
645 Dali::Vector< char > szLog;
646 szLog.Reserve( nLength ); // Don't call Resize as we don't want to initialise the data, just reserve a buffer
647 mGlAbstraction.GetShaderInfoLog( shaderId, nLength, &nLength, szLog.Begin() );
648 DALI_LOG_ERROR( "Shader Compiler Error: %s\n", szLog.Begin() );
651 DALI_ASSERT_ALWAYS( 0 && "Shader compilation failure" );
654 return compiled != 0;
659 LOG_GL( "LinkProgram(%d)\n", mProgramId );
660 CHECK_GL( mGlAbstraction, mGlAbstraction.LinkProgram( mProgramId ) );
663 LOG_GL( "GetProgramiv(%d)\n", mProgramId );
664 CHECK_GL( mGlAbstraction, mGlAbstraction.GetProgramiv( mProgramId, GL_LINK_STATUS, &linked ) );
666 if (linked == GL_FALSE)
668 DALI_LOG_ERROR("Shader failed to link \n");
671 mGlAbstraction.GetProgramiv( mProgramId, GL_INFO_LOG_LENGTH, &nLength);
674 Dali::Vector< char > szLog;
675 szLog.Reserve( nLength ); // Don't call Resize as we don't want to initialise the data, just reserve a buffer
676 mGlAbstraction.GetProgramInfoLog( mProgramId, nLength, &nLength, szLog.Begin() );
677 DALI_LOG_ERROR( "Shader Link Error: %s\n", szLog.Begin() );
680 DALI_ASSERT_ALWAYS( 0 && "Shader linking failure" );
683 mLinked = linked != GL_FALSE;
686 void Program::FreeShaders()
690 LOG_GL( "DeleteShader(%d)\n", mVertexShaderId );
691 CHECK_GL( mGlAbstraction, mGlAbstraction.DetachShader( mProgramId, mVertexShaderId ) );
692 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteShader( mVertexShaderId ) );
696 if (mFragmentShaderId)
698 LOG_GL( "DeleteShader(%d)\n", mFragmentShaderId );
699 CHECK_GL( mGlAbstraction, mGlAbstraction.DetachShader( mProgramId, mFragmentShaderId ) );
700 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteShader( mFragmentShaderId ) );
701 mFragmentShaderId = 0;
705 void Program::ResetAttribsUniformCache()
707 // reset attribute locations
708 for( unsigned i = 0; i < mAttributeLocations.size() ; ++i )
710 mAttributeLocations[ i ].second = ATTRIB_UNKNOWN;
713 // reset all gl uniform locations
714 for( unsigned int i = 0; i < mUniformLocations.size(); ++i )
716 // reset gl program locations and names
717 mUniformLocations[ i ].second = UNIFORM_NOT_QUERIED;
720 // reset uniform caches
721 mSizeUniformCache.x = mSizeUniformCache.y = mSizeUniformCache.z = 0.f;
723 for( int i = 0; i < MAX_UNIFORM_CACHE_SIZE; ++i )
725 // GL initializes uniforms to 0
726 mUniformCacheInt[ i ] = 0;
727 mUniformCacheFloat[ i ] = 0.0f;
728 mUniformCacheFloat2[ i ][ 0 ] = 0.0f;
729 mUniformCacheFloat2[ i ][ 1 ] = 0.0f;
730 mUniformCacheFloat4[ i ][ 0 ] = 0.0f;
731 mUniformCacheFloat4[ i ][ 1 ] = 0.0f;
732 mUniformCacheFloat4[ i ][ 2 ] = 0.0f;
733 mUniformCacheFloat4[ i ][ 3 ] = 0.0f;
737 } // namespace Internal