diff options
author | Oleg Evseev <ev.mipt@gmail.com> | 2016-04-30 01:06:30 +0300 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2016-08-13 15:37:44 +0000 |
commit | c818f3b70cdcac27b8aaff0b53a5790beebba9e7 (patch) | |
tree | ea746e0263df506362263e3e4c277bd447bcbacb /src/render/graphicshelpers/graphicscontext.cpp | |
parent | 8fed49011d501361e63aef7423a3939301ac8b6c (diff) |
Add partial data update support for QBuffer
Perform upadateData through queue of replacements specified by
QBufferUpdate: start position (offset) and QByteArray (replacing data)
Add example based on custom-mesh-cpp to show how updating data works.
Task-number: QTBUG-50720
Change-Id: I2eceb514af21209deb278d73c94773e39f300fb3
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/graphicshelpers/graphicscontext.cpp')
-rw-r--r-- | src/render/graphicshelpers/graphicscontext.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/render/graphicshelpers/graphicscontext.cpp b/src/render/graphicshelpers/graphicscontext.cpp index a44e7e98c..5169c8fb4 100644 --- a/src/render/graphicshelpers/graphicscontext.cpp +++ b/src/render/graphicshelpers/graphicscontext.cpp @@ -57,6 +57,7 @@ #include <Qt3DRender/private/buffermanager_p.h> #include <Qt3DRender/private/managers_p.h> #include <Qt3DRender/private/attachmentpack_p.h> +#include <Qt3DRender/private/qbuffer_p.h> #include <QOpenGLShaderProgram> #if !defined(QT_OPENGL_ES_2) @@ -1297,10 +1298,26 @@ void GraphicsContext::uploadDataToGLBuffer(Buffer *buffer, GLBuffer *b, bool rel { if (!bindGLBuffer(b, bufferTypeToGLBufferType(buffer->type()))) qCWarning(Render::Io) << Q_FUNC_INFO << "buffer bind failed"; - const int bufferSize = buffer->data().size(); - // TO DO: Handle usage pattern and sub data updates - b->allocate(this, bufferSize, false); // orphan the buffer - b->allocate(this, buffer->data().constData(), bufferSize, false); + // If the buffer is dirty (hence being called here) + // there are two possible cases + // * setData was called changing the whole data or functor (or the usage pattern) + // * partial buffer updates where received + + // Note: we assume the case where both setData/functor and updates are called to be a misuse + // with unexpected behavior + const QVector<Qt3DRender::QBufferUpdate> updates = std::move(buffer->pendingBufferUpdates()); + if (!updates.empty()) { + for (const Qt3DRender::QBufferUpdate &update : updates) { + // TO DO: based on the number of updates .., it might make sense to + // sometime use glMapBuffer rather than glBufferSubData + b->update(this, update.data.constData(), update.data.size(), update.offset); + } + } else { + const int bufferSize = buffer->data().size(); + // TO DO: Handle usage pattern + b->allocate(this, bufferSize, false); // orphan the buffer + b->allocate(this, buffer->data().constData(), bufferSize, false); + } if (releaseBuffer) { b->release(this); if (bufferTypeToGLBufferType(buffer->type()) == GLBuffer::ArrayBuffer) |