mirror of
https://github.com/DrBeef/Raze.git
synced 2025-01-18 23:21:43 +00:00
- fixed render state management.
There are effectively two states - the one in the backend and a local one in the drawer for the render list which is supposed to eliminate some of the more costly repeated calls. This higher level state was cached globally, which did not work anymore because the real render state could be changed elsewhere without this code realizing it. All this means that the render list drawer must create a new state cache for each call and also must apply its current pending render state before leaving to ensure that everything is properly reset.
This commit is contained in:
parent
aa67875792
commit
67b1963e7c
7 changed files with 20 additions and 55 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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{ };
|
||||
|
|
Loading…
Reference in a new issue