From 5070531ad77e3a9b44fac040006beb45a534e980 Mon Sep 17 00:00:00 2001 From: hiker Date: Fri, 8 May 2015 08:02:56 +1000 Subject: [PATCH] Converted more shaders. --- src/graphics/shaders.cpp | 90 ++++++++++++++-------- src/graphics/shaders.hpp | 107 ++++++++++++++++++-------- src/graphics/texture_read.cpp | 137 ++++++++++++++++++++++++++++++++-- src/graphics/texture_read.hpp | 26 ++++--- 4 files changed, 279 insertions(+), 81 deletions(-) diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 7f60a1ae0..62a1a2575 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -1046,7 +1046,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() @@ -1054,8 +1054,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() @@ -1065,7 +1066,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() @@ -1113,7 +1114,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() @@ -1124,7 +1125,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() @@ -1134,7 +1135,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() @@ -1179,7 +1184,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() @@ -1203,7 +1208,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() @@ -1225,7 +1230,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() @@ -1249,7 +1254,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"); } @@ -1270,10 +1275,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() @@ -1333,8 +1338,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); @@ -1370,7 +1375,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); @@ -1427,7 +1432,7 @@ namespace FullScreenShader GL_FRAGMENT_SHADER, "bloom.frag"); assignUniforms(); - assignSamplerNames(m_program, 0, "tex"); + assignSamplerNames(m_program, 0, "tex", ST_NEAREST_FILTERED); } BloomBlendShader::BloomBlendShader() @@ -1437,7 +1442,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() @@ -1447,7 +1454,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() @@ -1459,7 +1468,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() @@ -1469,7 +1478,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() @@ -1483,7 +1493,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"); } @@ -1512,7 +1523,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() @@ -1527,7 +1538,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"); } @@ -1543,7 +1556,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"); } @@ -1564,7 +1580,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() @@ -1576,7 +1594,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() @@ -1600,7 +1620,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() @@ -1609,7 +1633,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() @@ -1617,7 +1642,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"); } diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 5cfa8d68c..2f6e50ffb 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -226,19 +226,24 @@ 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(); @@ -257,56 +262,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(); @@ -318,13 +331,16 @@ public: DisplaceMaskShader(); }; -class DisplaceShader : public Shader, public TextureRead +class DisplaceShader : public Shader, + public TextureReadNew { public: DisplaceShader(); }; -class SkyboxShader : public Shader, public TextureReadNew +class SkyboxShader : public Shader, + public TextureReadNew { public: SkyboxShader(); @@ -364,7 +380,8 @@ namespace LightShader }; - class PointLightShader : public Shader, public TextureRead + class PointLightShader : public Shader, + public TextureReadNew { public: GLuint vbo; @@ -372,7 +389,8 @@ namespace LightShader PointLightShader(); }; - class PointLightScatterShader : public Shader, public TextureRead + class PointLightScatterShader : public Shader, + public TextureReadNew { public: GLuint vbo; @@ -394,39 +412,47 @@ 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(); @@ -439,32 +465,43 @@ 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(); @@ -478,20 +515,28 @@ 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; diff --git a/src/graphics/texture_read.cpp b/src/graphics/texture_read.cpp index 9dedb92cf..9fb2eaf35 100644 --- a/src/graphics/texture_read.cpp +++ b/src/graphics/texture_read.cpp @@ -24,14 +24,25 @@ 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_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, }; 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_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, +}; // ---------------------------------------------------------------------------- void TextureReadBaseNew::bindTextureNearest(GLuint texture_unit, GLuint tex) @@ -43,6 +54,7 @@ void TextureReadBaseNew::bindTextureNearest(GLuint texture_unit, GLuint tex) 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 // ---------------------------------------------------------------------------- @@ -78,7 +90,7 @@ void TextureReadBaseNew::bindCubemapTrilinear(unsigned tex_unit, unsigned tex) // ---------------------------------------------------------------------------- void TextureReadBaseNew::bindTextureNearestClamped(GLuint texture_unit, - GLuint tex_id) + GLuint tex_id) { glActiveTexture(GL_TEXTURE0 + texture_unit); glBindTexture(GL_TEXTURE_2D, tex_id); @@ -87,7 +99,9 @@ void TextureReadBaseNew::bindTextureNearestClamped(GLuint texture_unit, 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.); -} // bindTextureNearesClamped +} // bindTextureNearestClamped + +// ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- void TextureReadBaseNew::bindTextureBilinear(GLuint texture_unit, GLuint tex) @@ -114,10 +128,10 @@ void TextureReadBaseNew::bindTextureBilinearClamped(GLuint tex_unit, GLuint tex) } // bindTextureBilinearClamped // ---------------------------------------------------------------------------- -void TextureReadBaseNew::bindTextureSemiTrilinear(GLuint tex_unit, GLuint tex) +void TextureReadBaseNew::bindTextureSemiTrilinear(GLuint tex_unit, GLuint tex_id) { glActiveTexture(GL_TEXTURE0 + tex_unit); - glBindTexture(GL_TEXTURE_2D, tex); + 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); @@ -125,6 +139,47 @@ void TextureReadBaseNew::bindTextureSemiTrilinear(GLuint tex_unit, GLuint tex) 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) { @@ -138,6 +193,26 @@ GLuint TextureReadBaseNew::createSamplers(SamplerTypeNew sampler_type) 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(); default: assert(false); return 0; @@ -192,8 +267,54 @@ GLuint TextureReadBaseNew::createBilinearSampler() #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 // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- diff --git a/src/graphics/texture_read.hpp b/src/graphics/texture_read.hpp index 65f369e08..619d0ba22 100644 --- a/src/graphics/texture_read.hpp +++ b/src/graphics/texture_read.hpp @@ -29,14 +29,15 @@ enum SamplerTypeNew { ST_TRILINEAR_ANISOTROPIC_FILTERED, ST_TRILINEAR_CUBEMAP, ST_BILINEAR_FILTERED, - ST_MAX = ST_BILINEAR_FILTERED, - - ST_SEMI_TRILINEAR, - ST_BILINEAR_CLAMPED_FILTERED, - ST_NEARED_CLAMPED_FILTERED, ST_SHADOW_SAMPLER, + ST_TRILINEAR_CLAMPED_ARRAY2D, ST_VOLUME_LINEAR_FILTERED, - ST_TRILINEAR_CLAMPED_ARRAY2D + ST_NEARED_CLAMPED_FILTERED, + ST_BILINEAR_CLAMPED_FILTERED, + ST_MAX = ST_BILINEAR_CLAMPED_FILTERED, + + XST_SEMI_TRILINEAR, + XST_TRILINEAR_CLAMPED_ARRAY2D }; @@ -47,19 +48,24 @@ public: protected: static void bindTextureNearest(GLuint tex_unit, GLuint tex_id); - static void bindTextureBilinear(GLuint texture_unit, GLuint tex); - static void bindTextureBilinearClamped(GLuint tex_unit, GLuint tex); + 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(unsigned tex_unit, unsigned tex); - + static void bindCubemapTrilinear(unsigned tex_unit, unsigned tex_id); + static void bindTextureShadow(unsigned tex_unit, unsigned tex_id); + static void bindTrilinearClampedArrayTexture(unsigned tex_unit, unsigned tex_id); + static void bindTextureVolume(unsigned tex_unit, unsigned 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(); protected: static BindFunction m_all_bind_functions[];