Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion source/lib/ffglex/FFGLShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ void FFGLShader::FreeGLResources()
glDeleteProgram( programID );
programID = 0;
}

uniformLocations.clear();
}

void FFGLShader::Set( const char* name, float value )
Expand Down Expand Up @@ -229,7 +231,13 @@ GLuint FFGLShader::GetGLID() const
*/
GLint FFGLShader::FindUniform( const char* name ) const
{
return glGetUniformLocation( programID, name );
auto it = uniformLocations.find( name );
if( it != uniformLocations.end() )
return it->second;

GLint location = glGetUniformLocation( programID, name );
uniformLocations[ name ] = location;
return location;
}

bool FFGLShader::CompileVertexShader( const char* vertexShader )
Expand Down Expand Up @@ -318,6 +326,9 @@ bool FFGLShader::CompileFragmentShader( const char* fragmentShader )
}
bool FFGLShader::LinkProgram()
{
//Any cached uniform locations belong to the program we're about to replace, so they're no longer valid.
uniformLocations.clear();

programID = glCreateProgram();

glAttachShader( programID, vertexShaderID );
Expand Down
2 changes: 2 additions & 0 deletions source/lib/ffglex/FFGLShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <vector>
#include <string>
#include <string>
#include <unordered_map>

namespace ffglex
{
Expand Down Expand Up @@ -47,6 +48,7 @@ class FFGLShader final
GLuint fragmentShaderID; //!< The ID OpenGL gave our fragment shader. 0 for invalid.
GLuint programID; //!< The ID OpenGL gave our shader program. Bind this to use this shader. 0 for invalid.
std::vector< std::string > transformFeedbackVaryings;//!< The varyings that will be captured using a transform feedback. Ordered in the order of capturing.
mutable std::unordered_map< std::string, GLint > uniformLocations;//!< Cache of uniform name -> location for the currently linked programID, populated lazily by FindUniform.
};

}//End namespace ffglex