Skip to content

Commit

Permalink
- Fixed compilation of "- changed the stencil cap drawer to only cove…
Browse files Browse the repository at this point in the history
…r the area which is actually used by the portal.".
  • Loading branch information
drfrag666 committed Dec 10, 2018
1 parent de78923 commit ca71f82
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
54 changes: 31 additions & 23 deletions src/gl/scene/gl_portal.cpp
Expand Up @@ -124,7 +124,7 @@ void GLPortal::ClearScreen()
// DrawPortalStencil
//
//-----------------------------------------------------------------------------
void GLPortal::DrawPortalStencil(int pass)
void GLPortal::DrawPortalStencil(FDrawInfo *di, int pass)
{
if (mPrimIndices.Size() == 0)
{
Expand All @@ -146,25 +146,33 @@ void GLPortal::DrawPortalStencil(int pass)
if (pass == STP_AllInOne) glDepthMask(false);
else if (pass == STP_DepthRestore) glDepthRange(1, 1);

if (planesused & (1 << sector_t::floor))
if (di != nullptr)
{
auto verts = di->AllocVertices(4);
auto ptr = verts.first;
ptr[0].Set((float)boundingBox.Left(), -32767.f, (float)boundingBox.Top(), 0, 0);
ptr[1].Set((float)boundingBox.Right(), -32767.f, (float)boundingBox.Top(), 0, 0);
ptr[2].Set((float)boundingBox.Left(), -32767.f, (float)boundingBox.Bottom(), 0, 0);
ptr[3].Set((float)boundingBox.Right(), -32767.f, (float)boundingBox.Bottom(), 0, 0);
GLRenderer->mVBO->RenderArray(GL_TRIANGLE_STRIP, verts.second, 4);
if (planesused & (1 << sector_t::floor))
{
auto verts = di->AllocVertices(4);
auto ptr = verts.first;
ptr[0].Set((float)boundingBox.Left(), -32767.f, (float)boundingBox.Top(), 0, 0);
ptr[1].Set((float)boundingBox.Right(), -32767.f, (float)boundingBox.Top(), 0, 0);
ptr[2].Set((float)boundingBox.Left(), -32767.f, (float)boundingBox.Bottom(), 0, 0);
ptr[3].Set((float)boundingBox.Right(), -32767.f, (float)boundingBox.Bottom(), 0, 0);
GLRenderer->mVBO->RenderArray(GL_TRIANGLE_STRIP, verts.second, 4);
}
if (planesused & (1 << sector_t::ceiling))
{
auto verts = di->AllocVertices(4);
auto ptr = verts.first;
ptr[0].Set((float)boundingBox.Left(), 32767.f, (float)boundingBox.Top(), 0, 0);
ptr[1].Set((float)boundingBox.Right(), 32767.f, (float)boundingBox.Top(), 0, 0);
ptr[2].Set((float)boundingBox.Left(), 32767.f, (float)boundingBox.Bottom(), 0, 0);
ptr[3].Set((float)boundingBox.Right(), 32767.f, (float)boundingBox.Bottom(), 0, 0);
GLRenderer->mVBO->RenderArray(GL_TRIANGLE_STRIP, verts.second, 4);
}
}
if (planesused & (1 << sector_t::ceiling))
else
{
auto verts = di->AllocVertices(4);
auto ptr = verts.first;
ptr[0].Set((float)boundingBox.Left(), 32767.f, (float)boundingBox.Top(), 0, 0);
ptr[1].Set((float)boundingBox.Right(), 32767.f, (float)boundingBox.Top(), 0, 0);
ptr[2].Set((float)boundingBox.Left(), 32767.f, (float)boundingBox.Bottom(), 0, 0);
ptr[3].Set((float)boundingBox.Right(), 32767.f, (float)boundingBox.Bottom(), 0, 0);
GLRenderer->mVBO->RenderArray(GL_TRIANGLE_STRIP, verts.second, 4);
GLRenderer->mVBO->RenderArray(GL_TRIANGLE_FAN, FFlatVertexBuffer::STENCILTOP_INDEX, 4);
GLRenderer->mVBO->RenderArray(GL_TRIANGLE_FAN, FFlatVertexBuffer::STENCILBOTTOM_INDEX, 4);
}
if (pass == STP_DepthRestore) glDepthRange(0, 1);
}
Expand Down Expand Up @@ -213,7 +221,7 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo *outer_di, FDrawIn
}
else doquery = false; // some kind of error happened

DrawPortalStencil(STP_Stencil);
DrawPortalStencil(outer_di, STP_Stencil);

glEndQuery(GL_SAMPLES_PASSED);

Expand All @@ -223,7 +231,7 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo *outer_di, FDrawIn
glDepthMask(true); // enable z-buffer again
glDepthRange(1, 1);
glDepthFunc(GL_ALWAYS);
DrawPortalStencil(STP_DepthClear);
DrawPortalStencil(outer_di, STP_DepthClear);

// set normal drawing mode
gl_RenderState.EnableTexture(true);
Expand Down Expand Up @@ -256,7 +264,7 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo *outer_di, FDrawIn
// Note: We must draw the stencil with z-write enabled here because there is no second pass!

glDepthMask(true);
DrawPortalStencil(STP_AllInOne);
DrawPortalStencil(outer_di, STP_AllInOne);
glStencilFunc(GL_EQUAL, recursion + 1, ~0); // draw sky into stencil
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // this stage doesn't modify the stencil
gl_RenderState.EnableTexture(true);
Expand Down Expand Up @@ -360,7 +368,7 @@ void GLPortal::End(bool usestencil)
// first step: reset the depth buffer to max. depth
glDepthRange(1, 1); // always
glDepthFunc(GL_ALWAYS); // write the farthest depth value
DrawPortalStencil(STP_DepthClear);
DrawPortalStencil(nullptr, STP_DepthClear);
}
else
{
Expand All @@ -372,7 +380,7 @@ void GLPortal::End(bool usestencil)
glDepthRange(0, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
glStencilFunc(GL_EQUAL, recursion, ~0); // draw sky into stencil
DrawPortalStencil(STP_DepthRestore);
DrawPortalStencil(nullptr, STP_DepthRestore);
glDepthFunc(GL_LESS);


Expand Down Expand Up @@ -415,7 +423,7 @@ void GLPortal::End(bool usestencil)
gl_RenderState.BlendFunc(GL_ONE, GL_ZERO);
gl_RenderState.BlendEquation(GL_FUNC_ADD);
gl_RenderState.Apply();
DrawPortalStencil(STP_DepthRestore);
DrawPortalStencil(nullptr, STP_DepthRestore);
gl_RenderState.SetEffect(EFF_NONE);
gl_RenderState.EnableTexture(true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/gl/scene/gl_portal.h
Expand Up @@ -80,7 +80,7 @@ class GLPortal : public IPortal
STP_DepthRestore,
STP_AllInOne
};
void DrawPortalStencil(int pass);
void DrawPortalStencil(FDrawInfo *di, int pass);

AActor * savedviewactor;
ActorRenderFlags savedvisibility;
Expand Down

0 comments on commit ca71f82

Please sign in to comment.