1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-06-08 01:22:02 +00:00

Fix issues with empty VBO upload and vbo size desync

This commit is contained in:
fgenesis 2025-03-12 02:42:41 +01:00
parent e89dd41be6
commit 5f9d26c360
2 changed files with 16 additions and 9 deletions

View file

@ -70,7 +70,11 @@ void CurrentRender::onUpdate(float dt)
size_t usedsize; size_t usedsize;
do do
{ {
float *p = (float*)vbo.beginWrite(GPUBUFTYPE_VEC2_TC_RGBA, bytes, GPUACCESS_DEFAULT); // Usually we write much less data than maximally possible to the GPU,
// because most segments are off-screen and not visible.
// The hostcopy flag accumulates the used data in the host heap
// and only uploads what is necessary in the end
float *p = (float*)vbo.beginWrite(GPUBUFTYPE_VEC2_TC_RGBA, bytes, GPUACCESS_HOSTCOPY);
verts = writeVBOData(p); verts = writeVBOData(p);
usedsize = verts * 8 * sizeof(float); usedsize = verts * 8 * sizeof(float);
} }
@ -109,9 +113,6 @@ size_t CurrentRender::writeVBOData(float *p)
if (diff.isZero()) if (diff.isZero())
continue; continue;
float len = diff.getLength2D();
float texScale = len/256.0f;
if (isTouchingLine(p1, p2, dsq->screenCenter, dsq->cullRadius+w2)) if (isTouchingLine(p1, p2, dsq->screenCenter, dsq->cullRadius+w2))
{ {
Vector pl = diff.getPerpendicularLeft(); Vector pl = diff.getPerpendicularLeft();
@ -132,6 +133,8 @@ size_t CurrentRender::writeVBOData(float *p)
const float ao = P->animOffset; const float ao = P->animOffset;
const float a = P->amount; const float a = P->amount;
const float len = diff.getLength2D();
const float texScale = len/256.0f;
/* This builds a structure like this: /* This builds a structure like this:
a = 0 alpha a = 0 alpha

View file

@ -141,6 +141,8 @@ bool DynamicGPUBuffer::_commitWrite(size_t used)
// -> didn't map, but wrote to host memory. upload it. // -> didn't map, but wrote to host memory. upload it.
assert(_h_data); assert(_h_data);
assert(used <= _h_cap); assert(used <= _h_cap);
if(used)
{
if(used <= _d_cap) if(used <= _d_cap)
glBufferSubDataARB(_gl_binding, 0, used, _h_data); // update existing buffer glBufferSubDataARB(_gl_binding, 0, used, _h_data); // update existing buffer
else else
@ -149,6 +151,7 @@ bool DynamicGPUBuffer::_commitWrite(size_t used)
glBufferDataARB(_gl_binding, used, _h_data, _gl_usage); // alloc new buffer glBufferDataARB(_gl_binding, used, _h_data, _gl_usage); // alloc new buffer
} }
} }
}
// else nothing to do // else nothing to do
assert(used <= _h_cap); assert(used <= _h_cap);
@ -168,6 +171,7 @@ void DynamicGPUBuffer::upload(BufDataType type, const void* data, size_t size)
last = id; last = id;
glBindBufferARB(_gl_binding, id); glBindBufferARB(_gl_binding, id);
} }
_d_cap = size;
glBufferDataARB(_gl_binding, size, data, _gl_usage); glBufferDataARB(_gl_binding, size, data, _gl_usage);
} }
else else