From 54de0bf59fe8eb23aba23e39bd3060262b7bd294 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 28 Oct 2018 14:25:29 +0100 Subject: [PATCH] - changed a bit more stuff that doesn't need to be routed through the OpenGL interface anymore. --- src/gl/renderer/gl_renderer.cpp | 5 --- src/gl/renderer/gl_renderer.h | 1 - src/gl/scene/gl_drawinfo.cpp | 46 ---------------------- src/gl/scene/gl_drawinfo.h | 5 --- src/gl/scene/gl_scene.cpp | 3 +- src/gl/system/gl_framebuffer.cpp | 9 ----- src/gl/system/gl_framebuffer.h | 1 - src/hwrenderer/data/flatvertices.cpp | 19 +++++++++ src/hwrenderer/data/flatvertices.h | 19 +-------- src/hwrenderer/data/hw_viewpointbuffer.cpp | 2 +- src/hwrenderer/scene/hw_decal.cpp | 2 +- src/hwrenderer/scene/hw_drawinfo.h | 4 -- src/hwrenderer/scene/hw_drawlist.cpp | 25 ++++++++++++ src/hwrenderer/scene/hw_drawlist.h | 1 + src/hwrenderer/scene/hw_flats.cpp | 2 +- src/hwrenderer/scene/hw_portal.cpp | 2 +- src/hwrenderer/scene/hw_renderhacks.cpp | 6 +-- src/hwrenderer/scene/hw_sprites.cpp | 7 +++- src/hwrenderer/scene/hw_walls_vertex.cpp | 2 +- src/hwrenderer/scene/hw_weapon.cpp | 9 ++++- src/p_setup.cpp | 3 +- src/v_video.h | 1 - 22 files changed, 70 insertions(+), 104 deletions(-) diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index f69caffc0..3ca99d104 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -150,11 +150,6 @@ void FGLRenderer::ResetSWScene() swdrawer = nullptr; } -void FGLRenderer::SetupLevel() -{ - screen->mVertexData->CreateVBO(); -} - //=========================================================================== // // diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index bb427f1c5..760b9fb1e 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -81,7 +81,6 @@ public: void ClearBorders(); - void SetupLevel(); void ResetSWScene(); void PresentStereo(); diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index b80b74e9e..d6cb7f267 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -59,31 +59,6 @@ public: static FDrawInfo * gl_drawinfo; FDrawInfoList di_list; -//========================================================================== -// -// -// -//========================================================================== -void FDrawInfo::DrawSorted(int listindex) -{ - HWDrawList *dl = &drawlists[listindex]; - if (dl->drawitems.Size()==0) return; - - if (!dl->sorted) - { - screen->mVertexData->Map(); - dl->Sort(this); - screen->mVertexData->Unmap(); - } - gl_RenderState.ClearClipSplit(); - EnableClipDistance(1, true); - EnableClipDistance(2, true); - dl->DrawSorted(this, gl_RenderState, dl->sorted); - EnableClipDistance(1, false); - EnableClipDistance(2, false); - gl_RenderState.ClearClipSplit(); -} - //========================================================================== // // Try to reuse the lists as often as possible as they contain resources that @@ -183,13 +158,6 @@ void FDrawInfo::AddSubsectorToPortal(FSectorPortalGroup *ptg, subsector_t *sub) ptl->AddSubsector(sub); } -std::pair FDrawInfo::AllocVertices(unsigned int count) -{ - unsigned int index = -1; - auto p = screen->mVertexData->Alloc(count, &index); - return std::make_pair(p, index); -} - int FDrawInfo::UploadLights(FDynLightData &data) { return GLRenderer->mLights->UploadLights(data); @@ -232,20 +200,6 @@ void FDrawInfo::DrawIndexed(EDrawType dt, FRenderState &state, int index, int co drawcalls.Unclock(); } -void FDrawInfo::DrawModel(GLSprite *spr, FRenderState &state) -{ - FGLModelRenderer renderer(this, state, spr->dynlightindex); - renderer.RenderModel(spr->x, spr->y, spr->z, spr->modelframe, spr->actor, Viewpoint.TicFrac); - screen->mVertexData->Bind(state); -} - -void FDrawInfo::DrawHUDModel(HUDSprite *huds, FRenderState &state) -{ - FGLModelRenderer renderer(this, state, huds->lightindex); - renderer.RenderHUDModel(huds->weapon, huds->mx, huds->my); - screen->mVertexData->Bind(state); -} - void FDrawInfo::RenderPortal(HWPortal *p, bool usestencil) { auto gp = static_cast(p); diff --git a/src/gl/scene/gl_drawinfo.h b/src/gl/scene/gl_drawinfo.h index a1a1a110c..399512d47 100644 --- a/src/gl/scene/gl_drawinfo.h +++ b/src/gl/scene/gl_drawinfo.h @@ -39,13 +39,10 @@ struct FDrawInfo : public HWDrawInfo void AddFlat(GLFlat *flat, bool fog) override; void AddSprite(GLSprite *sprite, bool translucent) override; - std::pair AllocVertices(unsigned int count) override; int UploadLights(FDynLightData &data) override; void Draw(EDrawType dt, FRenderState &state, int index, int count, bool apply = true) override; void DrawIndexed(EDrawType dt, FRenderState &state, int index, int count, bool apply = true) override; - void DrawModel(GLSprite *spr, FRenderState &state) override; - void DrawHUDModel(HUDSprite *spr, FRenderState &state) override; void RenderPortal(HWPortal *p, bool stencil) override; void SetDepthMask(bool on) override; @@ -58,8 +55,6 @@ struct FDrawInfo : public HWDrawInfo void StartScene(); - void DrawSorted(int listindex); - void AddSubsectorToPortal(FSectorPortalGroup *portal, subsector_t *sub) override; void CreateScene(); diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index b084e838a..44c63fe2d 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -217,7 +217,8 @@ void FDrawInfo::RenderTranslucent() gl_RenderState.EnableBrightmap(true); drawlists[GLDL_TRANSLUCENTBORDER].Draw(this, gl_RenderState, true); glDepthMask(false); - DrawSorted(GLDL_TRANSLUCENT); + + drawlists[GLDL_TRANSLUCENT].DrawSorted(this, gl_RenderState); gl_RenderState.EnableBrightmap(false); diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index f27dcc4b3..fdcf12b90 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -391,15 +391,6 @@ void OpenGLFrameBuffer::SetViewportRects(IntRect *bounds) } } - -void OpenGLFrameBuffer::InitForLevel() -{ - if (GLRenderer != NULL) - { - GLRenderer->SetupLevel(); - } -} - void OpenGLFrameBuffer::UpdatePalette() { if (GLRenderer) diff --git a/src/gl/system/gl_framebuffer.h b/src/gl/system/gl_framebuffer.h index 9f14bbb5d..167841129 100644 --- a/src/gl/system/gl_framebuffer.h +++ b/src/gl/system/gl_framebuffer.h @@ -27,7 +27,6 @@ public: void CleanForRestart() override; void UpdatePalette() override; - void InitForLevel() override; void SetClearColor(int color) override; uint32_t GetCaps() override; void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV) override; diff --git a/src/hwrenderer/data/flatvertices.cpp b/src/hwrenderer/data/flatvertices.cpp index 047d6fde0..85fd380d2 100644 --- a/src/hwrenderer/data/flatvertices.cpp +++ b/src/hwrenderer/data/flatvertices.cpp @@ -379,6 +379,25 @@ void FFlatVertexBuffer::CheckUpdate(sector_t *sector) // //========================================================================== +std::pair FFlatVertexBuffer::AllocVertices(unsigned int count) +{ + FFlatVertex *p = GetBuffer(); + auto index = mCurIndex.fetch_add(count); + auto offset = index; + if (index + count >= BUFFER_SIZE_TO_USE) + { + // If a single scene needs 2'000'000 vertices there must be something very wrong. + I_FatalError("Out of vertex memory. Tried to allocate more than %u vertices for a single frame", index + count); + } + return std::make_pair(p, index); +} + +//========================================================================== +// +// +// +//========================================================================== + void FFlatVertexBuffer::Copy(int start, int count) { Map(); diff --git a/src/hwrenderer/data/flatvertices.h b/src/hwrenderer/data/flatvertices.h index b9a1ac157..e86969e07 100644 --- a/src/hwrenderer/data/flatvertices.h +++ b/src/hwrenderer/data/flatvertices.h @@ -56,7 +56,6 @@ class FFlatVertexBuffer unsigned int mIndex; std::atomic mCurIndex; - std::mutex mBufferMutex; unsigned int mNumReserved; @@ -119,23 +118,7 @@ public: return GetBuffer(mCurIndex); } - template - FFlatVertex *Alloc(int num, T *poffset) - { - again: - FFlatVertex *p = GetBuffer(); - auto index = mCurIndex.fetch_add(num); - *poffset = static_cast(index); - if (index + num >= BUFFER_SIZE_TO_USE) - { - std::lock_guard lock(mBufferMutex); - if (mCurIndex >= BUFFER_SIZE_TO_USE) // retest condition, in case another thread got here first - mCurIndex = mIndex; - - if (index >= BUFFER_SIZE_TO_USE) goto again; - } - return p; - } + std::pair AllocVertices(unsigned int count); void Reset() { diff --git a/src/hwrenderer/data/hw_viewpointbuffer.cpp b/src/hwrenderer/data/hw_viewpointbuffer.cpp index 2ab426d23..fca488d44 100644 --- a/src/hwrenderer/data/hw_viewpointbuffer.cpp +++ b/src/hwrenderer/data/hw_viewpointbuffer.cpp @@ -77,7 +77,7 @@ void GLViewpointBuffer::Set2D(HWDrawInfo *di, int width, int height) { HWViewpointUniforms matrices; matrices.SetDefaults(); - matrices.mProjectionMatrix.ortho(0, width, height, 0, -1.0f, 1.0f); + matrices.mProjectionMatrix.ortho(0, (float)width, (float)height, 0, -1.0f, 1.0f); matrices.CalcDependencies(); mBuffer->Map(); memcpy(mBuffer->Memory(), &matrices, sizeof(matrices)); diff --git a/src/hwrenderer/scene/hw_decal.cpp b/src/hwrenderer/scene/hw_decal.cpp index 2c6907b33..c4e19b9a4 100644 --- a/src/hwrenderer/scene/hw_decal.cpp +++ b/src/hwrenderer/scene/hw_decal.cpp @@ -409,7 +409,7 @@ void GLWall::ProcessDecal(HWDrawInfo *di, DBaseDecal *decal, const FVector3 &nor gldecal->lightlist = lightlist; memcpy(gldecal->dv, dv, sizeof(dv)); - auto verts = di->AllocVertices(4); + auto verts = screen->mVertexData->AllocVertices(4); gldecal->vertindex = verts.second; for (i = 0; i < 4; i++) diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index 3b8e5356d..e70761c99 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -343,13 +343,9 @@ public: GLDecal *AddDecal(bool onmirror); - virtual std::pair AllocVertices(unsigned int count) = 0; - virtual void ClearScreen() = 0; virtual void Draw(EDrawType dt, FRenderState &state, int index, int count, bool apply = true) = 0; virtual void DrawIndexed(EDrawType dt, FRenderState &state, int index, int count, bool apply = true) = 0; - virtual void DrawModel(GLSprite *spr, FRenderState &state) = 0; - virtual void DrawHUDModel(HUDSprite *spr, FRenderState &state) = 0; virtual void RenderPortal(HWPortal *p, bool usestencil) = 0; virtual void DrawScene(int drawmode) = 0; diff --git a/src/hwrenderer/scene/hw_drawlist.cpp b/src/hwrenderer/scene/hw_drawlist.cpp index c35eed81f..2224d7740 100644 --- a/src/hwrenderer/scene/hw_drawlist.cpp +++ b/src/hwrenderer/scene/hw_drawlist.cpp @@ -32,6 +32,7 @@ #include "g_levellocals.h" #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_drawlist.h" +#include "hwrenderer/data/flatvertices.h" #include "hwrenderer/utility/hw_clock.h" #include "hw_renderstate.h" @@ -908,3 +909,27 @@ void HWDrawList::DrawSorted(HWDrawInfo *di, FRenderState &state, SortNode * head } } +//========================================================================== +// +// +// +//========================================================================== +void HWDrawList::DrawSorted(HWDrawInfo *di, FRenderState &state) +{ + if (drawitems.Size() == 0) return; + + if (!sorted) + { + screen->mVertexData->Map(); + Sort(di); + screen->mVertexData->Unmap(); + } + state.ClearClipSplit(); + di->EnableClipDistance(1, true); + di->EnableClipDistance(2, true); + DrawSorted(di, state, sorted); + di->EnableClipDistance(1, false); + di->EnableClipDistance(2, false); + state.ClearClipSplit(); +} + diff --git a/src/hwrenderer/scene/hw_drawlist.h b/src/hwrenderer/scene/hw_drawlist.h index a51bf6f10..8975b1a14 100644 --- a/src/hwrenderer/scene/hw_drawlist.h +++ b/src/hwrenderer/scene/hw_drawlist.h @@ -109,6 +109,7 @@ public: void DrawFlats(HWDrawInfo *di, FRenderState &state, bool translucent); void DrawSorted(HWDrawInfo *di, FRenderState &state, SortNode * head); + void DrawSorted(HWDrawInfo *di, FRenderState &state); HWDrawList * next; } ; diff --git a/src/hwrenderer/scene/hw_flats.cpp b/src/hwrenderer/scene/hw_flats.cpp index 1bff9142f..1d0a817bf 100644 --- a/src/hwrenderer/scene/hw_flats.cpp +++ b/src/hwrenderer/scene/hw_flats.cpp @@ -395,7 +395,7 @@ void GLFlat::Process(HWDrawInfo *di, sector_t * model, int whichplane, bool fog) z = plane.plane.ZatPoint(0.f, 0.f); if (sector->special == GLSector_Skybox) { - auto vert = di->AllocVertices(4); + auto vert = screen->mVertexData->AllocVertices(4); CreateSkyboxVertices(vert.first); iboindex = vert.second; } diff --git a/src/hwrenderer/scene/hw_portal.cpp b/src/hwrenderer/scene/hw_portal.cpp index aed2942bf..183e8ac85 100644 --- a/src/hwrenderer/scene/hw_portal.cpp +++ b/src/hwrenderer/scene/hw_portal.cpp @@ -811,7 +811,7 @@ HWHorizonPortal::HWHorizonPortal(FPortalSceneState *s, GLHorizonInfo * pt, FRend // Draw to some far away boundary // This is not drawn as larger strips because it causes visual glitches. - auto verts = di->AllocVertices(1024 + 10); + auto verts = screen->mVertexData->AllocVertices(1024 + 10); auto ptr = verts.first; for (int xx = -32768; xx < 32768; xx += 4096) { diff --git a/src/hwrenderer/scene/hw_renderhacks.cpp b/src/hwrenderer/scene/hw_renderhacks.cpp index d9de834af..7ab286352 100644 --- a/src/hwrenderer/scene/hw_renderhacks.cpp +++ b/src/hwrenderer/scene/hw_renderhacks.cpp @@ -84,7 +84,7 @@ int HWDrawInfo::SetupLightsForOtherPlane(subsector_t * sub, FDynLightData &light int HWDrawInfo::CreateOtherPlaneVertices(subsector_t *sub, const secplane_t *plane) { - auto alloc = AllocVertices(sub->numlines); + auto alloc = screen->mVertexData->AllocVertices(sub->numlines); auto ptr = alloc.first; for (unsigned int k = 0; k < sub->numlines; k++) { @@ -722,7 +722,7 @@ void HWDrawInfo::PrepareUpperGap(seg_t * seg) ws.z1 = frontz; ws.z2 = backz; - auto vertices = AllocVertices(8); + auto vertices = screen->mVertexData->AllocVertices(8); CreateFloodStencilPoly(&ws, vertices.first); CreateFloodPoly(&ws, vertices.first+4, ws.z2, fakebsector, true); @@ -786,7 +786,7 @@ void HWDrawInfo::PrepareLowerGap(seg_t * seg) ws.z2 = frontz; ws.z1 = backz; - auto vertices = AllocVertices(8); + auto vertices = screen->mVertexData->AllocVertices(8); CreateFloodStencilPoly(&ws, vertices.first); CreateFloodPoly(&ws, vertices.first+4, ws.z1, fakebsector, false); diff --git a/src/hwrenderer/scene/hw_sprites.cpp b/src/hwrenderer/scene/hw_sprites.cpp index cfeb9da5f..06ef08925 100644 --- a/src/hwrenderer/scene/hw_sprites.cpp +++ b/src/hwrenderer/scene/hw_sprites.cpp @@ -42,6 +42,7 @@ #include "r_data/models/models.h" #include "vectors.h" +#include "hwrenderer/models/hw_models.h" #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_fakeflat.h" @@ -267,7 +268,9 @@ void GLSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent) } else { - di->DrawModel(this, state); + FGLModelRenderer renderer(di, state, dynlightindex); + renderer.RenderModel(x, y, z, modelframe, actor, di->Viewpoint.TicFrac); + screen->mVertexData->Bind(state); } } @@ -482,7 +485,7 @@ void GLSprite::CreateVertices(HWDrawInfo *di) { FVector3 v[4]; polyoffset = CalculateVertices(di, v, &di->Viewpoint.Pos); - auto vert = di->AllocVertices(4); + auto vert = screen->mVertexData->AllocVertices(4); auto vp = vert.first; vertexindex = vert.second; diff --git a/src/hwrenderer/scene/hw_walls_vertex.cpp b/src/hwrenderer/scene/hw_walls_vertex.cpp index b0042baff..70ba96369 100644 --- a/src/hwrenderer/scene/hw_walls_vertex.cpp +++ b/src/hwrenderer/scene/hw_walls_vertex.cpp @@ -267,7 +267,7 @@ 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)); - auto ret = di->AllocVertices(split ? CountVertices() : 4); + auto ret = screen->mVertexData->AllocVertices(split ? CountVertices() : 4); vertindex = ret.second; vertcount = CreateVertices(ret.first, split); } diff --git a/src/hwrenderer/scene/hw_weapon.cpp b/src/hwrenderer/scene/hw_weapon.cpp index 8a523b471..374b6ea9f 100644 --- a/src/hwrenderer/scene/hw_weapon.cpp +++ b/src/hwrenderer/scene/hw_weapon.cpp @@ -34,6 +34,8 @@ #include "r_data/models/models.h" #include "hw_weapon.h" #include "hw_fakeflat.h" + +#include "hwrenderer/models/hw_models.h" #include "hwrenderer/dynlights/hw_dynlightdata.h" #include "hwrenderer/textures/hw_material.h" #include "hwrenderer/utility/hw_lighting.h" @@ -75,7 +77,10 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state) if (huds->mframe) { state.AlphaFunc(Alpha_GEqual, 0); - DrawHUDModel(huds, state); + + FGLModelRenderer renderer(this, state, huds->lightindex); + renderer.RenderHUDModel(huds->weapon, huds->mx, huds->my); + screen->mVertexData->Bind(state); } else { @@ -464,7 +469,7 @@ bool HUDSprite::GetWeaponRect(HWDrawInfo *di, DPSprite *psp, float sx, float sy, v2 = tex->GetSpriteVB(); } - auto verts = di->AllocVertices(4); + auto verts = screen->mVertexData->AllocVertices(4); mx = verts.second; verts.first[0].Set(x1, y1, 0, u1, v1); diff --git a/src/p_setup.cpp b/src/p_setup.cpp index db5baf518..7ff907f8a 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -104,6 +104,7 @@ #include "types.h" #include "i_time.h" #include "scripting/vm/vm.h" +#include "hwrenderer/data/flatvertices.h" #include "fragglescript/t_fs.h" @@ -4115,7 +4116,7 @@ void P_SetupLevel (const char *lumpname, int position) // This must be done BEFORE the PolyObj Spawn!!! InitRenderInfo(); // create hardware independent renderer resources for the level. - screen->InitForLevel(); // create hardware dependent level resources (e.g. the vertex buffer) + screen->mVertexData->CreateVBO(); SWRenderer->SetColormap(); //The SW renderer needs to do some special setup for the level's default colormap. InitPortalGroups(); diff --git a/src/v_video.h b/src/v_video.h index 2e7e5a0f4..e28592388 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -485,7 +485,6 @@ public: // Report a game restart void InitPalette(); - virtual void InitForLevel() {} virtual void SetClearColor(int color) {} virtual uint32_t GetCaps(); virtual void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV);