- abstracted the vertex allocator.

This commit is contained in:
Christoph Oelckers 2018-04-26 20:07:56 +02:00
parent 9a1603b246
commit 937a2cf69f
7 changed files with 39 additions and 26 deletions

View file

@ -462,8 +462,8 @@ void GLDrawList::SortWallIntoWall(SortNode * head,SortNode * sort)
w->ztop[0]=ws->ztop[1]=izt; w->ztop[0]=ws->ztop[1]=izt;
w->zbottom[0]=ws->zbottom[1]=izb; w->zbottom[0]=ws->zbottom[1]=izb;
w->tcs[GLWall::LOLFT].u = w->tcs[GLWall::UPLFT].u = ws->tcs[GLWall::LORGT].u = ws->tcs[GLWall::UPRGT].u = iu; w->tcs[GLWall::LOLFT].u = w->tcs[GLWall::UPLFT].u = ws->tcs[GLWall::LORGT].u = ws->tcs[GLWall::UPRGT].u = iu;
ws->MakeVertices(false); ws->MakeVertices(gl_drawinfo, false);
w->MakeVertices(false); w->MakeVertices(gl_drawinfo, false);
SortNode * sort2=SortNodes.GetNew(); SortNode * sort2=SortNodes.GetNew();
memset(sort2,0,sizeof(SortNode)); memset(sort2,0,sizeof(SortNode));
@ -1317,3 +1317,9 @@ void FDrawInfo::AddSubsectorToPortal(FSectorPortalGroup *portal, subsector_t *su
portal->GetRenderState()->AddSubsector(sub); portal->GetRenderState()->AddSubsector(sub);
} }
std::pair<FFlatVertex *, unsigned int> FDrawInfo::AllocVertices(unsigned int count)
{
unsigned int index = -1;
auto p = GLRenderer->mVBO->Alloc(count, &index);
return std::make_pair(p, index);
}

View file

@ -180,6 +180,7 @@ struct FDrawInfo : public HWDrawInfo
void AddWall(GLWall *wall) override; void AddWall(GLWall *wall) override;
void AddMirrorSurface(GLWall *w) override; void AddMirrorSurface(GLWall *w) override;
void ProcessActorsInPortal(FLinePortalSpan *glport) override; void ProcessActorsInPortal(FLinePortalSpan *glport) override;
std::pair<FFlatVertex *, unsigned int> AllocVertices(unsigned int count) override;
// Legacy GL only. // Legacy GL only.
bool PutWallCompat(GLWall *wall, int passflag); bool PutWallCompat(GLWall *wall, int passflag);

View file

@ -23,6 +23,7 @@
#include "r_defs.h" #include "r_defs.h"
#include "hwrenderer/data/flatvertices.h" #include "hwrenderer/data/flatvertices.h"
#include "hwrenderer/scene/hw_drawinfo.h"
#include "gl/scene/gl_wall.h" #include "gl/scene/gl_wall.h"
EXTERN_CVAR(Bool, gl_seamless) EXTERN_CVAR(Bool, gl_seamless)
@ -234,3 +235,23 @@ int GLWall::CountVertices()
} }
return cnt; return cnt;
} }
//==========================================================================
//
// build the vertices for this wall
//
//==========================================================================
void GLWall::MakeVertices(HWDrawInfo *di, bool nosplit)
{
if (vertcount == 0)
{
bool split = (gl_seamless && !nosplit && seg->sidedef != nullptr && !(seg->sidedef->Flags & WALLF_POLYOBJ) && !(flags & GLWF_NOSPLIT));
vertcount = split ? CountVertices() : 4;
auto ret = di->AllocVertices(vertcount);
vertindex = ret.second;
CreateVertices(ret.first, split);
}
}

View file

