- use a uniform array to store vertex data to render dynamic stuff on GL 3.x hardware without the ARB_buffer_storage extension.
Due to the way the engine works it needs to render a lot of small primitives with frequent state changes. But due to the performance of buffer uploads it is impossible to upload each primitive's vertices to a buffer separately because buffer uploads nearly always stall the GPU. On the other hand, in order to reduce the amount of buffer uploads all the necessary state changes would have to be saved in an array until they can finally be used. This method also imposed an unacceptable overhead. Fortunately, uploading uniform arrays is very fast and doesn't cause GPU stalls, so now the engine puts the vertex data per primitive into a uniform array and uses a static vertex buffer to index the array in the vertex shader. This method offers the same performance as immediate mode but only uses core profile features.
This commit is contained in:
parent
6efefd9b7f
commit
f710518903
4 changed files with 95 additions and 8 deletions
|
|
@ -90,6 +90,14 @@ FFlatVertexBuffer::FFlatVertexBuffer()
|
|||
{
|
||||
vbo_shadowdata.Reserve(BUFFER_SIZE);
|
||||
map = &vbo_shadowdata[0];
|
||||
|
||||
FFlatVertex fill[20];
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
fill[i].Set(0, 0, 0, 100001.f, i);
|
||||
}
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
||||
glBufferData(GL_ARRAY_BUFFER, 20 * sizeof(FFlatVertex), fill, GL_STATIC_DRAW);
|
||||
}
|
||||
mIndex = mCurIndex = 0;
|
||||
}
|
||||
|
|
@ -109,15 +117,55 @@ FFlatVertexBuffer::~FFlatVertexBuffer()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
CVAR(Bool, gl_testbuffer, false, 0)
|
||||
|
||||
void FFlatVertexBuffer::ImmRenderBuffer(unsigned int primtype, unsigned int offset, unsigned int count)
|
||||
{
|
||||
glBegin(primtype);
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
if (!gl_testbuffer) // todo: remove the immediate mode calls once the uniform array method has been tested.
|
||||
{
|
||||
glTexCoord2fv(&map[offset + i].u);
|
||||
glVertex3fv(&map[offset + i].x);
|
||||
glBegin(primtype);
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
glTexCoord2fv(&map[offset + i].u);
|
||||
glVertex3fv(&map[offset + i].x);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (count > 20)
|
||||
{
|
||||
int start = offset;
|
||||
FFlatVertex ff = map[offset];
|
||||
while (count > 20)
|
||||
{
|
||||
|
||||
if (primtype == GL_TRIANGLE_FAN)
|
||||
{
|
||||
// split up the fan into multiple sub-fans
|
||||
map[offset] = map[start];
|
||||
glUniform1fv(GLRenderer->mShaderManager->GetActiveShader()->fakevb_index, 20 * 5, &map[offset].x);
|
||||
glDrawArrays(primtype, 0, 20);
|
||||
offset += 18;
|
||||
count -= 18;
|
||||
}
|
||||
else
|
||||
{
|
||||
// we only have triangle fans of this size so don't bother with strips and triangles here.
|
||||
break;
|
||||
}
|
||||
}
|
||||
map[offset] = map[start];
|
||||
glUniform1fv(GLRenderer->mShaderManager->GetActiveShader()->fakevb_index, count * 5, &map[offset].x);
|
||||
glDrawArrays(primtype, 0, count);
|
||||
map[offset] = ff;
|
||||
}
|
||||
else
|
||||
{
|
||||
glUniform1fv(GLRenderer->mShaderManager->GetActiveShader()->fakevb_index, count * 5, &map[offset].x);
|
||||
glDrawArrays(primtype, 0, count);
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
@ -324,7 +372,7 @@ void FFlatVertexBuffer::CreateVBO()
|
|||
|
||||
void FFlatVertexBuffer::BindVBO()
|
||||
{
|
||||
if (gl.flags & RFL_BUFFER_STORAGE)
|
||||
//if (gl.flags & RFL_BUFFER_STORAGE)
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue