Skip to content

Commit

Permalink
rewrite of HWWalls to allow grabbing the output from the render item …
Browse files Browse the repository at this point in the history
…generator.
  • Loading branch information
coelckers committed Oct 19, 2023
1 parent d65d1a3 commit 9cd57fa
Show file tree
Hide file tree
Showing 8 changed files with 422 additions and 290 deletions.
7 changes: 5 additions & 2 deletions src/rendering/hwrenderer/scene/hw_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "hw_clock.h"
#include "flatvertices.h"
#include "hw_vertexbuilder.h"
#include "hw_walldispatcher.h"

#ifdef ARCH_IA32
#include <immintrin.h>
Expand Down Expand Up @@ -105,6 +106,7 @@ static RenderJobQueue jobQueue; // One static queue is sufficient here. This cod
void HWDrawInfo::WorkerThread()
{
sector_t *front, *back;
HWWallDispatcher disp(this);

WTTotal.Clock();
isWorkerThread = true; // for adding asserts in GL API code. The worker thread may never call any GL API.
Expand Down Expand Up @@ -169,7 +171,7 @@ void HWDrawInfo::WorkerThread()
}
else back = nullptr;

wall.Process(this, job->seg, front, back);
wall.Process(&disp, job->seg, front, back);
rendered_lines++;
SetupWall.Unclock();
break;
Expand Down Expand Up @@ -348,9 +350,10 @@ void HWDrawInfo::AddLine (seg_t *seg, bool portalclip)
else
{
HWWall wall;
HWWallDispatcher disp(this);
SetupWall.Clock();
wall.sub = seg->Subsector;
wall.Process(this, seg, currentsector, backsector);
wall.Process(&disp, seg, currentsector, backsector);
rendered_lines++;
SetupWall.Unclock();
}
Expand Down
1 change: 0 additions & 1 deletion src/rendering/hwrenderer/scene/hw_drawinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ struct HWDrawInfo
int CalcLightLevel(int lightlevel, int rellight, bool weapon, int blendfactor);
PalEntry CalcLightColor(int light, PalEntry pe, int blendfactor);
float GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity, int blendfactor);
bool CheckFog(sector_t *frontsector, sector_t *backsector);
WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &pos, int cm, area_t in_area, const DVector3 &playerpos);

void PreparePlayerSprites2D(sector_t * viewsector, area_t in_area);
Expand Down
186 changes: 99 additions & 87 deletions src/rendering/hwrenderer/scene/hw_drawstructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#pragma warning(disable:4244)
#endif

bool CheckFog(FLevelLocals* Level, sector_t* frontsector, sector_t* backsector, ELightMode lightmode);

struct HWHorizonInfo;
struct HWSkyInfo;
struct F3DFloor;
Expand Down Expand Up @@ -113,6 +115,11 @@ struct texcoord
};

struct HWDrawInfo;
class HWWall;

// this only exists to keep HWWallDispatcher trivial

struct HWWallDispatcher;