@ -211,12 +211,13 @@ private:
void SplitWall(HWDrawInfo *di, sector_t * frontsector, bool translucent); void SplitWall(HWDrawInfo *di, sector_t * frontsector, bool translucent);
bool SetupLights(FDynLightData &lightdata); bool SetupLights(FDynLightData &lightdata);
void MakeVertices(bool nosplit);
void RenderWall(int textured); void RenderWall(int textured);
void RenderTextured(int rflags); void RenderTextured(int rflags);
void FloodPlane(int pass); void FloodPlane(int pass);
void MakeVertices(HWDrawInfo *di, bool nosplit);
void SkyPlane(HWDrawInfo *di, sector_t *sector, int plane, bool allowmirror); void SkyPlane(HWDrawInfo *di, sector_t *sector, int plane, bool allowmirror);
void SkyLine(HWDrawInfo *di, sector_t *sec, line_t *line); void SkyLine(HWDrawInfo *di, sector_t *sec, line_t *line);
void SkyNormal(HWDrawInfo *di, sector_t * fs,vertex_t * v1,vertex_t * v2); void SkyNormal(HWDrawInfo *di, sector_t * fs,vertex_t * v1,vertex_t * v2);

View file

@ -50,7 +50,7 @@ void FDrawInfo::AddWall(GLWall *wall)
if (translucent) // translucent walls if (translucent) // translucent walls
{ {
wall->ViewDistance = (r_viewpoint.Pos - (wall->seg->linedef->v1->fPos() + wall->seg->linedef->Delta() / 2)).XY().LengthSquared(); wall->ViewDistance = (r_viewpoint.Pos - (wall->seg->linedef->v1->fPos() + wall->seg->linedef->Delta() / 2)).XY().LengthSquared();
wall->MakeVertices(true); wall->MakeVertices(this, true);
auto newwall = drawlists[GLDL_TRANSLUCENT].NewWall(); auto newwall = drawlists[GLDL_TRANSLUCENT].NewWall();
*newwall = *wall; *newwall = *wall;
} }
@ -73,7 +73,7 @@ void FDrawInfo::AddWall(GLWall *wall)
{ {
list = masked ? GLDL_MASKEDWALLS : GLDL_PLAINWALLS; list = masked ? GLDL_MASKEDWALLS : GLDL_PLAINWALLS;
} }
wall->MakeVertices(false); wall->MakeVertices(this, false);
auto newwall = drawlists[list].NewWall(); auto newwall = drawlists[list].NewWall();
*newwall = *wall; *newwall = *wall;
} }
@ -133,7 +133,7 @@ void GLWall::PutPortal(HWDrawInfo *di, int ptype)
{ {
GLPortal * portal; GLPortal * portal;
MakeVertices(false); MakeVertices(di, false);
switch (ptype) switch (ptype)
{ {
// portals don't go into the draw list. // portals don't go into the draw list.

View file

@ -144,25 +144,6 @@ bool GLWall::SetupLights(FDynLightData &lightdata)
return true; return true;
} }
//==========================================================================
//
// build the vertices for this wall
//
//==========================================================================
void GLWall::MakeVertices(bool nosplit)
{
if (vertcount == 0)
{
bool split = (gl_seamless && !nosplit && seg->sidedef != nullptr && !(seg->sidedef->Flags & WALLF_POLYOBJ) && !(flags & GLWF_NOSPLIT));
vertcount = split ? CountVertices() : 4;
FFlatVertex *ptr = GLRenderer->mVBO->Alloc(vertcount, &vertindex);
CreateVertices(ptr, split);
}
}
//========================================================================== //==========================================================================
// //
// General purpose wall rendering function // General purpose wall rendering function

View file

@ -3,6 +3,8 @@
#include "r_defs.h" #include "r_defs.h"
struct FSectorPortalGroup; struct FSectorPortalGroup;
struct FLinePortalSpan;
struct FFlatVertex;
class GLWall; class GLWall;
//========================================================================== //==========================================================================
@ -125,6 +127,7 @@ public:
virtual void AddWall(GLWall *w) = 0; virtual void AddWall(GLWall *w) = 0;
virtual void AddMirrorSurface(GLWall *w) = 0; virtual void AddMirrorSurface(GLWall *w) = 0;
virtual void ProcessActorsInPortal(FLinePortalSpan *glport) = 0; virtual void ProcessActorsInPortal(FLinePortalSpan *glport) = 0;
virtual std::pair<FFlatVertex *, unsigned int> AllocVertices(unsigned int count) = 0;
}; };