From 849e80074e47a92361b628c2dfb1c702dd5cf3ca Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 31 Jul 2016 03:54:16 +0200 Subject: [PATCH] Added GLSL 120 fallback support --- src/gl/shaders/gl_blurshader.cpp | 30 ++++++++++++++++++++++++++++++ src/gl/shaders/gl_blurshader.h | 2 ++ 2 files changed, 32 insertions(+) diff --git a/src/gl/shaders/gl_blurshader.cpp b/src/gl/shaders/gl_blurshader.cpp index 14bcc28c5..10168148b 100644 --- a/src/gl/shaders/gl_blurshader.cpp +++ b/src/gl/shaders/gl_blurshader.cpp @@ -86,6 +86,20 @@ void FBlurShader::Blur(FFlatVertexBuffer *vbo, float blurAmount, int sampleCount else setup->HorizontalShader->Bind(); + if (gl.glslversion < 1.3) + { + if (vertical) + { + setup->VerticalScaleX.Set(1.0f / width); + setup->VerticalScaleY.Set(1.0f / height); + } + else + { + setup->HorizontalScaleX.Set(1.0f / width); + setup->HorizontalScaleY.Set(1.0f / height); + } + } + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, inputTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -145,6 +159,14 @@ FBlurShader::BlurSetup *FBlurShader::GetSetup(float blurAmount, int sampleCount) blurSetup.HorizontalShader->Link("horizontal blur"); blurSetup.HorizontalShader->Bind(); glUniform1i(glGetUniformLocation(*blurSetup.HorizontalShader.get(), "SourceTexture"), 0); + + if (gl.glslversion < 1.3) + { + blurSetup.VerticalScaleX.Init(*blurSetup.VerticalShader.get(), "ScaleX"); + blurSetup.VerticalScaleY.Init(*blurSetup.VerticalShader.get(), "ScaleY"); + blurSetup.HorizontalScaleX.Init(*blurSetup.HorizontalShader.get(), "ScaleX"); + blurSetup.HorizontalScaleY.Init(*blurSetup.HorizontalShader.get(), "ScaleY"); + } mBlurSetups.Push(blurSetup); @@ -188,6 +210,14 @@ FString FBlurShader::FragmentShaderCode(float blurAmount, int sampleCount, bool in vec2 TexCoord; uniform sampler2D SourceTexture; out vec4 FragColor; + #if __VERSION__ < 130 + uniform float ScaleX; + uniform float ScaleY; + vec4 textureOffset(sampler2D s, vec2 texCoord, ivec2 offset) + { + return texture2D(s, texCoord + vec2(ScaleX * float(offset.x), ScaleY * float(offset.y))); + } + #endif void main() { FragColor = %s; diff --git a/src/gl/shaders/gl_blurshader.h b/src/gl/shaders/gl_blurshader.h index 9bf4a9d5d..9af5a9101 100644 --- a/src/gl/shaders/gl_blurshader.h +++ b/src/gl/shaders/gl_blurshader.h @@ -23,6 +23,8 @@ private: int sampleCount; std::shared_ptr VerticalShader; std::shared_ptr HorizontalShader; + FBufferedUniform1f VerticalScaleX, VerticalScaleY; + FBufferedUniform1f HorizontalScaleX, HorizontalScaleY; }; BlurSetup *GetSetup(float blurAmount, int sampleCount);