class HWWall
{
Expand All @@ -121,13 +128,13 @@ class HWWall

enum
{
HWF_CLAMPX=1,
HWF_CLAMPY=2,
HWF_SKYHACK=4,
HWF_GLOW=8, // illuminated by glowing flats
HWF_NOSPLITUPPER=16,
HWF_NOSPLITLOWER=32,
HWF_NOSPLIT=64,
HWF_CLAMPX = 1,
HWF_CLAMPY = 2,
HWF_SKYHACK = 4,
HWF_GLOW = 8, // illuminated by glowing flats
HWF_NOSPLITUPPER = 16,
HWF_NOSPLITLOWER = 32,
HWF_NOSPLIT = 64,
HWF_TRANSLUCENT = 128,
HWF_NOSLICE = 256
};
Expand All @@ -151,21 +158,21 @@ class HWWall
friend struct HWDrawList;
friend class HWPortal;

vertex_t * vertexes[2]; // required for polygon splitting
FGameTexture *texture;
TArray<lightlist_t> *lightlist;
LightmapSurface *lightmap;
vertex_t* vertexes[2]; // required for polygon splitting
FGameTexture* texture;
TArray<lightlist_t>* lightlist;
LightmapSurface* lightmap;

HWSeg glseg;
float ztop[2],zbottom[2];
float ztop[2], zbottom[2];
texcoord tcs[4];
texcoord lightuv[4];
float lindex;
float alpha;

FColormap Colormap;
ERenderStyle RenderStyle;

float ViewDistance;

short lightlevel;
Expand All @@ -181,12 +188,17 @@ class HWWall
union
{
// it's either one of them but never more!
FSectorPortal *secportal; // sector portal (formerly skybox)
HWSkyInfo * sky; // for normal sky
HWHorizonInfo * horizon; // for horizon information
FSectorPortalGroup * portal; // stacked sector portals
secplane_t * planemirror; // for plane mirrors
FLinePortalSpan *lineportal; // line-to-line portals
FSectorPortal* secportal; // sector portal (formerly skybox)
HWSkyInfo* sky; // for normal sky
HWHorizonInfo* horizon; // for horizon information
FSectorPortalGroup* portal; // stacked sector portals
secplane_t* planemirror; // for plane mirrors
FLinePortalSpan* lineportal; // line-to-line portals
struct
{
int portaltype; // for the mesh builder. Real portals can only be assigned when being rendered.
int portalplane;
};
};


Expand All @@ -199,92 +211,92 @@ class HWWall
unsigned int vertcount;

public:
seg_t * seg; // this gives the easiest access to all other structs involved
subsector_t * sub; // For polyobjects
sector_t *frontsector, *backsector;
//private:
seg_t* seg; // this gives the easiest access to all other structs involved
subsector_t* sub; // For polyobjects
sector_t* frontsector, * backsector;
//private:

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

void Put3DWall(HWDrawInfo *di, lightlist_t * lightlist, bool translucent);
bool SplitWallComplex(HWDrawInfo *di, sector_t * frontsector, bool translucent, float& maplightbottomleft, float& maplightbottomright);
void SplitWall(HWDrawInfo *di, sector_t * frontsector, bool translucent);
void Put3DWall(HWWallDispatcher* di, lightlist_t* lightlist, bool translucent);
bool SplitWallComplex(HWWallDispatcher* di, sector_t* frontsector, bool translucent, float& maplightbottomleft, float& maplightbottomright);
void SplitWall(HWWallDispatcher* di, sector_t* frontsector, bool translucent);

void SetupLights(HWDrawInfo *di, FDynLightData &lightdata);
void SetupLights(HWDrawInfo* di, FDynLightData& lightdata);

void MakeVertices(HWDrawInfo *di, bool nosplit);
void MakeVertices(HWDrawInfo* di, bool nosplit);

void SkyPlane(HWDrawInfo *di, sector_t *sector, int plane, bool allowmirror);
void SkyLine(HWDrawInfo *di, sector_t *sec, line_t *line);
void SkyNormal(HWDrawInfo *di, sector_t * fs,vertex_t * v1,vertex_t * v2);
void SkyTop(HWDrawInfo *di, seg_t * seg,sector_t * fs,sector_t * bs,vertex_t * v1,vertex_t * v2);
void SkyBottom(HWDrawInfo *di, seg_t * seg,sector_t * fs,sector_t * bs,vertex_t * v1,vertex_t * v2);
void SkyPlane(HWWallDispatcher* di, sector_t* sector, int plane, bool allowmirror);
void SkyLine(HWWallDispatcher* di, sector_t* sec, line_t* line);
void SkyNormal(HWWallDispatcher* di, sector_t* fs, vertex_t* v1, vertex_t* v2);
void SkyTop(HWWallDispatcher* di, seg_t* seg, sector_t* fs, sector_t* bs, vertex_t* v1, vertex_t* v2);
void SkyBottom(HWWallDispatcher* di, seg_t* seg, sector_t* fs, sector_t* bs, vertex_t* v1, vertex_t* v2);

bool DoHorizon(HWDrawInfo *di, seg_t * seg,sector_t * fs, vertex_t * v1,vertex_t * v2);
bool DoHorizon(HWWallDispatcher* di, seg_t* seg, sector_t* fs, vertex_t* v1, vertex_t* v2);

bool SetWallCoordinates(seg_t * seg, FTexCoordInfo *tci, float ceilingrefheight,
bool SetWallCoordinates(seg_t* seg, FTexCoordInfo* tci, float ceilingrefheight,
float topleft, float topright, float bottomleft, float bottomright, float t_ofs);

void DoTexture(HWDrawInfo *di, int type,seg_t * seg,int peg,
float ceilingrefheight, float floorrefheight,
float CeilingHeightstart,float CeilingHeightend,
float FloorHeightstart,float FloorHeightend,
float v_offset);

void DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary,
sector_t * front, sector_t * back,
sector_t * realfront, sector_t * realback,
float fch1, float fch2, float ffh1, float ffh2,
float bch1, float bch2, float bfh1, float bfh2, float zalign);

void GetPlanePos(F3DFloor::planeref * planeref, float & left, float & right);

void BuildFFBlock(HWDrawInfo *di, seg_t * seg, F3DFloor * rover, int roverIndex,
float ff_topleft, float ff_topright,
float ff_bottomleft, float ff_bottomright);
void InverseFloors(HWDrawInfo *di, seg_t * seg, sector_t * frontsector,
float topleft, float topright,
float bottomleft, float bottomright);
void ClipFFloors(HWDrawInfo *di, seg_t * seg, F3DFloor * ffloor, int ffloorIndex, sector_t * frontsector,
float topleft, float topright,
float bottomleft, float bottomright);
void DoFFloorBlocks(HWDrawInfo *di, seg_t * seg, sector_t * frontsector, sector_t * backsector,
float fch1, float fch2, float ffh1, float ffh2,
float bch1, float bch2, float bfh1, float bfh2);

void ProcessDecal(HWDrawInfo *di, DBaseDecal *decal, const FVector3 &normal);
void ProcessDecals(HWDrawInfo *di);

int CreateVertices(FFlatVertex *&ptr, bool nosplit);
void SplitLeftEdge (FFlatVertex *&ptr);
void SplitRightEdge(FFlatVertex *&ptr);
void SplitUpperEdge(FFlatVertex *&ptr);
void SplitLowerEdge(FFlatVertex *&ptr);

void CountLeftEdge (unsigned &ptr);
void CountRightEdge(unsigned &ptr);
void DoTexture(HWWallDispatcher* di, int type, seg_t* seg, int peg,
float ceilingrefheight, float floorrefheight,
float CeilingHeightstart, float CeilingHeightend,
float FloorHeightstart, float FloorHeightend,
float v_offset);

void DoMidTexture(HWWallDispatcher* di, seg_t* seg, bool drawfogboundary,
sector_t* front, sector_t* back,
sector_t* realfront, sector_t* realback,
float fch1, float fch2, float ffh1, float ffh2,
float bch1, float bch2, float bfh1, float bfh2, float zalign);

void GetPlanePos(F3DFloor::planeref* planeref, float& left, float& right);

void BuildFFBlock(HWWallDispatcher* di, seg_t* seg, F3DFloor* rover, int roverIndex,
float ff_topleft, float ff_topright,
float ff_bottomleft, float ff_bottomright);
void InverseFloors(HWWallDispatcher* di, seg_t* seg, sector_t* frontsector,
float topleft, float topright,
float bottomleft, float bottomright);
void ClipFFloors(HWWallDispatcher* di, seg_t* seg, F3DFloor* ffloor, int ffloorIndex, sector_t* frontsector,
float topleft, float topright,
float bottomleft, float bottomright);
void DoFFloorBlocks(HWWallDispatcher* di, seg_t* seg, sector_t* frontsector, sector_t* backsector,
float fch1, float fch2, float ffh1, float ffh2,
float bch1, float bch2, float bfh1, float bfh2);

void ProcessDecal(HWDrawInfo* di, DBaseDecal* decal, const FVector3& normal);
void ProcessDecals(HWDrawInfo* di);

int CreateVertices(FFlatVertex*& ptr, bool nosplit);
void SplitLeftEdge(FFlatVertex*& ptr);
void SplitRightEdge(FFlatVertex*& ptr);
void SplitUpperEdge(FFlatVertex*& ptr);
void SplitLowerEdge(FFlatVertex*& ptr);

void CountLeftEdge(unsigned& ptr);
void CountRightEdge(unsigned& ptr);

int CountVertices();

void RenderWall(HWDrawInfo *di, FRenderState &state, int textured);
void RenderFogBoundary(HWDrawInfo *di, FRenderState &state);
void RenderMirrorSurface(HWDrawInfo *di, FRenderState &state);
void RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags);
void RenderTranslucentWall(HWDrawInfo *di, FRenderState &state);
void DrawDecalsForMirror(HWDrawInfo *di, FRenderState &state, TArray<HWDecal *> &decals);
void RenderWall(HWDrawInfo* di, FRenderState& state, int textured);
void RenderFogBoundary(HWDrawInfo* di, FRenderState& state);
void RenderMirrorSurface(HWDrawInfo* di, FRenderState& state);
void RenderTexturedWall(HWDrawInfo* di, FRenderState& state, int rflags);
void RenderTranslucentWall(HWDrawInfo* di, FRenderState& state);
void DrawDecalsForMirror(HWDrawInfo* di, FRenderState& state, TArray<HWDecal*>& decals);

