diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index 933af36a3..d08443c57 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 bc6fbe515..ef1e6221d 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 48e483985..9ca935269 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 c1e3b6086..20e139c58 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 e86969e07..c55448379 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 9ba878925..7222247b2 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 52a053d46..9f2a848b9 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 8309dee0d..a3ea2a63f 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 ad5d6e7cf..bdcf1f08e 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 bd442a19a..97eeb55a1 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);