diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 04ed3a5db..5c4d325a4 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -392,6 +392,62 @@ public: } // GlobalIlluminationReconstructionShader }; // GlobalIlluminationReconstructionShader +// ============================================================================ +class PassThroughShader : public TextureShader +{ +public: + PassThroughShader() + { + loadProgram(OBJECT, GL_VERTEX_SHADER, "screenquad.vert", + GL_FRAGMENT_SHADER, "passthrough.frag"); + assignUniforms("width", "height"); + assignSamplerNames(0, "tex", ST_BILINEAR_FILTERED); + } // PassThroughShader +}; // PassThroughShader + +// ============================================================================ +class LayerPassThroughShader : public Shader +{ +private: + GLuint m_tu_texture; + GLuint m_vao; + +public: + LayerPassThroughShader() + { + loadProgram(OBJECT, GL_VERTEX_SHADER, "screenquad.vert", + GL_FRAGMENT_SHADER, "layertexturequad.frag"); + m_tu_texture = 0; + assignUniforms("layer"); + assignTextureUnit(m_tu_texture, "tex"); + m_vao = createVAO(); + } // LayerPassThroughShader + // ------------------------------------------------------------------------ + void bindVertexArray() + { + glBindVertexArray(m_vao); + } // bindVertexArray + // ------------------------------------------------------------------------ + void activateTexture() + { + glActiveTexture(GL_TEXTURE0 + m_tu_texture); + } // activateTexture +}; // LayerPassThroughShader + +// ============================================================================ +class LinearizeDepthShader : public TextureShader +{ +public: + LinearizeDepthShader() + { + loadProgram(OBJECT, GL_VERTEX_SHADER, "screenquad.vert", + GL_FRAGMENT_SHADER, "linearizedepth.frag"); + assignUniforms("zn", "zf"); + assignSamplerNames(0, "texture", ST_BILINEAR_FILTERED); + } // LinearizeDepthShader +}; // LinearizeDepthShader + // ============================================================================ PostProcessing::PostProcessing(IVideoDriver* video_driver) @@ -926,22 +982,20 @@ void PostProcessing::renderGaussian17TapBlur(FrameBuffer &in_fbo, void PostProcessing::renderPassThrough(GLuint tex, unsigned width, unsigned height) { - FullScreenShader::PassThroughShader::getInstance()->setTextureUnits(tex); - DrawFullScreenEffect(width, height); + PassThroughShader::getInstance()->setTextureUnits(tex); + DrawFullScreenEffect(width, height); } // renderPassThrough // ---------------------------------------------------------------------------- void PostProcessing::renderTextureLayer(unsigned tex, unsigned layer) { - FullScreenShader::LayerPassThroughShader::getInstance()->use(); - glBindVertexArray(FullScreenShader::LayerPassThroughShader::getInstance()->vao); - - glActiveTexture(GL_TEXTURE0 + FullScreenShader::LayerPassThroughShader - ::getInstance()->TU_texture); + LayerPassThroughShader::getInstance()->use(); + LayerPassThroughShader::getInstance()->bindVertexArray(); + LayerPassThroughShader::getInstance()->activateTexture(); glBindTexture(GL_TEXTURE_2D_ARRAY, tex); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - FullScreenShader::LayerPassThroughShader::getInstance()->setUniforms(layer); + LayerPassThroughShader::getInstance()->setUniforms(layer); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } // renderTextureLayer @@ -966,9 +1020,9 @@ void PostProcessing::renderSSAO() // Generate linear depth buffer irr_driver->getFBO(FBO_LINEAR_DEPTH).Bind(); - FullScreenShader::LinearizeDepthShader::getInstance() + LinearizeDepthShader::getInstance() ->setTextureUnits(irr_driver->getDepthStencilTexture()); - DrawFullScreenEffect + DrawFullScreenEffect (irr_driver->getSceneManager()->getActiveCamera()->getNearValue(), irr_driver->getSceneManager()->getActiveCamera()->getFarValue() ); irr_driver->getFBO(FBO_SSAO).Bind(); diff --git a/src/graphics/shader.cpp b/src/graphics/shader.cpp index 817141aaf..f7a56e0d3 100644 --- a/src/graphics/shader.cpp +++ b/src/graphics/shader.cpp @@ -21,6 +21,7 @@ #include "graphics/central_settings.hpp" #include "graphics/gl_headers.hpp" #include "graphics/irr_driver.hpp" +#include "graphics/shared_gpu_objects.hpp" #include "io/file_manager.hpp" #include "utils/log.hpp" @@ -247,4 +248,23 @@ void ShaderBase::setAttribute(AttributeType type) } } // setAttribute +// ---------------------------------------------------------------------------- +GLuint ShaderBase::createVAO() +{ + GLuint vao; + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + GLuint attrib_position = glGetAttribLocation(m_program, "Position"); + GLuint attrib_texcoord = glGetAttribLocation(m_program, "Texcoord"); + glBindBuffer(GL_ARRAY_BUFFER, SharedGPUObjects::getQuadVBO()); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texcoord); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, + 4 * sizeof(float), 0); + glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, + 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); + glBindVertexArray(0); + return vao; +} // createVAO + // ============================================================================ diff --git a/src/graphics/shader.hpp b/src/graphics/shader.hpp index 573e46895..60975b869 100644 --- a/src/graphics/shader.hpp +++ b/src/graphics/shader.hpp @@ -91,6 +91,7 @@ public: const char **varyings, unsigned varyingscount); static void updateShaders(); + GLuint createVAO(); // ------------------------------------------------------------------------ /** Activates the shader calling glUseProgram. */ void use() { glUseProgram(m_program); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index c17c69a23..ccd400921 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -443,23 +443,6 @@ namespace MeshShader } - -static GLuint createVAO(GLuint Program) -{ - GLuint vao; - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - GLuint attrib_position = glGetAttribLocation(Program, "Position"); - GLuint attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); - glEnableVertexAttribArray(attrib_position); - glEnableVertexAttribArray(attrib_texcoord); - glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); - glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); - glBindVertexArray(0); - return vao; -} - namespace FullScreenShader { @@ -479,36 +462,6 @@ namespace FullScreenShader assignUniforms("direction", "col"); } - PassThroughShader::PassThroughShader() - { - loadProgram(OBJECT, - GL_VERTEX_SHADER, "screenquad.vert", - GL_FRAGMENT_SHADER, "passthrough.frag"); - - assignUniforms("width", "height"); - assignSamplerNames(0, "tex", ST_BILINEAR_FILTERED); - } - - LayerPassThroughShader::LayerPassThroughShader() - { - loadProgram(OBJECT, - GL_VERTEX_SHADER, "screenquad.vert", - GL_FRAGMENT_SHADER, "layertexturequad.frag"); - TU_texture = 0; - assignUniforms("layer"); - assignTextureUnit(TU_texture, "tex"); - vao = createVAO(m_program); - } - - LinearizeDepthShader::LinearizeDepthShader() - { - loadProgram(OBJECT, - GL_VERTEX_SHADER, "screenquad.vert", - GL_FRAGMENT_SHADER, "linearizedepth.frag"); - assignUniforms("zn", "zf"); - - assignSamplerNames(0, "texture", ST_BILINEAR_FILTERED); - } LightspaceBoundingBoxShader::LightspaceBoundingBoxShader() @@ -552,7 +505,7 @@ namespace FullScreenShader assignUniforms(); assignSamplerNames(0, "tex", ST_BILINEAR_FILTERED); - vao = createVAO(m_program); + vao = createVAO(); } SSAOShader::SSAOShader() diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 7e6473c99..15a7943c8 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -88,27 +88,6 @@ public: SunLightShader(); }; -class PassThroughShader : public TextureShader -{ -public: - PassThroughShader(); -}; - -class LayerPassThroughShader : public Shader -{ -public: - GLuint TU_texture; - GLuint vao; - - LayerPassThroughShader(); -}; - -class LinearizeDepthShader : public TextureShader -{ -public: - LinearizeDepthShader(); -}; - class LightspaceBoundingBoxShader : public TextureShader diff --git a/src/graphics/shared_gpu_objects.cpp b/src/graphics/shared_gpu_objects.cpp index 0ada1043c..79013a3c0 100644 --- a/src/graphics/shared_gpu_objects.cpp +++ b/src/graphics/shared_gpu_objects.cpp @@ -27,6 +27,7 @@ GLuint SharedGPUObjects::m_lighting_data_ubo; GLuint SharedGPUObjects::m_full_screen_quad_vao; GLuint SharedGPUObjects::m_ui_vao; GLuint SharedGPUObjects::m_quad_buffer; +GLuint SharedGPUObjects::m_quad_vbo; bool SharedGPUObjects::m_has_been_initialised = false; /** Initialises m_full_screen_quad_vbo. @@ -40,9 +41,8 @@ void SharedGPUObjects::initQuadVBO() 1., -1., 1., 0., // UpperRight 1., 1., 1., 1. // LowerRight }; - GLuint quad_vbo; - glGenBuffers(1, &quad_vbo); - glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); + glGenBuffers(1, &m_quad_vbo); + glBindBuffer(GL_ARRAY_BUFFER, m_quad_vbo); glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), QUAD_VERTEX, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); diff --git a/src/graphics/shared_gpu_objects.hpp b/src/graphics/shared_gpu_objects.hpp index b3588a690..8c6b52f4c 100644 --- a/src/graphics/shared_gpu_objects.hpp +++ b/src/graphics/shared_gpu_objects.hpp @@ -36,6 +36,7 @@ private: static GLuint m_full_screen_quad_vao; static GLuint m_ui_vao; static GLuint m_quad_buffer; + static GLuint m_quad_vbo; static void initQuadVBO(); static void initQuadBuffer(); @@ -108,7 +109,12 @@ public: assert(m_has_been_initialised); return m_quad_buffer; } // getQuadBuffer - + // ------------------------------------------------------------------------ + static GLuint getQuadVBO() + { + assert(m_has_been_initialised); + return m_quad_vbo; + } // getQuadVBO }; // class SharedGPUObjecctS