mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-02-21 11:01:36 +00:00
- Clean up plane rendering code slightly
This commit is contained in:
parent
fbaa3e7cb0
commit
393373a661
2 changed files with 111 additions and 100 deletions
|
@ -118,7 +118,7 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const PolyClip
|
|||
int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Viewpoint.extralight << 4;
|
||||
lightlevel = clamp(lightlevel + actualextralight, 0, 255);
|
||||
|
||||
UVTransform xform(ceiling ? fakeFloor->top.model->planes[sector_t::ceiling].xform : fakeFloor->top.model->planes[sector_t::floor].xform, tex);
|
||||
PolyPlaneUVTransform xform(ceiling ? fakeFloor->top.model->planes[sector_t::ceiling].xform : fakeFloor->top.model->planes[sector_t::floor].xform, tex);
|
||||
|
||||
TriVertex *vertices = PolyRenderer::Instance()->FrameMemory.AllocMemory<TriVertex>(sub->numlines);
|
||||
if (ceiling)
|
||||
|
@ -126,7 +126,7 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const PolyClip
|
|||
for (uint32_t i = 0; i < sub->numlines; i++)
|
||||
{
|
||||
seg_t *line = &sub->firstline[i];
|
||||
vertices[sub->numlines - 1 - i] = PlaneVertex(line->v1, fakeFloor->bottom.plane->ZatPoint(line->v1), xform);
|
||||
vertices[sub->numlines - 1 - i] = xform.GetVertex(line->v1, fakeFloor->bottom.plane->ZatPoint(line->v1));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -134,7 +134,7 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const PolyClip
|
|||
for (uint32_t i = 0; i < sub->numlines; i++)
|
||||
{
|
||||
seg_t *line = &sub->firstline[i];
|
||||
vertices[i] = PlaneVertex(line->v1, fakeFloor->top.plane->ZatPoint(line->v1), xform);
|
||||
vertices[i] = xform.GetVertex(line->v1, fakeFloor->top.plane->ZatPoint(line->v1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,7 +286,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const PolyClipPlane &
|
|||
#endif
|
||||
}
|
||||
|
||||
UVTransform transform(ceiling ? frontsector->planes[sector_t::ceiling].xform : frontsector->planes[sector_t::floor].xform, tex);
|
||||
PolyPlaneUVTransform transform(ceiling ? frontsector->planes[sector_t::ceiling].xform : frontsector->planes[sector_t::floor].xform, tex);
|
||||
|
||||
TriVertex *vertices = PolyRenderer::Instance()->FrameMemory.AllocMemory<TriVertex>(sub->numlines);
|
||||
|
||||
|
@ -295,7 +295,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const PolyClipPlane &
|
|||
for (uint32_t i = 0; i < sub->numlines; i++)
|
||||
{
|
||||
seg_t *line = &sub->firstline[i];
|
||||
vertices[sub->numlines - 1 - i] = PlaneVertex(line->v1, isSky ? skyHeight : frontsector->ceilingplane.ZatPoint(line->v1), transform);
|
||||
vertices[sub->numlines - 1 - i] = transform.GetVertex(line->v1, isSky ? skyHeight : frontsector->ceilingplane.ZatPoint(line->v1));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -303,7 +303,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const PolyClipPlane &
|
|||
for (uint32_t i = 0; i < sub->numlines; i++)
|
||||
{
|
||||
seg_t *line = &sub->firstline[i];
|
||||
vertices[i] = PlaneVertex(line->v1, isSky ? skyHeight : frontsector->floorplane.ZatPoint(line->v1), transform);
|
||||
vertices[i] = transform.GetVertex(line->v1, isSky ? skyHeight : frontsector->floorplane.ZatPoint(line->v1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,6 +356,12 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const PolyClipPlane &
|
|||
args.SetWriteDepth(false);
|
||||
args.DrawArray(vertices, sub->numlines, PolyDrawMode::TriangleFan);
|
||||
|
||||
RenderSkyWalls(args, sub, frontsector, portal, polyportal, ceiling, skyHeight, transform);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderPolyPlane::RenderSkyWalls(PolyDrawArgs &args, subsector_t *sub, sector_t *frontsector, FSectorPortal *portal, PolyDrawSectorPortal *polyportal, bool ceiling, double skyHeight, const PolyPlaneUVTransform &transform)
|
||||
{
|
||||
for (uint32_t i = 0; i < sub->numlines; i++)
|
||||
{
|
||||
TriVertex *wallvert = PolyRenderer::Instance()->FrameMemory.AllocMemory<TriVertex>(4);
|
||||
|
@ -411,42 +417,31 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const PolyClipPlane &
|
|||
|
||||
if (ceiling)
|
||||
{
|
||||
wallvert[0] = PlaneVertex(line->v1, skyHeight, transform);
|
||||
wallvert[1] = PlaneVertex(line->v2, skyHeight, transform);
|
||||
wallvert[2] = PlaneVertex(line->v2, skyBottomz2, transform);
|
||||
wallvert[3] = PlaneVertex(line->v1, skyBottomz1, transform);
|
||||
wallvert[0] = transform.GetVertex(line->v1, skyHeight);
|
||||
wallvert[1] = transform.GetVertex(line->v2, skyHeight);
|
||||
wallvert[2] = transform.GetVertex(line->v2, skyBottomz2);
|
||||
wallvert[3] = transform.GetVertex(line->v1, skyBottomz1);
|
||||
}
|
||||
else
|
||||
{
|
||||
wallvert[0] = PlaneVertex(line->v1, frontsector->floorplane.ZatPoint(line->v1), transform);
|
||||
wallvert[1] = PlaneVertex(line->v2, frontsector->floorplane.ZatPoint(line->v2), transform);
|
||||
wallvert[2] = PlaneVertex(line->v2, skyHeight, transform);
|
||||
wallvert[3] = PlaneVertex(line->v1, skyHeight, transform);
|
||||
wallvert[0] = transform.GetVertex(line->v1, frontsector->floorplane.ZatPoint(line->v1));
|
||||
wallvert[1] = transform.GetVertex(line->v2, frontsector->floorplane.ZatPoint(line->v2));
|
||||
wallvert[2] = transform.GetVertex(line->v2, skyHeight);
|
||||
wallvert[3] = transform.GetVertex(line->v1, skyHeight);
|
||||
}
|
||||
|
||||
args.DrawArray(wallvert, 4, PolyDrawMode::TriangleFan);
|
||||
|
||||
if (portal)
|
||||
{
|
||||
polyportal->Shape.push_back({ wallvert, 4, ccw });
|
||||
}
|
||||
polyportal->Shape.push_back({ wallvert, 4, args.FaceCullCCW() });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TriVertex RenderPolyPlane::PlaneVertex(vertex_t *v1, double height, const UVTransform &transform)
|
||||
{
|
||||
TriVertex v;
|
||||
v.x = (float)v1->fPos().X;
|
||||
v.y = (float)v1->fPos().Y;
|
||||
v.z = (float)height;
|
||||
v.w = 1.0f;
|
||||
v.u = transform.GetU(v.x, v.y);
|
||||
v.v = transform.GetV(v.x, v.y);
|
||||
return v;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
RenderPolyPlane::UVTransform::UVTransform(const FTransform &transform, FTexture *tex)
|
||||
PolyPlaneUVTransform::PolyPlaneUVTransform(const FTransform &transform, FTexture *tex)
|
||||
{
|
||||
if (tex)
|
||||
{
|
||||
|
@ -471,12 +466,24 @@ RenderPolyPlane::UVTransform::UVTransform(const FTransform &transform, FTexture
|
|||
}
|
||||
}
|
||||
|
||||
float RenderPolyPlane::UVTransform::GetU(float x, float y) const
|
||||
TriVertex PolyPlaneUVTransform::GetVertex(vertex_t *v1, double height) const
|
||||
{
|
||||
TriVertex v;
|
||||
v.x = (float)v1->fPos().X;
|
||||
v.y = (float)v1->fPos().Y;
|
||||
v.z = (float)height;
|
||||
v.w = 1.0f;
|
||||
v.u = GetU(v.x, v.y);
|
||||
v.v = GetV(v.x, v.y);
|
||||
return v;
|
||||
}
|
||||
|
||||
float PolyPlaneUVTransform::GetU(float x, float y) const
|
||||
{
|
||||
return (xOffs + x * cosine - y * sine) * xscale;
|
||||
}
|
||||
|
||||
float RenderPolyPlane::UVTransform::GetV(float x, float y) const
|
||||
float PolyPlaneUVTransform::GetV(float x, float y) const
|
||||
{
|
||||
return (yOffs - x * sine - y * cosine) * yscale;
|
||||
}
|
||||
|
|
|
@ -27,17 +27,14 @@
|
|||
class PolyDrawSectorPortal;
|
||||
class PolyCull;
|
||||
|
||||
class RenderPolyPlane
|
||||
class PolyPlaneUVTransform
|
||||
{
|
||||
public:
|
||||
static void RenderPlanes(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t stencilValue, double skyCeilingHeight, double skyFloorHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> §orPortals);
|
||||
static void Render3DPlanes(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, subsector_t *sub, uint32_t stencilValue);
|
||||
PolyPlaneUVTransform(const FTransform &transform, FTexture *tex);
|
||||
|
||||
TriVertex GetVertex(vertex_t *v1, double height) const;
|
||||
|
||||
private:
|
||||
struct UVTransform
|
||||
{
|
||||
UVTransform(const FTransform &transform, FTexture *tex);
|
||||
|
||||
float GetU(float x, float y) const;
|
||||
float GetV(float x, float y) const;
|
||||
|
||||
|
@ -46,9 +43,16 @@ private:
|
|||
float cosine;
|
||||
float sine;
|
||||
float xOffs, yOffs;
|
||||
};
|
||||
};
|
||||
|
||||
class RenderPolyPlane
|
||||
{
|
||||
public:
|
||||
static void RenderPlanes(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t stencilValue, double skyCeilingHeight, double skyFloorHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> §orPortals);
|
||||
static void Render3DPlanes(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, subsector_t *sub, uint32_t stencilValue);
|
||||
|
||||
private:
|
||||
void Render3DFloor(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, subsector_t *sub, uint32_t stencilValue, bool ceiling, F3DFloor *fakefloor);
|
||||
void Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t stencilValue, bool ceiling, double skyHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> §orPortals);
|
||||
TriVertex PlaneVertex(vertex_t *v1, double height, const UVTransform &transform);
|
||||
void RenderSkyWalls(PolyDrawArgs &args, subsector_t *sub, sector_t *frontsector, FSectorPortal *portal, PolyDrawSectorPortal *polyportal, bool ceiling, double skyHeight, const PolyPlaneUVTransform &transform);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue