diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index 73619e924..4daed793a 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -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 FDrawInfo::AllocVertices(unsigned int count) +{ + unsigned int index = -1; + auto p = GLRenderer->mVBO->Alloc(count, &index); + return std::make_pair(p, index); +} diff --git a/src/gl/scene/gl_drawinfo.h b/src/gl/scene/gl_drawinfo.h index 06bdbafcc..e08441374 100644 --- a/src/gl/scene/gl_drawinfo.h +++ b/src/gl/scene/gl_drawinfo.h @@ -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 AllocVertices(unsigned int count) override; // Legacy GL only. bool PutWallCompat(GLWall *wall, int passflag); diff --git a/src/gl/scene/gl_vertex.cpp b/src/gl/scene/gl_vertex.cpp index d0e59aa3e..ca476982b 100644 --- a/src/gl/scene/gl_vertex.cpp +++ b/src/gl/scene/gl_vertex.cpp @@ -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; -} \ No newline at end of file +} + +//========================================================================== +// +// 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); + } +} + diff --git a/src/gl/scene/gl_wall.h b/src/gl/scene/gl_wall.h index f94889615..f11d9588c 100644 --- a/src/gl/scene/gl_wall.h +++ b/src/gl/scene/gl_wall.h @@ -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); diff --git a/src/gl/scene/gl_walls.cpp b/src/gl/scene/gl_walls.cpp index 35351d454..b1dbc8271 100644 --- a/src/gl/scene/gl_walls.cpp +++ b/src/gl/scene/gl_walls.cpp @@ -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. diff --git a/src/gl/scene/gl_walls_draw.cpp b/src/gl/scene/gl_walls_draw.cpp index 9ace4fdcf..5517df36f 100644 --- a/src/gl/scene/gl_walls_draw.cpp +++ b/src/gl/scene/gl_walls_draw.cpp @@ -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 diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index 6d5476902..071bc5f31 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -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 AllocVertices(unsigned int count) = 0; };