Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ogl: fix ubo workaround
  • Loading branch information
degasus committed Aug 23, 2013
1 parent 1469342 commit c9e13f6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
5 changes: 4 additions & 1 deletion Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp
Expand Up @@ -33,9 +33,12 @@ void SetPSConstant4fvByName(const char * name, unsigned int offset, const float
{
if (tmp.shader.UniformLocations[a] == -1)
return;
else if (tmp.shader.UniformSize[a] <= offset)
return;
else
{
glUniform4fv(tmp.shader.UniformLocations[a] + offset, count, f);
unsigned int maxcount= tmp.shader.UniformSize[a]-offset;
glUniform4fv(tmp.shader.UniformLocations[a] + offset, std::min(count, maxcount), f);
return;
}
}
Expand Down
40 changes: 29 additions & 11 deletions Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp
Expand Up @@ -78,17 +78,35 @@ void SHADER::SetProgramVariables()
glUniformBlockBinding(glprogid, VSBlock_id, 2);
}

// We cache our uniform locations for now
// Once we move up to a newer version of GLSL, ~1.30
// We can remove this

// (Sonicadvance): For some reason this fails on my hardware
//glGetUniformIndices(glprogid, NUM_UNIFORMS, UniformNames, UniformLocations);
// Got to do it this crappy way.
UniformLocations[0] = glGetUniformLocation(glprogid, UniformNames[0]);
if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
for (int a = 1; a < NUM_UNIFORMS; ++a)
UniformLocations[a] = glGetUniformLocation(glprogid, UniformNames[a]);
// UBO workaround
for (int a = 0; a < NUM_UNIFORMS; ++a)
{
UniformLocations[a] = glGetUniformLocation(glprogid, UniformNames[a]);
UniformSize[a] = 0;
if(g_ActiveConfig.backend_info.bSupportsGLSLUBO)
break;
}
if(!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
int max_uniforms = 0;
char name[50];
int size;

glGetProgramiv(glprogid, GL_ACTIVE_UNIFORMS, &max_uniforms);
for(int i=0; i<max_uniforms; i++)
{
glGetActiveUniform(glprogid, i, sizeof(name), NULL, &size, NULL, name);
for (int a = 0; a < NUM_UNIFORMS; ++a)
{
if(strstr(name, UniformNames[a]))
{
UniformSize[a] = size;
break;
}
}
}
}


// Bind Texture Sampler
for (int a = 0; a <= 9; ++a)
Expand Down
1 change: 1 addition & 0 deletions Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.h
Expand Up @@ -56,6 +56,7 @@ struct SHADER

std::string strvprog, strpprog;
GLint UniformLocations[NUM_UNIFORMS];
u32 UniformSize[NUM_UNIFORMS];

void SetProgramVariables();
void SetProgramBindings();
Expand Down
5 changes: 4 additions & 1 deletion Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp
Expand Up @@ -33,9 +33,12 @@ void SetVSConstant4fvByName(const char * name, unsigned int offset, const float
{
if (tmp.shader.UniformLocations[a] == -1)
return;
else if (tmp.shader.UniformSize[a] <= offset)
return;
else
{
glUniform4fv(tmp.shader.UniformLocations[a] + offset, count, f);
unsigned int maxcount= tmp.shader.UniformSize[a]-offset;
glUniform4fv(tmp.shader.UniformLocations[a] + offset, std::min(count, maxcount), f);
return;
}
}
Expand Down

0 comments on commit c9e13f6

Please sign in to comment.