From 8daaf61160c526817b49c0acbaa660243f400c54 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 8 Aug 2016 14:24:48 +0200 Subject: [PATCH] - predefine the vertex data for the blend overlay which will never change throughout the lifetime of the GLRenderer object. --- src/gl/data/gl_vertexbuffer.cpp | 20 +++++++++++++++++--- src/gl/data/gl_vertexbuffer.h | 2 +- src/gl/renderer/gl_renderer.cpp | 4 ++-- src/gl/renderer/gl_renderer.h | 2 +- src/gl/scene/gl_scene.cpp | 12 ++---------- src/gl/system/gl_framebuffer.cpp | 2 +- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/gl/data/gl_vertexbuffer.cpp b/src/gl/data/gl_vertexbuffer.cpp index 1d69c2547..4cb0efd6a 100644 --- a/src/gl/data/gl_vertexbuffer.cpp +++ b/src/gl/data/gl_vertexbuffer.cpp @@ -109,7 +109,7 @@ void FSimpleVertexBuffer::set(FSimpleVertex *verts, int count) // //========================================================================== -FFlatVertexBuffer::FFlatVertexBuffer() +FFlatVertexBuffer::FFlatVertexBuffer(int width, int height) : FVertexBuffer(gl.buffermethod == BM_PERSISTENT) { if (gl.buffermethod == BM_PERSISTENT) @@ -125,7 +125,22 @@ FFlatVertexBuffer::FFlatVertexBuffer() vbo_shadowdata.Reserve(BUFFER_SIZE); map = new FFlatVertex[BUFFER_SIZE]; } - mNumReserved = mIndex = mCurIndex = 0; + mIndex = mCurIndex = 0; + mNumReserved = 8; + vbo_shadowdata.Resize(mNumReserved); + + // the first quad is reserved for handling coordinates through uniforms. + vbo_shadowdata[0].Set(1, 0, 0, 0, 0); + vbo_shadowdata[1].Set(2, 0, 0, 0, 0); + vbo_shadowdata[2].Set(3, 0, 0, 0, 0); + vbo_shadowdata[3].Set(4, 0, 0, 0, 0); + + // and the second one for the fullscreen quad used for blend overlays. + vbo_shadowdata[4].Set(0, 0, 0, 0, 0); + vbo_shadowdata[5].Set(0, (float)height, 0, 0, 0); + vbo_shadowdata[6].Set((float)width, 0, 0, 0, 0); + vbo_shadowdata[7].Set((float)width, (float)height, 0, 0, 0); + } FFlatVertexBuffer::~FFlatVertexBuffer() @@ -350,7 +365,6 @@ void FFlatVertexBuffer::UpdatePlaneVertices(sector_t *sec, int plane) void FFlatVertexBuffer::CreateVBO() { - vbo_shadowdata.Resize(mNumReserved); CreateFlatVBO(); mCurIndex = mIndex = vbo_shadowdata.Size(); memcpy(map, &vbo_shadowdata[0], vbo_shadowdata.Size() * sizeof(FFlatVertex)); diff --git a/src/gl/data/gl_vertexbuffer.h b/src/gl/data/gl_vertexbuffer.h index ce598965f..31251653d 100644 --- a/src/gl/data/gl_vertexbuffer.h +++ b/src/gl/data/gl_vertexbuffer.h @@ -84,7 +84,7 @@ class FFlatVertexBuffer : public FVertexBuffer public: TArray vbo_shadowdata; // this is kept around for updating the actual (non-readable) buffer and as stand-in for pre GL 4.x - FFlatVertexBuffer(); + FFlatVertexBuffer(int width, int height); ~FFlatVertexBuffer(); void BindVBO(); diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index 2716c6a2c..b00396e21 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -113,7 +113,7 @@ FGLRenderer::FGLRenderer(OpenGLFrameBuffer *fb) void gl_LoadModels(); void gl_FlushModels(); -void FGLRenderer::Initialize() +void FGLRenderer::Initialize(int width, int height) { mBuffers = new FGLRenderBuffers(); mBloomExtractShader = new FBloomExtractShader(); @@ -137,7 +137,7 @@ void FGLRenderer::Initialize() glpart = FTexture::CreateTexture(Wads.GetNumForFullName("glstuff/glpart.png"), FTexture::TEX_MiscPatch); mirrortexture = FTexture::CreateTexture(Wads.GetNumForFullName("glstuff/mirror.png"), FTexture::TEX_MiscPatch); - mVBO = new FFlatVertexBuffer; + mVBO = new FFlatVertexBuffer(width, height); mSkyVBO = new FSkyVertexBuffer; if (gl.lightmethod != LM_SOFTWARE) mLights = new FLightBuffer(); else mLights = NULL; diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index 8a00e6ce4..0fe91dae2 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -129,7 +129,7 @@ public: void SetViewAngle(DAngle viewangle); void SetupView(float viewx, float viewy, float viewz, DAngle viewangle, bool mirror, bool planemirror); - void Initialize(); + void Initialize(int width, int height); void CreateScene(); void RenderMultipassStuff(); diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 16bb6cd34..44118087d 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -525,16 +525,8 @@ void gl_FillScreen() gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.EnableTexture(false); gl_RenderState.Apply(); - FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer(); - ptr->Set(0, 0, 0, 0, 0); - ptr++; - ptr->Set(0, (float)SCREENHEIGHT, 0, 0, 0); - ptr++; - ptr->Set((float)SCREENWIDTH, 0, 0, 0, 0); - ptr++; - ptr->Set((float)SCREENWIDTH, (float)SCREENHEIGHT, 0, 0, 0); - ptr++; - GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP); + // The fullscreen quad is stored at index 4 in the main vertex buffer. + glDrawArrays(GL_TRIANGLE_STRIP, 4, 4); } //========================================================================== diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 151683d56..495df07e8 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -164,7 +164,7 @@ void OpenGLFrameBuffer::InitializeState() //int h = GetHeight(); //glViewport(0, (trueH - h)/2, GetWidth(), GetHeight()); - GLRenderer->Initialize(); + GLRenderer->Initialize(GetWidth(), GetHeight()); GLRenderer->SetOutputViewport(nullptr); Begin2D(false); }