- allow vertex buffers for all GL versions. At least on NVidia this is horrendously slow without GL_ARB_buffer_storage but we'll need this code for some benchmarking.

This commit is contained in:
Christoph Oelckers 2014-06-14 15:00:10 +02:00
parent 0ce6b40672
commit f3cc331436
2 changed files with 39 additions and 28 deletions

View file

@ -45,21 +45,24 @@
#include "c_cvars.h" #include "c_cvars.h"
#include "gl/system/gl_interface.h" #include "gl/system/gl_interface.h"
#include "gl/renderer/gl_renderer.h" #include "gl/renderer/gl_renderer.h"
#include "gl/renderer/gl_renderstate.h"
#include "gl/data/gl_data.h" #include "gl/data/gl_data.h"
#include "gl/data/gl_vertexbuffer.h" #include "gl/data/gl_vertexbuffer.h"
CUSTOM_CVAR(Int, gl_usevbo, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) CUSTOM_CVAR(Int, gl_usevbo, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
{ {
if (self < -1 || self > 1 || !(gl.flags & RFL_BUFFER_STORAGE)) if (self < -1 || self > 1 /* || !(gl.flags & RFL_BUFFER_STORAGE)*/)
{ {
self = 0; self = 0;
} }
/*
else if (self == -1) else if (self == -1)
{ {
if (!(gl.flags & RFL_BUFFER_STORAGE)) self = 0; if (!(gl.flags & RFL_BUFFER_STORAGE)) self = 0;
else self = 1; else self = 1;
} }
*/
} }
//========================================================================== //==========================================================================
@ -91,17 +94,20 @@ FVertexBuffer::~FVertexBuffer()
FFlatVertexBuffer::FFlatVertexBuffer() FFlatVertexBuffer::FFlatVertexBuffer()
: FVertexBuffer() : FVertexBuffer()
{
if (gl.flags & RFL_BUFFER_STORAGE)
{ {
unsigned int bytesize = BUFFER_SIZE * sizeof(FFlatVertex); unsigned int bytesize = BUFFER_SIZE * sizeof(FFlatVertex);
glBindBuffer(GL_ARRAY_BUFFER, vbo_id); glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
if (gl.flags & RFL_BUFFER_STORAGE)
{
glBufferStorage(GL_ARRAY_BUFFER, bytesize, NULL, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT); 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); map = (FFlatVertex*)glMapBufferRange(GL_ARRAY_BUFFER, 0, bytesize, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT);
} }
else else
{ {
map = NULL; glBufferData(GL_ARRAY_BUFFER, bytesize, NULL, GL_STREAM_DRAW);
vbo_shadowdata.Reserve(BUFFER_SIZE);
vbo_shadowdata.Clear();
map = &vbo_shadowdata[0];
} }
mIndex = mCurIndex = 0; mIndex = mCurIndex = 0;
} }
@ -274,7 +280,7 @@ void FFlatVertexBuffer::UpdatePlaneVertices(sector_t *sec, int plane)
secplane_t &splane = sec->GetSecPlane(plane); secplane_t &splane = sec->GetSecPlane(plane);
FFlatVertex *vt = &vbo_shadowdata[startvt]; FFlatVertex *vt = &vbo_shadowdata[startvt];
FFlatVertex *mapvt = &map[startvt]; FFlatVertex *mapvt = &map[startvt];
for(int i=0; i<countvt; i++, vt++) for(int i=0; i<countvt; i++, vt++, mapvt++)
{ {
vt->z = splane.ZatPoint(vt->x, vt->y); vt->z = splane.ZatPoint(vt->x, vt->y);
if (plane == sector_t::floor && sec->transdoor) vt->z -= 1; if (plane == sector_t::floor && sec->transdoor) vt->z -= 1;
@ -291,21 +297,16 @@ void FFlatVertexBuffer::UpdatePlaneVertices(sector_t *sec, int plane)
void FFlatVertexBuffer::CreateVBO() void FFlatVertexBuffer::CreateVBO()
{ {
vbo_shadowdata.Clear(); vbo_shadowdata.Clear();
CreateFlatVBO();
mCurIndex = mIndex = vbo_shadowdata.Size();
if (gl.flags & RFL_BUFFER_STORAGE) if (gl.flags & RFL_BUFFER_STORAGE)
{ {
CreateFlatVBO();
memcpy(map, &vbo_shadowdata[0], vbo_shadowdata.Size() * sizeof(FFlatVertex)); memcpy(map, &vbo_shadowdata[0], vbo_shadowdata.Size() * sizeof(FFlatVertex));
mCurIndex = mIndex = vbo_shadowdata.Size();
} }
else if (sectors) else
{ {
// set all VBO info to invalid values so that we can save some checks in the rendering code glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
for(int i=0;i<numsectors;i++) glBufferSubData(GL_ARRAY_BUFFER, 0, vbo_shadowdata.Size() * sizeof(FFlatVertex), &vbo_shadowdata[0]);
{
sectors[i].vboindex[3] = sectors[i].vboindex[2] =
sectors[i].vboindex[1] = sectors[i].vboindex[0] = -1;
sectors[i].vboheight[1] = sectors[i].vboheight[0] = FIXED_MIN;
}
} }
} }
@ -316,8 +317,6 @@ void FFlatVertexBuffer::CreateVBO()
//========================================================================== //==========================================================================
void FFlatVertexBuffer::BindVBO() void FFlatVertexBuffer::BindVBO()
{
if (gl.flags & RFL_BUFFER_STORAGE)
{ {
glBindBuffer(GL_ARRAY_BUFFER, vbo_id); glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
@ -327,7 +326,6 @@ void FFlatVertexBuffer::BindVBO()
glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_COLOR_ARRAY);
} }
}
//========================================================================== //==========================================================================
// //
@ -337,7 +335,7 @@ void FFlatVertexBuffer::BindVBO()
void FFlatVertexBuffer::CheckPlanes(sector_t *sector) void FFlatVertexBuffer::CheckPlanes(sector_t *sector)
{ {
if (gl.flags & RFL_BUFFER_STORAGE) //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])
{ {

View file

@ -2,6 +2,7 @@
#define __VERTEXBUFFER_H #define __VERTEXBUFFER_H
#include "tarray.h" #include "tarray.h"
#include "gl/system/gl_interface.h"
struct vertex_t; struct vertex_t;
struct secplane_t; struct secplane_t;
@ -60,6 +61,8 @@ public:
void BindVBO(); void BindVBO();
void CheckUpdate(sector_t *sector); void CheckUpdate(sector_t *sector);
bool SetBufferMode(bool hw);
FFlatVertex *GetBuffer() FFlatVertex *GetBuffer()
{ {
return &map[mCurIndex]; return &map[mCurIndex];
@ -78,6 +81,16 @@ public:
{ {
unsigned int offset; unsigned int offset;
unsigned int count = GetCount(newptr, &offset); unsigned int count = GetCount(newptr, &offset);
if (!(gl.flags & RFL_BUFFER_STORAGE))
{
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
void *p = glMapBufferRange(GL_ARRAY_BUFFER, offset * sizeof(FFlatVertex), count * sizeof(FFlatVertex), GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT);
if (p != NULL)
{
memcpy(p, &vbo_shadowdata[offset], count * sizeof(FFlatVertex));
glUnmapBuffer(GL_ARRAY_BUFFER);
}
}
glDrawArrays(primtype, offset, count); glDrawArrays(primtype, offset, count);
} }
#endif #endif
@ -135,7 +148,7 @@ private:
void SkyVertex(int r, int c, bool yflip); void SkyVertex(int r, int c, bool yflip);
void CreateSkyHemisphere(int hemi); void CreateSkyHemisphere(int hemi);
void CreateDome(); void CreateDome();
void RenderRow(int prim, int row, bool color); void RenderRow(int prim, int row);
public: public: