From b83c2056a8a1d36eb037f461ad17a11a42a444f2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 26 Aug 2016 00:01:51 +0200 Subject: [PATCH] - store the stencil caps in the reserved part of the main vertex buffer instead of constantly recreating them. --- src/gl/data/gl_vertexbuffer.cpp | 13 ++++++++++++- src/gl/data/gl_vertexbuffer.h | 6 +++++- src/gl/scene/gl_portal.cpp | 29 +++++++---------------------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/gl/data/gl_vertexbuffer.cpp b/src/gl/data/gl_vertexbuffer.cpp index 05fd475c07..7e77849545 100644 --- a/src/gl/data/gl_vertexbuffer.cpp +++ b/src/gl/data/gl_vertexbuffer.cpp @@ -153,7 +153,7 @@ FFlatVertexBuffer::FFlatVertexBuffer(int width, int height) map = new FFlatVertex[BUFFER_SIZE]; } mIndex = mCurIndex = 0; - mNumReserved = 12; + mNumReserved = NUM_RESERVED; vbo_shadowdata.Resize(mNumReserved); // the first quad is reserved for handling coordinates through uniforms. @@ -174,6 +174,17 @@ FFlatVertexBuffer::FFlatVertexBuffer(int width, int height) vbo_shadowdata[10].Set(1.0f, -1.0f, 0, 1.f, 0.0f); vbo_shadowdata[11].Set(1.0f, 1.0f, 0, 1.f, 1.f); + // The next two are the stencil caps. + vbo_shadowdata[12].Set(-32767.0f, 32767.0f, -32767.0f, 0, 0); + vbo_shadowdata[13].Set(-32767.0f, 32767.0f, 32767.0f, 0, 0); + vbo_shadowdata[14].Set(32767.0f, 32767.0f, 32767.0f, 0, 0); + vbo_shadowdata[15].Set(32767.0f, 32767.0f, -32767.0f, 0, 0); + + vbo_shadowdata[16].Set(-32767.0f, -32767.0f, -32767.0f, 0, 0); + vbo_shadowdata[17].Set(-32767.0f, -32767.0f, 32767.0f, 0, 0); + vbo_shadowdata[18].Set(32767.0f, -32767.0f, 32767.0f, 0, 0); + vbo_shadowdata[19].Set(32767.0f, -32767.0f, -32767.0f, 0, 0); + } FFlatVertexBuffer::~FFlatVertexBuffer() diff --git a/src/gl/data/gl_vertexbuffer.h b/src/gl/data/gl_vertexbuffer.h index 5e6912a10c..68f1013675 100644 --- a/src/gl/data/gl_vertexbuffer.h +++ b/src/gl/data/gl_vertexbuffer.h @@ -87,7 +87,11 @@ public: { QUAD_INDEX = 0, FULLSCREEN_INDEX = 4, - PRESENT_INDEX = 8 + PRESENT_INDEX = 8, + STENCILTOP_INDEX = 12, + STENCILBOTTOM_INDEX = 16, + + NUM_RESERVED = 20 }; TArray vbo_shadowdata; // this is kept around for updating the actual (non-readable) buffer and as stand-in for pre GL 4.x diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index bb71668053..628e0f915c 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -147,40 +147,25 @@ void GLPortal::DrawPortalStencil() { if (mPrimIndices.Size() == 0) { - bool cap = NeedCap() && lines.Size() > 1; - mPrimIndices.Resize(2 * lines.Size() + 4 * cap); + mPrimIndices.Resize(2 * lines.Size()); - for (unsigned int i = 0; imVBO->GetBuffer(); - ptr[0].Set(-32767.0f, 32767.0f, -32767.0f, 0, 0); - ptr[1].Set(-32767.0f, 32767.0f, 32767.0f, 0, 0); - ptr[2].Set(32767.0f, 32767.0f, 32767.0f, 0, 0); - ptr[3].Set(32767.0f, 32767.0f, -32767.0f, 0, 0); - ptr += 4; - mPrimIndices[n + 1] = GLRenderer->mVBO->GetCount(ptr, &mPrimIndices[n]); - ptr[0].Set(-32767.0f, -32767.0f, -32767.0f, 0, 0); - ptr[1].Set(-32767.0f, -32767.0f, 32767.0f, 0, 0); - ptr[2].Set(32767.0f, -32767.0f, 32767.0f, 0, 0); - ptr[3].Set(32767.0f, -32767.0f, -32767.0f, 0, 0); - ptr += 4; - mPrimIndices[n + 3] = GLRenderer->mVBO->GetCount(ptr, &mPrimIndices[n + 2]); - } } gl_RenderState.Apply(); for (unsigned int i = 0; i < mPrimIndices.Size(); i += 2) { GLRenderer->mVBO->RenderArray(GL_TRIANGLE_FAN, mPrimIndices[i], mPrimIndices[i + 1]); } + if (NeedCap() && lines.Size() > 1) + { + glDrawArrays(GL_TRIANGLE_FAN, FFlatVertexBuffer::STENCILTOP_INDEX, 4); + glDrawArrays(GL_TRIANGLE_FAN, FFlatVertexBuffer::STENCILBOTTOM_INDEX, 4); + } }