Skip to content
Permalink
Browse files

- changed the stencil cap drawer to only cover the area which is actu…

…ally used by the portal.

This will now both exclude floor caps when only ceiling elements are used and everything outside the bounding box of active portal lines.
Hopefully this is enough to fix the issues with portal caps but of course it is not foolproof if someone just makes the right setup.

# Conflicts:
#	src/hwrenderer/scene/hw_portal.cpp
#	src/hwrenderer/scene/hw_portal.h
#	src/hwrenderer/scene/hw_walls.cpp
#	src/r_data/r_sections.cpp
#	src/r_data/r_sections.h

- Using FBoundingBox instead of BoundingRect for the implementation.
- Added Contains methods to FBoundingBox.
Doesn't compile yet. (drfrag)
  • Loading branch information...
coelckers authored and drfrag666 committed Nov 14, 2018
1 parent a1cf590 commit de61fcd4a836e4aa9a5687d545804e07cb6ed116
@@ -78,7 +78,7 @@ struct FDrawInfo : public HWDrawInfo
void AddWall(GLWall *wall) override;
void AddMirrorSurface(GLWall *w) override;
GLDecal *AddDecal(bool onmirror) override;
void AddPortal(GLWall *w, int portaltype) override;
void AddPortal(GLWall *w, int portaltype, int plane) override;
void AddFlat(GLFlat *flat, bool fog) override;
void AddSprite(GLSprite *sprite, bool translucent) override;
void AddHUDSprite(HUDSprite *huds) override;
@@ -145,17 +145,32 @@ void GLPortal::DrawPortalStencil(int pass)
{
if (pass == STP_AllInOne) glDepthMask(false);
else if (pass == STP_DepthRestore) glDepthRange(1, 1);
GLRenderer->mVBO->RenderArray(GL_TRIANGLE_FAN, FFlatVertexBuffer::STENCILTOP_INDEX, 4);
GLRenderer->mVBO->RenderArray(GL_TRIANGLE_FAN, FFlatVertexBuffer::STENCILBOTTOM_INDEX, 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 (pass == STP_DepthRestore) glDepthRange(0, 1);
}
}






//-----------------------------------------------------------------------------
//
// Start
@@ -513,6 +528,14 @@ bool GLPortal::RenderFirstSkyPortal(int recursion)
best=p;
bestindex=i;
}

// If the portal area contains the current camera viewpoint, let's always use it because it's likely to give the largest area.
if (p->boundingBox.Contains(r_viewpoint.Pos))
{
best = p;
bestindex = i;
break;
}
}
}

@@ -55,6 +55,7 @@ class GLPortal : public IPortal
static TArray<GLPortal *> portals;
static int recursion;
static unsigned int QueryObject;

protected:
static TArray<float> planestack;
static int MirrorFlag;
@@ -67,6 +68,9 @@ class GLPortal : public IPortal
static int inupperstack;
static bool inskybox;

FBoundingBox boundingBox;
int planesused = 0;

private:

enum
@@ -122,6 +126,8 @@ class GLPortal : public IPortal
void AddLine(GLWall * l)
{
lines.Push(*l);
boundingBox.AddToBox(DVector2(l->glseg.x1, l->glseg.y1));
boundingBox.AddToBox(DVector2(l->glseg.x2, l->glseg.y2));
}

static int GetRecursion()
@@ -416,9 +416,9 @@ void FDrawInfo::AddMirrorSurface(GLWall *w)
//
//==========================================================================

void FDrawInfo::AddPortal(GLWall *wall, int ptype)
void FDrawInfo::AddPortal(GLWall *wall, int ptype, int plane)
{
GLPortal * portal;
GLPortal * portal = nullptr;

wall->MakeVertices(this, false);
switch (ptype)
@@ -492,6 +492,11 @@ void FDrawInfo::AddPortal(GLWall *wall, int ptype)
break;
}
wall->vertcount = 0;

if (plane != -1 && portal)
{
portal->planesused |= (1<<plane);
}
}

//==========================================================================
@@ -183,7 +183,7 @@ struct HWDrawInfo
virtual void AddSubsectorToPortal(FSectorPortalGroup *portal, subsector_t *sub) = 0;

virtual void AddWall(GLWall *w) = 0;
virtual void AddPortal(GLWall *w, int portaltype) = 0;
virtual void AddPortal(GLWall *w, int portaltype, int plane) = 0;
virtual void AddMirrorSurface(GLWall *w) = 0;
virtual void AddFlat(GLFlat *flat, bool fog) = 0;
virtual void AddSprite(GLSprite *sprite, bool translucent) = 0;
@@ -198,7 +198,7 @@ class GLWall
//private:

void PutWall(HWDrawInfo *di, bool translucent);
void PutPortal(HWDrawInfo *di, int ptype);
void PutPortal(HWDrawInfo *di, int ptype, int plane);
void CheckTexturePosition(FTexCoordInfo *tci);

