diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 30f8ca2d8..263fcb856 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -7646,6 +7646,7 @@ killsprite: GLInterface.EnableBlend(false); GLInterface.EnableAlphaTest(true); GLInterface.SetClamp(1+2); + GLInterface.SetDepthBias(-2, -256); if (spritesortcnt < numSprites) { @@ -7714,7 +7715,7 @@ killsprite: GLInterface.EnableBlend(true); GLInterface.EnableAlphaTest(true); GLInterface.SetDepthMask(false); - } + } #endif vec2f_t pos; @@ -7855,6 +7856,7 @@ killsprite: { GLInterface.SetDepthMask(true); GLInterface.SetClamp(0); + GLInterface.SetDepthBias(0, 0); } #endif diff --git a/source/glbackend/gl_renderstate.h b/source/glbackend/gl_renderstate.h index a7a290246..1fd5fbfbf 100644 --- a/source/glbackend/gl_renderstate.h +++ b/source/glbackend/gl_renderstate.h @@ -55,6 +55,21 @@ enum PRSFlags }; +struct FDepthBiasState +{ + float mFactor; + float mUnits; + bool mChanged; + + void Reset() + { + mFactor = 0; + mUnits = 0; + mChanged = false; + } +}; + + struct PolymostRenderState { int vindex, vcount, primtype; @@ -72,6 +87,7 @@ struct PolymostRenderState short matrixIndex[NUMMATRICES] = { 0,0,0,0,0 }; PalEntry fullscreenTint = 0xffffff, hictint = 0xffffff, hictint_overlay = 0xffffff; int hictint_flags = -1; + FDepthBiasState mBias{ }; int StateFlags = STF_COLORMASK|STF_DEPTHMASK; FRenderStyle Style{}; diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index dbe5e2851..b72f4fe64 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -428,6 +428,19 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState) else glDisable(GL_SCISSOR_TEST); } + if (mBias.mChanged) + { + if (mBias.mFactor == 0 && mBias.mUnits == 0) + { + glDisable(GL_POLYGON_OFFSET_FILL); + } + else + { + glEnable(GL_POLYGON_OFFSET_FILL); + } + glPolygonOffset(mBias.mFactor, mBias.mUnits); + mBias.mChanged = false; + } StateFlags &= ~(STF_CLEARCOLOR | STF_CLEARDEPTH | STF_VIEWPORTSET | STF_SCISSORSET); oldState.Flags = StateFlags; diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index 0f4c6e1b4..400314181 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -225,6 +225,20 @@ public: void ReadPixels(int w, int h, uint8_t* buffer); + void SetDepthBias(float a, float b) + { + renderState.mBias.mFactor = a; + renderState.mBias.mUnits = b; + renderState.mBias.mChanged = true; + } + + void ClearDepthBias() + { + renderState.mBias.mFactor = 0; + renderState.mBias.mUnits = 0; + renderState.mBias.mChanged = true; + } + void SetPaletteData(int index, const uint8_t* data) { palmanager.SetPalette(index, data);