diff --git a/Aquaria/CurrentRender.cpp b/Aquaria/CurrentRender.cpp index 676c066..06b89fa 100644 --- a/Aquaria/CurrentRender.cpp +++ b/Aquaria/CurrentRender.cpp @@ -70,7 +70,11 @@ void CurrentRender::onUpdate(float dt) size_t usedsize; 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); usedsize = verts * 8 * sizeof(float); } @@ -109,9 +113,6 @@ size_t CurrentRender::writeVBOData(float *p) if (diff.isZero()) continue; - float len = diff.getLength2D(); - float texScale = len/256.0f; - if (isTouchingLine(p1, p2, dsq->screenCenter, dsq->cullRadius+w2)) { Vector pl = diff.getPerpendicularLeft(); @@ -132,6 +133,8 @@ size_t CurrentRender::writeVBOData(float *p) const float ao = P->animOffset; const float a = P->amount; + const float len = diff.getLength2D(); + const float texScale = len/256.0f; /* This builds a structure like this: a = 0 alpha diff --git a/BBGE/VertexBuffer.cpp b/BBGE/VertexBuffer.cpp index a063ece..ed0d303 100644 --- a/BBGE/VertexBuffer.cpp +++ b/BBGE/VertexBuffer.cpp @@ -141,12 +141,15 @@ bool DynamicGPUBuffer::_commitWrite(size_t used) // -> didn't map, but wrote to host memory. upload it. assert(_h_data); assert(used <= _h_cap); - if(used <= _d_cap) - glBufferSubDataARB(_gl_binding, 0, used, _h_data); // update existing buffer - else + if(used) { - _d_cap = used; - glBufferDataARB(_gl_binding, used, _h_data, _gl_usage); // alloc new buffer + if(used <= _d_cap) + glBufferSubDataARB(_gl_binding, 0, used, _h_data); // update existing buffer + else + { + _d_cap = used; + glBufferDataARB(_gl_binding, used, _h_data, _gl_usage); // alloc new buffer + } } } // else nothing to do @@ -168,6 +171,7 @@ void DynamicGPUBuffer::upload(BufDataType type, const void* data, size_t size) last = id; glBindBufferARB(_gl_binding, id); } + _d_cap = size; glBufferDataARB(_gl_binding, size, data, _gl_usage); } else