diff --git a/src/gl/data/gl_vertexbuffer.cpp b/src/gl/data/gl_vertexbuffer.cpp index c09996bf0..f68883edf 100644 --- a/src/gl/data/gl_vertexbuffer.cpp +++ b/src/gl/data/gl_vertexbuffer.cpp @@ -96,7 +96,7 @@ FFlatVertexBuffer::FFlatVertexBuffer() glBindBuffer(GL_ARRAY_BUFFER, vbo_id); glBufferStorage(GL_ARRAY_BUFFER, bytesize, NULL, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT); map = (FFlatVertex*)glMapBufferRange(GL_ARRAY_BUFFER, 0, bytesize, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT); - mIndex = mCurIndex = 0; + mNumReserved = mIndex = mCurIndex = 0; } else { @@ -109,7 +109,7 @@ FFlatVertexBuffer::FFlatVertexBuffer() } glBindBuffer(GL_ARRAY_BUFFER, vbo_id); glBufferData(GL_ARRAY_BUFFER, BUFFER_SIZE * sizeof(FFlatVertex), map, GL_STREAM_DRAW); - mIndex = mCurIndex = 20; + mNumReserved = mIndex = mCurIndex = 20; } glBindVertexArray(vao_id); @@ -390,6 +390,11 @@ void FFlatVertexBuffer::UpdatePlaneVertices(sector_t *sec, int plane) if (plane == sector_t::floor && sec->transdoor) vt->z -= 1; mapvt->z = vt->z; } + if (!(gl.flags & RFL_BUFFER_STORAGE)) + { + glBindBuffer(GL_ARRAY_BUFFER, vbo_id); + glBufferSubData(GL_ARRAY_BUFFER, startvt * sizeof(FFlatVertex), countvt * sizeof(FFlatVertex), &vbo_shadowdata[startvt]); + } } //========================================================================== @@ -400,12 +405,20 @@ void FFlatVertexBuffer::UpdatePlaneVertices(sector_t *sec, int plane) void FFlatVertexBuffer::CreateVBO() { - vbo_shadowdata.Clear(); - if (gl.flags & RFL_BUFFER_STORAGE) + if (!(gl.flags & RFL_NOBUFFER)) { + vbo_shadowdata.Resize(mNumReserved); CreateFlatVBO(); - memcpy(map, &vbo_shadowdata[0], vbo_shadowdata.Size() * sizeof(FFlatVertex)); mCurIndex = mIndex = vbo_shadowdata.Size(); + if (gl.flags & RFL_BUFFER_STORAGE) + { + memcpy(map, &vbo_shadowdata[0], vbo_shadowdata.Size() * sizeof(FFlatVertex)); + } + else + { + glBindBuffer(GL_ARRAY_BUFFER, vbo_id); + glBufferSubData(GL_ARRAY_BUFFER, mNumReserved * sizeof(FFlatVertex), (mIndex - mNumReserved) * sizeof(FFlatVertex), &vbo_shadowdata[mNumReserved]); + } } else if (sectors) { @@ -417,6 +430,7 @@ void FFlatVertexBuffer::CreateVBO() sectors[i].vboheight[1] = sectors[i].vboheight[0] = FIXED_MIN; } } + } //========================================================================== @@ -427,39 +441,28 @@ void FFlatVertexBuffer::CreateVBO() void FFlatVertexBuffer::CheckPlanes(sector_t *sector) { - if (gl.flags & RFL_BUFFER_STORAGE) + if (sector->GetPlaneTexZ(sector_t::ceiling) != sector->vboheight[sector_t::ceiling]) { - if (sector->GetPlaneTexZ(sector_t::ceiling) != sector->vboheight[sector_t::ceiling]) - { - //if (sector->ceilingdata == NULL) // only update if there's no thinker attached - { - UpdatePlaneVertices(sector, sector_t::ceiling); - sector->vboheight[sector_t::ceiling] = sector->GetPlaneTexZ(sector_t::ceiling); - } - } - if (sector->GetPlaneTexZ(sector_t::floor) != sector->vboheight[sector_t::floor]) - { - //if (sector->floordata == NULL) // only update if there's no thinker attached - { - UpdatePlaneVertices(sector, sector_t::floor); - sector->vboheight[sector_t::floor] = sector->GetPlaneTexZ(sector_t::floor); - } - } + UpdatePlaneVertices(sector, sector_t::ceiling); + sector->vboheight[sector_t::ceiling] = sector->GetPlaneTexZ(sector_t::ceiling); + } + if (sector->GetPlaneTexZ(sector_t::floor) != sector->vboheight[sector_t::floor]) + { + UpdatePlaneVertices(sector, sector_t::floor); + sector->vboheight[sector_t::floor] = sector->GetPlaneTexZ(sector_t::floor); } } //========================================================================== // // checks the validity of all planes attached to this sector -// and updates them if possible. Anything moving will not be -// updated unless it stops. This is to ensure that we never -// have to synchronize with the rendering process. +// and updates them if possible. // //========================================================================== void FFlatVertexBuffer::CheckUpdate(sector_t *sector) { - if (gl.flags & RFL_BUFFER_STORAGE) + if (!(gl.flags & RFL_NOBUFFER)) { CheckPlanes(sector); sector_t *hs = sector->GetHeightSec(); diff --git a/src/gl/data/gl_vertexbuffer.h b/src/gl/data/gl_vertexbuffer.h index cb287f6c8..b6d61f2da 100644 --- a/src/gl/data/gl_vertexbuffer.h +++ b/src/gl/data/gl_vertexbuffer.h @@ -47,6 +47,7 @@ class FFlatVertexBuffer : public FVertexBuffer FFlatVertex *map; unsigned int mIndex; unsigned int mCurIndex; + unsigned int mNumReserved; void CheckPlanes(sector_t *sector); diff --git a/src/gl/system/gl_interface.cpp b/src/gl/system/gl_interface.cpp index 72d5a457b..2d5f13125 100644 --- a/src/gl/system/gl_interface.cpp +++ b/src/gl/system/gl_interface.cpp @@ -120,7 +120,7 @@ void gl_LoadExtensions() // Don't even start if it's lower than 3.0 - if (strcmp(version, "3.0") < 0) + if (strcmp(version, "3.0") < 0) { I_FatalError("Unsupported OpenGL version.\nAt least GL 3.0 is required to run " GAMENAME ".\n"); } @@ -129,8 +129,9 @@ void gl_LoadExtensions() gl.version = strtod(version, NULL) + 0.01f; gl.glslversion = strtod((char*)glGetString(GL_SHADING_LANGUAGE_VERSION), NULL) + 0.01f; - gl.vendorstring=(char*)glGetString(GL_VENDOR); + gl.vendorstring = (char*)glGetString(GL_VENDOR); + if (!strstr(gl.vendorstring, "NVIDIA Corporation")); gl.flags |= RFL_NOBUFFER; if (CheckExtension("GL_ARB_texture_compression")) gl.flags|=RFL_TEXTURE_COMPRESSION; if (CheckExtension("GL_EXT_texture_compression_s3tc")) gl.flags|=RFL_TEXTURE_COMPRESSION_S3TC; if (CheckExtension("GL_ARB_buffer_storage") && !Args->CheckParm("-nopersistentbuffers")) diff --git a/src/gl/system/gl_interface.h b/src/gl/system/gl_interface.h index 2209f0bed..d33ce77fc 100644 --- a/src/gl/system/gl_interface.h +++ b/src/gl/system/gl_interface.h @@ -14,6 +14,7 @@ enum RenderFlags RFL_SHADER_STORAGE_BUFFER = 16, // to be used later for a parameter buffer RFL_BASEINDEX = 32, // currently unused RFL_COREPROFILE = 64, + RFL_NOBUFFER = 128, // the static buffer makes no sense on GL 3.x AMD and Intel hardware, as long as compatibility mode is on }; enum TexMode