- move stencil recursion counter to render state.

This commit is contained in:
Christoph Oelckers 2018-10-21 10:58:11 +02:00
parent a97d71a3c3
commit acad8315d0
5 changed files with 30 additions and 19 deletions

View File

@ -240,8 +240,7 @@ void FGLRenderState::Apply()
if (mStencil.mChanged)
{
int recursion = GLRenderer->mPortalState.GetRecursion();
glStencilFunc(GL_EQUAL, recursion + mStencil.mOffsVal, ~0); // draw sky into stencil
glStencilFunc(GL_EQUAL, mStencil.mBaseVal + mStencil.mOffsVal, ~0); // draw sky into stencil
glStencilOp(GL_KEEP, GL_KEEP, op2gl[mStencil.mOperation]); // this stage doesn't modify the stencil
bool cmon = !(mStencil.mFlags & SF_ColorMaskOff);

View File

@ -201,6 +201,12 @@ public:
return mPassType == GBUFFER_PASS ? 3 : 1;
}
// Temporary helper.
int GetStencilCounter()
{
return mStencil.mBaseVal;
}
};
extern FGLRenderState gl_RenderState;

View File

@ -133,7 +133,7 @@ bool GLPortal::Start(bool usestencil, bool doquery, HWDrawInfo *outer_di, HWDraw
}
// Create stencil
glStencilFunc(GL_EQUAL, mState->recursion, ~0); // create stencil
glStencilFunc(GL_EQUAL, gl_RenderState.GetStencilCounter(), ~0); // create stencil
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); // increment stencil of valid pixels
{
glColorMask(0,0,0,0); // don't write to the graphics buffer
@ -157,7 +157,7 @@ bool GLPortal::Start(bool usestencil, bool doquery, HWDrawInfo *outer_di, HWDraw
if (doquery) glEndQuery(GL_SAMPLES_PASSED);
// Clear Z-buffer
glStencilFunc(GL_EQUAL, mState->recursion + 1, ~0); // draw sky into stencil
glStencilFunc(GL_EQUAL, gl_RenderState.GetStencilCounter() + 1, ~0); // draw sky into stencil
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // this stage doesn't modify the stencil
glDepthMask(true); // enable z-buffer again
glDepthRange(1, 1);
@ -179,7 +179,7 @@ bool GLPortal::Start(bool usestencil, bool doquery, HWDrawInfo *outer_di, HWDraw
{
// restore default stencil op.
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glStencilFunc(GL_EQUAL, mState->recursion, ~0); // draw sky into stencil
glStencilFunc(GL_EQUAL, gl_RenderState.GetStencilCounter(), ~0); // draw sky into stencil
return false;
}
}
@ -192,7 +192,7 @@ bool GLPortal::Start(bool usestencil, bool doquery, HWDrawInfo *outer_di, HWDraw
glDepthMask(true);
DrawPortalStencil(STP_AllInOne);
glStencilFunc(GL_EQUAL, mState->recursion + 1, ~0); // draw sky into stencil
glStencilFunc(GL_EQUAL, gl_RenderState.GetStencilCounter() + 1, ~0); // draw sky into stencil
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // this stage doesn't modify the stencil
gl_RenderState.EnableTexture(true);
glColorMask(1,1,1,1);
@ -201,9 +201,7 @@ bool GLPortal::Start(bool usestencil, bool doquery, HWDrawInfo *outer_di, HWDraw
glDepthMask(false); // don't write to Z-buffer!
}
}
mState->recursion++;
gl_RenderState.IncStencilValue();
}
else
{
@ -265,7 +263,7 @@ void GLPortal::End(HWDrawInfo *di, bool usestencil)
glDepthFunc(GL_LEQUAL);
glDepthRange(0, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
glStencilFunc(GL_EQUAL, mState->recursion, ~0); // draw sky into stencil
glStencilFunc(GL_EQUAL, gl_RenderState.GetStencilCounter(), ~0); // draw sky into stencil
DrawPortalStencil(STP_DepthRestore);
glDepthFunc(GL_LESS);
@ -273,11 +271,11 @@ void GLPortal::End(HWDrawInfo *di, bool usestencil)
gl_RenderState.EnableTexture(true);
gl_RenderState.SetEffect(EFF_NONE);
glColorMask(1, 1, 1, 1);
mState->recursion--;
gl_RenderState.DecStencilValue();
// restore old stencil op.
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glStencilFunc(GL_EQUAL, mState->recursion, ~0); // draw sky into stencil
glStencilFunc(GL_EQUAL, gl_RenderState.GetStencilCounter(), ~0); // draw sky into stencil
}
else
{

View File

@ -79,8 +79,6 @@ public:
struct FPortalSceneState
{
int recursion = 0;
int MirrorFlag = 0;
int PlaneMirrorFlag = 0;
int renderdepth = 0;
@ -101,11 +99,6 @@ struct FPortalSceneState
UniquePlaneMirrors.Clear();
}
int GetRecursion() const
{
return recursion;
}
bool isMirrored() const
{
return !!((MirrorFlag ^ PlaneMirrorFlag) & 1);

View File

@ -74,6 +74,7 @@ struct FMaterialState
struct FStencilState
{
int mBaseVal;
int mOffsVal;
int mOperation;
int mFlags;
@ -81,6 +82,7 @@ struct FStencilState
void Reset()
{
mBaseVal = 0;
mOffsVal = 0;
mOperation = SOP_Keep;
mFlags = SF_AllOn;
@ -402,6 +404,19 @@ public:
mStencil.mChanged = true;
}
void IncStencilValue()
{
mStencil.mBaseVal++;
mStencil.mChanged = true;
}
void DecStencilValue()
{
mStencil.mBaseVal--;
mStencil.mChanged = true;
}
void SetColor(int sectorlightlevel, int rellight, bool fullbright, const FColormap &cm, float alpha, bool weapon = false);
void SetFog(int lightlevel, int rellight, bool fullbright, const FColormap *cmap, bool isadditive);