From 96a7afec18542396f8e9a0b0f75d219a08725b3f Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 11 Apr 2016 16:06:39 +0200 Subject: Route ShaderEffect through the old GL impl Register the common QQuickShaderEffect class as ShaderEffect to QML. In case of GL this will route to QQuickOpenGLShaderEffect. For others the default no-op implementation is used (at least for now). Later this new implementation will route to a backend-specific scenegraph node via the adaptation layer. This also means that QQuickOpenGLShaderEffect is no longer a QQuickItem and QQuickShaderEffect must handle everything item-related and forward. Change-Id: I1ff4b674253543a04978a69f4a3b67f3a44dd983 Reviewed-by: Andy Nichols --- src/quick/items/qquickshadereffect.cpp | 137 +++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) (limited to 'src/quick/items/qquickshadereffect.cpp') diff --git a/src/quick/items/qquickshadereffect.cpp b/src/quick/items/qquickshadereffect.cpp index e604e80d96..71f5e56e32 100644 --- a/src/quick/items/qquickshadereffect.cpp +++ b/src/quick/items/qquickshadereffect.cpp @@ -38,6 +38,10 @@ ****************************************************************************/ #include +#include +#ifndef QT_NO_OPENGL +#include +#endif QT_BEGIN_NAMESPACE @@ -189,10 +193,19 @@ QT_BEGIN_NAMESPACE \sa {Item Layers} */ +QSGContextFactoryInterface::Flags qsg_backend_flags(); + QQuickShaderEffect::QQuickShaderEffect(QQuickItem *parent) : QQuickItem(parent) { setFlag(QQuickItem::ItemHasContents); + +#ifndef QT_NO_OPENGL + if (!qsg_backend_flags().testFlag(QSGContextFactoryInterface::SupportsShaderEffectV2)) + m_glImpl = new QQuickOpenGLShaderEffect(this, this); + else + m_glImpl = nullptr; +#endif } /*! @@ -206,11 +219,19 @@ QQuickShaderEffect::QQuickShaderEffect(QQuickItem *parent) QByteArray QQuickShaderEffect::fragmentShader() const { +#ifndef QT_NO_OPENGL + if (m_glImpl) + return m_glImpl->fragmentShader(); +#endif return QByteArray(); } void QQuickShaderEffect::setFragmentShader(const QByteArray &code) { +#ifndef QT_NO_OPENGL + if (m_glImpl) + m_glImpl->setFragmentShader(code); +#endif Q_UNUSED(code); } @@ -224,11 +245,19 @@ void QQuickShaderEffect::setFragmentShader(const QByteArray &code) QByteArray QQuickShaderEffect::vertexShader() const { +#ifndef QT_NO_OPENGL + if (m_glImpl) + return m_glImpl->vertexShader(); +#endif return QByteArray(); } void QQuickShaderEffect::setVertexShader(const QByteArray &code) { +#ifndef QT_NO_OPENGL + if (m_glImpl) + m_glImpl->setVertexShader(code); +#endif Q_UNUSED(code); } @@ -243,11 +272,19 @@ void QQuickShaderEffect::setVertexShader(const QByteArray &code) bool QQuickShaderEffect::blending() const { +#ifndef QT_NO_OPENGL + if (m_glImpl) + return m_glImpl->blending(); +#endif return true; } void QQuickShaderEffect::setBlending(bool enable) { +#ifndef QT_NO_OPENGL + if (m_glImpl) + m_glImpl->setBlending(enable); +#endif Q_UNUSED(enable); } @@ -266,11 +303,19 @@ void QQuickShaderEffect::setBlending(bool enable) QVariant QQuickShaderEffect::mesh() const { +#ifndef QT_NO_OPENGL + if (m_glImpl) + return m_glImpl->mesh(); +#endif return QVariant(); } void QQuickShaderEffect::setMesh(const QVariant &mesh) { +#ifndef QT_NO_OPENGL + if (m_glImpl) + m_glImpl->setMesh(mesh); +#endif Q_UNUSED(mesh); } @@ -290,11 +335,19 @@ void QQuickShaderEffect::setMesh(const QVariant &mesh) QQuickShaderEffect::CullMode QQuickShaderEffect::cullMode() const { +#ifndef QT_NO_OPENGL + if (m_glImpl) + return m_glImpl->cullMode(); +#endif return NoCulling; } void QQuickShaderEffect::setCullMode(CullMode face) { +#ifndef QT_NO_OPENGL + if (m_glImpl) + m_glImpl->setCullMode(face); +#endif Q_UNUSED(face); } @@ -321,11 +374,19 @@ void QQuickShaderEffect::setCullMode(CullMode face) bool QQuickShaderEffect::supportsAtlasTextures() const { +#ifndef QT_NO_OPENGL + if (m_glImpl) + return m_glImpl->supportsAtlasTextures(); +#endif return false; } void QQuickShaderEffect::setSupportsAtlasTextures(bool supports) { +#ifndef QT_NO_OPENGL + if (m_glImpl) + m_glImpl->setSupportsAtlasTextures(supports); +#endif Q_UNUSED(supports); } @@ -359,12 +420,88 @@ void QQuickShaderEffect::setSupportsAtlasTextures(bool supports) QString QQuickShaderEffect::log() const { +#ifndef QT_NO_OPENGL + if (m_glImpl) + return m_glImpl->log(); +#endif return QString(); } QQuickShaderEffect::Status QQuickShaderEffect::status() const { +#ifndef QT_NO_OPENGL + if (m_glImpl) + return m_glImpl->status(); +#endif return Uncompiled; } +bool QQuickShaderEffect::event(QEvent *e) +{ +#ifndef QT_NO_OPENGL + if (m_glImpl) + m_glImpl->handleEvent(e); +#endif + return QQuickItem::event(e); +} + +void QQuickShaderEffect::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ +#ifndef QT_NO_OPENGL + if (m_glImpl) + m_glImpl->handleGeometryChanged(newGeometry, oldGeometry); +#endif + QQuickItem::geometryChanged(newGeometry, oldGeometry); +} + +QSGNode *QQuickShaderEffect::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) +{ +#ifndef QT_NO_OPENGL + if (m_glImpl) + return m_glImpl->handleUpdatePaintNode(oldNode, updatePaintNodeData); +#endif + return nullptr; +} + +void QQuickShaderEffect::componentComplete() +{ +#ifndef QT_NO_OPENGL + if (m_glImpl) + m_glImpl->handleComponentComplete(); +#endif + QQuickItem::componentComplete(); +} + +void QQuickShaderEffect::itemChange(ItemChange change, const ItemChangeData &value) +{ +#ifndef QT_NO_OPENGL + if (m_glImpl) + m_glImpl->handleItemChange(change, value); +#endif + QQuickItem::itemChange(change, value); +} + +bool QQuickShaderEffect::isComponentComplete() const +{ + return QQuickItem::isComponentComplete(); +} + +void QQuickShaderEffect::sourceDestroyed(QObject *object) +{ +#ifndef QT_NO_OPENGL + if (m_glImpl) + m_glImpl->handleSourceDestroyed(object); +#endif + Q_UNUSED(object); +} + +void QQuickShaderEffect::propertyChanged(int mappedId) +{ +#ifndef QT_NO_OPENGL + if (m_glImpl) + m_glImpl->handlePropertyChanged(mappedId); +#endif + Q_UNUSED(mappedId); +} + QT_END_NAMESPACE -- cgit v1.2.3