diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 73d7d5ef3..807912bca 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -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)) diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index a07cd3401..63fdab4ea 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -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(); diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index db3e68298..870b6184a 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -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); - } - } -} - //========================================================================== // // diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index 6675e235e..c825996ee 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -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 { diff --git a/src/gl/textures/gl_material.cpp b/src/gl/textures/gl_material.cpp index b6d83eb52..9ec948b37 100644 --- a/src/gl/textures/gl_material.cpp +++ b/src/gl/textures/gl_material.cpp @@ -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.