From a564892fab24987b7fa3e01057fda1dd44634cb1 Mon Sep 17 00:00:00 2001 From: vladislavbelov Date: Thu, 4 Feb 2021 20:03:03 +0000 Subject: [PATCH] Removes redundant normalizations for float types. Tested By: Langbart Differential Revision: https://code.wildfiregames.com/D3517 This was SVN commit r24833. --- source/graphics/ShaderProgram.cpp | 4 ++-- source/renderer/InstancingModelRenderer.cpp | 2 +- source/renderer/PatchRData.cpp | 15 ++++++++++++--- source/renderer/WaterManager.cpp | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/source/graphics/ShaderProgram.cpp b/source/graphics/ShaderProgram.cpp index da91b4ba0b..e6a811f44c 100644 --- a/source/graphics/ShaderProgram.cpp +++ b/source/graphics/ShaderProgram.cpp @@ -638,13 +638,13 @@ public: virtual void NormalPointer(GLenum type, GLsizei stride, const void* pointer) { - pglVertexAttribPointerARB(2, 3, type, GL_TRUE, stride, pointer); + pglVertexAttribPointerARB(2, 3, type, (type == GL_FLOAT ? GL_FALSE : GL_TRUE), stride, pointer); m_ValidStreams |= STREAM_NORMAL; } virtual void ColorPointer(GLint size, GLenum type, GLsizei stride, const void* pointer) { - pglVertexAttribPointerARB(3, size, type, GL_TRUE, stride, pointer); + pglVertexAttribPointerARB(3, size, type, (type == GL_FLOAT ? GL_FALSE : GL_TRUE), stride, pointer); m_ValidStreams |= STREAM_COLOR; } diff --git a/source/renderer/InstancingModelRenderer.cpp b/source/renderer/InstancingModelRenderer.cpp index 85a342f85e..1e96104618 100644 --- a/source/renderer/InstancingModelRenderer.cpp +++ b/source/renderer/InstancingModelRenderer.cpp @@ -324,7 +324,7 @@ void InstancingModelRenderer::PrepareModelDef(const CShaderProgramPtr& shader, i shader->NormalPointer(GL_FLOAT, stride, base + m->imodeldef->m_Normal.offset); if (m->calculateTangents) - shader->VertexAttribPointer(str_a_tangent, 4, GL_FLOAT, GL_TRUE, stride, base + m->imodeldef->m_Tangent.offset); + shader->VertexAttribPointer(str_a_tangent, 4, GL_FLOAT, GL_FALSE, stride, base + m->imodeldef->m_Tangent.offset); // The last UV set is STREAM_UV3 for (size_t uv = 0; uv < 4; ++uv) diff --git a/source/renderer/PatchRData.cpp b/source/renderer/PatchRData.cpp index 7880f5001b..eeab471837 100644 --- a/source/renderer/PatchRData.cpp +++ b/source/renderer/PatchRData.cpp @@ -159,6 +159,9 @@ void CPatchRData::BuildBlends() std::vector blendStacks; blendStacks.reserve(PATCH_SIZE*PATCH_SIZE); + std::vector blends; + blends.reserve(9); + // For each tile in patch .. for (ssize_t j = 0; j < PATCH_SIZE; ++j) { @@ -167,8 +170,7 @@ void CPatchRData::BuildBlends() ssize_t gx = m_Patch->m_X * PATCH_SIZE + i; ssize_t gz = m_Patch->m_Z * PATCH_SIZE + j; - std::vector blends; - blends.reserve(9); + blends.clear(); // Compute a blend for every tile in the 3x3 square around this tile for (size_t n = 0; n < 9; ++n) @@ -973,6 +975,8 @@ void CPatchRData::RenderBlends( const CShaderProgramPtr& shader = techBase->GetShader(pass); TerrainRenderer::PrepareShader(shader, shadow); + Handle lastBlendTex = 0; + for (BatchesStack::iterator itt = itTechBegin; itt != itTechEnd; ++itt) { if (itt->m_Texture->GetMaterial().GetSamplers().empty()) @@ -984,7 +988,12 @@ void CPatchRData::RenderBlends( for (const CMaterial::TextureSampler& samp : samplers) shader->BindTexture(samp.Name, samp.Sampler); - shader->BindTexture(str_blendTex, itt->m_Texture->m_TerrainAlpha->second.m_hCompositeAlphaMap); + Handle currentBlendTex = itt->m_Texture->m_TerrainAlpha->second.m_hCompositeAlphaMap; + if (currentBlendTex != lastBlendTex) + { + shader->BindTexture(str_blendTex, currentBlendTex); + lastBlendTex = currentBlendTex; + } itt->m_Texture->GetMaterial().GetStaticUniforms().BindUniforms(shader); diff --git a/source/renderer/WaterManager.cpp b/source/renderer/WaterManager.cpp index 8b23ab838e..3ee0410d0e 100644 --- a/source/renderer/WaterManager.cpp +++ b/source/renderer/WaterManager.cpp @@ -887,7 +887,7 @@ void WaterManager::RenderWaves(const CFrustum& frustrum) shader->VertexPointer(3, GL_FLOAT, stride, &base[VBchunk->m_Index].m_BasePosition); shader->TexCoordPointer(GL_TEXTURE0, 2, GL_UNSIGNED_BYTE, stride, &base[VBchunk->m_Index].m_UV); // NormalPointer(gl_FLOAT, stride, &base[m_VBWater->m_Index].m_UV) - pglVertexAttribPointerARB(2, 2, GL_FLOAT, GL_TRUE, stride, &base[VBchunk->m_Index].m_PerpVect); // replaces commented above because my normal is vec2 + pglVertexAttribPointerARB(2, 2, GL_FLOAT, GL_FALSE, stride, &base[VBchunk->m_Index].m_PerpVect); // replaces commented above because my normal is vec2 shader->VertexAttribPointer(str_a_apexPosition, 3, GL_FLOAT, false, stride, &base[VBchunk->m_Index].m_ApexPosition); shader->VertexAttribPointer(str_a_splashPosition, 3, GL_FLOAT, false, stride, &base[VBchunk->m_Index].m_SplashPosition); shader->VertexAttribPointer(str_a_retreatPosition, 3, GL_FLOAT, false, stride, &base[VBchunk->m_Index].m_RetreatPosition);