mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-28 06:42:09 +00:00
Add support for multiple portals
This commit is contained in:
parent
3de7f1a387
commit
93af906a1d
5 changed files with 24 additions and 12 deletions
|
@ -44,7 +44,7 @@ void RenderPolyScene::Render()
|
||||||
ClearBuffers();
|
ClearBuffers();
|
||||||
SetSceneViewport();
|
SetSceneViewport();
|
||||||
SetupPerspectiveMatrix();
|
SetupPerspectiveMatrix();
|
||||||
MainPortal.SetViewpoint(WorldToClip, 0);
|
MainPortal.SetViewpoint(WorldToClip, GetNextStencilValue());
|
||||||
MainPortal.Render();
|
MainPortal.Render();
|
||||||
Skydome.Render(WorldToClip);
|
Skydome.Render(WorldToClip);
|
||||||
MainPortal.RenderTranslucent();
|
MainPortal.RenderTranslucent();
|
||||||
|
@ -63,6 +63,7 @@ void RenderPolyScene::ClearBuffers()
|
||||||
PolyVertexBuffer::Clear();
|
PolyVertexBuffer::Clear();
|
||||||
PolyStencilBuffer::Instance()->Clear(RenderTarget->GetWidth(), RenderTarget->GetHeight(), 0);
|
PolyStencilBuffer::Instance()->Clear(RenderTarget->GetWidth(), RenderTarget->GetHeight(), 0);
|
||||||
PolySubsectorGBuffer::Instance()->Resize(RenderTarget->GetPitch(), RenderTarget->GetHeight());
|
PolySubsectorGBuffer::Instance()->Resize(RenderTarget->GetPitch(), RenderTarget->GetHeight());
|
||||||
|
NextStencilValue = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderPolyScene::SetSceneViewport()
|
void RenderPolyScene::SetSceneViewport()
|
||||||
|
|
|
@ -42,6 +42,8 @@ public:
|
||||||
|
|
||||||
static RenderPolyScene *Instance();
|
static RenderPolyScene *Instance();
|
||||||
|
|
||||||
|
uint32_t GetNextStencilValue() { uint32_t value = NextStencilValue; NextStencilValue += 2; return value; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ClearBuffers();
|
void ClearBuffers();
|
||||||
void SetSceneViewport();
|
void SetSceneViewport();
|
||||||
|
@ -51,4 +53,5 @@ private:
|
||||||
RenderPolyPortal MainPortal;
|
RenderPolyPortal MainPortal;
|
||||||
PolySkyDome Skydome;
|
PolySkyDome Skydome;
|
||||||
RenderPolyPlayerSprites PlayerSprites;
|
RenderPolyPlayerSprites PlayerSprites;
|
||||||
|
uint32_t NextStencilValue = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -264,7 +264,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, subsector_t *sub, uin
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
args.stencilwritevalue = 252;
|
args.stencilwritevalue = polyportal->StencilValue;
|
||||||
PolyTriangleDrawer::draw(args, TriDrawVariant::Stencil, TriBlendMode::Copy);
|
PolyTriangleDrawer::draw(args, TriDrawVariant::Stencil, TriBlendMode::Copy);
|
||||||
polyportal->Shape.push_back({ args.vinput, args.vcount, args.ccw, subsectorDepth });
|
polyportal->Shape.push_back({ args.vinput, args.vcount, args.ccw, subsectorDepth });
|
||||||
}
|
}
|
||||||
|
@ -273,7 +273,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, subsector_t *sub, uin
|
||||||
{
|
{
|
||||||
if (portal)
|
if (portal)
|
||||||
{
|
{
|
||||||
args.stencilwritevalue = 252;
|
args.stencilwritevalue = polyportal->StencilValue;
|
||||||
polyportal->Shape.push_back({ args.vinput, args.vcount, args.ccw, subsectorDepth });
|
polyportal->Shape.push_back({ args.vinput, args.vcount, args.ccw, subsectorDepth });
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "sbar.h"
|
#include "sbar.h"
|
||||||
#include "r_data/r_translate.h"
|
#include "r_data/r_translate.h"
|
||||||
#include "r_poly_portal.h"
|
#include "r_poly_portal.h"
|
||||||
|
#include "r_poly.h"
|
||||||
#include "gl/data/gl_data.h"
|
#include "gl/data/gl_data.h"
|
||||||
|
|
||||||
CVAR(Bool, r_debug_cull, 0, 0)
|
CVAR(Bool, r_debug_cull, 0, 0)
|
||||||
|
@ -192,14 +193,15 @@ void RenderPolyPortal::RenderTranslucent()
|
||||||
{
|
{
|
||||||
for (auto it = SectorPortals.rbegin(); it != SectorPortals.rend(); ++it)
|
for (auto it = SectorPortals.rbegin(); it != SectorPortals.rend(); ++it)
|
||||||
{
|
{
|
||||||
(*it)->RenderTranslucent();
|
auto &portal = *it;
|
||||||
|
portal->RenderTranslucent();
|
||||||
|
|
||||||
PolyDrawArgs args;
|
PolyDrawArgs args;
|
||||||
args.objectToClip = &WorldToClip;
|
args.objectToClip = &WorldToClip;
|
||||||
args.mode = TriangleDrawMode::Fan;
|
args.mode = TriangleDrawMode::Fan;
|
||||||
args.stenciltestvalue = 253;
|
args.stenciltestvalue = portal->StencilValue + 1;
|
||||||
args.stencilwritevalue = 1;
|
args.stencilwritevalue = StencilValue;
|
||||||
for (const auto &verts : (*it)->Shape)
|
for (const auto &verts : portal->Shape)
|
||||||
{
|
{
|
||||||
args.vinput = verts.Vertices;
|
args.vinput = verts.Vertices;
|
||||||
args.vcount = verts.Count;
|
args.vcount = verts.Count;
|
||||||
|
@ -211,14 +213,15 @@ void RenderPolyPortal::RenderTranslucent()
|
||||||
|
|
||||||
for (auto it = LinePortals.rbegin(); it != LinePortals.rend(); ++it)
|
for (auto it = LinePortals.rbegin(); it != LinePortals.rend(); ++it)
|
||||||
{
|
{
|
||||||
(*it)->RenderTranslucent();
|
auto &portal = *it;
|
||||||
|
portal->RenderTranslucent();
|
||||||
|
|
||||||
PolyDrawArgs args;
|
PolyDrawArgs args;
|
||||||
args.objectToClip = &WorldToClip;
|
args.objectToClip = &WorldToClip;
|
||||||
args.mode = TriangleDrawMode::Fan;
|
args.mode = TriangleDrawMode::Fan;
|
||||||
args.stenciltestvalue = 253;
|
args.stenciltestvalue = portal->StencilValue + 1;
|
||||||
args.stencilwritevalue = 1;
|
args.stencilwritevalue = StencilValue;
|
||||||
for (const auto &verts : (*it)->Shape)
|
for (const auto &verts : portal->Shape)
|
||||||
{
|
{
|
||||||
args.vinput = verts.Vertices;
|
args.vinput = verts.Vertices;
|
||||||
args.vcount = verts.Count;
|
args.vcount = verts.Count;
|
||||||
|
@ -257,6 +260,7 @@ void RenderPolyPortal::RenderTranslucent()
|
||||||
|
|
||||||
PolyDrawSectorPortal::PolyDrawSectorPortal(FSectorPortal *portal, bool ceiling) : Portal(portal), Ceiling(ceiling)
|
PolyDrawSectorPortal::PolyDrawSectorPortal(FSectorPortal *portal, bool ceiling) : Portal(portal), Ceiling(ceiling)
|
||||||
{
|
{
|
||||||
|
StencilValue = RenderPolyScene::Instance()->GetNextStencilValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PolyDrawSectorPortal::Render()
|
void PolyDrawSectorPortal::Render()
|
||||||
|
@ -289,7 +293,7 @@ void PolyDrawSectorPortal::Render()
|
||||||
TriMatrix::translate((float)-ViewPos.X, (float)-ViewPos.Y, (float)-ViewPos.Z);
|
TriMatrix::translate((float)-ViewPos.X, (float)-ViewPos.Y, (float)-ViewPos.Z);
|
||||||
TriMatrix worldToClip = TriMatrix::perspective(fovy, ratio, 5.0f, 65535.0f) * worldToView;
|
TriMatrix worldToClip = TriMatrix::perspective(fovy, ratio, 5.0f, 65535.0f) * worldToView;
|
||||||
|
|
||||||
RenderPortal.SetViewpoint(worldToClip, 252);
|
RenderPortal.SetViewpoint(worldToClip, StencilValue);
|
||||||
RenderPortal.Render();
|
RenderPortal.Render();
|
||||||
|
|
||||||
RestoreGlobals();
|
RestoreGlobals();
|
||||||
|
@ -349,6 +353,8 @@ void PolyDrawSectorPortal::RestoreGlobals()
|
||||||
PolyDrawLinePortal::PolyDrawLinePortal(line_t *src, line_t *dest, bool mirror) : Src(src), Dest(dest)
|
PolyDrawLinePortal::PolyDrawLinePortal(line_t *src, line_t *dest, bool mirror) : Src(src), Dest(dest)
|
||||||
{
|
{
|
||||||
// To do: do what R_EnterPortal and PortalDrawseg does
|
// To do: do what R_EnterPortal and PortalDrawseg does
|
||||||
|
|
||||||
|
StencilValue = RenderPolyScene::Instance()->GetNextStencilValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PolyDrawLinePortal::Render()
|
void PolyDrawLinePortal::Render()
|
||||||
|
|
|
@ -128,6 +128,7 @@ public:
|
||||||
void RenderTranslucent();
|
void RenderTranslucent();
|
||||||
|
|
||||||
FSectorPortal *Portal;
|
FSectorPortal *Portal;
|
||||||
|
uint32_t StencilValue = 0;
|
||||||
std::vector<PolyPortalVertexRange> Shape;
|
std::vector<PolyPortalVertexRange> Shape;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -153,6 +154,7 @@ public:
|
||||||
void Render();
|
void Render();
|
||||||
void RenderTranslucent();
|
void RenderTranslucent();
|
||||||
|
|
||||||
|
uint32_t StencilValue = 0;
|
||||||
std::vector<PolyPortalVertexRange> Shape;
|
std::vector<PolyPortalVertexRange> Shape;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue