From 48bc5550d77987e7262ba5390abab7c3eb9d864c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 30 Oct 2018 19:28:47 +0100 Subject: [PATCH] - removed the Bind function from FFlatVertexBuffer. This is not flexible enough. There was already one place where this was not supposed to go through the render state. The new interface allows more general use of the contained buffer objects. --- src/gl/renderer/gl_postprocess.cpp | 5 +++-- src/gl/renderer/gl_renderer.cpp | 4 ++-- src/gl/system/gl_buffers.cpp | 2 +- src/hwrenderer/data/flatvertices.cpp | 12 ------------ src/hwrenderer/data/flatvertices.h | 7 ++++++- src/hwrenderer/scene/hw_drawinfo.cpp | 2 +- src/hwrenderer/scene/hw_renderstate.h | 7 +++++++ src/hwrenderer/scene/hw_sprites.cpp | 2 +- src/hwrenderer/scene/hw_weapon.cpp | 2 +- src/hwrenderer/utility/hw_draw2d.cpp | 2 +- 10 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index 933af36a30..d08443c574 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -30,6 +30,7 @@ #include "m_png.h" #include "r_utility.h" #include "d_player.h" +#include "gl/system/gl_buffers.h" #include "gl/system/gl_framebuffer.h" #include "hwrenderer/utility/hw_cvars.h" #include "gl/system/gl_debug.h" @@ -56,8 +57,8 @@ namespace OpenGLRenderer void FGLRenderer::RenderScreenQuad() { - screen->mVertexData->Bind(gl_RenderState); - gl_RenderState.ApplyBuffers(); + auto buffer = static_cast(screen->mVertexData->GetBufferObjects().first); + buffer->Bind(nullptr); glDrawArrays(GL_TRIANGLE_STRIP, FFlatVertexBuffer::PRESENT_INDEX, 4); } diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index bc6fbe5151..ef1e6221d9 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -220,7 +220,7 @@ void FGLRenderer::UpdateShadowMap() sector_t *FGLRenderer::RenderView(player_t* player) { - screen->mVertexData->Bind(gl_RenderState); + gl_RenderState.SetVertexBuffer(screen->mVertexData); screen->mVertexData->Reset(); sector_t *retsec; @@ -344,7 +344,7 @@ void FGLRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, i mBuffers = mSaveBuffers; P_FindParticleSubsectors(); // make sure that all recently spawned particles have a valid subsector. - screen->mVertexData->Bind(gl_RenderState); + gl_RenderState.SetVertexBuffer(screen->mVertexData); screen->mVertexData->Reset(); screen->mLights->Clear(); screen->mViewpoints->Clear(); diff --git a/src/gl/system/gl_buffers.cpp b/src/gl/system/gl_buffers.cpp index 48e483985a..9ca935269f 100644 --- a/src/gl/system/gl_buffers.cpp +++ b/src/gl/system/gl_buffers.cpp @@ -186,7 +186,7 @@ void GLVertexBuffer::Bind(int *offsets) { int i = 0; - // This is what gets called from RenderState.Apply. It shouldn't be called anywhere else. + // This is what gets called from RenderState.Apply. It shouldn't be called anywhere else if the render state is in use GLBuffer::Bind(); for(auto &attrinf : mAttributeInfo) { diff --git a/src/hwrenderer/data/flatvertices.cpp b/src/hwrenderer/data/flatvertices.cpp index c1e3b60864..20e139c586 100644 --- a/src/hwrenderer/data/flatvertices.cpp +++ b/src/hwrenderer/data/flatvertices.cpp @@ -411,18 +411,6 @@ void FFlatVertexBuffer::Copy(int start, int count) // //========================================================================== -void FFlatVertexBuffer::Bind(FRenderState &state) -{ - state.SetVertexBuffer(mVertexBuffer, 0, 0); - state.SetIndexBuffer(mIndexBuffer); -} - -//========================================================================== -// -// -// -//========================================================================== - void FFlatVertexBuffer::CreateVBO() { vbo_shadowdata.Resize(mNumReserved); diff --git a/src/hwrenderer/data/flatvertices.h b/src/hwrenderer/data/flatvertices.h index e86969e074..c554483792 100644 --- a/src/hwrenderer/data/flatvertices.h +++ b/src/hwrenderer/data/flatvertices.h @@ -103,7 +103,11 @@ public: ~FFlatVertexBuffer(); void OutputResized(int width, int height); - void Bind(FRenderState &state); + std::pair GetBufferObjects() const + { + return std::make_pair(mVertexBuffer, mIndexBuffer); + } + void CreateVBO(); void Copy(int start, int count); @@ -147,6 +151,7 @@ protected: 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.cpp b/src/hwrenderer/scene/hw_drawinfo.cpp index 9ba8789254..7222247b2c 100644 --- a/src/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/hwrenderer/scene/hw_drawinfo.cpp @@ -588,7 +588,7 @@ void HWDrawInfo::RenderPortal(HWPortal *p, FRenderState &state, bool usestencil) state.SetLightIndex(-1); gp->DrawContents(new_di, state); new_di->EndDrawInfo(); - screen->mVertexData->Bind(state); + state.SetVertexBuffer(screen->mVertexData); screen->mViewpoints->Bind(state, vpIndex); gp->RemoveStencil(this, state, usestencil); diff --git a/src/hwrenderer/scene/hw_renderstate.h b/src/hwrenderer/scene/hw_renderstate.h index 52a053d46e..9f2a848b92 100644 --- a/src/hwrenderer/scene/hw_renderstate.h +++ b/src/hwrenderer/scene/hw_renderstate.h @@ -457,6 +457,13 @@ public: mIndexBuffer = ib; } + template void SetVertexBuffer(T *buffer) + { + auto ptrs = buffer->GetBufferObjects(); + SetVertexBuffer(ptrs.first, 0, 0); + SetIndexBuffer(ptrs.second); + } + void SetInterpolationFactor(float fac) { mInterpolationFactor = fac; diff --git a/src/hwrenderer/scene/hw_sprites.cpp b/src/hwrenderer/scene/hw_sprites.cpp index 8309dee0d2..a3ea2a63f1 100644 --- a/src/hwrenderer/scene/hw_sprites.cpp +++ b/src/hwrenderer/scene/hw_sprites.cpp @@ -271,7 +271,7 @@ void GLSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent) { FGLModelRenderer renderer(di, state, dynlightindex); renderer.RenderModel(x, y, z, modelframe, actor, di->Viewpoint.TicFrac); - screen->mVertexData->Bind(state); + state.SetVertexBuffer(screen->mVertexData); } } diff --git a/src/hwrenderer/scene/hw_weapon.cpp b/src/hwrenderer/scene/hw_weapon.cpp index ad5d6e7cf1..bdcf1f08e8 100644 --- a/src/hwrenderer/scene/hw_weapon.cpp +++ b/src/hwrenderer/scene/hw_weapon.cpp @@ -81,7 +81,7 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state) FGLModelRenderer renderer(this, state, huds->lightindex); renderer.RenderHUDModel(huds->weapon, huds->mx, huds->my); - screen->mVertexData->Bind(state); + state.SetVertexBuffer(screen->mVertexData); } else { diff --git a/src/hwrenderer/utility/hw_draw2d.cpp b/src/hwrenderer/utility/hw_draw2d.cpp index bd442a19a3..97eeb55a1a 100644 --- a/src/hwrenderer/utility/hw_draw2d.cpp +++ b/src/hwrenderer/utility/hw_draw2d.cpp @@ -212,7 +212,7 @@ void Draw2D(F2DDrawer *drawer, FRenderState &state) state.SetScissor(-1, -1, -1, -1); state.SetRenderStyle(STYLE_Translucent); - screen->mVertexData->Bind(state); + state.SetVertexBuffer(screen->mVertexData); state.EnableTexture(true); state.EnableBrightmap(true); state.SetTextureMode(TM_NORMAL);