From 1481a110a517b18577da04a500193f9956f0d125 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 30 Mar 2014 20:49:14 +0200 Subject: [PATCH] Use utils function for renderbloom/blend --- src/graphics/post_processing.cpp | 23 ++++------------------- src/graphics/shaders.cpp | 13 ++++++++++--- src/graphics/shaders.hpp | 6 ++++-- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index ba32f9ee6..62c7a98e2 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -210,18 +210,11 @@ void renderBloom(ITexture *in) const float threshold = World::getWorld()->getTrack()->getBloomThreshold(); glUseProgram(FullScreenShader::BloomShader::Program); glBindVertexArray(FullScreenShader::BloomShader::vao); - glUniform1f(FullScreenShader::BloomShader::uniform_low, threshold); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, getTextureGLuint(in)); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glUniform1i(FullScreenShader::BloomShader::uniform_texture, 0); + setTexture(0, getTextureGLuint(in), GL_NEAREST, GL_NEAREST); + FullScreenShader::BloomShader::setUniforms(0); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - glBindVertexArray(0); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } static @@ -235,18 +228,10 @@ void renderBloomBlend(ITexture *in) glUseProgram(FullScreenShader::BloomBlendShader::Program); glBindVertexArray(FullScreenShader::BloomBlendShader::vao); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, getTextureGLuint(in)); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glUniform1i(FullScreenShader::BloomBlendShader::uniform_texture, 0); + setTexture(0, getTextureGLuint(in), GL_LINEAR, GL_LINEAR); + FullScreenShader::BloomBlendShader::setUniforms(0); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - glBindVertexArray(0); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - glEnable(GL_DEPTH_TEST); - glDisable(GL_BLEND); } static diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index eac01581d..4a05532f3 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -1762,7 +1762,6 @@ namespace FullScreenShader { GLuint BloomShader::Program; GLuint BloomShader::uniform_texture; - GLuint BloomShader::uniform_low; GLuint BloomShader::vao; void BloomShader::init() { @@ -1770,13 +1769,16 @@ namespace FullScreenShader GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/bloom.frag").c_str()); uniform_texture = glGetUniformLocation(Program, "tex"); - uniform_low = glGetUniformLocation(Program, "low"); vao = createVAO(Program); } + void BloomShader::setUniforms(unsigned TU_tex) + { + glUniform1i(FullScreenShader::BloomShader::uniform_texture, TU_tex); + } + GLuint BloomBlendShader::Program; GLuint BloomBlendShader::uniform_texture; - GLuint BloomBlendShader::uniform_low; GLuint BloomBlendShader::vao; void BloomBlendShader::init() { @@ -1787,6 +1789,11 @@ namespace FullScreenShader vao = createVAO(Program); } + void BloomBlendShader::setUniforms(unsigned TU_tex) + { + glUniform1i(FullScreenShader::BloomShader::uniform_texture, TU_tex); + } + GLuint ColorLevelShader::Program; GLuint ColorLevelShader::uniform_tex; GLuint ColorLevelShader::uniform_inlevel; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 0948448c0..f9b531472 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -457,20 +457,22 @@ class BloomShader { public: static GLuint Program; - static GLuint uniform_texture, uniform_low; + static GLuint uniform_texture; static GLuint vao; static void init(); + static void setUniforms(unsigned TU_tex); }; class BloomBlendShader { public: static GLuint Program; - static GLuint uniform_texture, uniform_low; + static GLuint uniform_texture; static GLuint vao; static void init(); + static void setUniforms(unsigned TU_tex); }; class ColorLevelShader