From 5f09d3b7ef7b8915d9e69b310fa2bf12fd5b4ce6 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 26 Aug 2016 01:46:39 +0200 Subject: [PATCH] Add FBufferedUniformSampler because sampler uniforms may default bind to other locations than zero --- src/gl/shaders/gl_bloomshader.h | 4 ++-- src/gl/shaders/gl_lensshader.h | 2 +- src/gl/shaders/gl_presentshader.h | 2 +- src/gl/shaders/gl_shader.h | 22 ++++++++++++++++++++++ src/gl/shaders/gl_tonemapshader.h | 4 ++-- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/gl/shaders/gl_bloomshader.h b/src/gl/shaders/gl_bloomshader.h index cbc740ab60..b20277a42d 100644 --- a/src/gl/shaders/gl_bloomshader.h +++ b/src/gl/shaders/gl_bloomshader.h @@ -8,7 +8,7 @@ class FBloomExtractShader public: void Bind(); - FBufferedUniform1i SceneTexture; + FBufferedUniformSampler SceneTexture; FBufferedUniform1f Exposure; FBufferedUniform2f Scale; FBufferedUniform2f Offset; @@ -22,7 +22,7 @@ class FBloomCombineShader public: void Bind(); - FBufferedUniform1i BloomTexture; + FBufferedUniformSampler BloomTexture; private: FShaderProgram mShader; diff --git a/src/gl/shaders/gl_lensshader.h b/src/gl/shaders/gl_lensshader.h index ef0810e4ea..7e9ef63926 100644 --- a/src/gl/shaders/gl_lensshader.h +++ b/src/gl/shaders/gl_lensshader.h @@ -8,7 +8,7 @@ class FLensShader public: void Bind(); - FBufferedUniform1i InputTexture; + FBufferedUniformSampler InputTexture; FBufferedUniform1f AspectRatio; FBufferedUniform1f Scale; FBufferedUniform4f LensDistortionCoefficient; diff --git a/src/gl/shaders/gl_presentshader.h b/src/gl/shaders/gl_presentshader.h index b54fa2e36e..6f4e899bb7 100644 --- a/src/gl/shaders/gl_presentshader.h +++ b/src/gl/shaders/gl_presentshader.h @@ -8,7 +8,7 @@ class FPresentShader public: void Bind(); - FBufferedUniform1i InputTexture; + FBufferedUniformSampler InputTexture; FBufferedUniform1f InvGamma; FBufferedUniform1f Contrast; FBufferedUniform1f Brightness; diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index 75e4b4e5e5..52ca59ec78 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -201,6 +201,28 @@ public: } }; +class FBufferedUniformSampler +{ + int mBuffer; + int mIndex; + +public: + void Init(GLuint hShader, const GLchar *name) + { + mIndex = glGetUniformLocation(hShader, name); + mBuffer = -1; + } + + void Set(int newvalue) + { + if (newvalue != mBuffer) + { + mBuffer = newvalue; + glUniform1i(mIndex, newvalue); + } + } +}; + class FShader { diff --git a/src/gl/shaders/gl_tonemapshader.h b/src/gl/shaders/gl_tonemapshader.h index 9d427713fe..7ec24117b1 100644 --- a/src/gl/shaders/gl_tonemapshader.h +++ b/src/gl/shaders/gl_tonemapshader.h @@ -8,9 +8,9 @@ class FTonemapShader public: void Bind(); - FBufferedUniform1i SceneTexture; + FBufferedUniformSampler SceneTexture; FBufferedUniform1f Exposure; - FBufferedUniform1i PaletteLUT; + FBufferedUniformSampler PaletteLUT; static bool IsPaletteMode();