diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 272546915..d26b9b821 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -2607,7 +2607,6 @@ killsprite: { GLInterface.EnableBlend(false); GLInterface.EnableAlphaTest(true); - GLInterface.SetClamp(1+2); GLInterface.SetDepthBias(-2, -256); if (spritesortcnt < numSprites) @@ -2660,8 +2659,7 @@ killsprite: } } - GLInterface.SetClamp(0); - int32_t numMaskWalls = maskwallcnt; + int32_t numMaskWalls = maskwallcnt; maskwallcnt = 0; for (i = 0; i < numMaskWalls; i++) { @@ -2703,11 +2701,6 @@ killsprite: _equation p1eq = equation(pos.x, pos.y, dot.x, dot.y); _equation p2eq = equation(pos.x, pos.y, dot2.x, dot2.y); -#ifdef USE_OPENGL - if (videoGetRenderMode() == REND_POLYMOST) - GLInterface.SetClamp(1+2); -#endif - i = spritesortcnt; while (i) { @@ -2807,8 +2800,7 @@ killsprite: } renderFinishScene(); GLInterface.SetDepthMask(true); - GLInterface.SetClamp(0); - GLInterface.SetDepthBias(0, 0); + GLInterface.SetDepthBias(0, 0); } diff --git a/source/build/src/mdsprite.cpp b/source/build/src/mdsprite.cpp index 0197a2c17..2ce91d095 100644 --- a/source/build/src/mdsprite.cpp +++ b/source/build/src/mdsprite.cpp @@ -1643,8 +1643,6 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) k3 = (float)sintable[sext->roll&2047] * (1.f/16384.f); } - int prevClamp = GLInterface.GetClamp(); - GLInterface.SetClamp(0); VSMatrix imat = 0; imat.scale(1024, 1024, 1024); GLInterface.SetMatrix(Matrix_Model, &imat); @@ -1795,7 +1793,6 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) GLInterface.SetIdentityMatrix(Matrix_Model); GLInterface.SetTinting(-1, 0xffffff, 0xffffff); - GLInterface.SetClamp(prevClamp); globalnoeffect=0; return 1; diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 602c349fc..f06e2a07b 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -1828,8 +1828,6 @@ static void polymost_flatskyrender(vec2f_t const* const dpxy, int32_t const n, i int const npot = (1<<(widthBits(globalpicnum))) != tileWidth(globalpicnum); int const xpanning = (hw_parallaxskypanning?global_cf_xpanning:0); - GLInterface.SetClamp((npot || xpanning != 0) ? 0 : 2); - int picnumbak = globalpicnum; ti = globalpicnum; o.y = fviewingrange/(ghalfx*256.f); o.z = 1.f/o.y; @@ -1967,8 +1965,6 @@ static void polymost_flatskyrender(vec2f_t const* const dpxy, int32_t const n, i globalpicnum = picnumbak; - GLInterface.SetClamp(0); - flatskyrender = 1; GLInterface.useMapFog = f; } diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index f436a2a27..625cfff4b 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -1134,8 +1134,6 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) #endif const float phack[2] = { 0, 1.f/256.f }; - int prevClamp = GLInterface.GetClamp(); - GLInterface.SetClamp(0); #if 1 int palId = TRANSLATION(Translation_Remap + curbasepal, globalpal); auto palette = GPalette.TranslationToTable(palId); @@ -1209,7 +1207,6 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) } GLInterface.Draw(DT_Triangles, qstart, qdone * 6); - GLInterface.SetClamp(prevClamp); //------------ GLInterface.SetCull(Cull_None); diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index 60eb58320..4ba6f4cf8 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -101,14 +101,6 @@ OpenGLRenderer::FHardwareTexture* GLInstance::NewTexture(int numchannels) return new OpenGLRenderer::FHardwareTexture(numchannels); } -void GLInstance::ResetFrame() -{ - GLState s; - lastState = s; // Back to defaults. - lastState.Style.BlendOp = -1; // invalidate. This forces a reset for the next operation - -} - void GLInstance::Draw(EDrawType type, size_t start, size_t count) { assert (BufferLock > 0); @@ -123,12 +115,21 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count) void GLInstance::DoDraw() { - for (auto& rs : rendercommands) + GLState lastState; + + if (rendercommands.Size() > 0) { - rs.Apply(*screen->RenderState(), lastState); - screen->RenderState()->Draw(rs.primtype, rs.vindex, rs.vcount); + lastState.Flags = ~rendercommands[0].StateFlags; // Force ALL flags to be considered 'changed'. + lastState.DepthFunc = INT_MIN; // Something totally invalid. + + for (auto& rs : rendercommands) + { + rs.Apply(*screen->RenderState(), lastState); + screen->RenderState()->Draw(rs.primtype, rs.vindex, rs.vcount); + } + renderState.Apply(*screen->RenderState(), lastState); // apply any pending change before returning. + rendercommands.Clear(); } - rendercommands.Clear(); matrixArray.Resize(1); } @@ -143,7 +144,7 @@ int GLInstance::SetMatrix(int num, const VSMatrix *mat) void GLInstance::SetIdentityMatrix(int num) { - renderState.matrixIndex[num] = 0; + renderState.matrixIndex[num] = -1; } @@ -463,7 +464,6 @@ void videoShowFrame(int32_t w) screen->SetSceneRenderTarget(useSSAO); twodpsp.Clear(); twod->Clear(); - GLInterface.ResetFrame(); } diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index 7ea6dba15..6baf52d58 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -76,9 +76,8 @@ enum struct GLState { - int Flags = STF_COLORMASK | STF_DEPTHMASK; - FRenderStyle Style{}; - int DepthFunc = -1; + int Flags; + int DepthFunc; }; class GLInstance @@ -91,9 +90,6 @@ public: FGameTexture* currentTexture = nullptr; int MatrixChange = 0; - // Cached GL state. - GLState lastState; - PolymostRenderState renderState; @@ -103,8 +99,7 @@ public: void Init(int y); void InitGLState(int fogmode, int multisample); - void ResetFrame(); - + void Deinit(); static int GetTexDimension(int value) @@ -154,18 +149,6 @@ public: void SetPalswap(int index); - int GetClamp() - { - return 0;// int(renderState.Clamp[0] + 2 * renderState.Clamp[1]); - } - - void SetClamp(int clamp) - { - // This option is totally pointless and should be removed. - //renderState.Clamp[0] = clamp & 1; - //renderState.Clamp[1] = !!(clamp & 2); - } - void SetShade(int32_t shade, int numshades) { renderState.Shade = clamp(shade, 0, numshades-1); diff --git a/source/glbackend/pm_renderstate.h b/source/glbackend/pm_renderstate.h index b890489ac..b83203285 100644 --- a/source/glbackend/pm_renderstate.h +++ b/source/glbackend/pm_renderstate.h @@ -57,7 +57,7 @@ struct PolymostRenderState float AlphaThreshold = 0.5f; bool AlphaTest = true; float Color[4] = { 1,1,1,1 }; - short matrixIndex[NUMMATRICES] = { 0 }; + short matrixIndex[NUMMATRICES] = { -1 }; PalEntry fullscreenTint = 0xffffff, hictint = 0xffffff, hictint_overlay = 0xffffff; int hictint_flags = -1; FDepthBiasState mBias{ };