-void Renderer::SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map )
-{
- GLint location = program.GetUniformLocation(map.uniformIndex);
- if( Program::UNIFORM_UNKNOWN != location )
- {
- // switch based on property type to use correct GL uniform setter
- switch ( map.propertyValue->GetType() )
- {
- case Property::INTEGER:
- {
- program.SetUniform1i( location, map.propertyValue->GetInteger( bufferIndex ) );
- break;
- }
- case Property::FLOAT:
- {
- program.SetUniform1f( location, map.propertyValue->GetFloat( bufferIndex ) );
- break;
- }
- case Property::VECTOR2:
- {
- Vector2 value( map.propertyValue->GetVector2( bufferIndex ) );
- program.SetUniform2f( location, value.x, value.y );
- break;
- }
-
- case Property::VECTOR3:
- {
- Vector3 value( map.propertyValue->GetVector3( bufferIndex ) );
- program.SetUniform3f( location, value.x, value.y, value.z );
- break;
- }
-
- case Property::VECTOR4:
- {
- Vector4 value( map.propertyValue->GetVector4( bufferIndex ) );
- program.SetUniform4f( location, value.x, value.y, value.z, value.w );
- break;
- }
-
- case Property::ROTATION:
- {
- Quaternion value( map.propertyValue->GetQuaternion( bufferIndex ) );
- program.SetUniform4f( location, value.mVector.x, value.mVector.y, value.mVector.z, value.mVector.w );
- break;
- }
-
- case Property::MATRIX:
- {
- const Matrix& value = map.propertyValue->GetMatrix(bufferIndex);
- program.SetUniformMatrix4fv(location, 1, value.AsFloat() );
- break;
- }
-
- case Property::MATRIX3:
- {
- const Matrix3& value = map.propertyValue->GetMatrix3(bufferIndex);
- program.SetUniformMatrix3fv(location, 1, value.AsFloat() );
- break;
- }
-
- default:
- {
- // Other property types are ignored
- break;
- }
- }
- }
-}
-
-bool Renderer::BindTextures( Context& context, SceneGraph::TextureCache& textureCache, Program& program )
-{
- unsigned int textureUnit = 0;
- bool result = true;
-
- std::vector<Render::Sampler*>& samplers( mRenderDataProvider->GetSamplers() );
-
- std::vector<Render::Texture>& textures( mRenderDataProvider->GetTextures() );
- GLint uniformLocation(-1);
- for( size_t i(0); result && i<textures.size(); ++i )
- {
- ResourceId textureId = textures[i].GetTextureId();
- Internal::Texture* texture = textureCache.GetTexture( textureId );
- if( texture )
- {
- result = textureCache.BindTexture( texture, textureId, GL_TEXTURE_2D, (TextureUnit)textureUnit );
-
- if( result )
- {
- GLint uniformLocation;
-
- //TODO : This is a bug, result variable is being shadowed. Fix it!
- bool result = program.GetSamplerUniformLocation( i, uniformLocation );
- if( result && Program::UNIFORM_UNKNOWN != uniformLocation )
- {
- program.SetUniform1i( uniformLocation, textureUnit );