summaryrefslogtreecommitdiffstats
path: root/src/render/backend/rendershaderdata.cpp
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire.ecortex@kdab.com>2014-11-24 07:39:26 +0100
committerSean Harmer <sean.harmer@kdab.com>2014-12-12 14:17:28 +0100
commit9fe16cad683cac7fa7f13e39e8168b1cefd193fc (patch)
tree213f04e1744e2a119c0880a6ef9190b7e4ce9dac /src/render/backend/rendershaderdata.cpp
parentc1d0e22c9d061f0fdbffed2e88da2961258b6cdd (diff)
RenderShaderData: update UBO uniform by uniform
Instead of updating the whole UBO at once, we keep track of the QShaderData/member in the uniform block that have changed and upload only the buffer from the uniform offset to uniform offset + size. Change-Id: Ib69302183b17dbe15985b405406c8fed88c022bb Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/backend/rendershaderdata.cpp')
-rw-r--r--src/render/backend/rendershaderdata.cpp31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/render/backend/rendershaderdata.cpp b/src/render/backend/rendershaderdata.cpp
index 8f02635e8..63db21bea 100644
--- a/src/render/backend/rendershaderdata.cpp
+++ b/src/render/backend/rendershaderdata.cpp
@@ -93,20 +93,34 @@ void RenderShaderData::appendActiveProperty(const QString &propertyName, const S
void RenderShaderData::updateUniformBuffer(QGraphicsContext *ctx)
{
+ const QHash<QString, ShaderUniform>::const_iterator uniformsEnd = m_activeProperties.end();
+ QHash<QString, ShaderUniform>::const_iterator uniformsIt = m_activeProperties.begin();
+
if (!m_ubo.isCreated()) {
m_ubo.create(ctx);
m_ubo.allocate(ctx, m_block.m_size);
+ // We need to fill the UBO the first time it is created
+ while (uniformsIt != uniformsEnd) {
+ ctx->buildUniformBuffer(m_properties.value(uniformsIt.key()), uniformsIt.value(), m_data);
+ ++uniformsIt;
+ }
+ // Upload the whole buffer to GPU for the first time
+ m_ubo.update(ctx, m_data.constData(), m_block.m_size);
}
- // TO DO: Only update values that have changed rather than the whole buffer
- QHash<QString, ShaderUniform>::const_iterator uniformsIt = m_activeProperties.begin();
- const QHash<QString, ShaderUniform>::const_iterator uniformsEnd = m_activeProperties.end();
-
- while (uniformsIt != uniformsEnd) {
- ctx->buildUniformBuffer(m_properties.value(uniformsIt.key()), uniformsIt.value(), m_data);
- ++uniformsIt;
+ Q_FOREACH (const QString &property, m_updatedProperties) {
+ uniformsIt = m_activeProperties.begin();
+ while (uniformsIt != uniformsEnd) {
+ if (uniformsIt.key() == property) {
+ // Update CPU side sub buffer
+ ctx->buildUniformBuffer(m_properties.value(uniformsIt.key()), uniformsIt.value(), m_data);
+ // Upload sub buffer to GPU
+ m_ubo.update(ctx, m_data.constData() + uniformsIt.value().m_offset, uniformsIt.value().m_rawByteSize, uniformsIt.value().m_offset);
+ }
+ ++uniformsIt;
+ }
}
- m_ubo.update(ctx, m_data.constData(), m_block.m_size);
+ m_updatedProperties.clear();
}
// Make sure QGraphicsContext::bindUniformBlock is called prior to this
@@ -127,6 +141,7 @@ void RenderShaderData::sceneChangeEvent(const QSceneChangePtr &e)
QString propertyName = QString::fromLatin1(propertyChange->propertyName());
if (m_properties.contains(propertyName)) {
m_properties.insert(propertyName, propertyChange->value());
+ m_updatedProperties.append(propertyName);
m_needsBufferUpdate = true;
}
}