forked from mirrors/0ad
Moves GLSL-specific uniform name workaround (added in 227f9e403f) to CShaderProgramGLSL.
This was SVN commit r26816.
This commit is contained in:
@@ -153,15 +153,12 @@ X(screenSize)
|
||||
X(shadingColor)
|
||||
X(shadowDistance)
|
||||
X(shadowDistances)
|
||||
X2(shadowDistances_0, "shadowDistances[0]")
|
||||
X(shadowScale)
|
||||
X(shadowTex)
|
||||
X(shadowTransform)
|
||||
X(shadowTransforms)
|
||||
X2(shadowTransforms_0, "shadowTransforms[0]")
|
||||
X(sharpness)
|
||||
X(skinBlendMatrices)
|
||||
X2(skinBlendMatrices_0, "skinBlendMatrices[0]")
|
||||
X(skyBoxRot)
|
||||
X(skyCube)
|
||||
X(sky_simple)
|
||||
|
||||
@@ -377,10 +377,6 @@ void InstancingModelRenderer::RenderModel(
|
||||
{
|
||||
// Bind matrices for current animation state.
|
||||
// Add 1 to NumBones because of the special 'root' bone.
|
||||
// HACK: NVIDIA drivers return uniform name with "[0]", Intel Windows drivers without;
|
||||
// try uploading both names since one of them should work, and this is easier than
|
||||
// canonicalising the uniform names in CShaderProgramGLSL
|
||||
shader->Uniform(str_skinBlendMatrices_0, mdldef->GetNumBones() + 1, model->GetAnimatedBoneMatrices());
|
||||
shader->Uniform(str_skinBlendMatrices, mdldef->GetNumBones() + 1, model->GetAnimatedBoneMatrices());
|
||||
}
|
||||
|
||||
|
||||
@@ -655,9 +655,7 @@ void ShadowMap::BindTo(Renderer::Backend::GL::CShaderProgram* shader) const
|
||||
shadowDistances.emplace_back(cascade.Distance);
|
||||
shadowTransforms.emplace_back(cascade.TextureMatrix);
|
||||
}
|
||||
shader->Uniform(str_shadowTransforms_0, GetCascadeCount(), shadowTransforms.data());
|
||||
shader->Uniform(str_shadowTransforms, GetCascadeCount(), shadowTransforms.data());
|
||||
shader->Uniform(str_shadowDistances_0, GetCascadeCount(), shadowDistances.data());
|
||||
shader->Uniform(str_shadowDistances, GetCascadeCount(), shadowDistances.data());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -608,6 +608,7 @@ public:
|
||||
ogl_WarnIfError();
|
||||
for (GLint i = 0; i < numUniforms; ++i)
|
||||
{
|
||||
// TODO: use GL_ACTIVE_UNIFORM_MAX_LENGTH for the size.
|
||||
char name[256] = {0};
|
||||
GLsizei nameLength = 0;
|
||||
GLint size = 0;
|
||||
@@ -615,10 +616,21 @@ public:
|
||||
glGetActiveUniform(m_Program, i, ARRAY_SIZE(name), &nameLength, &size, &type, name);
|
||||
ogl_WarnIfError();
|
||||
|
||||
GLint loc = glGetUniformLocation(m_Program, name);
|
||||
const GLint location = glGetUniformLocation(m_Program, name);
|
||||
|
||||
// OpenGL specification is a bit vague about a name returned by glGetActiveUniform.
|
||||
// NVIDIA drivers return uniform name with "[0]", Intel Windows drivers without;
|
||||
while (nameLength > 3 &&
|
||||
name[nameLength - 3] == '[' &&
|
||||
name[nameLength - 2] == '0' &&
|
||||
name[nameLength - 1] == ']')
|
||||
{
|
||||
nameLength -= 3;
|
||||
}
|
||||
name[nameLength] = 0;
|
||||
|
||||
CStrIntern nameIntern(name);
|
||||
m_Uniforms[nameIntern] = std::make_pair(loc, type);
|
||||
m_Uniforms[nameIntern] = std::make_pair(location, type);
|
||||
|
||||
// Assign sampler uniforms to sequential texture units
|
||||
if (type == GL_SAMPLER_2D
|
||||
@@ -628,10 +640,10 @@ public:
|
||||
#endif
|
||||
)
|
||||
{
|
||||
int unit = (int)m_Samplers.size();
|
||||
const int unit = static_cast<int>(m_Samplers.size());
|
||||
m_Samplers[nameIntern].first = (type == GL_SAMPLER_CUBE ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D);
|
||||
m_Samplers[nameIntern].second = unit;
|
||||
glUniform1i(loc, unit); // link uniform to unit
|
||||
glUniform1i(location, unit); // link uniform to unit
|
||||
ogl_WarnIfError();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user