1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-07-03 22:44:32 +00:00

fixes to VertexBuffer

- only reallocate if size changes
- fix logic error in the rare case of glUnmapBufferARB() failing
This commit is contained in:
fgenesis 2025-03-04 03:08:11 +01:00
parent 3a55777d63
commit 5eecf2d84c
2 changed files with 11 additions and 6 deletions

View file

@ -92,9 +92,12 @@ void* DynamicGPUBuffer::beginWrite(BufDataType type, size_t newsize, unsigned ac
glBindBufferARB(_gl_binding, id); glBindBufferARB(_gl_binding, id);
} }
if(!(access & GPUACCESS_HOSTCOPY)) if(!(access & GPUACCESS_HOSTCOPY))
{
if(_d_cap != newsize)
{ {
_d_cap = newsize; _d_cap = newsize;
glBufferDataARB(_gl_binding, newsize, NULL, _gl_usage); // orphan buffer glBufferDataARB(_gl_binding, newsize, NULL, _gl_usage); // orphan buffer
}
void *p = glMapBufferARB(_gl_binding, GL_WRITE_ONLY_ARB); void *p = glMapBufferARB(_gl_binding, GL_WRITE_ONLY_ARB);
_d_map = p; _d_map = p;
if(p) if(p)
@ -131,10 +134,8 @@ bool DynamicGPUBuffer::_commitWrite(size_t used)
if(_d_map) if(_d_map)
{ {
assert(used <= _d_cap); assert(used <= _d_cap);
bool ok = glUnmapBufferARB(_gl_binding); // can fail
if(ok)
_d_map = NULL; _d_map = NULL;
return ok; return glUnmapBufferARB(_gl_binding); // can fail
} }
// otherwise, the prev. call to glMapBufferARB failed (or GPUACCESS_HOSTCOPY was set). // otherwise, the prev. call to glMapBufferARB failed (or GPUACCESS_HOSTCOPY was set).
// -> didn't map, but wrote to host memory. upload it. // -> didn't map, but wrote to host memory. upload it.

View file

@ -82,6 +82,10 @@ public:
// Pass invert==true to draw from bottom to top. // Pass invert==true to draw from bottom to top.
size_t initGridIndices_Triangles(size_t w, size_t h, bool invert, unsigned access); size_t initGridIndices_Triangles(size_t w, size_t h, bool invert, unsigned access);
// For debugging only
inline unsigned _glBufferId() const { return _bufid; }
private: private:
void* _allocBytes(size_t bytes); void* _allocBytes(size_t bytes);