- 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->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;
ws->MakeVertices(false);
w->MakeVertices(false);
ws->MakeVertices(gl_drawinfo, false);
w->MakeVertices(gl_drawinfo, false);
SortNode * sort2=SortNodes.GetNew();
memset(sort2,0,sizeof(SortNode));
@ -1317,3 +1317,9 @@ void FDrawInfo::AddSubsectorToPortal(FSectorPortalGroup *portal, subsector_t *su
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 AddMirrorSurface(GLWall *w) override;
void ProcessActorsInPortal(FLinePortalSpan *glport) override;
std::pair<FFlatVertex *, unsigned int> AllocVertices(unsigned int count) override;
// Legacy GL only.
bool PutWallCompat(GLWall *wall, int passflag);

View File

@ -23,6 +23,7 @@
#include "r_defs.h"
#include "hwrenderer/data/flatvertices.h"
#include "hwrenderer/scene/hw_drawinfo.h"
#include "gl/scene/gl_wall.h"
EXTERN_CVAR(Bool, gl_seamless)
@ -233,4 +234,24 @@ int GLWall::CountVertices()
}
}
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);
bool SetupLights(FDynLightData &lightdata);
void MakeVertices(bool nosplit);
void RenderWall(int textured);
void RenderTextured(int rflags);
void FloodPlane(int pass);
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);

View File

@ -50,7 +50,7 @@ void FDrawInfo::AddWall(GLWall *wall)
if (translucent) // translucent walls
{
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();
*newwall = *wall;
}
@ -73,7 +73,7 @@ void FDrawInfo::AddWall(GLWall *wall)
{
list = masked ? GLDL_MASKEDWALLS : GLDL_PLAINWALLS;
}
wall->MakeVertices(false);
wall->MakeVertices(this, false);
auto newwall = drawlists[list].NewWall();
*newwall = *wall;
}
@ -133,7 +133,7 @@ void GLWall::PutPortal(HWDrawInfo *di, int ptype)
{
GLPortal * portal;
MakeVertices(false);
MakeVertices(di, false);
switch (ptype)
{
// portals don't go into the draw list.

View File

@ -144,25 +144,6 @@ bool GLWall::SetupLights(FDynLightData &lightdata)
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

View File

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