diff --git a/sources.cmake b/sources.cmake index dfc0e3774..5b3d0c21e 100644 --- a/sources.cmake +++ b/sources.cmake @@ -1,5 +1,5 @@ # Modify this file to change the last-modified date when you add/remove a file. -# This will then trigger a new cmake run automatically. +# This will then trigger a new cmake run automatically. file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp") file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp") file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*") diff --git a/src/graphics/gpuparticles.cpp b/src/graphics/gpuparticles.cpp index a63225994..ad8f753d8 100644 --- a/src/graphics/gpuparticles.cpp +++ b/src/graphics/gpuparticles.cpp @@ -17,7 +17,6 @@ #include "graphics/irr_driver.hpp" #include "graphics/glwrap.hpp" -#include "graphics/shaders_util.hpp" #include "gpuparticles.hpp" #include "io/file_manager.hpp" #include "config/user_config.hpp" @@ -33,7 +32,7 @@ /** Transform feedback shader that simulates the particles on GPU. */ class PointEmitterShader : public Shader - < PointEmitterShader, core::matrix4, int, int, float > + < PointEmitterShader, core::matrix4, int, int, float > { public: PointEmitterShader() @@ -52,8 +51,8 @@ public: */ class SimpleParticleRender : public Shader, - public TextureRead + public TextureReadNew { public: SimpleParticleRender() @@ -64,7 +63,8 @@ public: GL_FRAGMENT_SHADER, "particle.frag"); assignUniforms("color_from", "color_to"); - assignSamplerNames(m_program, 0, "tex", 1, "dtex"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 1, "dtex", ST_NEAREST_FILTERED); } // SimpleParticleRender }; // SimpleParticleRender @@ -72,8 +72,8 @@ public: // ============================================================================ class FlipParticleRender : public Shader, - public TextureRead < Trilinear_Anisotropic_Filtered, - Nearest_Filtered > + public TextureReadNew < ST_TRILINEAR_ANISOTROPIC_FILTERED, + ST_NEAREST_FILTERED > { public: FlipParticleRender() @@ -83,7 +83,8 @@ public: GL_FRAGMENT_SHADER, "utils/getPosFromUVDepth.frag", GL_FRAGMENT_SHADER, "particle.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "tex", 1, "dtex"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 1, "dtex", ST_NEAREST_FILTERED); } }; // FlipParticleShader diff --git a/src/graphics/shader.hpp b/src/graphics/shader.hpp index 934687c8c..2ff315750 100644 --- a/src/graphics/shader.hpp +++ b/src/graphics/shader.hpp @@ -54,8 +54,8 @@ protected: void bypassUBO() const; - // ------------------------------------------------------------------------ - // Ends vararg template + // ======================================================================== + /** Ends recursion. */ template void loadAndAttachShader() { @@ -72,6 +72,7 @@ protected: loadAndAttachShader(args...); } // loadAndAttachShader // ------------------------------------------------------------------------ + /** Convenience interface using const char. */ template void loadAndAttachShader(GLint shader_type, const char *name, Types ... args) @@ -109,6 +110,22 @@ private: if (block_index != GL_INVALID_INDEX) glUniformBlockBinding(m_program, block_index, index); } // bindPoint + + + // ======================================================================== + // assignUniforms: Variadic Template +protected: + /** This variadic template collects all names of uniforms in + * a std::vector. It used assignUnfiromsImpl for the actual recursive + * implementation. */ + template + void assignUniforms(U... rest) + { + static_assert(sizeof...(rest) == sizeof...(Args), + "Count of Uniform's name mismatch"); + assignUniformsImpl(rest...); + } // assignUniforms +private: // ------------------------------------------------------------------------ /** End of recursive implementation of assignUniforms. */ void assignUniformsImpl() @@ -129,6 +146,28 @@ private: assignUniformsImpl(rest...); } // assignUniformsImpl + + // ============================================== + // setUniforms: Variadic template implementation. + +public: + /** Sets the uniforms for this shader. */ + void setUniforms(const Args & ... args) const + { + if (!CVS->isARBUniformBufferObjectUsable()) + bypassUBO(); + setUniformsImpl(args...); + } // setUniforms + // ------------------------------------------------------------------------ +private: + /** Implementation for setUniforms for a vector uniform. */ + template + void setUniformsImpl(const std::vector &v, Args1... arg) const + { + glUniform1fv(m_uniforms[N], (int)v.size(), v.data()); + setUniformsImpl(arg...); + } // setUniformsImpl + // ------------------------------------------------------------------------ /** End of recursion for setUniforms implementation. */ @@ -136,6 +175,7 @@ private: void setUniformsImpl() const { } // setUniformImpl + // ------------------------------------------------------------------------ /** Implementation for setUniforms for a matrix uniform. */ template @@ -209,59 +249,60 @@ private: setUniformsImpl(arg...); } // setUniformsImpl - // ------------------------------------------------------------------------ - /** Implementation for setUniforms for a vector uniform. */ - template - void setUniformsImpl(const std::vector &v, Args1... arg) const - { - glUniform1fv(m_uniforms[N], (int)v.size(), v.data()); - setUniformsImpl(arg...); - } // setUniformsImpl - // ------------------------------------------------------------------------ - /** End recursion for variadic template. */ - template - void printFileList() - { - return; - } // printFileList - - // ------------------------------------------------------------------------ + // printFileList: Variadic template for printing a list of shader filenames + // ======================================================================== /** Variadic template to print a list of file names. - * \param shader_type Ignored (used since the variadic calling function - * has this parameter). - * \param filepath Name of the file to print. - */ + * \param shader_type Ignored (used since the variadic calling function + * has this parameter). + * \param filepath Name of the file to print. + */ +protected: template void printFileList(GLint shader_type, const char *filepath, Types ... args) { Log::error("shader", filepath); printFileList(args...); } // printFileList -protected: - // ======================================================================== - void assignTextureUnit(GLuint index, const char* uniform) - { - glUseProgram(m_program); - GLuint uniform_loc = glGetUniformLocation(m_program, uniform); - glUniform1i(uniform_loc, index); - glUseProgram(0); - } // assignTextureUnit // ------------------------------------------------------------------------ + /** End recursion for variadic template. */ +private: + template + void printFileList() + { + return; + } // printFileList + + + // Variadic template implementation of assignTextureUnig + // ======================================================================== +public: + /** Variadic top level/public interface. It does the calls to glUseProgram + * and uses assignTextureUnitNoUse() in recursion to avoid unnecessary + * calls to glUseProgram. + * \param index Index of the texture. + * \param uniform Uniform name. + */ template void assignTextureUnit(GLuint index, const char* uniform, T1... rest) { glUseProgram(m_program); GLuint uniform_loc = glGetUniformLocation(m_program, uniform); glUniform1i(uniform_loc, index); + // Avoid doing any additional glUseProgram for the remaining calls assignTextureUnitNoUse(rest...); glUseProgram(0); } // assignTextureUnit - // ------------------------------------------------------------------------ - void assignTextureUnitNoUse() {} +private: // ------------------------------------------------------------------------ + /** End of recursion. */ + void assignTextureUnitNoUse() {} + + // ------------------------------------------------------------------------ + /** Recursive implementation of assignTextureUnit, but without the call + * to gluseProgram (which is done by the public interface). */ template void assignTextureUnitNoUse(GLuint index, const char* uniform, T1... rest) { @@ -270,14 +311,22 @@ protected: assignTextureUnitNoUse(rest...); } // assignTextureUnitNoUse + // ======================================================================== public: + /** Constructor. Adds the static kill function of this shader to the list + * of all kill function, which is used for the debugging feature of + * reloading all shaders. + */ Shader() { m_all_kill_functions.push_back(this->kill); - } + } // Shader + // ------------------------------------------------------------------------ + /** Load a list of shaders and links them all together. + */ template void loadProgram(AttributeType type, Types ... args) { @@ -301,26 +350,6 @@ public: } } // loadProgram - // ------------------------------------------------------------------------ - /** This variadic template collects all names of uniforms in - * a std::vector. */ - template - void assignUniforms(U... rest) - { - static_assert(sizeof...(rest) == sizeof...(Args), - "Count of Uniform's name mismatch"); - assignUniformsImpl(rest...); - } // assignUniforms - - // ------------------------------------------------------------------------ - /** Sets the uniforms for this shader. */ - void setUniforms(const Args & ... args) const - { - if (!CVS->isARBUniformBufferObjectUsable()) - bypassUBO(); - setUniformsImpl(args...); - } // setUniforms - }; // Shader diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 309fd6df6..d91add179 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -97,7 +97,6 @@ #include "graphics/irr_driver.hpp" #include "graphics/gpuparticles.hpp" #include "graphics/shaders.hpp" -#include "graphics/shaders_util.hpp" #include "io/file_manager.hpp" #include "utils/log.hpp" #include "graphics/glwrap.hpp" @@ -521,231 +520,8 @@ namespace UtilShader using namespace UtilShader; -void setTextureSampler(GLenum tp, GLuint texunit, GLuint tid, GLuint sid) -{ -#ifdef GL_VERSION_3_3 - glActiveTexture(GL_TEXTURE0 + texunit); - glBindTexture(tp, tid); - glBindSampler(texunit, sid); -#endif -} -GLuint createNearestSampler() -{ -#ifdef GL_VERSION_3_3 - unsigned id; - glGenSamplers(1, &id); - glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_REPEAT); - glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_REPEAT); - glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); - return id; -#endif -} - -void BindTextureNearest(GLuint TU, GLuint tex) -{ - glActiveTexture(GL_TEXTURE0 + TU); - glBindTexture(GL_TEXTURE_2D, tex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); -} - -GLuint createBilinearSampler() -{ -#ifdef GL_VERSION_3_3 - unsigned id; - glGenSamplers(1, &id); - glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_REPEAT); - glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_REPEAT); - glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); - return id; -#endif -} - -void BindTextureBilinear(GLuint TU, GLuint tex) -{ - glActiveTexture(GL_TEXTURE0 + TU); - glBindTexture(GL_TEXTURE_2D, tex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); -} - -GLuint createBilinearClampedSampler() -{ -#ifdef GL_VERSION_3_3 - unsigned id; - glGenSamplers(1, &id); - glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); - return id; -#endif -} - -void BindTextureBilinearClamped(GLuint TU, GLuint tex) -{ - glActiveTexture(GL_TEXTURE0 + TU); - glBindTexture(GL_TEXTURE_2D, tex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); -} - -GLuint createSemiTrilinearSampler() -{ -#ifdef GL_VERSION_3_3 - unsigned id; - glGenSamplers(1, &id); - glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); - return id; -#endif -} - -void BindTextureSemiTrilinear(GLuint TU, GLuint tex) -{ - glActiveTexture(GL_TEXTURE0 + TU); - glBindTexture(GL_TEXTURE_2D, tex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); -} - -GLuint createTrilinearSampler() -{ -#ifdef GL_VERSION_3_3 - unsigned id; - glGenSamplers(1, &id); - glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_REPEAT); - glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_REPEAT); - - int aniso = UserConfigParams::m_anisotropic; - if (aniso == 0) aniso = 1; - glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)aniso); - return id; -#endif -} - -void BindTextureTrilinearAnisotropic(GLuint TU, GLuint tex) -{ - glActiveTexture(GL_TEXTURE0 + TU); - glBindTexture(GL_TEXTURE_2D, tex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - - int aniso = UserConfigParams::m_anisotropic; - if (aniso == 0) aniso = 1; - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)aniso); -} - -void BindCubemapTrilinear(unsigned TU, unsigned tex) -{ - glActiveTexture(GL_TEXTURE0 + TU); - glBindTexture(GL_TEXTURE_CUBE_MAP, tex); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT); - - int aniso = UserConfigParams::m_anisotropic; - if (aniso == 0) aniso = 1; - glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)aniso); -} - -GLuint createShadowSampler() -{ -#ifdef GL_VERSION_3_3 - unsigned id; - glGenSamplers(1, &id); - glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glSamplerParameterf(id, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); - glSamplerParameterf(id, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); - return id; -#endif -} - -void BindTextureShadow(GLuint TU, GLuint tex) -{ - glActiveTexture(GL_TEXTURE0 + TU); - glBindTexture(GL_TEXTURE_2D_ARRAY, tex); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); - glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); -} - - -GLuint createTrilinearClampedArray() -{ -#ifdef GL_VERSION_3_3 - unsigned id; - glGenSamplers(1, &id); - glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - int aniso = UserConfigParams::m_anisotropic; - if (aniso == 0) aniso = 1; - glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)aniso); - return id; -#endif -} - -void BindTrilinearClampedArrayTexture(unsigned TU, unsigned tex) -{ - glActiveTexture(GL_TEXTURE0 + TU); - glBindTexture(GL_TEXTURE_2D_ARRAY, tex); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - int aniso = UserConfigParams::m_anisotropic; - if (aniso == 0) aniso = 1; - glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)aniso); -} - -void BindTextureVolume(GLuint TU, GLuint tex) -{ - glActiveTexture(GL_TEXTURE0 + TU); - glBindTexture(GL_TEXTURE_3D, tex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); -} - unsigned getGLSLVersion() { return CVS->getGLSLVersion(); @@ -760,7 +536,7 @@ namespace UtilShader GL_FRAGMENT_SHADER, "importance_sampling_specular.frag"); assignUniforms("PermutationMatrix", "ViewportSize"); TU_Samples = 1; - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_CUBEMAP); assignTextureUnit(TU_Samples, "samples"); } } @@ -775,7 +551,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, "utils/encode_normal.frag", GL_FRAGMENT_SHADER, "object_pass1.frag"); assignUniforms("ModelMatrix", "InverseModelMatrix"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } ObjectRefPass1Shader::ObjectRefPass1Shader() @@ -785,7 +561,8 @@ namespace MeshShader GL_FRAGMENT_SHADER, "utils/encode_normal.frag", GL_FRAGMENT_SHADER, "objectref_pass1.frag"); assignUniforms("ModelMatrix", "InverseModelMatrix", "TextureMatrix"); - assignSamplerNames(m_program, 0, "tex", 1, "glosstex"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 1, "glosstex",ST_TRILINEAR_ANISOTROPIC_FILTERED); } GrassPass1Shader::GrassPass1Shader() @@ -795,7 +572,8 @@ namespace MeshShader GL_FRAGMENT_SHADER, "utils/encode_normal.frag", GL_FRAGMENT_SHADER, "objectref_pass1.frag"); assignUniforms("ModelMatrix", "InverseModelMatrix", "windDir"); - assignSamplerNames(m_program, 0, "tex", 1, "glosstex"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 1, "glosstex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } NormalMapShader::NormalMapShader() @@ -805,7 +583,8 @@ namespace MeshShader GL_FRAGMENT_SHADER, "utils/encode_normal.frag", GL_FRAGMENT_SHADER, "normalmap.frag"); assignUniforms("ModelMatrix", "InverseModelMatrix"); - assignSamplerNames(m_program, 1, "normalMap", 0, "DiffuseForAlpha"); + assignSamplerNames(m_program, 1, "normalMap", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 0, "DiffuseForAlpha", ST_TRILINEAR_ANISOTROPIC_FILTERED); } InstancedObjectPass1Shader::InstancedObjectPass1Shader() @@ -817,7 +596,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, "instanced_object_pass1.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "glosstex"); + assignSamplerNames(m_program, 0, "glosstex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } InstancedObjectRefPass1Shader::InstancedObjectRefPass1Shader() @@ -829,7 +608,8 @@ namespace MeshShader GL_FRAGMENT_SHADER, "instanced_objectref_pass1.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "tex", 1, "glosstex"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 1, "glosstex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } InstancedGrassPass1Shader::InstancedGrassPass1Shader() @@ -840,7 +620,8 @@ namespace MeshShader GL_FRAGMENT_SHADER, "utils/encode_normal.frag", GL_FRAGMENT_SHADER, "instanced_objectref_pass1.frag"); assignUniforms("windDir"); - assignSamplerNames(m_program, 0, "tex", 1, "glosstex"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 1, "glosstex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } InstancedNormalMapShader::InstancedNormalMapShader() @@ -851,7 +632,8 @@ namespace MeshShader GL_FRAGMENT_SHADER, "utils/encode_normal.frag", GL_FRAGMENT_SHADER, "instanced_normalmap.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "normalMap", 1, "glossMap"); + assignSamplerNames(m_program, 0, "normalMap", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 1, "glossMap", ST_TRILINEAR_ANISOTROPIC_FILTERED); } // Solid Lit pass shaders @@ -862,7 +644,11 @@ namespace MeshShader GL_FRAGMENT_SHADER, "utils/getLightFactor.frag", GL_FRAGMENT_SHADER, "object_pass2.frag"); assignUniforms("ModelMatrix", "TextureMatrix"); - assignSamplerNames(m_program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo", 4, "SpecMap"); + assignSamplerNames(m_program, 0, "DiffuseMap", ST_NEAREST_FILTERED, + 1, "SpecularMap", ST_NEAREST_FILTERED, + 2, "SSAO", ST_BILINEAR_FILTERED, + 3, "Albedo", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 4, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED); } InstancedObjectPass2Shader::InstancedObjectPass2Shader() @@ -873,7 +659,11 @@ namespace MeshShader GL_FRAGMENT_SHADER, "utils/getLightFactor.frag", GL_FRAGMENT_SHADER, "instanced_object_pass2.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo", 4, "SpecMap"); + assignSamplerNames(m_program, 0, "DiffuseMap", ST_NEAREST_FILTERED, + 1, "SpecularMap", ST_NEAREST_FILTERED, + 2, "SSAO", ST_BILINEAR_FILTERED, + 3, "Albedo", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 4, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED); } InstancedObjectRefPass2Shader::InstancedObjectRefPass2Shader() @@ -884,7 +674,11 @@ namespace MeshShader GL_FRAGMENT_SHADER, "utils/getLightFactor.frag", GL_FRAGMENT_SHADER, "instanced_objectref_pass2.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo", 4, "SpecMap"); + assignSamplerNames(m_program, 0, "DiffuseMap", ST_NEAREST_FILTERED, + 1, "SpecularMap", ST_NEAREST_FILTERED, + 2, "SSAO", ST_BILINEAR_FILTERED, + 3, "Albedo", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 4, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED); } DetailledObjectPass2Shader::DetailledObjectPass2Shader() @@ -894,7 +688,12 @@ namespace MeshShader GL_FRAGMENT_SHADER, "utils/getLightFactor.frag", GL_FRAGMENT_SHADER, "detailledobject_pass2.frag"); assignUniforms("ModelMatrix"); - assignSamplerNames(m_program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo", 4, "Detail", 5, "SpecMap"); + assignSamplerNames(m_program, 0, "DiffuseMap", ST_NEAREST_FILTERED, + 1, "SpecularMap", ST_NEAREST_FILTERED, + 2, "SSAO", ST_BILINEAR_FILTERED, + 3, "Albedo", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 4, "Detail", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 5, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED); } InstancedDetailledObjectPass2Shader::InstancedDetailledObjectPass2Shader() @@ -905,7 +704,12 @@ namespace MeshShader GL_FRAGMENT_SHADER, "utils/getLightFactor.frag", GL_FRAGMENT_SHADER, "instanced_detailledobject_pass2.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo", 4, "Detail", 5, "SpecMap"); + assignSamplerNames(m_program, 0, "DiffuseMap", ST_NEAREST_FILTERED, + 1, "SpecularMap", ST_NEAREST_FILTERED, + 2, "SSAO", ST_BILINEAR_FILTERED, + 3, "Albedo", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 4, "Detail", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 5, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED); } ObjectUnlitShader::ObjectUnlitShader() @@ -914,7 +718,10 @@ namespace MeshShader GL_VERTEX_SHADER, "object_pass.vert", GL_FRAGMENT_SHADER, "object_unlit.frag"); assignUniforms("ModelMatrix", "TextureMatrix"); - assignSamplerNames(m_program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "tex"); + assignSamplerNames(m_program, 0, "DiffuseMap", ST_NEAREST_FILTERED, + 1, "SpecularMap", ST_NEAREST_FILTERED, + 2, "SSAO", ST_BILINEAR_FILTERED, + 3, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } InstancedObjectUnlitShader::InstancedObjectUnlitShader() @@ -924,7 +731,10 @@ namespace MeshShader GL_VERTEX_SHADER, "instanced_object_pass.vert", GL_FRAGMENT_SHADER, "instanced_object_unlit.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "tex"); + assignSamplerNames(m_program, 0, "DiffuseMap", ST_NEAREST_FILTERED, + 1, "SpecularMap", ST_NEAREST_FILTERED, + 2, "SSAO", ST_BILINEAR_FILTERED, + 3, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } ObjectRefPass2Shader::ObjectRefPass2Shader() @@ -934,7 +744,11 @@ namespace MeshShader GL_FRAGMENT_SHADER, "utils/getLightFactor.frag", GL_FRAGMENT_SHADER, "objectref_pass2.frag"); assignUniforms("ModelMatrix", "TextureMatrix"); - assignSamplerNames(m_program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo", 4, "SpecMap"); + assignSamplerNames(m_program, 0, "DiffuseMap", ST_NEAREST_FILTERED, + 1, "SpecularMap", ST_NEAREST_FILTERED, + 2, "SSAO", ST_BILINEAR_FILTERED, + 3, "Albedo", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 4, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED); } GrassPass2Shader::GrassPass2Shader() @@ -944,7 +758,11 @@ namespace MeshShader GL_FRAGMENT_SHADER, "utils/getLightFactor.frag", GL_FRAGMENT_SHADER, "grass_pass2.frag"); assignUniforms("ModelMatrix", "windDir"); - assignSamplerNames(m_program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "Albedo", 4, "SpecMap"); + assignSamplerNames(m_program, 0, "DiffuseMap", ST_NEAREST_FILTERED, + 1, "SpecularMap", ST_NEAREST_FILTERED, + 2, "SSAO", ST_BILINEAR_FILTERED, + 3, "Albedo", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 4, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED); } InstancedGrassPass2Shader::InstancedGrassPass2Shader() @@ -955,7 +773,12 @@ namespace MeshShader GL_FRAGMENT_SHADER, "utils/getLightFactor.frag", GL_FRAGMENT_SHADER, "instanced_grass_pass2.frag"); assignUniforms("windDir", "SunDir"); - assignSamplerNames(m_program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "dtex", 4, "Albedo", 5, "SpecMap"); + assignSamplerNames(m_program, 0, "DiffuseMap", ST_NEAREST_FILTERED, + 1, "SpecularMap", ST_NEAREST_FILTERED, + 2, "SSAO", ST_BILINEAR_FILTERED, + 3, "dtex", ST_NEAREST_FILTERED, + 4, "Albedo", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 5, "SpecMap", ST_TRILINEAR_ANISOTROPIC_FILTERED); } SphereMapShader::SphereMapShader() @@ -966,7 +789,10 @@ namespace MeshShader GL_FRAGMENT_SHADER, "utils/getPosFromUVDepth.frag", GL_FRAGMENT_SHADER, "objectpass_spheremap.frag"); assignUniforms("ModelMatrix", "InverseModelMatrix"); - assignSamplerNames(m_program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "tex"); + assignSamplerNames(m_program, 0, "DiffuseMap", ST_NEAREST_FILTERED, + 1, "SpecularMap", ST_NEAREST_FILTERED, + 2, "SSAO", ST_BILINEAR_FILTERED, + 3, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } InstancedSphereMapShader::InstancedSphereMapShader() @@ -978,7 +804,10 @@ namespace MeshShader GL_FRAGMENT_SHADER, "utils/getPosFromUVDepth.frag", GL_FRAGMENT_SHADER, "instanced_objectpass_spheremap.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "DiffuseMap", 1, "SpecularMap", 2, "SSAO", 3, "tex"); + assignSamplerNames(m_program, 0, "DiffuseMap", ST_NEAREST_FILTERED, + 1, "SpecularMap", ST_NEAREST_FILTERED, + 2, "SSAO", ST_BILINEAR_FILTERED, + 3, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } SplattingShader::SplattingShader() @@ -990,14 +819,14 @@ namespace MeshShader assignUniforms("ModelMatrix"); assignSamplerNames(m_program, - 0, "DiffuseMap", - 1, "SpecularMap", - 2, "SSAO", - 3, "tex_layout", - 4, "tex_detail0", - 5, "tex_detail1", - 6, "tex_detail2", - 7, "tex_detail3"); + 0, "DiffuseMap", ST_NEAREST_FILTERED, + 1, "SpecularMap", ST_NEAREST_FILTERED, + 2, "SSAO", ST_BILINEAR_FILTERED, + 3, "tex_layout", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 4, "tex_detail0", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 5, "tex_detail1", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 6, "tex_detail2", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 7, "tex_detail3", ST_TRILINEAR_ANISOTROPIC_FILTERED); } TransparentShader::TransparentShader() @@ -1006,7 +835,7 @@ namespace MeshShader GL_VERTEX_SHADER, "object_pass.vert", GL_FRAGMENT_SHADER, "transparent.frag"); assignUniforms("ModelMatrix", "TextureMatrix"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } TransparentFogShader::TransparentFogShader() @@ -1014,8 +843,9 @@ namespace MeshShader loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert", GL_FRAGMENT_SHADER, "transparentfog.frag"); - assignUniforms("ModelMatrix", "TextureMatrix", "fogmax", "startH", "endH", "start", "end", "col"); - assignSamplerNames(m_program, 0, "tex"); + assignUniforms("ModelMatrix", "TextureMatrix", "fogmax", "startH", + "endH", "start", "end", "col"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } BillboardShader::BillboardShader() @@ -1025,7 +855,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, "billboard.frag"); assignUniforms("ModelViewMatrix", "ProjectionMatrix", "Position", "Size"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } ColorizeShader::ColorizeShader() @@ -1073,7 +903,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, "rsm.frag"); assignUniforms("RSMMatrix", "ModelMatrix", "TextureMatrix"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } InstancedRSMShader::InstancedRSMShader() @@ -1084,7 +914,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, "instanced_rsm.frag"); assignUniforms("RSMMatrix"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } SplattingRSMShader::SplattingRSMShader() @@ -1094,7 +924,11 @@ namespace MeshShader GL_FRAGMENT_SHADER, "splatting_rsm.frag"); assignUniforms("RSMMatrix", "ModelMatrix"); - assignSamplerNames(m_program, 0, "tex_layout", 1, "tex_detail0", 2, "tex_detail1", 3, "tex_detail2", 4, "tex_detail3"); + assignSamplerNames(m_program, 0, "tex_layout", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 1, "tex_detail0", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 2, "tex_detail1", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 3, "tex_detail2", ST_TRILINEAR_ANISOTROPIC_FILTERED, + 4, "tex_detail3", ST_TRILINEAR_ANISOTROPIC_FILTERED); } InstancedShadowShader::InstancedShadowShader() @@ -1139,7 +973,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, "shadowref.frag"); } assignUniforms("layer", "ModelMatrix"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } InstancedRefShadowShader::InstancedRefShadowShader() @@ -1163,7 +997,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, "instanced_shadowref.frag"); } assignUniforms("layer"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } GrassShadowShader::GrassShadowShader() @@ -1185,7 +1019,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, "instanced_shadowref.frag"); } assignUniforms("layer", "ModelMatrix", "windDir"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } InstancedGrassShadowShader::InstancedGrassShadowShader() @@ -1209,7 +1043,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, "instanced_shadowref.frag"); } - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); assignUniforms("layer", "windDir"); } @@ -1230,10 +1064,10 @@ namespace MeshShader assignUniforms("ModelMatrix", "dir", "dir2"); assignSamplerNames(m_program, - 0, "displacement_tex", - 1, "color_tex", - 2, "mask_tex", - 3, "tex"); + 0, "displacement_tex", ST_BILINEAR_FILTERED, + 1, "color_tex", ST_BILINEAR_FILTERED, + 2, "mask_tex", ST_BILINEAR_FILTERED, + 3, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED); } SkyboxShader::SkyboxShader() @@ -1242,7 +1076,7 @@ namespace MeshShader GL_VERTEX_SHADER, "sky.vert", GL_FRAGMENT_SHADER, "sky.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_CUBEMAP); glGenVertexArrays(1, &vao); glBindVertexArray(vao); @@ -1293,8 +1127,8 @@ namespace LightShader GL_FRAGMENT_SHADER, "pointlight.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "ntex", 1, "dtex"); - + assignSamplerNames(m_program, 0, "ntex", ST_NEAREST_FILTERED, + 1, "dtex", ST_NEAREST_FILTERED); glGenVertexArrays(1, &vao); glBindVertexArray(vao); @@ -1330,7 +1164,7 @@ namespace LightShader GL_FRAGMENT_SHADER, "pointlightscatter.frag"); assignUniforms("density", "fogcol"); - assignSamplerNames(m_program, 0, "dtex"); + assignSamplerNames(m_program, 0, "dtex", ST_NEAREST_FILTERED); glGenVertexArrays(1, &vao); glBindVertexArray(vao); @@ -1387,7 +1221,7 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "bloom.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_NEAREST_FILTERED); } BloomBlendShader::BloomBlendShader() @@ -1397,7 +1231,9 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "bloomblend.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "tex_128", 1, "tex_256", 2, "tex_512"); + assignSamplerNames(m_program, 0, "tex_128", ST_BILINEAR_FILTERED, + 1, "tex_256", ST_BILINEAR_FILTERED, + 2, "tex_512", ST_BILINEAR_FILTERED); } LensBlendShader::LensBlendShader() @@ -1407,7 +1243,9 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "lensblend.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "tex_128", 1, "tex_256", 2, "tex_512"); + assignSamplerNames(m_program, 0, "tex_128", ST_BILINEAR_FILTERED, + 1, "tex_256", ST_BILINEAR_FILTERED, + 2, "tex_512", ST_BILINEAR_FILTERED); } ToneMapShader::ToneMapShader() @@ -1419,7 +1257,7 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "tonemap.frag"); assignUniforms("vignette_weight"); - assignSamplerNames(m_program, 0, "text"); + assignSamplerNames(m_program, 0, "text", ST_NEAREST_FILTERED); } DepthOfFieldShader::DepthOfFieldShader() @@ -1429,7 +1267,8 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "dof.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "tex", 1, "dtex"); + assignSamplerNames(m_program, 0, "tex", ST_BILINEAR_FILTERED, + 1, "dtex", ST_NEAREST_FILTERED); } SunLightShader::SunLightShader() @@ -1443,7 +1282,8 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "utils/SunMRP.frag", GL_FRAGMENT_SHADER, "sunlight.frag"); - assignSamplerNames(m_program, 0, "ntex", 1, "dtex"); + assignSamplerNames(m_program, 0, "ntex", ST_NEAREST_FILTERED, + 1, "dtex", ST_NEAREST_FILTERED); assignUniforms("direction", "col"); } @@ -1457,7 +1297,9 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "utils/SpecularIBL.frag", GL_FRAGMENT_SHADER, "IBL.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "ntex", 1, "dtex", 2, "probe"); + assignSamplerNames(m_program, 0, "ntex", ST_NEAREST_FILTERED, + 1, "dtex", ST_NEAREST_FILTERED, + 2, "probe", ST_TRILINEAR_CUBEMAP); } DegradedIBLShader::DegradedIBLShader() @@ -1470,7 +1312,7 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "utils/SpecularIBL.frag", GL_FRAGMENT_SHADER, "degraded_ibl.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "ntex"); + assignSamplerNames(m_program, 0, "ntex", ST_NEAREST_FILTERED); } ShadowedSunLightShaderPCF::ShadowedSunLightShaderPCF() @@ -1485,7 +1327,9 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "sunlightshadow.frag"); // Use 8 to circumvent a catalyst bug when binding sampler - assignSamplerNames(m_program, 0, "ntex", 1, "dtex", 8, "shadowtex"); + assignSamplerNames(m_program, 0, "ntex", ST_NEAREST_FILTERED, + 1, "dtex", ST_NEAREST_FILTERED, + 8, "shadowtex", ST_SHADOW_SAMPLER); assignUniforms("split0", "split1", "split2", "splitmax", "shadow_res"); } @@ -1501,7 +1345,10 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "sunlightshadowesm.frag"); // Use 8 to circumvent a catalyst bug when binding sampler - assignSamplerNames(m_program, 0, "ntex", 1, "dtex", 8, "shadowtex"); + assignSamplerNames(m_program, 0, "ntex", ST_NEAREST_FILTERED, + 1, "dtex", ST_NEAREST_FILTERED, + 8, "shadowtex", ST_TRILINEAR_CLAMPED_ARRAY2D); + assignUniforms("split0", "split1", "split2", "splitmax"); } @@ -1522,7 +1369,9 @@ namespace FullScreenShader } assignUniforms("RSMMatrix", "RHMatrix", "extents", "suncol"); - assignSamplerNames(m_program, 0, "ctex", 1, "ntex", 2, "dtex"); + assignSamplerNames(m_program, 0, "ctex", ST_BILINEAR_FILTERED, + 1, "ntex", ST_BILINEAR_FILTERED, + 2, "dtex", ST_BILINEAR_FILTERED); } NVWorkaroundRadianceHintsConstructionShader::NVWorkaroundRadianceHintsConstructionShader() @@ -1534,7 +1383,9 @@ namespace FullScreenShader assignUniforms("RSMMatrix", "RHMatrix", "extents", "slice", "suncol"); - assignSamplerNames(m_program, 0, "ctex", 1, "ntex", 2, "dtex"); + assignSamplerNames(m_program, 0, "ctex", ST_BILINEAR_FILTERED, + 1, "ntex", ST_BILINEAR_FILTERED, + 2, "dtex", ST_BILINEAR_FILTERED); } RHDebug::RHDebug() @@ -1558,7 +1409,11 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "gi.frag"); assignUniforms("RHMatrix", "InvRHMatrix", "extents"); - assignSamplerNames(m_program, 0, "ntex", 1, "dtex", 2, "SHR", 3, "SHG", 4, "SHB"); + assignSamplerNames(m_program, 0, "ntex", ST_NEAREST_FILTERED, + 1, "dtex", ST_NEAREST_FILTERED, + 2, "SHR", ST_VOLUME_LINEAR_FILTERED, + 3, "SHG", ST_VOLUME_LINEAR_FILTERED, + 4, "SHB", ST_VOLUME_LINEAR_FILTERED); } Gaussian17TapHShader::Gaussian17TapHShader() @@ -1567,7 +1422,8 @@ namespace FullScreenShader GL_VERTEX_SHADER, "screenquad.vert", GL_FRAGMENT_SHADER, "bilateralH.frag"); assignUniforms("pixel"); - assignSamplerNames(m_program, 0, "tex", 1, "depth"); + assignSamplerNames(m_program, 0, "tex", ST_BILINEAR_CLAMPED_FILTERED, + 1, "depth", ST_BILINEAR_CLAMPED_FILTERED); } ComputeGaussian17TapHShader::ComputeGaussian17TapHShader() @@ -1575,7 +1431,8 @@ namespace FullScreenShader loadProgram(OBJECT, GL_COMPUTE_SHADER, "bilateralH.comp"); TU_dest = 2; assignUniforms("pixel"); - assignSamplerNames(m_program, 0, "source", 1, "depth"); + assignSamplerNames(m_program, 0, "source", ST_NEARED_CLAMPED_FILTERED, + 1, "depth", ST_NEARED_CLAMPED_FILTERED); assignTextureUnit(TU_dest, "dest"); } @@ -1585,7 +1442,7 @@ namespace FullScreenShader GL_COMPUTE_SHADER, "gaussian6h.comp"); TU_dest = 1; assignUniforms("pixel", "weights"); - assignSamplerNames(m_program, 0, "source"); + assignSamplerNames(m_program, 0, "source", ST_BILINEAR_CLAMPED_FILTERED); assignTextureUnit(TU_dest, "dest"); } @@ -1595,7 +1452,7 @@ namespace FullScreenShader GL_COMPUTE_SHADER, "blurshadowH.comp"); TU_dest = 1; assignUniforms("pixel", "weights"); - assignSamplerNames(m_program, 0, "source"); + assignSamplerNames(m_program, 0, "source", ST_NEARED_CLAMPED_FILTERED); assignTextureUnit(TU_dest, "dest"); } @@ -1606,7 +1463,7 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "gaussian6h.frag"); assignUniforms("pixel", "sigma"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_BILINEAR_CLAMPED_FILTERED); } HorizontalBlurShader::HorizontalBlurShader() @@ -1616,7 +1473,7 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "gaussian6h.frag"); assignUniforms("pixel"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_BILINEAR_CLAMPED_FILTERED); } Gaussian3HBlurShader::Gaussian3HBlurShader() @@ -1626,7 +1483,7 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "gaussian3h.frag"); assignUniforms("pixel"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_BILINEAR_CLAMPED_FILTERED); } Gaussian17TapVShader::Gaussian17TapVShader() @@ -1636,7 +1493,8 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "bilateralV.frag"); assignUniforms("pixel"); - assignSamplerNames(m_program, 0, "tex", 1, "depth"); + assignSamplerNames(m_program, 0, "tex", ST_BILINEAR_CLAMPED_FILTERED, + 1, "depth", ST_BILINEAR_CLAMPED_FILTERED); } ComputeGaussian17TapVShader::ComputeGaussian17TapVShader() @@ -1645,7 +1503,8 @@ namespace FullScreenShader GL_COMPUTE_SHADER, "bilateralV.comp"); TU_dest = 2; assignUniforms("pixel"); - assignSamplerNames(m_program, 0, "source", 1, "depth"); + assignSamplerNames(m_program, 0, "source", ST_NEARED_CLAMPED_FILTERED, + 1, "depth", ST_NEARED_CLAMPED_FILTERED); assignTextureUnit(TU_dest, "dest"); } @@ -1655,7 +1514,7 @@ namespace FullScreenShader GL_COMPUTE_SHADER, "gaussian6v.comp"); TU_dest = 1; assignUniforms("pixel", "weights"); - assignSamplerNames(m_program, 0, "source"); + assignSamplerNames(m_program, 0, "source", ST_BILINEAR_CLAMPED_FILTERED); assignTextureUnit(TU_dest, "dest"); } @@ -1665,7 +1524,7 @@ namespace FullScreenShader GL_COMPUTE_SHADER, "blurshadowV.comp"); TU_dest = 1; assignUniforms("pixel", "weights"); - assignSamplerNames(m_program, 0, "source"); + assignSamplerNames(m_program, 0, "source", ST_NEARED_CLAMPED_FILTERED); assignTextureUnit(TU_dest, "dest"); } @@ -1676,7 +1535,7 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "gaussian6v.frag"); assignUniforms("pixel", "sigma"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_BILINEAR_CLAMPED_FILTERED); } Gaussian3VBlurShader::Gaussian3VBlurShader() @@ -1686,7 +1545,7 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "gaussian3v.frag"); assignUniforms("pixel"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_BILINEAR_CLAMPED_FILTERED); } PassThroughShader::PassThroughShader() @@ -1696,7 +1555,7 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "passthrough.frag"); assignUniforms("width", "height"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_BILINEAR_FILTERED); } LayerPassThroughShader::LayerPassThroughShader() @@ -1717,7 +1576,7 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "linearizedepth.frag"); assignUniforms("zn", "zf"); - assignSamplerNames(m_program, 0, "texture"); + assignSamplerNames(m_program, 0, "texture", ST_BILINEAR_FILTERED); } @@ -1726,7 +1585,7 @@ namespace FullScreenShader loadProgram(OBJECT, GL_COMPUTE_SHADER, "Lightspaceboundingbox.comp", GL_COMPUTE_SHADER, "utils/getPosFromUVDepth.frag"); - assignSamplerNames(m_program, 0, "depth"); + assignSamplerNames(m_program, 0, "depth", ST_NEAREST_FILTERED); assignUniforms("SunCamMatrix", "split0", "split1", "split2", "splitmax"); GLuint block_idx = glGetProgramResourceIndex(m_program, GL_SHADER_STORAGE_BLOCK, "BoundingBoxes"); glShaderStorageBlockBinding(m_program, block_idx, 2); @@ -1748,7 +1607,7 @@ namespace FullScreenShader loadProgram(OBJECT, GL_COMPUTE_SHADER, "depthhistogram.comp", GL_COMPUTE_SHADER, "utils/getPosFromUVDepth.frag"); - assignSamplerNames(m_program, 0, "depth"); + assignSamplerNames(m_program, 0, "depth", ST_NEAREST_FILTERED); GLuint block_idx = glGetProgramResourceIndex(m_program, GL_SHADER_STORAGE_BLOCK, "Histogram"); glShaderStorageBlockBinding(m_program, block_idx, 1); @@ -1761,7 +1620,7 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "glow.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_BILINEAR_FILTERED); vao = createVAO(m_program); } @@ -1774,7 +1633,7 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "ssao.frag"); assignUniforms("radius", "k", "sigma"); - assignSamplerNames(m_program, 0, "dtex"); + assignSamplerNames(m_program, 0, "dtex", ST_SEMI_TRILINEAR); } FogShader::FogShader() @@ -1785,7 +1644,7 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "fog.frag"); assignUniforms("density", "col"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_NEAREST_FILTERED); } MotionBlurShader::MotionBlurShader() @@ -1795,7 +1654,8 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "utils/getPosFromUVDepth.frag", GL_FRAGMENT_SHADER, "motion_blur.frag"); assignUniforms("previous_viewproj", "center", "boost_amount", "mask_radius"); - assignSamplerNames(m_program, 0, "color_buffer", 1, "dtex"); + assignSamplerNames(m_program, 0, "color_buffer", ST_BILINEAR_CLAMPED_FILTERED, + 1, "dtex", ST_NEAREST_FILTERED); } GodFadeShader::GodFadeShader() @@ -1805,7 +1665,7 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "godfade.frag"); assignUniforms("col"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_BILINEAR_FILTERED); } GodRayShader::GodRayShader() @@ -1815,7 +1675,7 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "godray.frag"); assignUniforms("sunpos"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_BILINEAR_FILTERED); } MLAAColorEdgeDetectionSHader::MLAAColorEdgeDetectionSHader() @@ -1825,7 +1685,7 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "mlaa_color1.frag"); assignUniforms("PIXEL_SIZE"); - assignSamplerNames(m_program, 0, "colorMapG"); + assignSamplerNames(m_program, 0, "colorMapG", ST_NEAREST_FILTERED); } MLAABlendWeightSHader::MLAABlendWeightSHader() @@ -1835,7 +1695,8 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "mlaa_blend2.frag"); assignUniforms("PIXEL_SIZE"); - assignSamplerNames(m_program, 0, "edgesMap", 1, "areaMap"); + assignSamplerNames(m_program, 0, "edgesMap", ST_BILINEAR_FILTERED, + 1, "areaMap", ST_NEAREST_FILTERED); } MLAAGatherSHader::MLAAGatherSHader() @@ -1845,7 +1706,8 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "mlaa_neigh3.frag"); assignUniforms("PIXEL_SIZE"); - assignSamplerNames(m_program, 0, "blendMap", 1, "colorMap"); + assignSamplerNames(m_program, 0, "blendMap", ST_NEAREST_FILTERED, + 1, "colorMap", ST_NEAREST_FILTERED); } } @@ -1858,7 +1720,7 @@ namespace UIShader GL_VERTEX_SHADER, "primitive2dlist.vert", GL_FRAGMENT_SHADER, "transparent.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_BILINEAR_FILTERED); } TextureRectShader::TextureRectShader() @@ -1868,7 +1730,7 @@ namespace UIShader GL_FRAGMENT_SHADER, "texturedquad.frag"); assignUniforms("center", "size", "texcenter", "texsize"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_BILINEAR_FILTERED); } UniformColoredTextureRectShader::UniformColoredTextureRectShader() @@ -1879,7 +1741,7 @@ namespace UIShader assignUniforms("center", "size", "texcenter", "texsize", "color"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_BILINEAR_FILTERED); } ColoredTextureRectShader::ColoredTextureRectShader() @@ -1889,7 +1751,7 @@ namespace UIShader GL_FRAGMENT_SHADER, "colortexturedquad.frag"); assignUniforms("center", "size", "texcenter", "texsize"); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_BILINEAR_FILTERED); glGenVertexArrays(1, &vao); glBindVertexArray(vao); diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index d2976b54a..d97699e89 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -20,7 +20,6 @@ #include "config/user_config.hpp" #include "graphics/shader.hpp" -#include "graphics/shaders_util.hpp" #include "graphics/texture_read.hpp" #include @@ -50,7 +49,7 @@ public: }; class SpecularIBLGenerator : public Shader, - public TextureRead + public TextureReadNew { public: GLuint TU_Samples; @@ -62,146 +61,188 @@ public: namespace MeshShader { class ObjectPass1Shader : public Shader, - public TextureRead + public TextureReadNew { public: ObjectPass1Shader(); }; class ObjectRefPass1Shader : public Shader, - public TextureRead + public TextureReadNew { public: ObjectRefPass1Shader(); }; -class GrassPass1Shader : public Shader, public TextureRead +class GrassPass1Shader : public Shader, + public TextureReadNew { public: GrassPass1Shader(); }; -class NormalMapShader : public Shader, public TextureRead +class NormalMapShader : public Shader, + public TextureReadNew { public: NormalMapShader(); }; -class InstancedObjectPass1Shader : public Shader, public TextureRead +class InstancedObjectPass1Shader : public Shader, + public TextureReadNew { public: InstancedObjectPass1Shader(); }; -class InstancedObjectRefPass1Shader : public Shader, public TextureRead +class InstancedObjectRefPass1Shader : public Shader, + public TextureReadNew { public: InstancedObjectRefPass1Shader(); }; -class InstancedGrassPass1Shader : public Shader, public TextureRead +class InstancedGrassPass1Shader : public Shader, + public TextureReadNew { public: InstancedGrassPass1Shader(); }; -class InstancedNormalMapShader : public Shader, public TextureRead +class InstancedNormalMapShader : public Shader, + public TextureReadNew { public: InstancedNormalMapShader(); }; -class ObjectPass2Shader : public Shader, public TextureRead +class ObjectPass2Shader : public Shader, + public TextureReadNew { public: ObjectPass2Shader(); }; -class InstancedObjectPass2Shader : public Shader, public TextureRead +class InstancedObjectPass2Shader : public Shader, + public TextureReadNew { public: InstancedObjectPass2Shader(); }; -class InstancedObjectRefPass2Shader : public Shader, public TextureRead +class InstancedObjectRefPass2Shader : public Shader, + public TextureReadNew { public: InstancedObjectRefPass2Shader(); }; -class DetailledObjectPass2Shader : public Shader, public TextureRead +class DetailledObjectPass2Shader : public Shader, + public TextureReadNew { public: DetailledObjectPass2Shader(); }; -class InstancedDetailledObjectPass2Shader : public Shader, public TextureRead +class InstancedDetailledObjectPass2Shader : public Shader, + public TextureReadNew { public: InstancedDetailledObjectPass2Shader(); }; -class ObjectUnlitShader : public Shader, public TextureRead +class ObjectUnlitShader : public Shader, + public TextureReadNew { public: ObjectUnlitShader(); }; -class InstancedObjectUnlitShader : public Shader, public TextureRead +class InstancedObjectUnlitShader : public Shader, + public TextureReadNew { public: InstancedObjectUnlitShader(); }; -class ObjectRefPass2Shader : public Shader, public TextureRead +class ObjectRefPass2Shader : public Shader, + public TextureReadNew { public: ObjectRefPass2Shader(); }; -class GrassPass2Shader : public Shader, public TextureRead +class GrassPass2Shader : public Shader, + public TextureReadNew { public: GrassPass2Shader(); }; -class InstancedGrassPass2Shader : public Shader, public TextureRead +class InstancedGrassPass2Shader : public Shader, + public TextureReadNew { public: InstancedGrassPass2Shader(); }; -class SphereMapShader : public Shader, public TextureRead +class SphereMapShader : public Shader, + public TextureReadNew { public: SphereMapShader(); }; -class InstancedSphereMapShader : public Shader, public TextureRead +class InstancedSphereMapShader : public Shader, + public TextureReadNew { public: InstancedSphereMapShader(); }; -class SplattingShader : public Shader, public TextureRead +class SplattingShader : public Shader, + public TextureReadNew { public: SplattingShader(); }; -class TransparentShader : public Shader, public TextureRead +class TransparentShader : public Shader, + public TextureReadNew { public: TransparentShader(); }; -class TransparentFogShader : public Shader, public TextureRead +class TransparentFogShader : public Shader, + public TextureReadNew { public: TransparentFogShader(); }; -class BillboardShader : public Shader, public TextureRead +class BillboardShader : public Shader, + public TextureReadNew { public: BillboardShader(); @@ -220,56 +261,64 @@ public: InstancedColorizeShader(); }; -class ShadowShader : public Shader, public TextureRead<> +class ShadowShader : public Shader, public TextureReadNew<> { public: ShadowShader(); }; -class RSMShader : public Shader, public TextureRead +class RSMShader : public Shader, + public TextureReadNew { public: RSMShader(); }; -class InstancedRSMShader : public Shader, public TextureRead +class InstancedRSMShader : public Shader, + public TextureReadNew { public: InstancedRSMShader(); }; class SplattingRSMShader : public Shader, - public TextureRead + public TextureReadNew { public: SplattingRSMShader(); }; -class InstancedShadowShader : public Shader, public TextureRead<> +class InstancedShadowShader : public Shader, public TextureReadNew<> { public: InstancedShadowShader(); }; -class RefShadowShader : public Shader, public TextureRead +class RefShadowShader : public Shader, + public TextureReadNew { public: RefShadowShader(); }; -class InstancedRefShadowShader : public Shader, public TextureRead +class InstancedRefShadowShader : public Shader, + public TextureReadNew { public: InstancedRefShadowShader(); }; -class GrassShadowShader : public Shader, public TextureRead +class GrassShadowShader : public Shader, + public TextureReadNew { public: GrassShadowShader(); }; -class InstancedGrassShadowShader : public Shader, public TextureRead +class InstancedGrassShadowShader : public Shader, + public TextureReadNew { public: InstancedGrassShadowShader(); @@ -281,13 +330,16 @@ public: DisplaceMaskShader(); }; -class DisplaceShader : public Shader, public TextureRead +class DisplaceShader : public Shader, + public TextureReadNew { public: DisplaceShader(); }; -class SkyboxShader : public Shader, public TextureRead +class SkyboxShader : public Shader, + public TextureReadNew { public: SkyboxShader(); @@ -327,7 +379,8 @@ namespace LightShader }; - class PointLightShader : public Shader, public TextureRead + class PointLightShader : public Shader, + public TextureReadNew { public: GLuint vbo; @@ -335,7 +388,8 @@ namespace LightShader PointLightShader(); }; - class PointLightScatterShader : public Shader, public TextureRead + class PointLightScatterShader : public Shader, + public TextureReadNew { public: GLuint vbo; @@ -357,76 +411,96 @@ static void DrawFullScreenEffect(Args...args) namespace FullScreenShader { -class BloomShader : public Shader, public TextureRead +class BloomShader : public Shader, + public TextureReadNew { public: BloomShader(); }; -class BloomBlendShader : public Shader, public TextureRead +class BloomBlendShader : public Shader, + public TextureReadNew { public: BloomBlendShader(); }; -class LensBlendShader : public Shader, public TextureRead +class LensBlendShader : public Shader, + public TextureReadNew { public: LensBlendShader(); }; -class ToneMapShader : public Shader, public TextureRead +class ToneMapShader : public Shader, + public TextureReadNew { public: ToneMapShader(); }; -class DepthOfFieldShader : public Shader, public TextureRead +class DepthOfFieldShader : public Shader, + public TextureReadNew { public: DepthOfFieldShader(); }; -class SunLightShader : public Shader, public TextureRead +class SunLightShader : public Shader, + public TextureReadNew { public: SunLightShader(); }; -class IBLShader : public Shader, public TextureRead +class IBLShader : public Shader, + public TextureReadNew { public: IBLShader(); }; -class DegradedIBLShader : public Shader, public TextureRead +class DegradedIBLShader : public Shader, + public TextureReadNew { public: DegradedIBLShader(); }; -class ShadowedSunLightShaderPCF : public Shader, public TextureRead +class ShadowedSunLightShaderPCF : public Shader, + public TextureReadNew { public: ShadowedSunLightShaderPCF(); }; -class ShadowedSunLightShaderESM : public Shader, public TextureRead +class ShadowedSunLightShaderESM : public Shader, + public TextureReadNew { public: ShadowedSunLightShaderESM(); }; -class RadianceHintsConstructionShader : public Shader, public TextureRead +class RadianceHintsConstructionShader : public Shader, + public TextureReadNew { public: RadianceHintsConstructionShader(); }; // Workaround for a bug found in kepler nvidia linux and fermi nvidia windows -class NVWorkaroundRadianceHintsConstructionShader : public Shader, public TextureRead +class NVWorkaroundRadianceHintsConstructionShader : public Shader, + public TextureReadNew { public: NVWorkaroundRadianceHintsConstructionShader(); @@ -440,65 +514,80 @@ public: RHDebug(); }; -class GlobalIlluminationReconstructionShader : public Shader, - public TextureRead +class GlobalIlluminationReconstructionShader : public Shader, + public TextureReadNew { public: GlobalIlluminationReconstructionShader(); }; -class Gaussian17TapHShader : public Shader, public TextureRead +class Gaussian17TapHShader : public Shader, + public TextureReadNew { public: Gaussian17TapHShader(); }; -class ComputeGaussian17TapHShader : public Shader, public TextureRead +class ComputeGaussian17TapHShader : public Shader, + public TextureReadNew { public: GLuint TU_dest; ComputeGaussian17TapHShader(); }; -class ComputeGaussian6HBlurShader : public Shader >, public TextureRead +class ComputeGaussian6HBlurShader : public Shader >, + public TextureReadNew { public: GLuint TU_dest; ComputeGaussian6HBlurShader(); }; -class ComputeShadowBlurHShader : public Shader >, public TextureRead +class ComputeShadowBlurHShader : public Shader >, + public TextureReadNew { public: GLuint TU_dest; ComputeShadowBlurHShader(); }; -class Gaussian6HBlurShader : public Shader, public TextureRead +class Gaussian6HBlurShader : public Shader, + public TextureReadNew { public: Gaussian6HBlurShader(); }; -class HorizontalBlurShader : public Shader, public TextureRead +class HorizontalBlurShader : public Shader, + public TextureReadNew { public: HorizontalBlurShader(); }; -class Gaussian3HBlurShader : public Shader, public TextureRead +class Gaussian3HBlurShader : public Shader, + public TextureReadNew { public: Gaussian3HBlurShader(); }; -class Gaussian17TapVShader : public Shader, public TextureRead +class Gaussian17TapVShader : public Shader, + public TextureReadNew { public: Gaussian17TapVShader(); }; -class ComputeGaussian17TapVShader : public Shader, public TextureRead +class ComputeGaussian17TapVShader : public Shader, + public TextureReadNew { public: GLuint TU_dest; @@ -506,33 +595,38 @@ public: ComputeGaussian17TapVShader(); }; -class ComputeGaussian6VBlurShader : public Shader >, public TextureRead +class ComputeGaussian6VBlurShader : public Shader >, + public TextureReadNew { public: GLuint TU_dest; ComputeGaussian6VBlurShader(); }; -class ComputeShadowBlurVShader : public Shader >, public TextureRead +class ComputeShadowBlurVShader : public Shader >, + public TextureReadNew { public: GLuint TU_dest; ComputeShadowBlurVShader(); }; -class Gaussian6VBlurShader : public Shader, public TextureRead +class Gaussian6VBlurShader : public Shader, + public TextureReadNew { public: Gaussian6VBlurShader(); }; -class Gaussian3VBlurShader : public Shader, public TextureRead +class Gaussian3VBlurShader : public Shader, + public TextureReadNew { public: Gaussian3VBlurShader(); }; -class PassThroughShader : public Shader, public TextureRead +class PassThroughShader : public Shader, + public TextureReadNew { public: PassThroughShader(); @@ -547,13 +641,17 @@ public: LayerPassThroughShader(); }; -class LinearizeDepthShader : public Shader, public TextureRead +class LinearizeDepthShader : public Shader, + public TextureReadNew { public: LinearizeDepthShader(); }; -class LightspaceBoundingBoxShader : public Shader, public TextureRead < Nearest_Filtered > +class LightspaceBoundingBoxShader : public Shader, + public TextureReadNew { public: LightspaceBoundingBoxShader(); @@ -565,13 +663,15 @@ public: ShadowMatrixesGenerationShader(); }; -class DepthHistogramShader : public Shader, public TextureRead +class DepthHistogramShader : public Shader, + public TextureReadNew { public: DepthHistogramShader(); }; -class GlowShader : public Shader, public TextureRead +class GlowShader : public Shader, + public TextureReadNew { public: GLuint vao; @@ -579,49 +679,57 @@ public: GlowShader(); }; -class SSAOShader : public Shader, public TextureRead +class SSAOShader : public Shader, + public TextureReadNew { public: SSAOShader(); }; -class FogShader : public Shader, public TextureRead +class FogShader : public Shader, + public TextureReadNew { public: FogShader(); }; -class MotionBlurShader : public Shader, public TextureRead +class MotionBlurShader : public Shader, + public TextureReadNew { public: MotionBlurShader(); }; -class GodFadeShader : public Shader, public TextureRead +class GodFadeShader : public Shader, + public TextureReadNew { public: GodFadeShader(); }; -class GodRayShader : public Shader, public TextureRead +class GodRayShader : public Shader, + public TextureReadNew { public: GodRayShader(); }; -class MLAAColorEdgeDetectionSHader : public Shader, public TextureRead +class MLAAColorEdgeDetectionSHader : public Shader, + public TextureReadNew { public: MLAAColorEdgeDetectionSHader(); }; -class MLAABlendWeightSHader : public Shader, public TextureRead +class MLAABlendWeightSHader : public Shader, + public TextureReadNew { public: MLAABlendWeightSHader(); }; -class MLAAGatherSHader : public Shader, public TextureRead +class MLAAGatherSHader : public Shader, + public TextureReadNew { public: MLAAGatherSHader(); @@ -632,25 +740,36 @@ public: namespace UIShader { -class Primitive2DList : public Shader, public TextureRead < Bilinear_Filtered > +class Primitive2DList : public Shader, + public TextureReadNew { public: Primitive2DList(); }; -class TextureRectShader : public Shader, public TextureRead +class TextureRectShader : public Shader, + public TextureReadNew { public: TextureRectShader(); }; -class UniformColoredTextureRectShader : public Shader, public TextureRead +class UniformColoredTextureRectShader : public Shader, + public TextureReadNew { public: UniformColoredTextureRectShader(); }; -class ColoredTextureRectShader : public Shader, public TextureRead +class ColoredTextureRectShader : public Shader, + public TextureReadNew { public: GLuint colorvbo; @@ -659,7 +778,8 @@ public: ColoredTextureRectShader(); }; -class ColoredRectShader : public Shader +class ColoredRectShader : public Shader { public: ColoredRectShader(); diff --git a/src/graphics/shaders_util.hpp b/src/graphics/shaders_util.hpp deleted file mode 100644 index 2fafb8f4a..000000000 --- a/src/graphics/shaders_util.hpp +++ /dev/null @@ -1,347 +0,0 @@ -// SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 2014-2015 SuperTuxKart-Team -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 3 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#ifndef SHADERS_UTIL_HPP -#define SHADERS_UTIL_HPP - -#include "graphics/central_settings.hpp" -#include "utils/singleton.hpp" -#include -#include -#include -#include -#include "gl_headers.hpp" - -bool needsUBO(); - -unsigned getGLSLVersion(); - - -enum AttributeType -{ - OBJECT, - PARTICLES_SIM, - PARTICLES_RENDERING, -}; - -void setAttribute(AttributeType Tp, GLuint ProgramID); - -void bypassUBO(GLuint Program); - -enum SamplerType { - Trilinear_Anisotropic_Filtered, - Semi_trilinear, - Bilinear_Filtered, - Bilinear_Clamped_Filtered, - Neared_Clamped_Filtered, - Nearest_Filtered, - Shadow_Sampler, - Volume_Linear_Filtered, - Trilinear_cubemap, - Trilinear_Clamped_Array2D, -}; - -void setTextureSampler(GLenum, GLuint, GLuint, GLuint); - -template -struct CreateSamplers; - -template -struct BindTexture; - -template<> -struct CreateSamplers<> -{ - static void exec(std::vector &, std::vector &e) - {} -}; - -template<> -struct BindTexture<> -{ - template - static void exec(const std::vector &TU) - {} -}; - -GLuint createNearestSampler(); - -template -struct CreateSamplers -{ - static void exec(std::vector &v, std::vector &e) - { - v.push_back(createNearestSampler()); - e.push_back(GL_TEXTURE_2D); - CreateSamplers::exec(v, e); - } -}; - -void BindTextureNearest(unsigned TU, unsigned tid); - -template -struct BindTexture -{ - template - static void exec(const std::vector &TU, GLuint TexId, Args... args) - { - BindTextureNearest(TU[N], TexId); - BindTexture::template exec(TU, args...); - } -}; - -template -struct CreateSamplers -{ - static void exec(std::vector &v, std::vector &e) - { - unsigned id; - glGenSamplers(1, &id); - glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); - - v.push_back(createNearestSampler()); - e.push_back(GL_TEXTURE_2D); - CreateSamplers::exec(v, e); - } -}; - -template -struct BindTexture -{ - template - static void exec(const std::vector &TU, GLuint TexId, Args... args) - { - glActiveTexture(GL_TEXTURE0 + TU[N]); - glBindTexture(GL_TEXTURE_2D, TexId); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); - BindTexture::template exec(TU, args...); - } -}; - -GLuint createBilinearSampler(); - -template -struct CreateSamplers -{ - static void exec(std::vector &v, std::vector &e) - { - v.push_back(createBilinearSampler()); - e.push_back(GL_TEXTURE_2D); - CreateSamplers::exec(v, e); - } -}; - -void BindTextureBilinear(unsigned TU, unsigned tex); - -template -struct BindTexture -{ - template - static void exec(const std::vector &TU, GLuint TexId, Args... args) - { - BindTextureBilinear(TU[N], TexId); - BindTexture::template exec(TU, args...); - } -}; - -GLuint createBilinearClampedSampler(); - -template -struct CreateSamplers -{ - static void exec(std::vector &v, std::vector &e) - { - v.push_back(createBilinearClampedSampler()); - e.push_back(GL_TEXTURE_2D); - CreateSamplers::exec(v, e); - } -}; - -void BindTextureBilinearClamped(unsigned TU, unsigned tex); - -template -struct BindTexture -{ - template - static void exec(const std::vector &TU, GLuint TexId, Args... args) - { - BindTextureBilinearClamped(TU[N], TexId); - BindTexture::template exec(TU, args...); - } -}; - -GLuint createSemiTrilinearSampler(); - -template -struct CreateSamplers -{ - static void exec(std::vector &v, std::vector &e) - { - v.push_back(createSemiTrilinearSampler()); - e.push_back(GL_TEXTURE_2D); - CreateSamplers::exec(v, e); - } -}; - -void BindTextureSemiTrilinear(unsigned TU, unsigned tex); - -template -struct BindTexture -{ - template - static void exec(const std::vector &TU, GLuint TexId, Args... args) - { - BindTextureSemiTrilinear(TU[N], TexId); - BindTexture::template exec(TU, args...); - } -}; - -GLuint createTrilinearSampler(); - -template -struct CreateSamplers -{ - static void exec(std::vector &v, std::vector &e) - { - v.push_back(createTrilinearSampler()); - e.push_back(GL_TEXTURE_2D); - CreateSamplers::exec(v, e); - } -}; - -void BindTextureTrilinearAnisotropic(unsigned TU, unsigned tex); - -template -struct CreateSamplers -{ - static void exec(std::vector &v, std::vector &e) - { - v.push_back(createTrilinearSampler()); - e.push_back(GL_TEXTURE_CUBE_MAP); - CreateSamplers::exec(v, e); - } -}; - -void BindCubemapTrilinear(unsigned TU, unsigned tex); - -template -struct BindTexture -{ - template - static void exec(const std::vector &TU, GLuint TexId, Args... args) - { - BindCubemapTrilinear(TU[N], TexId); - BindTexture::template exec(TU, args...); - } -}; - -template -struct BindTexture -{ - template - static void exec(const std::vector &TU, GLuint TexId, Args... args) - { - BindTextureTrilinearAnisotropic(TU[N], TexId); - BindTexture::template exec(TU, args...); - } -}; - -template -struct CreateSamplers -{ - static void exec(std::vector &v, std::vector &e) - { - v.push_back(createBilinearSampler()); - e.push_back(GL_TEXTURE_3D); - CreateSamplers::exec(v, e); - } -}; - -void BindTextureVolume(unsigned TU, unsigned tex); - -template -struct BindTexture -{ - template - static void exec(const std::vector &TU, GLuint TexId, Args... args) - { - BindTextureVolume(TU[N], TexId); - BindTexture::template exec(TU, args...); - } -}; - -GLuint createShadowSampler(); - -template -struct CreateSamplers -{ - static void exec(std::vector &v, std::vector &e) - { - v.push_back(createShadowSampler()); - e.push_back(GL_TEXTURE_2D_ARRAY); - CreateSamplers::exec(v, e); - } -}; - -void BindTextureShadow(unsigned TU, unsigned tex); - -template -struct BindTexture -{ - template - static void exec(const std::vector &TU, GLuint TexId, Args... args) - { - BindTextureShadow(TU[N], TexId); - BindTexture::template exec(TU, args...); - } -}; - -GLuint createTrilinearClampedArray(); - -template -struct CreateSamplers -{ - static void exec(std::vector &v, std::vector &e) - { - v.push_back(createTrilinearClampedArray()); - e.push_back(GL_TEXTURE_2D_ARRAY); - CreateSamplers::exec(v, e); - } -}; - -void BindTrilinearClampedArrayTexture(unsigned TU, unsigned tex); - -template -struct BindTexture -{ - template - static void exec(const std::vector &TU, GLuint TexId, Args... args) - { - BindTrilinearClampedArrayTexture(TU[N], TexId); - BindTexture::template exec(TU, args...); - } -}; - -#endif diff --git a/src/graphics/texture_read.cpp b/src/graphics/texture_read.cpp new file mode 100644 index 000000000..ecc986948 --- /dev/null +++ b/src/graphics/texture_read.cpp @@ -0,0 +1,339 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2014-2015 SuperTuxKart-Team +// (C) 2015 Joerg Henrichs +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "graphics/texture_read.hpp" + +#include "config/user_config.hpp" + +TextureReadBaseNew::BindFunction TextureReadBaseNew::m_all_bind_functions[] = +{ /* ST_NEAREST_FILTERED */ &TextureReadBaseNew::bindTextureNearest, + /* ST_TRILINEAR_ANISOTROPIC_FILTERED */ &TextureReadBaseNew::bindTextureTrilinearAnisotropic, + /* ST_TRILINEAR_CUBEMAP */ &TextureReadBaseNew::bindCubemapTrilinear, + /* ST_BILINEAR_FILTERED */ &TextureReadBaseNew::bindTextureBilinear, + /* ST_SHADOW_SAMPLER */ &TextureReadBaseNew::bindTextureShadow, + /* ST_TRILINEAR_CLAMPED_ARRAY2D */ &TextureReadBaseNew::bindTrilinearClampedArrayTexture, + /* ST_VOLUME_LINEAR_FILTERED */ &TextureReadBaseNew::bindTextureVolume, + /* ST_NEARED_CLAMPED_FILTERED */ &TextureReadBaseNew::bindTextureNearestClamped, + /* ST_BILINEAR_CLAMPED_FILTERED */ &TextureReadBaseNew::bindTextureBilinearClamped, + /* ST_SEMI_TRILINEAR */ &TextureReadBaseNew::bindTextureSemiTrilinear +}; + +GLuint TextureReadBaseNew::m_all_texture_types[] = +{ /* ST_NEAREST_FILTERED */ GL_TEXTURE_2D, + /* ST_TRILINEAR_ANISOTROPIC_FILTERED */ GL_TEXTURE_2D, + /* ST_TRILINEAR_CUBEMAP */ GL_TEXTURE_CUBE_MAP, + /* ST_BILINEAR_FILTERED */ GL_TEXTURE_2D , + /* ST_SHADOW_SAMPLER */ GL_TEXTURE_2D_ARRAY, + /* ST_TRILINEAR_CLAMPED_ARRAY2D */ GL_TEXTURE_2D_ARRAY, + /* ST_VOLUME_LINEAR_FILTERED */ GL_TEXTURE_3D, + /* ST_NEARED_CLAMPED_FILTERED */ GL_TEXTURE_2D, + /* ST_BILINEAR_CLAMPED_FILTERED */ GL_TEXTURE_2D, + /* ST_SEMI_TRILINEAR */ GL_TEXTURE_2D +}; + +// ---------------------------------------------------------------------------- +void TextureReadBaseNew::bindTextureNearest(GLuint texture_unit, GLuint tex) +{ + glActiveTexture(GL_TEXTURE0 + texture_unit); + glBindTexture(GL_TEXTURE_2D, tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); + +} // bindTextureNearest + +// ---------------------------------------------------------------------------- +void TextureReadBaseNew::bindTextureTrilinearAnisotropic(GLuint tex_unit, GLuint tex) +{ + glActiveTexture(GL_TEXTURE0 + tex_unit); + glBindTexture(GL_TEXTURE_2D, tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + int aniso = UserConfigParams::m_anisotropic; + if (aniso == 0) aniso = 1; + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)aniso); +} // bindTextureTrilinearAnisotropic + +// ---------------------------------------------------------------------------- +void TextureReadBaseNew::bindCubemapTrilinear(unsigned tex_unit, unsigned tex) +{ + glActiveTexture(GL_TEXTURE0 + tex_unit); + glBindTexture(GL_TEXTURE_CUBE_MAP, tex); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT); + + int aniso = UserConfigParams::m_anisotropic; + if (aniso == 0) aniso = 1; + glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_ANISOTROPY_EXT, + (float)aniso); +} // bindCubemapTrilinear + +// ---------------------------------------------------------------------------- +void TextureReadBaseNew::bindTextureNearestClamped(GLuint texture_unit, + GLuint tex_id) +{ + glActiveTexture(GL_TEXTURE0 + texture_unit); + glBindTexture(GL_TEXTURE_2D, tex_id); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); +} // bindTextureNearestClamped + +// ---------------------------------------------------------------------------- + +// ---------------------------------------------------------------------------- +void TextureReadBaseNew::bindTextureBilinear(GLuint texture_unit, GLuint tex) +{ + glActiveTexture(GL_TEXTURE0 + texture_unit); + glBindTexture(GL_TEXTURE_2D, tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); +} // bindTextureBilinear + +// ---------------------------------------------------------------------------- +void TextureReadBaseNew::bindTextureBilinearClamped(GLuint tex_unit, GLuint tex) +{ + glActiveTexture(GL_TEXTURE0 + tex_unit); + glBindTexture(GL_TEXTURE_2D, tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); +} // bindTextureBilinearClamped + +// ---------------------------------------------------------------------------- +void TextureReadBaseNew::bindTextureSemiTrilinear(GLuint tex_unit, GLuint tex_id) +{ + glActiveTexture(GL_TEXTURE0 + tex_unit); + glBindTexture(GL_TEXTURE_2D, tex_id); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); +} // bindTextureSemiTrilinear + +// ---------------------------------------------------------------------------- +void TextureReadBaseNew::bindTextureShadow(GLuint tex_unit, GLuint tex_id) +{ + glActiveTexture(GL_TEXTURE0 + tex_unit); + glBindTexture(GL_TEXTURE_2D_ARRAY, tex_id); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); + glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); +} // bindTextureShadow + +// ---------------------------------------------------------------------------- +void TextureReadBaseNew::bindTrilinearClampedArrayTexture(unsigned tex_unit, + unsigned tex_id) +{ + glActiveTexture(GL_TEXTURE0 + tex_unit); + glBindTexture(GL_TEXTURE_2D_ARRAY, tex_id); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + int aniso = UserConfigParams::m_anisotropic; + if (aniso == 0) aniso = 1; + glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)aniso); +} // bindTrilinearClampedArrayTexture + +// ---------------------------------------------------------------------------- +void TextureReadBaseNew::bindTextureVolume(unsigned tex_unit, unsigned tex_id) +{ + glActiveTexture(GL_TEXTURE0 + tex_unit); + glBindTexture(GL_TEXTURE_3D, tex_id); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); +} // bindTextureVolume + +// ---------------------------------------------------------------------------- + +GLuint TextureReadBaseNew::createSamplers(SamplerTypeNew sampler_type) +{ + switch (sampler_type) + { + case ST_NEAREST_FILTERED: + return createNearestSampler(); + case ST_TRILINEAR_ANISOTROPIC_FILTERED: + return createTrilinearSampler(); + case ST_TRILINEAR_CUBEMAP: + return createTrilinearSampler(); + case ST_BILINEAR_FILTERED: + return createBilinearSampler(); + case ST_SHADOW_SAMPLER: + return createShadowSampler(); + case ST_TRILINEAR_CLAMPED_ARRAY2D: + return createTrilinearClampedArray(); + case ST_VOLUME_LINEAR_FILTERED: + return createBilinearSampler(); + case ST_NEARED_CLAMPED_FILTERED: + { + // WHAT'S THAT?????????????????? + unsigned id; + glGenSamplers(1, &id); + glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); + return createNearestSampler(); + } + case ST_BILINEAR_CLAMPED_FILTERED: + return createBilinearClampedSampler(); + case ST_SEMI_TRILINEAR: + return createSemiTrilinearSampler(); + default: + assert(false); + return 0; + } // switch +} // createSamplers + +// ---------------------------------------------------------------------------- +GLuint TextureReadBaseNew::createNearestSampler() +{ +#ifdef GL_VERSION_3_3 + unsigned id; + glGenSamplers(1, &id); + glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_REPEAT); + glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_REPEAT); + glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); + return id; +#endif +} // createNearestSampler + +// ---------------------------------------------------------------------------- +GLuint TextureReadBaseNew::createTrilinearSampler() +{ +#ifdef GL_VERSION_3_3 + unsigned id; + glGenSamplers(1, &id); + glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_REPEAT); + glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_REPEAT); + + int aniso = UserConfigParams::m_anisotropic; + if (aniso == 0) aniso = 1; + glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)aniso); + return id; +#endif +} // createTrilinearSampler + +// ---------------------------------------------------------------------------- +GLuint TextureReadBaseNew::createBilinearSampler() +{ +#ifdef GL_VERSION_3_3 + unsigned id; + glGenSamplers(1, &id); + glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_REPEAT); + glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_REPEAT); + glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); + return id; +#endif +} // createBilinearSampler +// ---------------------------------------------------------------------------- +GLuint TextureReadBaseNew::createShadowSampler() +{ +#ifdef GL_VERSION_3_3 + unsigned id; + glGenSamplers(1, &id); + glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glSamplerParameterf(id, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); + glSamplerParameterf(id, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); + return id; +#endif +} // createShadowSampler + +// ---------------------------------------------------------------------------- +GLuint TextureReadBaseNew::createBilinearClampedSampler() +{ +#ifdef GL_VERSION_3_3 + unsigned id; + glGenSamplers(1, &id); + glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); + return id; +#endif +} // createBilinearClampedSampler + + +// ---------------------------------------------------------------------------- +GLuint TextureReadBaseNew::createTrilinearClampedArray() +{ +#ifdef GL_VERSION_3_3 + unsigned id; + glGenSamplers(1, &id); + glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + int aniso = UserConfigParams::m_anisotropic; + if (aniso == 0) aniso = 1; + glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)aniso); + return id; +#endif +} // createTrilinearClampedArray +// ---------------------------------------------------------------------------- +GLuint TextureReadBaseNew::createSemiTrilinearSampler() +{ +#ifdef GL_VERSION_3_3 + unsigned id; + glGenSamplers(1, &id); + glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.); + return id; +#endif +} // createSemiTrilinearSampler + +// ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- diff --git a/src/graphics/texture_read.hpp b/src/graphics/texture_read.hpp index 5063ed98d..b18fb4a75 100644 --- a/src/graphics/texture_read.hpp +++ b/src/graphics/texture_read.hpp @@ -18,12 +18,69 @@ #ifndef HEADER_TEXTURE_READ_HPP #define HEADER_TEXTURE_READ_HPP -#include "shaders_util.hpp" +#include "graphics/gl_headers.hpp" +#include +#include -template -class TextureRead + +enum SamplerTypeNew { + ST_MIN, + ST_NEAREST_FILTERED = ST_MIN, + ST_TRILINEAR_ANISOTROPIC_FILTERED, + ST_TRILINEAR_CUBEMAP, + ST_BILINEAR_FILTERED, + ST_SHADOW_SAMPLER, + ST_TRILINEAR_CLAMPED_ARRAY2D, + ST_VOLUME_LINEAR_FILTERED, + ST_NEARED_CLAMPED_FILTERED, + ST_BILINEAR_CLAMPED_FILTERED, + ST_SEMI_TRILINEAR, + ST_MAX = ST_SEMI_TRILINEAR +}; // SamplerTypeNew + + +class TextureReadBaseNew +{ +public: + typedef std::function BindFunction; + protected: + static void bindTextureNearest(GLuint tex_unit, GLuint tex_id); + static void bindTextureBilinear(GLuint texture_unit, GLuint tex_id); + static void bindTextureBilinearClamped(GLuint tex_unit, GLuint tex_id); + static void bindTextureNearestClamped(GLuint tex_unit, GLuint tex_id); + static void bindTextureTrilinearAnisotropic(GLuint tex_unit, GLuint tex_id); + static void bindTextureSemiTrilinear(GLuint tex_unit, GLuint tex_id); + static void bindCubemapTrilinear(GLuint tex_unit, GLuint tex_id); + static void bindTextureShadow(GLuint tex_unit, GLuint tex_id); + static void bindTrilinearClampedArrayTexture(GLuint tex_unit, GLuint tex_id); + static void bindTextureVolume(GLuint tex_unit, GLuint tex_id); + + GLuint createSamplers(SamplerTypeNew sampler_type); +private: + + static GLuint createNearestSampler(); + static GLuint createTrilinearSampler(); + static GLuint createBilinearSampler(); + static GLuint createShadowSampler(); + static GLuint createTrilinearClampedArray(); + static GLuint createBilinearClampedSampler(); + static GLuint createSemiTrilinearSampler(); +protected: + static BindFunction m_all_bind_functions[]; + std::vector m_bind_functions; + static GLuint m_all_texture_types[]; +}; // TextureReadBaseNew + +// ============================================================================ + +template +class TextureReadNew : public TextureReadBaseNew +{ + +private: + std::vector m_texture_units; std::vector m_texture_type; std::vector m_texture_location; @@ -47,26 +104,36 @@ private: * list of arguments. */ template - void assignTextureNamesImpl(GLuint program, GLuint tex_unit, - const char *name, Args...args) + void assignTextureNamesImpl(GLuint program, GLuint tex_unit, + const char *name, SamplerTypeNew sampler_type, + Args...args) { + + m_sampler_ids.push_back(createSamplers(sampler_type)); + + assert(sampler_type >= ST_MIN && sampler_type <= ST_MAX); + m_texture_type.push_back(m_all_texture_types[sampler_type]); + GLuint location = glGetUniformLocation(program, name); m_texture_location.push_back(location); glUniform1i(location, tex_unit); m_texture_units.push_back(tex_unit); + + // Duplicated assert + assert(sampler_type >= ST_MIN && sampler_type <= ST_MAX); + m_bind_functions.push_back( m_all_bind_functions[sampler_type]); + assignTextureNamesImpl(program, args...); } // assignTextureNamesImpl // ------------------------------------------------------------------------ -protected: +public: /** The protected interface for setting sampler names - it is only called * from instances. */ template void assignSamplerNames(GLuint program, Args...args) { - CreateSamplers::exec(m_sampler_ids, m_texture_type); - glUseProgram(program); assignTextureNamesImpl<0>(program, args...); glUseProgram(0); @@ -86,10 +153,20 @@ protected: /** The recursive implementation. */ template - void setTextureUnitsImpl(GLuint texid, TexIds... args) + void setTextureUnitsImpl(GLuint tex_id, TexIds... args) { - setTextureSampler(m_texture_type[N], m_texture_units[N], texid, - m_sampler_ids[N]); + if (CVS->getGLSLVersion() >= 330) + { +#ifdef GL_VERSION_3_3 + glActiveTexture(GL_TEXTURE0 + m_texture_units[N]); + glBindTexture(m_texture_type[N], tex_id); + glBindSampler(m_texture_units[N], m_sampler_ids[N]); +#endif + } + else + { + m_bind_functions[N](m_texture_units[N], tex_id); + } setTextureUnitsImpl(args...); } // setTextureUnitsImpl @@ -100,11 +177,8 @@ public: template void setTextureUnits(TexIds... args) { - if (getGLSLVersion() >= 330) - setTextureUnitsImpl<0>(args...); - else - BindTexture::template exec<0>(m_texture_units, args...); - } // SetTextureUnits + setTextureUnitsImpl<0>(args...); + } // setTextureUnits // ======================================================================== @@ -148,13 +222,14 @@ public: // ------------------------------------------------------------------------ /** Destructor which frees al lsampler ids. */ - ~TextureRead() + ~TextureReadNew() { for (unsigned i = 0; i < m_sampler_ids.size(); i++) glDeleteSamplers(1, &m_sampler_ids[i]); - } // ~TextureRead + } // ~TextureReadNew -}; // class TextureRead +}; // class TextureReadNew + #endif