diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2016-06-23 10:37:03 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2016-07-05 08:00:21 +0000 |
commit | 8c745d808527684836d04da9014ee33c7cf8b6f1 (patch) | |
tree | 7f1ab16a2639f91afe153e1d897ed36ac091d446 /src/particles/qquickcustomparticle.cpp | |
parent | 5b470b6b6ad07975f9f9a56425a09b4827e87650 (diff) |
QtQuick: clean up shader effect property connections
- Don't use a signal mapper, but handle the mapping using a custom slot
object and a lambda to do the dispatching ourselves.
- Don't do meta-calls by property name, but by index.
- Cache the meta-object.
- Resolve the property indices by using the QML property cache.
For a shader with 6 property connections, the time spent goes from 320k
instructions to 80k instructions (valgrind on x86_64).
Task-number: QTBUG-53901
Change-Id: I2809198cf62f9716b3683798222203fc3e97fbb3
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
Diffstat (limited to 'src/particles/qquickcustomparticle.cpp')
-rw-r--r-- | src/particles/qquickcustomparticle.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/particles/qquickcustomparticle.cpp b/src/particles/qquickcustomparticle.cpp index a89b0d6a3b..8ee431aeb2 100644 --- a/src/particles/qquickcustomparticle.cpp +++ b/src/particles/qquickcustomparticle.cpp @@ -94,7 +94,8 @@ struct PlainVertices { QQuickCustomParticle::QQuickCustomParticle(QQuickItem* parent) : QQuickParticlePainter(parent) - , m_common(this) + , m_common(this, [this](int mappedId){this->propertyChanged(mappedId);}) + , m_myMetaObject(nullptr) , m_dirtyUniforms(true) , m_dirtyUniformValues(true) , m_dirtyTextureProviders(true) @@ -114,7 +115,10 @@ QQuickCustomParticle::~QQuickCustomParticle() void QQuickCustomParticle::componentComplete() { - m_common.updateShader(this, Key::FragmentShader); + if (!m_myMetaObject) + m_myMetaObject = metaObject(); + + m_common.updateShader(this, m_myMetaObject, Key::FragmentShader); updateVertexShader(); reset(); QQuickParticlePainter::componentComplete(); @@ -138,7 +142,7 @@ void QQuickCustomParticle::setFragmentShader(const QByteArray &code) m_common.source.sourceCode[Key::FragmentShader] = code; m_dirtyProgram = true; if (isComponentComplete()) { - m_common.updateShader(this, Key::FragmentShader); + m_common.updateShader(this, m_myMetaObject, Key::FragmentShader); reset(); } emit fragmentShaderChanged(); @@ -202,7 +206,6 @@ void QQuickCustomParticle::setVertexShader(const QByteArray &code) void QQuickCustomParticle::updateVertexShader() { m_common.disconnectPropertySignals(this, Key::VertexShader); - qDeleteAll(m_common.signalMappers[Key::VertexShader]); m_common.uniformData[Key::VertexShader].clear(); m_common.signalMappers[Key::VertexShader].clear(); m_common.attributes.clear(); @@ -225,9 +228,9 @@ void QQuickCustomParticle::updateVertexShader() const QByteArray &code = m_common.source.sourceCode[Key::VertexShader]; if (!code.isEmpty()) - m_common.lookThroughShaderCode(this, Key::VertexShader, code); + m_common.lookThroughShaderCode(this, m_myMetaObject, Key::VertexShader, code); - m_common.connectPropertySignals(this, Key::VertexShader); + m_common.connectPropertySignals(this, m_myMetaObject, Key::VertexShader); } void QQuickCustomParticle::reset() @@ -392,7 +395,7 @@ void QQuickCustomParticle::sourceDestroyed(QObject *object) void QQuickCustomParticle::propertyChanged(int mappedId) { bool textureProviderChanged; - m_common.propertyChanged(this, mappedId, &textureProviderChanged); + m_common.propertyChanged(this, m_myMetaObject, mappedId, &textureProviderChanged); m_dirtyTextureProviders |= textureProviderChanged; m_dirtyUniformValues = true; update(); |