- make the shader timer part of the render state.

This commit is contained in:
Christoph Oelckers 2014-07-26 20:56:10 +02:00
parent 637aa9d77e
commit bdf5bbd34e
5 changed files with 12 additions and 48 deletions

View File

@ -88,20 +88,6 @@ void FRenderState::Reset()
mClipHeightBottom = -65536.f;
}
//==========================================================================
//
// Set texture shader info
//
//==========================================================================
void FRenderState::SetupShader(int &shaderindex, float warptime)
{
mEffectState = shaderindex;
if (shaderindex > 0) GLRenderer->mShaderManager->SetWarpSpeed(shaderindex, warptime);
}
//==========================================================================
//
// Apply shader settings
@ -149,6 +135,7 @@ bool FRenderState::ApplyShader()
activeShader->muInterpolationFactor.Set(mInterpolationFactor);
activeShader->muClipHeightTop.Set(mClipHeightTop);
activeShader->muClipHeightBottom.Set(mClipHeightBottom);
activeShader->muTimer.Set(gl_frameMS * mShaderTimer / 1000.f);
#ifndef CORE_PROFILE
if (!(gl.flags & RFL_COREPROFILE))

View File

@ -61,6 +61,7 @@ class FRenderState
float mClipHeightTop, mClipHeightBottom;
bool mModelMatrixEnabled;
bool mTextureMatrixEnabled;
float mShaderTimer;
FVertexBuffer *mVertexBuffer, *mCurrentVertexBuffer;
FStateVec4 mColor;
@ -97,7 +98,12 @@ public:
void Reset();
void SetupShader(int &shaderindex, float warptime);
void SetShader(int shaderindex, float warptime)
{
mEffectState = shaderindex;
mShaderTimer = warptime;
}
void Apply();
void ApplyMatrices();

View File

@ -210,8 +210,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
muClipHeightTop.Init(hShader, "uClipHeightTop");
muClipHeightBottom.Init(hShader, "uClipHeightBottom");
muAlphaThreshold.Init(hShader, "uAlphaThreshold");
muTimer.Init(hShader, "timer");
timer_index = glGetUniformLocation(hShader, "timer");
lights_index = glGetUniformLocation(hShader, "lights");
fakevb_index = glGetUniformLocation(hShader, "fakeVB");
projectionmatrix_index = glGetUniformLocation(hShader, "ProjectionMatrix");
@ -481,34 +481,6 @@ void FShaderManager::SetActiveShader(FShader *sh)
}
//==========================================================================
//
// To avoid maintenance this will be set when a warped texture is bound
// because at that point the draw buffer needs to be flushed anyway.
//
//==========================================================================
void FShaderManager::SetWarpSpeed(unsigned int eff, float speed)
{
// indices 0-2 match the warping modes, 3 is brightmap, 4 no texture, the following are custom
if (eff < mTextureEffects.Size())
{
FShader *sh = mTextureEffects[eff];
float warpphase = gl_frameMS * speed / 1000.f;
if (gl.flags & RFL_SEPARATE_SHADER_OBJECTS)
{
glProgramUniform1f(sh->GetHandle(), sh->timer_index, warpphase);
}
else
{
// not so pretty...
sh->Bind();
glUniform1f(sh->timer_index, warpphase);
}
}
}
//==========================================================================
//
//

View File

@ -199,8 +199,8 @@ class FShader
FBufferedUniform1f muClipHeightTop;
FBufferedUniform1f muClipHeightBottom;
FBufferedUniform1f muAlphaThreshold;
FBufferedUniform1f muTimer;
int timer_index;
int lights_index;
int projectionmatrix_index;
int viewmatrix_index;
@ -262,7 +262,6 @@ public:
int Find(const char *mame);
FShader *BindEffect(int effect);
void SetActiveShader(FShader *sh);
void SetWarpSpeed(unsigned int eff, float speed);
void ApplyMatrices(VSMatrix *proj, VSMatrix *view);
FShader *GetActiveShader() const
{

View File

@ -737,7 +737,7 @@ void FMaterial::Bind(int clampmode, int translation, int overrideshader)
int maxbound = 0;
bool allowhires = tex->xScale == FRACUNIT && tex->yScale == FRACUNIT;
gl_RenderState.SetupShader(shaderindex, tex->gl_info.shaderspeed);
gl_RenderState.SetShader(shaderindex, tex->gl_info.shaderspeed);
if (tex->bHasCanvas || tex->bWarped) clampmode = 0;
else if (clampmode != -1) clampmode &= 3;
@ -784,7 +784,7 @@ void FMaterial::BindPatch(int translation, int overrideshader, bool alphatexture
int shaderindex = overrideshader > 0? overrideshader : mShaderIndex;
int maxbound = 0;
gl_RenderState.SetupShader(shaderindex, tex->gl_info.shaderspeed);
gl_RenderState.SetShader(shaderindex, tex->gl_info.shaderspeed);
const FHardwareTexture *glpatch = mBaseLayer->BindPatch(0, translation, alphatexture);
// The only multitexture effect usable on sprites is the brightmap.