void Put3DWall(HWDrawInfo *di, lightlist_t * lightlist, bool translucent);
@@ -122,7 +122,7 @@ void GLWall::SkyPlane(HWDrawInfo *di, sector_t *sector, int plane, bool allowref
skyinfo.init(sector->sky, Colormap.FadeColor);
ptype = PORTALTYPE_SKY;
sky = &skyinfo;
PutPortal(di, ptype);
PutPortal(di, ptype, plane);
}
else if (sportal != nullptr)
{
@@ -162,7 +162,7 @@ void GLWall::SkyPlane(HWDrawInfo *di, sector_t *sector, int plane, bool allowref
}
if (ptype != -1)
{
PutPortal(di, ptype);
PutPortal(di, ptype, plane);
}
}

@@ -197,7 +197,7 @@ void GLWall::SkyLine(HWDrawInfo *di, sector_t *fs, line_t *line)
ztop[1] = zceil[1];
zbottom[0] = zfloor[0];
zbottom[1] = zfloor[1];
PutPortal(di, ptype);
PutPortal(di, ptype, -1);
}


@@ -208,9 +208,9 @@ void GLWall::PutWall(HWDrawInfo *di, bool translucent)
flags &= ~GLWF_TRANSLUCENT;
}

void GLWall::PutPortal(HWDrawInfo *di, int ptype)
void GLWall::PutPortal(HWDrawInfo *di, int ptype, int plane)
{
di->AddPortal(this, ptype);
di->AddPortal(this, ptype, plane);
}

//==========================================================================
@@ -472,7 +472,7 @@ bool GLWall::DoHorizon(HWDrawInfo *di, seg_t * seg,sector_t * fs, vertex_t * v1,

if (di->FixedColormap) hi.colormap.Clear();
horizon = &hi;
PutPortal(di, PORTALTYPE_HORIZON);
PutPortal(di, PORTALTYPE_HORIZON, -1);
}
ztop[1] = ztop[0] = zbottom[0];
}
@@ -501,7 +501,7 @@ bool GLWall::DoHorizon(HWDrawInfo *di, seg_t * seg,sector_t * fs, vertex_t * v1,

if (di->FixedColormap) hi.colormap.Clear();
horizon = &hi;
PutPortal(di, PORTALTYPE_HORIZON);
PutPortal(di, PORTALTYPE_HORIZON, -1);
}
}
return true;
@@ -758,7 +758,7 @@ void GLWall::DoTexture(HWDrawInfo *di, int _type,seg_t * seg, int peg,

if (seg->linedef->special == Line_Mirror && _type == RENDERWALL_M1S && gl_mirrors)
{
PutPortal(di, PORTALTYPE_MIRROR);
PutPortal(di, PORTALTYPE_MIRROR, -1);
}
else
{
@@ -1592,7 +1592,7 @@ void GLWall::Process(HWDrawInfo *di, seg_t *seg, sector_t * frontsector, sector_
ztop[1] = zceil[1];
zbottom[0] = zfloor[0];
zbottom[1] = zfloor[1];
PutPortal(di, PORTALTYPE_LINETOLINE);
PutPortal(di, PORTALTYPE_LINETOLINE, -1);
}
else if (seg->linedef->GetTransferredPortal())
{
@@ -1699,7 +1699,7 @@ void GLWall::Process(HWDrawInfo *di, seg_t *seg, sector_t * frontsector, sector_
ztop[1] = bch2;
zbottom[0] = bfh1;
zbottom[1] = bfh2;
PutPortal(di, PORTALTYPE_LINETOLINE);
PutPortal(di, PORTALTYPE_LINETOLINE, -1);
}
else if (backsector->e->XFloor.ffloors.Size() || frontsector->e->XFloor.ffloors.Size())
{
@@ -91,6 +91,22 @@ class FBoundingBox
int BoxOnLineSide (const line_t *ld) const;

void Set(int index, double value) {m_Box[index] = value;}

bool Contains(const FBoundingBox & other) const
{
return m_Box[BOXLEFT] <= other.m_Box[BOXLEFT] && m_Box[BOXTOP] <= other.m_Box[BOXTOP] && m_Box[BOXRIGHT] >= other.m_Box[BOXRIGHT] && m_Box[BOXBOTTOM] >= other.m_Box[BOXBOTTOM];
}

bool Contains(double x, double y) const
{
return m_Box[BOXLEFT] <= x && m_Box[BOXTOP] <= y && m_Box[BOXRIGHT] >= x && m_Box[BOXBOTTOM] >= y;
}

template <class T>
bool Contains(const T &vec) const
{
return m_Box[BOXLEFT] <= vec.X && m_Box[BOXTOP] <= vec.Y && m_Box[BOXRIGHT] >= vec.X && m_Box[BOXBOTTOM] >= vec.Y;
}

protected:
double m_Box[4];

0 comments on commit de61fcd

Please sign in to comment.
You can’t perform that action at this time.