public:
void Process(HWDrawInfo *di, seg_t *seg, sector_t *frontsector, sector_t *backsector);
void ProcessLowerMiniseg(HWDrawInfo *di, seg_t *seg, sector_t *frontsector, sector_t *backsector);
void Process(HWWallDispatcher* di, seg_t* seg, sector_t* frontsector, sector_t* backsector);
void ProcessLowerMiniseg(HWWallDispatcher* di, seg_t* seg, sector_t* frontsector, sector_t* backsector);

float PointOnSide(float x,float y)
float PointOnSide(float x, float y)
{
return -((y-glseg.y1)*(glseg.x2-glseg.x1)-(x-glseg.x1)*(glseg.y2-glseg.y1));
return -((y - glseg.y1) * (glseg.x2 - glseg.x1) - (x - glseg.x1) * (glseg.y2 - glseg.y1));
}

void DrawWall(HWDrawInfo *di, FRenderState &state, bool translucent);
void DrawWall(HWDrawInfo* di, FRenderState& state, bool translucent);

};

Expand Down
2 changes: 1 addition & 1 deletion src/rendering/hwrenderer/scene/hw_lighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ float HWDrawInfo::GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfog
//
//==========================================================================

bool HWDrawInfo::CheckFog(sector_t *frontsector, sector_t *backsector)
bool CheckFog(FLevelLocals* Level, sector_t *frontsector, sector_t *backsector, ELightMode lightmode)
{
if (frontsector == backsector) return false; // there can't be a boundary if both sides are in the same sector.

Expand Down
4 changes: 3 additions & 1 deletion src/rendering/hwrenderer/scene/hw_renderhacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "hw_lightbuffer.h"
#include "hwrenderer/scene/hw_portal.h"
#include "hw_fakeflat.h"
#include "hw_walldispatcher.h"

//==========================================================================
//
Expand Down Expand Up @@ -1117,7 +1118,8 @@ void HWDrawInfo::ProcessLowerMinisegs(TArray<seg_t *> &lowersegs)
{
seg_t * seg=lowersegs[j];
HWWall wall;
wall.ProcessLowerMiniseg(this, seg, seg->Subsector->render_sector, seg->PartnerSeg->Subsector->render_sector);
HWWallDispatcher disp(this);
wall.ProcessLowerMiniseg(&disp, seg, seg->Subsector->render_sector, seg->PartnerSeg->Subsector->render_sector);
rendered_lines++;
}
}
Expand Down
Loading

0 comments on commit 9cd57fa

Please sign in to comment.