Add FBufferedUniformSampler because sampler uniforms may default bind to other locations than zero

This commit is contained in:
Magnus Norddahl 2016-08-26 01:46:39 +02:00
parent b68bbaf617
commit 5f09d3b7ef
5 changed files with 28 additions and 6 deletions

View file

@ -8,7 +8,7 @@ class FBloomExtractShader
public: public:
void Bind(); void Bind();
FBufferedUniform1i SceneTexture; FBufferedUniformSampler SceneTexture;
FBufferedUniform1f Exposure; FBufferedUniform1f Exposure;
FBufferedUniform2f Scale; FBufferedUniform2f Scale;
FBufferedUniform2f Offset; FBufferedUniform2f Offset;
@ -22,7 +22,7 @@ class FBloomCombineShader
public: public:
void Bind(); void Bind();
FBufferedUniform1i BloomTexture; FBufferedUniformSampler BloomTexture;
private: private:
FShaderProgram mShader; FShaderProgram mShader;

View file

@ -8,7 +8,7 @@ class FLensShader
public: public:
void Bind(); void Bind();
FBufferedUniform1i InputTexture; FBufferedUniformSampler InputTexture;
FBufferedUniform1f AspectRatio; FBufferedUniform1f AspectRatio;
FBufferedUniform1f Scale; FBufferedUniform1f Scale;
FBufferedUniform4f LensDistortionCoefficient; FBufferedUniform4f LensDistortionCoefficient;

View file

@ -8,7 +8,7 @@ class FPresentShader
public: public:
void Bind(); void Bind();
FBufferedUniform1i InputTexture; FBufferedUniformSampler InputTexture;
FBufferedUniform1f InvGamma; FBufferedUniform1f InvGamma;
FBufferedUniform1f Contrast; FBufferedUniform1f Contrast;
FBufferedUniform1f Brightness; FBufferedUniform1f Brightness;

View file

@ -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 class FShader
{ {

View file

@ -8,9 +8,9 @@ class FTonemapShader
public: public:
void Bind(); void Bind();
FBufferedUniform1i SceneTexture; FBufferedUniformSampler SceneTexture;
FBufferedUniform1f Exposure; FBufferedUniform1f Exposure;
FBufferedUniform1i PaletteLUT; FBufferedUniformSampler PaletteLUT;
static bool IsPaletteMode(); static bool IsPaletteMode();