From a97b58fa27e648afff6f6097896957ba6db0f4d9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 2 Aug 2014 20:41:13 +0200 Subject: [PATCH] - added check for light uniform buffer overflows, because uniform buffers on Intel are rather small. --- src/gl/dynlights/gl_lightbuffer.cpp | 32 ++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/gl/dynlights/gl_lightbuffer.cpp b/src/gl/dynlights/gl_lightbuffer.cpp index c507b1657d..b787be9e25 100644 --- a/src/gl/dynlights/gl_lightbuffer.cpp +++ b/src/gl/dynlights/gl_lightbuffer.cpp @@ -52,13 +52,15 @@ FLightBuffer::FLightBuffer() if (gl.flags & RFL_SHADER_STORAGE_BUFFER) { mBufferType = GL_SHADER_STORAGE_BUFFER; - mBlockAlign = 0; + mBlockAlign = -1; + mBlockSize = BUFFER_SIZE; } else { mBufferType = GL_UNIFORM_BUFFER; - mBlockSize = 2048;// gl.maxuniformblock / 4 - 100; - mBlockAlign = 1024;// ((mBlockSize * 2) & ~(gl.uniformblockalignment - 1)) / 4; // count in vec4's + mBlockSize = gl.maxuniformblock / 16; + if (mBlockSize > 2048) mBlockSize = 2048; // we don't really need a larger buffer + mBlockAlign = mBlockSize / 2; } glGenBuffers(1, &mBufferId); @@ -92,6 +94,30 @@ int FLightBuffer::UploadLights(FDynLightData &data) int size2 = data.arrays[2].Size()/4; int totalsize = size0 + size1 + size2 + 1; + if (mBlockAlign >= 0 && totalsize + (mIndex % mBlockAlign) > mBlockSize) + { + mIndex = ((mIndex + mBlockAlign) / mBlockAlign) * mBlockAlign; + + // can't be rendered all at once. + if (totalsize > mBlockSize) + { + int diff = totalsize - mBlockSize; + + size2 -= diff; + if (size2 < 0) + { + size1 += size2; + size2 = 0; + } + if (size1 < 0) + { + size0 += size1; + size1 = 0; + } + totalsize = size0 + size1 + size2 + 1; + } + } + if (totalsize <= 1) return -1; if (mIndex + totalsize > BUFFER_SIZE)