From 2514753afb3826705744277c4ecc15749e2d5ba8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 22 May 2018 18:48:10 +0200 Subject: [PATCH] - make the vertex buffer accessible from the hwrenderer code. --- src/gl/data/gl_vertexbuffer.cpp | 5 +++-- src/gl/data/gl_vertexbuffer.h | 10 ---------- src/gl/scene/gl_bsp.cpp | 3 ++- src/gl/scene/gl_drawinfo.cpp | 1 + src/gl/scene/gl_portal.cpp | 6 +++--- src/gl/scene/gl_scene.cpp | 1 + src/hwrenderer/data/flatvertices.cpp | 18 +++++++++--------- src/hwrenderer/data/flatvertices.h | 11 +++++------ src/hwrenderer/scene/hw_drawinfo.h | 4 ++++ src/hwrenderer/scene/hw_portal.h | 2 +- 10 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/gl/data/gl_vertexbuffer.cpp b/src/gl/data/gl_vertexbuffer.cpp index ce32b3ab4..335c7740c 100644 --- a/src/gl/data/gl_vertexbuffer.cpp +++ b/src/gl/data/gl_vertexbuffer.cpp @@ -157,6 +157,7 @@ FFlatVertexBuffer::FFlatVertexBuffer(int width, int height) mIndex = mCurIndex = 0; mNumReserved = NUM_RESERVED; + mMap = map; Map(); memcpy(map, &vbo_shadowdata[0], mNumReserved * sizeof(FFlatVertex)); Unmap(); @@ -215,7 +216,7 @@ void FFlatVertexBuffer::Map() unsigned int bytesize = BUFFER_SIZE * sizeof(FFlatVertex); glBindBuffer(GL_ARRAY_BUFFER, vbo_id); gl_RenderState.ResetVertexBuffer(); - map = (FFlatVertex*)glMapBufferRange(GL_ARRAY_BUFFER, 0, bytesize, GL_MAP_WRITE_BIT|GL_MAP_UNSYNCHRONIZED_BIT); + mMap = map = (FFlatVertex*)glMapBufferRange(GL_ARRAY_BUFFER, 0, bytesize, GL_MAP_WRITE_BIT|GL_MAP_UNSYNCHRONIZED_BIT); } } @@ -227,7 +228,7 @@ void FFlatVertexBuffer::Unmap() glBindBuffer(GL_ARRAY_BUFFER, vbo_id); gl_RenderState.ResetVertexBuffer(); glUnmapBuffer(GL_ARRAY_BUFFER); - map = nullptr; + mMap = map = nullptr; } } diff --git a/src/gl/data/gl_vertexbuffer.h b/src/gl/data/gl_vertexbuffer.h index 28fe8f45c..de741b251 100644 --- a/src/gl/data/gl_vertexbuffer.h +++ b/src/gl/data/gl_vertexbuffer.h @@ -177,16 +177,6 @@ public: #endif - void CheckPlanes(sector_t *sector) - { - FFlatVertexGenerator::CheckPlanes(sector, map); - } - - void CheckUpdate(sector_t *sector) - { - FFlatVertexGenerator::CheckUpdate(sector, map); - } - void Reset() { mCurIndex = mIndex; diff --git a/src/gl/scene/gl_bsp.cpp b/src/gl/scene/gl_bsp.cpp index b5bc58e46..d01706b6d 100644 --- a/src/gl/scene/gl_bsp.cpp +++ b/src/gl/scene/gl_bsp.cpp @@ -37,6 +37,7 @@ #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_portal.h" #include "hwrenderer/utility/hw_clock.h" +#include "hwrenderer/data/flatvertices.h" EXTERN_CVAR(Bool, gl_render_segs) @@ -452,7 +453,7 @@ void HWDrawInfo::DoSubsector(subsector_t * sub) if (sector->validcount != validcount) { - GLRenderer->mVBO->CheckUpdate(sector); + mVBO->CheckUpdate(sector); } // [RH] Add particles diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index b67f23fb4..abcdbe70b 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -199,6 +199,7 @@ FDrawInfo *FDrawInfo::StartDrawInfo(GLSceneDrawer *drawer) { FDrawInfo *di=di_list.GetNew(); di->mDrawer = drawer; + di->mVBO = GLRenderer->mVBO; di->mClipper = &staticClipper; staticClipper.Clear(); di->FixedColormap = drawer->FixedColormap; diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index 6a0d86132..ce96aa658 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -425,11 +425,11 @@ void GLPortal::End(bool usestencil) //----------------------------------------------------------------------------- void GLPortal::StartFrame() { - GLPortal * p=NULL; + GLPortal * p = nullptr; portals.Push(p); - if (renderdepth==0) + if (renderdepth == 0) { - inskybox=false; + inskybox = false; screen->instack[sector_t::floor] = screen->instack[sector_t::ceiling] = 0; } renderdepth++; diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 422bb58a6..d3a1a2e22 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -557,6 +557,7 @@ void GLSceneDrawer::ProcessScene(FDrawInfo *di, bool toscreen) int mapsection = R_PointInSubsector(r_viewpoint.Pos)->mapsection; di->CurrentMapSections.Set(mapsection); + GLRenderer->mCurrentPortal = nullptr; DrawScene(di, toscreen ? DM_MAINVIEW : DM_OFFSCREEN); } diff --git a/src/hwrenderer/data/flatvertices.cpp b/src/hwrenderer/data/flatvertices.cpp index 86bf78261..f069a7989 100644 --- a/src/hwrenderer/data/flatvertices.cpp +++ b/src/hwrenderer/data/flatvertices.cpp @@ -233,13 +233,13 @@ void FFlatVertexGenerator::CreateFlatVertices() // //========================================================================== -void FFlatVertexGenerator::UpdatePlaneVertices(sector_t *sec, int plane, FFlatVertex *map) +void FFlatVertexGenerator::UpdatePlaneVertices(sector_t *sec, int plane) { int startvt = sec->vboindex[plane]; int countvt = sec->vbocount[plane]; secplane_t &splane = sec->GetSecPlane(plane); FFlatVertex *vt = &vbo_shadowdata[startvt]; - FFlatVertex *mapvt = &map[startvt]; + FFlatVertex *mapvt = &mMap[startvt]; for(int i=0; iz = (float)splane.ZatPoint(vt->x, vt->y); @@ -266,16 +266,16 @@ void FFlatVertexGenerator::CreateVertices() // //========================================================================== -void FFlatVertexGenerator::CheckPlanes(sector_t *sector, FFlatVertex *map) +void FFlatVertexGenerator::CheckPlanes(sector_t *sector) { if (sector->GetPlaneTexZ(sector_t::ceiling) != sector->vboheight[sector_t::ceiling]) { - UpdatePlaneVertices(sector, sector_t::ceiling, map); + UpdatePlaneVertices(sector, sector_t::ceiling); sector->vboheight[sector_t::ceiling] = sector->GetPlaneTexZ(sector_t::ceiling); } if (sector->GetPlaneTexZ(sector_t::floor) != sector->vboheight[sector_t::floor]) { - UpdatePlaneVertices(sector, sector_t::floor, map); + UpdatePlaneVertices(sector, sector_t::floor); sector->vboheight[sector_t::floor] = sector->GetPlaneTexZ(sector_t::floor); } } @@ -287,11 +287,11 @@ void FFlatVertexGenerator::CheckPlanes(sector_t *sector, FFlatVertex *map) // //========================================================================== -void FFlatVertexGenerator::CheckUpdate(sector_t *sector, FFlatVertex *map) +void FFlatVertexGenerator::CheckUpdate(sector_t *sector) { - CheckPlanes(sector, map); + CheckPlanes(sector); sector_t *hs = sector->GetHeightSec(); - if (hs != NULL) CheckPlanes(hs, map); + if (hs != NULL) CheckPlanes(hs); for (unsigned i = 0; i < sector->e->XFloor.ffloors.Size(); i++) - CheckPlanes(sector->e->XFloor.ffloors[i]->model, map); + CheckPlanes(sector->e->XFloor.ffloors[i]->model); } diff --git a/src/hwrenderer/data/flatvertices.h b/src/hwrenderer/data/flatvertices.h index 9a45558b5..ee390218f 100644 --- a/src/hwrenderer/data/flatvertices.h +++ b/src/hwrenderer/data/flatvertices.h @@ -45,10 +45,9 @@ class FFlatVertexGenerator { protected: TArray vbo_shadowdata; + FFlatVertex *mMap; - void CheckPlanes(sector_t *sector); - public: enum { @@ -70,12 +69,12 @@ private: int CreateSectorVertices(sector_t *sec, const secplane_t &plane, int floor); int CreateVertices(int h, sector_t *sec, const secplane_t &plane, int floor); void CreateFlatVertices(); - void UpdatePlaneVertices(sector_t *sec, int plane, FFlatVertex *map); + void UpdatePlaneVertices(sector_t *sec, int plane); protected: void CreateVertices(); - void CheckPlanes(sector_t *sector, FFlatVertex *map); - void CheckUpdate(sector_t *sector, FFlatVertex *map); - + void CheckPlanes(sector_t *sector); +public: + void CheckUpdate(sector_t *sector); }; #endif \ No newline at end of file diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index ad34a4c52..e9db60a09 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -3,6 +3,7 @@ #include #include "r_defs.h" + struct FSectorPortalGroup; struct FLinePortalSpan; struct FFlatVertex; @@ -16,6 +17,7 @@ struct FDynLightData; struct HUDSprite; class Clipper; class IPortal; +class FFlatVertexGenerator; //========================================================================== // @@ -107,9 +109,11 @@ struct HWDrawInfo TArray ss_renderflags; TArray no_renderflags; + // This is needed by the BSP traverser. BitArray CurrentMapSections; // this cannot be a single number, because a group of portals with the same displacement may link different sections. area_t in_area; fixed_t viewx, viewy; // since the nodes are still fixed point, keeping the view position also fixed point for node traversal is faster. + FFlatVertexGenerator *mVBO; // this class needs access because the sector vertex updating is part of BSP traversal. private: diff --git a/src/hwrenderer/scene/hw_portal.h b/src/hwrenderer/scene/hw_portal.h index 2347be86d..695daaa98 100644 --- a/src/hwrenderer/scene/hw_portal.h +++ b/src/hwrenderer/scene/hw_portal.h @@ -36,7 +36,7 @@ struct GLHorizonInfo class IPortal { public: - virtual ~IPortal(); + virtual ~IPortal() {} virtual int ClipSeg(seg_t *seg) { return PClip_Inside; } virtual int ClipSubsector(subsector_t *sub) { return PClip_Inside; } virtual int ClipPoint(const DVector2 &pos) { return PClip_Inside; }