- use a software buffer for immediate mode rendering. This allows using the regular buffer code to collect data for both render modes and allows removal of a lot of duplicated code.
This commit is contained in:
parent
5b302ed3a6
commit
3644073bbd
12 changed files with 232 additions and 636 deletions
|
|
@ -53,7 +53,7 @@ CUSTOM_CVAR(Int, gl_usevbo, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCA
|
|||
{
|
||||
if (self < -1 || self > 1 || !(gl.flags & RFL_BUFFER_STORAGE))
|
||||
{
|
||||
self = 0;
|
||||
if (self != 0) self = 0;
|
||||
}
|
||||
else if (self == -1)
|
||||
{
|
||||
|
|
@ -101,7 +101,8 @@ FFlatVertexBuffer::FFlatVertexBuffer()
|
|||
}
|
||||
else
|
||||
{
|
||||
map = NULL;
|
||||
vbo_shadowdata.Reserve(BUFFER_SIZE);
|
||||
map = &vbo_shadowdata[0];
|
||||
}
|
||||
mIndex = mCurIndex = 0;
|
||||
}
|
||||
|
|
@ -113,6 +114,25 @@ FFlatVertexBuffer::~FFlatVertexBuffer()
|
|||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Renders the buffer's contents with immediate mode functions
|
||||
// This is here so that the immediate mode fallback does not need
|
||||
// to double all rendering code and can instead reuse the buffer-based version
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FFlatVertexBuffer::ImmRenderBuffer(unsigned int primtype, unsigned int offset, unsigned int count)
|
||||
{
|
||||
glBegin(primtype);
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
glTexCoord2fv(&map[offset + i].u);
|
||||
glVertex3fv(&map[offset + i].x);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Initialize a single vertex
|
||||
|
|
@ -369,7 +389,7 @@ void FFlatVertexBuffer::CheckPlanes(sector_t *sector)
|
|||
|
||||
void FFlatVertexBuffer::CheckUpdate(sector_t *sector)
|
||||
{
|
||||
if (vbo_arg == 2)
|
||||
if (gl.flags & RFL_BUFFER_STORAGE)
|
||||
{
|
||||
CheckPlanes(sector);
|
||||
sector_t *hs = sector->GetHeightSec();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "tarray.h"
|
||||
#include "gl/utility/gl_clock.h"
|
||||
#include "gl/system/gl_interface.h"
|
||||
|
||||
struct vertex_t;
|
||||
struct secplane_t;
|
||||
|
|
@ -43,6 +44,7 @@ struct FFlatVertex
|
|||
class FFlatVertexBuffer : public FVertexBuffer
|
||||
{
|
||||
FFlatVertex *map;
|
||||
FFlatVertex mDrawBuffer[1000];
|
||||
unsigned int mIndex;
|
||||
unsigned int mCurIndex;
|
||||
|
||||
|
|
@ -50,9 +52,10 @@ class FFlatVertexBuffer : public FVertexBuffer
|
|||
|
||||
const unsigned int BUFFER_SIZE = 2000000;
|
||||
|
||||
void ImmRenderBuffer(unsigned int primtype, unsigned int offset, unsigned int count);
|
||||
|
||||
public:
|
||||
int vbo_arg;
|
||||
TArray<FFlatVertex> vbo_shadowdata; // this is kept around for updating the actual (non-readable) buffer
|
||||
TArray<FFlatVertex> vbo_shadowdata; // this is kept around for updating the actual (non-readable) buffer and as stand-in for pre GL 4.x
|
||||
|
||||
FFlatVertexBuffer();
|
||||
~FFlatVertexBuffer();
|
||||
|
|
@ -67,6 +70,7 @@ public:
|
|||
}
|
||||
unsigned int GetCount(FFlatVertex *newptr, unsigned int *poffset)
|
||||
{
|
||||
|
||||
unsigned int newofs = (unsigned int)(newptr - map);
|
||||
unsigned int diff = newofs - mCurIndex;
|
||||
*poffset = mCurIndex;
|
||||
|
|
@ -75,16 +79,29 @@ public:
|
|||
return diff;
|
||||
}
|
||||
#ifdef __GL_PCH_H // we need the system includes for this but we cannot include them ourselves without creating #define clashes. The affected files wouldn't try to draw anyway.
|
||||
void RenderArray(unsigned int primtype, unsigned int offset, unsigned int count)
|
||||
{
|
||||
drawcalls.Clock();
|
||||
if (gl.flags & RFL_BUFFER_STORAGE)
|
||||
{
|
||||
glDrawArrays(primtype, offset, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImmRenderBuffer(primtype, offset, count);
|
||||
}
|
||||
drawcalls.Unclock();
|
||||
}
|
||||
|
||||
void RenderCurrent(FFlatVertex *newptr, unsigned int primtype, unsigned int *poffset = NULL, unsigned int *pcount = NULL)
|
||||
{
|
||||
unsigned int offset;
|
||||
unsigned int count = GetCount(newptr, &offset);
|
||||
drawcalls.Clock();
|
||||
glDrawArrays(primtype, offset, count);
|
||||
drawcalls.Unclock();
|
||||
RenderArray(primtype, offset, count);
|
||||
if (poffset) *poffset = offset;
|
||||
if (pcount) *pcount = count;
|
||||
}
|
||||
|
||||
#endif
|
||||
void Reset()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue