From f8d3815a70e285b0c842a034ec7b0f79e4f38fde Mon Sep 17 00:00:00 2001 From: Hleb Valoshka <375gnu@gmail.com> Date: Fri, 19 Jul 2019 00:47:30 +0300 Subject: [PATCH] Move duplicated setVertexArrays to RenderContext --- src/celengine/rendcontext.cpp | 93 ++++++++++++----------------------- src/celengine/rendcontext.h | 7 +-- 2 files changed, 32 insertions(+), 68 deletions(-) diff --git a/src/celengine/rendcontext.cpp b/src/celengine/rendcontext.cpp index 00f0d5d0..cdb99c44 100644 --- a/src/celengine/rendcontext.cpp +++ b/src/celengine/rendcontext.cpp @@ -183,6 +183,37 @@ RenderContext::drawGroup(const Mesh::PrimitiveGroup& group) } +void +RenderContext::setVertexArrays(const Mesh::VertexDescription& desc, + const void* vertexData) +{ + setStandardVertexArrays(desc, vertexData); + setExtendedVertexArrays(desc, vertexData); + + // Normally, the shader that will be used depends only on the material. + // But the presence of point size and normals can also affect the + // shader, so force an update of the material if those attributes appear + // or disappear in the new set of vertex arrays. + bool usePointSizeNow = (desc.getAttribute(Mesh::PointSize).format == Mesh::Float1); + bool useNormalsNow = (desc.getAttribute(Mesh::Normal).format == Mesh::Float3); + bool useColorsNow = (desc.getAttribute(Mesh::Color0).format != Mesh::InvalidFormat); + bool useTexCoordsNow = (desc.getAttribute(Mesh::Texture0).format != Mesh::InvalidFormat); + + if (usePointSizeNow != usePointSize || + useNormalsNow != useNormals || + useColorsNow != useColors || + useTexCoordsNow != useTexCoords) + { + usePointSize = usePointSizeNow; + useNormals = useNormalsNow; + useColors = useColorsNow; + useTexCoords = useTexCoordsNow; + if (getMaterial() != nullptr) + makeCurrent(*getMaterial()); + } +} + + void setStandardVertexArrays(const Mesh::VertexDescription& desc, const void* vertexData) @@ -602,37 +633,6 @@ GLSL_RenderContext::makeCurrent(const Material& m) } -void -GLSL_RenderContext::setVertexArrays(const Mesh::VertexDescription& desc, - const void* vertexData) -{ - setStandardVertexArrays(desc, vertexData); - setExtendedVertexArrays(desc, vertexData); - - // Normally, the shader that will be used depends only on the material. - // But the presence of point size and normals can also affect the - // shader, so force an update of the material if those attributes appear - // or disappear in the new set of vertex arrays. - bool usePointSizeNow = (desc.getAttribute(Mesh::PointSize).format == Mesh::Float1); - bool useNormalsNow = (desc.getAttribute(Mesh::Normal).format == Mesh::Float3); - bool useColorsNow = (desc.getAttribute(Mesh::Color0).format != Mesh::InvalidFormat); - bool useTexCoordsNow = (desc.getAttribute(Mesh::Texture0).format != Mesh::InvalidFormat); - - if (usePointSizeNow != usePointSize || - useNormalsNow != useNormals || - useColorsNow != useColors || - useTexCoordsNow != useTexCoords) - { - usePointSize = usePointSizeNow; - useNormals = useNormalsNow; - useColors = useColorsNow; - useTexCoords = useTexCoordsNow; - if (getMaterial() != nullptr) - makeCurrent(*getMaterial()); - } -} - - void GLSL_RenderContext::setAtmosphere(const Atmosphere* _atmosphere) { @@ -768,34 +768,3 @@ GLSLUnlit_RenderContext::makeCurrent(const Material& m) } } } - - -void -GLSLUnlit_RenderContext::setVertexArrays(const Mesh::VertexDescription& desc, - const void* vertexData) -{ - setStandardVertexArrays(desc, vertexData); - setExtendedVertexArrays(desc, vertexData); - - // Normally, the shader that will be used depends only on the material. - // But the presence of point size and normals can also affect the - // shader, so force an update of the material if those attributes appear - // or disappear in the new set of vertex arrays. - bool usePointSizeNow = (desc.getAttribute(Mesh::PointSize).format == Mesh::Float1); - bool useNormalsNow = (desc.getAttribute(Mesh::Normal).format == Mesh::Float3); - bool useColorsNow = (desc.getAttribute(Mesh::Color0).format != Mesh::InvalidFormat); - bool useTexCoordsNow = (desc.getAttribute(Mesh::Texture0).format != Mesh::InvalidFormat); - - if (usePointSizeNow != usePointSize || - useNormalsNow != useNormals || - useColorsNow != useColors || - useTexCoordsNow != useTexCoords) - { - usePointSize = usePointSizeNow; - useNormals = useNormalsNow; - useColors = useColorsNow; - useTexCoords = useTexCoordsNow; - if (getMaterial() != nullptr) - makeCurrent(*getMaterial()); - } -} diff --git a/src/celengine/rendcontext.h b/src/celengine/rendcontext.h index 3f3e44b5..617814e8 100644 --- a/src/celengine/rendcontext.h +++ b/src/celengine/rendcontext.h @@ -28,7 +28,7 @@ class RenderContext virtual void makeCurrent(const cmod::Material&) = 0; virtual void setVertexArrays(const cmod::Mesh::VertexDescription& desc, - const void* vertexData) = 0; + const void* vertexData); virtual void drawGroup(const cmod::Mesh::PrimitiveGroup& group); const cmod::Material* getMaterial() const; @@ -79,9 +79,6 @@ class GLSL_RenderContext : public RenderContext ~GLSL_RenderContext() override; void makeCurrent(const cmod::Material&) override; - void setVertexArrays(const cmod::Mesh::VertexDescription& desc, - const void* vertexData) override; - void setLunarLambert(float); void setAtmosphere(const Atmosphere*); @@ -112,8 +109,6 @@ class GLSLUnlit_RenderContext : public RenderContext ~GLSLUnlit_RenderContext() override; void makeCurrent(const cmod::Material&) override; - void setVertexArrays(const cmod::Mesh::VertexDescription& desc, - const void* vertexData) override; private: void initLightingEnvironment();