diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 8b7c5d14d..e3a3b0af4 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -57,6 +57,36 @@ public: } // InstancedColorizeShader }; // InstancedColorizeShader +// ============================================================================ +class ViewFrustrumShader : public Shader +{ +private: + GLuint m_frustrum_vao; + +public: ViewFrustrumShader() + { + loadProgram(OBJECT, GL_VERTEX_SHADER, "frustrum.vert", + GL_FRAGMENT_SHADER, "coloredquad.frag"); + + assignUniforms("color", "idx"); + + glGenVertexArrays(1, &m_frustrum_vao); + glBindVertexArray(m_frustrum_vao); + glBindBuffer(GL_ARRAY_BUFFER, SharedGPUObjects::getFrustrumVBO()); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, + SharedGPUObjects::getFrustrumIndices()); + glBindVertexArray(0); + } // ViewFrustrumShader + // ------------------------------------------------------------------------ + void bindVertexArray() + { + glBindVertexArray(m_frustrum_vao); + } // bindVertexArray + +}; // ViewFrustrumShader + // ============================================================================ extern std::vector BoundingBoxes; @@ -646,12 +676,12 @@ void IrrDriver::renderParticles() static void renderWireFrameFrustrum(float *tmp, unsigned i) { - MeshShader::ViewFrustrumShader::getInstance()->use(); - glBindVertexArray(MeshShader::ViewFrustrumShader::getInstance()->frustrumvao); + ViewFrustrumShader::getInstance()->use(); + ViewFrustrumShader::getInstance()->bindVertexArray(); glBindBuffer(GL_ARRAY_BUFFER, SharedGPUObjects::getFrustrumVBO()); glBufferSubData(GL_ARRAY_BUFFER, 0, 8 * 3 * sizeof(float), (void *)tmp); - MeshShader::ViewFrustrumShader::getInstance()->setUniforms(video::SColor(255, 0, 255, 0), i); + ViewFrustrumShader::getInstance()->setUniforms(video::SColor(255, 0, 255, 0), i); glDrawElements(GL_LINES, 24, GL_UNSIGNED_INT, 0); } diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 98b9c3262..df125c7f8 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -497,6 +497,20 @@ public: } // DisplaceShader }; // DisplaceShader +// ============================================================================ +class NormalVisualizer : public Shader +{ +public: + NormalVisualizer() + { + loadProgram(OBJECT, GL_VERTEX_SHADER, "utils/getworldmatrix.vert", + GL_VERTEX_SHADER, "instanced_object_pass.vert", + GL_GEOMETRY_SHADER, "normal_visualizer.geom", + GL_FRAGMENT_SHADER, "coloredquad.frag"); + assignUniforms("color"); + } // NormalVisualizer +}; // NormalVisualizer + // ============================================================================ struct DefaultMaterial { @@ -1412,11 +1426,11 @@ template static void renderInstancedMeshNormals() { std::vector &meshes = T::InstancedList::getInstance()->SolidPass; - MeshShader::NormalVisualizer::getInstance()->use(); + NormalVisualizer::getInstance()->use(); glBindVertexArray(VAOManager::getInstance()->getInstanceVAO(T::VertexType, T::Instance)); for (unsigned i = 0; i < meshes.size(); i++) { - MeshShader::NormalVisualizer::getInstance()->setUniforms(video::SColor(255, 0, 255, 0)); + NormalVisualizer::getInstance()->setUniforms(video::SColor(255, 0, 255, 0)); glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, (const void*)((SolidPassCmd::getInstance()->Offset[T::MaterialType] + i) * sizeof(DrawElementsIndirectCommand))); @@ -1427,11 +1441,11 @@ static void renderInstancedMeshNormals() template static void renderMultiMeshNormals() { - MeshShader::NormalVisualizer::getInstance()->use(); + NormalVisualizer::getInstance()->use(); glBindVertexArray(VAOManager::getInstance()->getInstanceVAO(T::VertexType, T::Instance)); if (SolidPassCmd::getInstance()->Size[T::MaterialType]) { - MeshShader::NormalVisualizer::getInstance()->setUniforms(video::SColor(255, 0, 255, 0)); + NormalVisualizer::getInstance()->setUniforms(video::SColor(255, 0, 255, 0)); glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, (const void*)(SolidPassCmd::getInstance()->Offset[T::MaterialType] * sizeof(DrawElementsIndirectCommand)), (int)SolidPassCmd::getInstance()->Size[T::MaterialType], diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 4af69a5fe..c30bcba55 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -441,33 +441,6 @@ namespace MeshShader assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } - NormalVisualizer::NormalVisualizer() - { - loadProgram(OBJECT, - GL_VERTEX_SHADER, "utils/getworldmatrix.vert", - GL_VERTEX_SHADER, "instanced_object_pass.vert", - GL_GEOMETRY_SHADER, "normal_visualizer.geom", - GL_FRAGMENT_SHADER, "coloredquad.frag"); - assignUniforms("color"); - } - - ViewFrustrumShader::ViewFrustrumShader() - { - loadProgram(OBJECT, - GL_VERTEX_SHADER, "frustrum.vert", - GL_FRAGMENT_SHADER, "coloredquad.frag"); - - assignUniforms("color", "idx"); - - glGenVertexArrays(1, &frustrumvao); - glBindVertexArray(frustrumvao); - glBindBuffer(GL_ARRAY_BUFFER, SharedGPUObjects::getFrustrumVBO()); - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, - SharedGPUObjects::getFrustrumIndices()); - glBindVertexArray(0); - } } namespace LightShader diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 157d574e5..cb2fd9045 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -65,21 +65,6 @@ public: TransparentFogShader(); }; - -class NormalVisualizer : public Shader -{ -public: - NormalVisualizer(); -}; - -class ViewFrustrumShader : public Shader -{ -public: - GLuint frustrumvao; - - ViewFrustrumShader(); -}; - } #define MAXLIGHT 32