From e25ed728bccdf8e75502f800b35456d9121add98 Mon Sep 17 00:00:00 2001 From: vladislavbelov Date: Sat, 23 Apr 2022 21:39:15 +0000 Subject: [PATCH] Moves GLSL-specific uniform name workaround (added in rP11490) to CShaderProgramGLSL. git-svn-id: https://svn.wildfiregames.com/public/ps/trunk@26816 3db68df2-c116-0410-a063-a993310a9797 --- source/ps/CStrInternStatic.h | 3 --- source/renderer/InstancingModelRenderer.cpp | 4 ---- source/renderer/ShadowMap.cpp | 2 -- source/renderer/backend/gl/ShaderProgram.cpp | 20 ++++++++++++++++---- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/source/ps/CStrInternStatic.h b/source/ps/CStrInternStatic.h index 16fd2d9e4a..cc2b4a3533 100644 --- a/source/ps/CStrInternStatic.h +++ b/source/ps/CStrInternStatic.h @@ -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) diff --git a/source/renderer/InstancingModelRenderer.cpp b/source/renderer/InstancingModelRenderer.cpp index e3e08794af..e7a7dc7fea 100644 --- a/source/renderer/InstancingModelRenderer.cpp +++ b/source/renderer/InstancingModelRenderer.cpp @@ -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()); } diff --git a/source/renderer/ShadowMap.cpp b/source/renderer/ShadowMap.cpp index 6df367c371..f59050175d 100644 --- a/source/renderer/ShadowMap.cpp +++ b/source/renderer/ShadowMap.cpp @@ -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()); } } diff --git a/source/renderer/backend/gl/ShaderProgram.cpp b/source/renderer/backend/gl/ShaderProgram.cpp index a4c748c6db..33fb33ce59 100644 --- a/source/renderer/backend/gl/ShaderProgram.cpp +++ b/source/renderer/backend/gl/ShaderProgram.cpp @@ -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(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(); } } -- 2.11.4.GIT