Add the skeleton for the new, more generic shader effect impl

which should route and place most of its work into the scenegraph.

And fix a test.

Change-Id: I04f29cba53c2bab62e41b3b524794d3c4d20a472
Reviewed-by: Andy Nichols <andy.nichols@theqtcompany.com>
This commit is contained in:
Laszlo Agocs 2016-04-12 12:12:30 +02:00
parent 3d2b9ef7ec
commit b943809c41
9 changed files with 333 additions and 80 deletions

View File

@ -94,6 +94,7 @@ struct PlainVertices {
QQuickCustomParticle::QQuickCustomParticle(QQuickItem* parent) QQuickCustomParticle::QQuickCustomParticle(QQuickItem* parent)
: QQuickParticlePainter(parent) : QQuickParticlePainter(parent)
, m_common(this)
, m_dirtyUniforms(true) , m_dirtyUniforms(true)
, m_dirtyUniformValues(true) , m_dirtyUniformValues(true)
, m_dirtyTextureProviders(true) , m_dirtyTextureProviders(true)

View File

@ -75,6 +75,7 @@ HEADERS += \
$$PWD/qquickshadereffectsource_p.h \ $$PWD/qquickshadereffectsource_p.h \
$$PWD/qquickshadereffectmesh_p.h \ $$PWD/qquickshadereffectmesh_p.h \
$$PWD/qquickshadereffect_p.h \ $$PWD/qquickshadereffect_p.h \
$$PWD/qquickgenericshadereffect_p.h \
$$PWD/qquickrendercontrol.h \ $$PWD/qquickrendercontrol.h \
$$PWD/qquickrendercontrol_p.h $$PWD/qquickrendercontrol_p.h
@ -128,6 +129,7 @@ SOURCES += \
$$PWD/qquickshadereffectsource.cpp \ $$PWD/qquickshadereffectsource.cpp \
$$PWD/qquickshadereffectmesh.cpp \ $$PWD/qquickshadereffectmesh.cpp \
$$PWD/qquickshadereffect.cpp \ $$PWD/qquickshadereffect.cpp \
$$PWD/qquickgenericshadereffect.cpp \
$$PWD/qquickrendercontrol.cpp $$PWD/qquickrendercontrol.cpp
# Items that depend on OpenGL Renderer # Items that depend on OpenGL Renderer

View File

@ -0,0 +1,127 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <private/qquickgenericshadereffect_p.h>
QT_BEGIN_NAMESPACE
// The generic shader effect is used when the scenegraph backend indicates
// SupportsShaderEffectV2. This, unlike the monolithic and interconnected (e.g.
// with particles) OpenGL variant, passes most of the work to a scenegraph node
// created via the adaptation layer, thus allowing different implementation in
// the backends.
QQuickGenericShaderEffect::QQuickGenericShaderEffect(QQuickShaderEffect *item, QObject *parent)
: QObject(parent)
, m_item(item)
, m_meshResolution(1, 1)
, m_mesh(0)
, m_cullMode(QQuickShaderEffect::NoCulling)
, m_status(QQuickShaderEffect::Uncompiled)
, m_blending(true)
, m_supportsAtlasTextures(false)
{
}
QQuickGenericShaderEffect::~QQuickGenericShaderEffect()
{
}
void QQuickGenericShaderEffect::setFragmentShader(const QByteArray &code)
{
Q_UNUSED(code);
}
void QQuickGenericShaderEffect::setVertexShader(const QByteArray &code)
{
Q_UNUSED(code);
}
void QQuickGenericShaderEffect::setBlending(bool enable)
{
Q_UNUSED(enable);
}
QVariant QQuickGenericShaderEffect::mesh() const
{
return m_mesh ? qVariantFromValue(static_cast<QObject *>(m_mesh))
: qVariantFromValue(m_meshResolution);
}
void QQuickGenericShaderEffect::setMesh(const QVariant &mesh)
{
Q_UNUSED(mesh);
}
void QQuickGenericShaderEffect::setCullMode(QQuickShaderEffect::CullMode face)
{
Q_UNUSED(face);
}
void QQuickGenericShaderEffect::setSupportsAtlasTextures(bool supports)
{
Q_UNUSED(supports);
}
void QQuickGenericShaderEffect::handleEvent(QEvent *event)
{
Q_UNUSED(event);
}
void QQuickGenericShaderEffect::handleGeometryChanged(const QRectF &, const QRectF &)
{
}
QSGNode *QQuickGenericShaderEffect::handleUpdatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *)
{
Q_UNUSED(oldNode);
return nullptr;
}
void QQuickGenericShaderEffect::handleComponentComplete()
{
}
void QQuickGenericShaderEffect::handleItemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value)
{
Q_UNUSED(change);
Q_UNUSED(value);
}
QT_END_NAMESPACE

View File

@ -0,0 +1,113 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QQUICKGENERICSHADEREFFECT_P_H
#define QQUICKGENERICSHADEREFFECT_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtQuick/qquickitem.h>
#include <private/qtquickglobal_p.h>
#include "qquickshadereffect_p.h"
#include "qquickshadereffectmesh_p.h"
QT_BEGIN_NAMESPACE
class Q_QUICK_PRIVATE_EXPORT QQuickGenericShaderEffect : public QObject
{
Q_OBJECT
public:
QQuickGenericShaderEffect(QQuickShaderEffect *item, QObject *parent = 0);
~QQuickGenericShaderEffect();
QByteArray fragmentShader() const { return QByteArray(); }
void setFragmentShader(const QByteArray &code);
QByteArray vertexShader() const { return QByteArray(); }
void setVertexShader(const QByteArray &code);
bool blending() const { return m_blending; }
void setBlending(bool enable);
QVariant mesh() const;
void setMesh(const QVariant &mesh);
QQuickShaderEffect::CullMode cullMode() const { return m_cullMode; }
void setCullMode(QQuickShaderEffect::CullMode face);
QString log() const { return m_log; }
QQuickShaderEffect::Status status() const { return m_status; }
bool supportsAtlasTextures() const { return m_supportsAtlasTextures; }
void setSupportsAtlasTextures(bool supports);
void handleEvent(QEvent *);
void handleGeometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
QSGNode *handleUpdatePaintNode(QSGNode *, QQuickItem::UpdatePaintNodeData *);
void handleComponentComplete();
void handleItemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value);
QString parseLog() { return QString(); }
private:
QQuickShaderEffect *m_item;
QSize m_meshResolution;
QQuickShaderEffectMesh *m_mesh;
QQuickGridMesh m_defaultMesh;
QQuickShaderEffect::CullMode m_cullMode;
QString m_log;
QQuickShaderEffect::Status m_status;
uint m_blending : 1;
uint m_supportsAtlasTextures : 1;
};
QT_END_NAMESPACE
#endif // QQUICKGENERICSHADEREFFECT_P_H

View File

@ -193,13 +193,13 @@ void QQuickOpenGLShaderEffectCommon::disconnectPropertySignals(QQuickItem *item,
const UniformData &d = uniformData[shaderType].at(i); const UniformData &d = uniformData[shaderType].at(i);
QSignalMapper *mapper = signalMappers[shaderType].at(i); QSignalMapper *mapper = signalMappers[shaderType].at(i);
QObject::disconnect(item, 0, mapper, SLOT(map())); QObject::disconnect(item, 0, mapper, SLOT(map()));
QObject::disconnect(mapper, SIGNAL(mapped(int)), item, SLOT(propertyChanged(int))); QObject::disconnect(mapper, SIGNAL(mapped(int)), host, SLOT(propertyChanged(int)));
if (d.specialType == UniformData::Sampler) { if (d.specialType == UniformData::Sampler) {
QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value)); QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value));
if (source) { if (source) {
if (item->window()) if (item->window())
QQuickItemPrivate::get(source)->derefWindow(); QQuickItemPrivate::get(source)->derefWindow();
QObject::disconnect(source, SIGNAL(destroyed(QObject*)), item, SLOT(sourceDestroyed(QObject*))); QObject::disconnect(source, SIGNAL(destroyed(QObject*)), host, SLOT(sourceDestroyed(QObject*)));
} }
} }
} }
@ -219,7 +219,7 @@ void QQuickOpenGLShaderEffectCommon::connectPropertySignals(QQuickItem *item, Ke
const QByteArray signalName = '2' + mp.notifySignal().methodSignature(); const QByteArray signalName = '2' + mp.notifySignal().methodSignature();
QSignalMapper *mapper = signalMappers[shaderType].at(i); QSignalMapper *mapper = signalMappers[shaderType].at(i);
QObject::connect(item, signalName, mapper, SLOT(map())); QObject::connect(item, signalName, mapper, SLOT(map()));
QObject::connect(mapper, SIGNAL(mapped(int)), item, SLOT(propertyChanged(int))); QObject::connect(mapper, SIGNAL(mapped(int)), host, SLOT(propertyChanged(int)));
} else { } else {
// If the source is set via a dynamic property, like the layer is, then we need this // If the source is set via a dynamic property, like the layer is, then we need this
// check to disable the warning. // check to disable the warning.
@ -232,7 +232,7 @@ void QQuickOpenGLShaderEffectCommon::connectPropertySignals(QQuickItem *item, Ke
if (source) { if (source) {
if (item->window()) if (item->window())
QQuickItemPrivate::get(source)->refWindow(item->window()); QQuickItemPrivate::get(source)->refWindow(item->window());
QObject::connect(source, SIGNAL(destroyed(QObject*)), item, SLOT(sourceDestroyed(QObject*))); QObject::connect(source, SIGNAL(destroyed(QObject*)), host, SLOT(sourceDestroyed(QObject*)));
} }
} }
} }
@ -499,7 +499,7 @@ void QQuickOpenGLShaderEffectCommon::propertyChanged(QQuickItem *item, int mappe
// would trigger both to be disconnected. Without the connection we'll end up // would trigger both to be disconnected. Without the connection we'll end up
// with a dangling pointer in the uniformData. // with a dangling pointer in the uniformData.
if (qquick_uniqueInUniformData(source, uniformData, shaderType, index)) if (qquick_uniqueInUniformData(source, uniformData, shaderType, index))
QObject::disconnect(source, SIGNAL(destroyed(QObject*)), item, SLOT(sourceDestroyed(QObject*))); QObject::disconnect(source, SIGNAL(destroyed(QObject*)), host, SLOT(sourceDestroyed(QObject*)));
} }
d.value = item->property(d.name.constData()); d.value = item->property(d.name.constData());
@ -512,7 +512,7 @@ void QQuickOpenGLShaderEffectCommon::propertyChanged(QQuickItem *item, int mappe
// will not get a parent. In those cases, 'source' should get the window from 'item'. // will not get a parent. In those cases, 'source' should get the window from 'item'.
if (item->window()) if (item->window())
QQuickItemPrivate::get(source)->refWindow(item->window()); QQuickItemPrivate::get(source)->refWindow(item->window());
QObject::connect(source, SIGNAL(destroyed(QObject*)), item, SLOT(sourceDestroyed(QObject*))); QObject::connect(source, SIGNAL(destroyed(QObject*)), host, SLOT(sourceDestroyed(QObject*)));
} }
if (textureProviderChanged) if (textureProviderChanged)
*textureProviderChanged = true; *textureProviderChanged = true;
@ -530,6 +530,7 @@ QQuickOpenGLShaderEffect::QQuickOpenGLShaderEffect(QQuickShaderEffect *item, QOb
, m_mesh(0) , m_mesh(0)
, m_cullMode(QQuickShaderEffect::NoCulling) , m_cullMode(QQuickShaderEffect::NoCulling)
, m_status(QQuickShaderEffect::Uncompiled) , m_status(QQuickShaderEffect::Uncompiled)
, m_common(this)
, m_blending(true) , m_blending(true)
, m_dirtyUniforms(true) , m_dirtyUniforms(true)
, m_dirtyUniformValues(true) , m_dirtyUniformValues(true)
@ -563,9 +564,9 @@ void QQuickOpenGLShaderEffect::setFragmentShader(const QByteArray &code)
m_item->update(); m_item->update();
if (m_status != QQuickShaderEffect::Uncompiled) { if (m_status != QQuickShaderEffect::Uncompiled) {
m_status = QQuickShaderEffect::Uncompiled; m_status = QQuickShaderEffect::Uncompiled;
emit statusChanged(); emit m_item->statusChanged();
} }
emit fragmentShaderChanged(); emit m_item->fragmentShaderChanged();
} }
void QQuickOpenGLShaderEffect::setVertexShader(const QByteArray &code) void QQuickOpenGLShaderEffect::setVertexShader(const QByteArray &code)
@ -583,9 +584,9 @@ void QQuickOpenGLShaderEffect::setVertexShader(const QByteArray &code)
m_item->update(); m_item->update();
if (m_status != QQuickShaderEffect::Uncompiled) { if (m_status != QQuickShaderEffect::Uncompiled) {
m_status = QQuickShaderEffect::Uncompiled; m_status = QQuickShaderEffect::Uncompiled;
emit statusChanged(); emit m_item->statusChanged();
} }
emit vertexShaderChanged(); emit m_item->vertexShaderChanged();
} }
void QQuickOpenGLShaderEffect::setBlending(bool enable) void QQuickOpenGLShaderEffect::setBlending(bool enable)
@ -596,7 +597,7 @@ void QQuickOpenGLShaderEffect::setBlending(bool enable)
m_blending = enable; m_blending = enable;
m_item->update(); m_item->update();
emit blendingChanged(); emit m_item->blendingChanged();
} }
QVariant QQuickOpenGLShaderEffect::mesh() const QVariant QQuickOpenGLShaderEffect::mesh() const
@ -638,7 +639,7 @@ void QQuickOpenGLShaderEffect::setMesh(const QVariant &mesh)
m_dirtyMesh = true; m_dirtyMesh = true;
m_dirtyParseLog = true; m_dirtyParseLog = true;
m_item->update(); m_item->update();
emit meshChanged(); emit m_item->meshChanged();
} }
void QQuickOpenGLShaderEffect::setCullMode(QQuickShaderEffect::CullMode face) void QQuickOpenGLShaderEffect::setCullMode(QQuickShaderEffect::CullMode face)
@ -647,7 +648,7 @@ void QQuickOpenGLShaderEffect::setCullMode(QQuickShaderEffect::CullMode face)
return; return;
m_cullMode = face; m_cullMode = face;
m_item->update(); m_item->update();
emit cullModeChanged(); emit m_item->cullModeChanged();
} }
void QQuickOpenGLShaderEffect::setSupportsAtlasTextures(bool supports) void QQuickOpenGLShaderEffect::setSupportsAtlasTextures(bool supports)
@ -656,7 +657,7 @@ void QQuickOpenGLShaderEffect::setSupportsAtlasTextures(bool supports)
return; return;
m_supportsAtlasTextures = supports; m_supportsAtlasTextures = supports;
updateGeometry(); updateGeometry();
emit supportsAtlasTexturesChanged(); emit m_item->supportsAtlasTexturesChanged();
} }
QString QQuickOpenGLShaderEffect::parseLog() QString QQuickOpenGLShaderEffect::parseLog()
@ -702,16 +703,16 @@ void QQuickOpenGLShaderEffect::updateLogAndStatus(const QString &log, int status
{ {
m_log = parseLog() + log; m_log = parseLog() + log;
m_status = QQuickShaderEffect::Status(status); m_status = QQuickShaderEffect::Status(status);
emit logChanged(); emit m_item->logChanged();
emit statusChanged(); emit m_item->statusChanged();
} }
void QQuickOpenGLShaderEffect::handleSourceDestroyed(QObject *object) void QQuickOpenGLShaderEffect::sourceDestroyed(QObject *object)
{ {
m_common.sourceDestroyed(object); m_common.sourceDestroyed(object);
} }
void QQuickOpenGLShaderEffect::handlePropertyChanged(int mappedId) void QQuickOpenGLShaderEffect::propertyChanged(int mappedId)
{ {
bool textureProviderChanged; bool textureProviderChanged;
m_common.propertyChanged(m_item, mappedId, &textureProviderChanged); m_common.propertyChanged(m_item, mappedId, &textureProviderChanged);
@ -829,8 +830,8 @@ QSGNode *QQuickOpenGLShaderEffect::handleUpdatePaintNode(QSGNode *oldNode, QQuic
m_log += QLatin1String("*** Mesh ***\n"); m_log += QLatin1String("*** Mesh ***\n");
m_log += log; m_log += log;
m_status = QQuickShaderEffect::Error; m_status = QQuickShaderEffect::Error;
emit logChanged(); emit m_item->logChanged();
emit statusChanged(); emit m_item->statusChanged();
} }
delete node; delete node;
return 0; return 0;

View File

@ -74,6 +74,7 @@ struct Q_QUICK_PRIVATE_EXPORT QQuickOpenGLShaderEffectCommon
typedef QQuickOpenGLShaderEffectMaterialKey Key; typedef QQuickOpenGLShaderEffectMaterialKey Key;
typedef QQuickOpenGLShaderEffectMaterial::UniformData UniformData; typedef QQuickOpenGLShaderEffectMaterial::UniformData UniformData;
QQuickOpenGLShaderEffectCommon(QObject *host) : host(host) { }
~QQuickOpenGLShaderEffectCommon(); ~QQuickOpenGLShaderEffectCommon();
void disconnectPropertySignals(QQuickItem *item, Key::ShaderType shaderType); void disconnectPropertySignals(QQuickItem *item, Key::ShaderType shaderType);
void connectPropertySignals(QQuickItem *item, Key::ShaderType shaderType); void connectPropertySignals(QQuickItem *item, Key::ShaderType shaderType);
@ -88,6 +89,7 @@ struct Q_QUICK_PRIVATE_EXPORT QQuickOpenGLShaderEffectCommon
void sourceDestroyed(QObject *object); void sourceDestroyed(QObject *object);
void propertyChanged(QQuickItem *item, int mappedId, bool *textureProviderChanged); void propertyChanged(QQuickItem *item, int mappedId, bool *textureProviderChanged);
QObject *host;
Key source; Key source;
QVector<QByteArray> attributes; QVector<QByteArray> attributes;
QVector<UniformData> uniformData[Key::ShaderTypeCount]; QVector<UniformData> uniformData[Key::ShaderTypeCount];
@ -127,29 +129,18 @@ public:
QString parseLog(); QString parseLog();
Q_SIGNALS:
void fragmentShaderChanged();
void vertexShaderChanged();
void blendingChanged();
void meshChanged();
void cullModeChanged();
void logChanged();
void statusChanged();
void supportsAtlasTexturesChanged();
protected:
void handleEvent(QEvent *); void handleEvent(QEvent *);
void handleGeometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); void handleGeometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
QSGNode *handleUpdatePaintNode(QSGNode *, QQuickItem::UpdatePaintNodeData *); QSGNode *handleUpdatePaintNode(QSGNode *, QQuickItem::UpdatePaintNodeData *);
void handleComponentComplete(); void handleComponentComplete();
void handleItemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value); void handleItemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value);
void handleSourceDestroyed(QObject *object);
void handlePropertyChanged(int mappedId);
private Q_SLOTS: private Q_SLOTS:
void updateGeometry(); void updateGeometry();
void updateGeometryIfAtlased(); void updateGeometryIfAtlased();
void updateLogAndStatus(const QString &log, int status); void updateLogAndStatus(const QString &log, int status);
void sourceDestroyed(QObject *object);
void propertyChanged(int mappedId);
private: private:
friend class QQuickCustomMaterialShader; friend class QQuickCustomMaterialShader;
@ -178,8 +169,6 @@ private:
uint m_dirtyGeometry : 1; uint m_dirtyGeometry : 1;
uint m_customVertexShader : 1; uint m_customVertexShader : 1;
uint m_supportsAtlasTextures : 1; uint m_supportsAtlasTextures : 1;
friend class QQuickShaderEffect;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -42,6 +42,7 @@
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
#include <private/qquickopenglshadereffect_p.h> #include <private/qquickopenglshadereffect_p.h>
#endif #endif
#include <private/qquickgenericshadereffect_p.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -196,16 +197,18 @@ QT_BEGIN_NAMESPACE
QSGContextFactoryInterface::Flags qsg_backend_flags(); QSGContextFactoryInterface::Flags qsg_backend_flags();
QQuickShaderEffect::QQuickShaderEffect(QQuickItem *parent) QQuickShaderEffect::QQuickShaderEffect(QQuickItem *parent)
: QQuickItem(parent) : QQuickItem(parent),
m_glImpl(nullptr),
m_impl(nullptr)
{ {
setFlag(QQuickItem::ItemHasContents); setFlag(QQuickItem::ItemHasContents);
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
if (!qsg_backend_flags().testFlag(QSGContextFactoryInterface::SupportsShaderEffectV2)) if (!qsg_backend_flags().testFlag(QSGContextFactoryInterface::SupportsShaderEffectV2))
m_glImpl = new QQuickOpenGLShaderEffect(this, this); m_glImpl = new QQuickOpenGLShaderEffect(this, this);
else
m_glImpl = nullptr;
#endif #endif
if (!m_glImpl)
m_impl = new QQuickGenericShaderEffect(this, this);
} }
/*! /*!
@ -223,16 +226,18 @@ QByteArray QQuickShaderEffect::fragmentShader() const
if (m_glImpl) if (m_glImpl)
return m_glImpl->fragmentShader(); return m_glImpl->fragmentShader();
#endif #endif
return QByteArray(); return m_impl->fragmentShader();
} }
void QQuickShaderEffect::setFragmentShader(const QByteArray &code) void QQuickShaderEffect::setFragmentShader(const QByteArray &code)
{ {
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
if (m_glImpl) if (m_glImpl) {
m_glImpl->setFragmentShader(code); m_glImpl->setFragmentShader(code);
return;
}
#endif #endif
Q_UNUSED(code); m_impl->setFragmentShader(code);
} }
/*! /*!
@ -249,16 +254,18 @@ QByteArray QQuickShaderEffect::vertexShader() const
if (m_glImpl) if (m_glImpl)
return m_glImpl->vertexShader(); return m_glImpl->vertexShader();
#endif #endif
return QByteArray(); return m_impl->vertexShader();
} }
void QQuickShaderEffect::setVertexShader(const QByteArray &code) void QQuickShaderEffect::setVertexShader(const QByteArray &code)
{ {
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
if (m_glImpl) if (m_glImpl) {
m_glImpl->setVertexShader(code); m_glImpl->setVertexShader(code);
return;
}
#endif #endif
Q_UNUSED(code); m_impl->setVertexShader(code);
} }
/*! /*!
@ -276,16 +283,18 @@ bool QQuickShaderEffect::blending() const
if (m_glImpl) if (m_glImpl)
return m_glImpl->blending(); return m_glImpl->blending();
#endif #endif
return true; return m_impl->blending();
} }
void QQuickShaderEffect::setBlending(bool enable) void QQuickShaderEffect::setBlending(bool enable)
{ {
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
if (m_glImpl) if (m_glImpl) {
m_glImpl->setBlending(enable); m_glImpl->setBlending(enable);
return;
}
#endif #endif
Q_UNUSED(enable); m_impl->setBlending(enable);
} }
/*! /*!
@ -307,16 +316,18 @@ QVariant QQuickShaderEffect::mesh() const
if (m_glImpl) if (m_glImpl)
return m_glImpl->mesh(); return m_glImpl->mesh();
#endif #endif
return QVariant(); return m_impl->mesh();
} }
void QQuickShaderEffect::setMesh(const QVariant &mesh) void QQuickShaderEffect::setMesh(const QVariant &mesh)
{ {
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
if (m_glImpl) if (m_glImpl) {
m_glImpl->setMesh(mesh); m_glImpl->setMesh(mesh);
return;
}
#endif #endif
Q_UNUSED(mesh); m_impl->setMesh(mesh);
} }
/*! /*!
@ -339,16 +350,18 @@ QQuickShaderEffect::CullMode QQuickShaderEffect::cullMode() const
if (m_glImpl) if (m_glImpl)
return m_glImpl->cullMode(); return m_glImpl->cullMode();
#endif #endif
return NoCulling; return m_impl->cullMode();
} }
void QQuickShaderEffect::setCullMode(CullMode face) void QQuickShaderEffect::setCullMode(CullMode face)
{ {
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
if (m_glImpl) if (m_glImpl) {
m_glImpl->setCullMode(face); m_glImpl->setCullMode(face);
return;
}
#endif #endif
Q_UNUSED(face); return m_impl->setCullMode(face);
} }
/*! /*!
@ -378,16 +391,18 @@ bool QQuickShaderEffect::supportsAtlasTextures() const
if (m_glImpl) if (m_glImpl)
return m_glImpl->supportsAtlasTextures(); return m_glImpl->supportsAtlasTextures();
#endif #endif
return false; return m_impl->supportsAtlasTextures();
} }
void QQuickShaderEffect::setSupportsAtlasTextures(bool supports) void QQuickShaderEffect::setSupportsAtlasTextures(bool supports)
{ {
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
if (m_glImpl) if (m_glImpl) {
m_glImpl->setSupportsAtlasTextures(supports); m_glImpl->setSupportsAtlasTextures(supports);
return;
}
#endif #endif
Q_UNUSED(supports); m_impl->setSupportsAtlasTextures(supports);
} }
/*! /*!
@ -424,7 +439,7 @@ QString QQuickShaderEffect::log() const
if (m_glImpl) if (m_glImpl)
return m_glImpl->log(); return m_glImpl->log();
#endif #endif
return QString(); return m_impl->log();
} }
QQuickShaderEffect::Status QQuickShaderEffect::status() const QQuickShaderEffect::Status QQuickShaderEffect::status() const
@ -433,24 +448,31 @@ QQuickShaderEffect::Status QQuickShaderEffect::status() const
if (m_glImpl) if (m_glImpl)
return m_glImpl->status(); return m_glImpl->status();
#endif #endif
return Uncompiled; return m_impl->status();
} }
bool QQuickShaderEffect::event(QEvent *e) bool QQuickShaderEffect::event(QEvent *e)
{ {
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
if (m_glImpl) if (m_glImpl) {
m_glImpl->handleEvent(e); m_glImpl->handleEvent(e);
return QQuickItem::event(e);
}
#endif #endif
m_impl->handleEvent(e);
return QQuickItem::event(e); return QQuickItem::event(e);
} }
void QQuickShaderEffect::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) void QQuickShaderEffect::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{ {
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
if (m_glImpl) if (m_glImpl) {
m_glImpl->handleGeometryChanged(newGeometry, oldGeometry); m_glImpl->handleGeometryChanged(newGeometry, oldGeometry);
QQuickItem::geometryChanged(newGeometry, oldGeometry);
return;
}
#endif #endif
m_impl->handleGeometryChanged(newGeometry, oldGeometry);
QQuickItem::geometryChanged(newGeometry, oldGeometry); QQuickItem::geometryChanged(newGeometry, oldGeometry);
} }
@ -460,24 +482,32 @@ QSGNode *QQuickShaderEffect::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDa
if (m_glImpl) if (m_glImpl)
return m_glImpl->handleUpdatePaintNode(oldNode, updatePaintNodeData); return m_glImpl->handleUpdatePaintNode(oldNode, updatePaintNodeData);
#endif #endif
return nullptr; return m_impl->handleUpdatePaintNode(oldNode, updatePaintNodeData);
} }
void QQuickShaderEffect::componentComplete() void QQuickShaderEffect::componentComplete()
{ {
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
if (m_glImpl) if (m_glImpl) {
m_glImpl->handleComponentComplete(); m_glImpl->handleComponentComplete();
QQuickItem::componentComplete();
return;
}
#endif #endif
m_impl->handleComponentComplete();
QQuickItem::componentComplete(); QQuickItem::componentComplete();
} }
void QQuickShaderEffect::itemChange(ItemChange change, const ItemChangeData &value) void QQuickShaderEffect::itemChange(ItemChange change, const ItemChangeData &value)
{ {
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
if (m_glImpl) if (m_glImpl) {
m_glImpl->handleItemChange(change, value); m_glImpl->handleItemChange(change, value);
QQuickItem::itemChange(change, value);
return;
}
#endif #endif
m_impl->handleItemChange(change, value);
QQuickItem::itemChange(change, value); QQuickItem::itemChange(change, value);
} }
@ -486,22 +516,13 @@ bool QQuickShaderEffect::isComponentComplete() const
return QQuickItem::isComponentComplete(); return QQuickItem::isComponentComplete();
} }
void QQuickShaderEffect::sourceDestroyed(QObject *object) QString QQuickShaderEffect::parseLog()
{ {
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
if (m_glImpl) if (m_glImpl)
m_glImpl->handleSourceDestroyed(object); return m_glImpl->parseLog();
#endif #endif
Q_UNUSED(object); return m_impl->parseLog();
}
void QQuickShaderEffect::propertyChanged(int mappedId)
{
#ifndef QT_NO_OPENGL
if (m_glImpl)
m_glImpl->handlePropertyChanged(mappedId);
#endif
Q_UNUSED(mappedId);
} }
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -57,6 +57,7 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QQuickOpenGLShaderEffect; class QQuickOpenGLShaderEffect;
class QQuickGenericShaderEffect;
class Q_QUICK_PRIVATE_EXPORT QQuickShaderEffect : public QQuickItem class Q_QUICK_PRIVATE_EXPORT QQuickShaderEffect : public QQuickItem
{ {
@ -109,6 +110,7 @@ public:
Status status() const; Status status() const;
bool isComponentComplete() const; bool isComponentComplete() const;
QString parseLog();
Q_SIGNALS: Q_SIGNALS:
void fragmentShaderChanged(); void fragmentShaderChanged();
@ -127,14 +129,11 @@ protected:
void componentComplete() override; void componentComplete() override;
void itemChange(ItemChange change, const ItemChangeData &value) override; void itemChange(ItemChange change, const ItemChangeData &value) override;
private Q_SLOTS:
void sourceDestroyed(QObject *object);
void propertyChanged(int mappedId);
private: private:
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
QQuickOpenGLShaderEffect *m_glImpl; QQuickOpenGLShaderEffect *m_glImpl;
#endif #endif
QQuickGenericShaderEffect *m_impl;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -35,7 +35,7 @@
#include <QtQuick/QQuickView> #include <QtQuick/QQuickView>
#include "../../shared/util.h" #include "../../shared/util.h"
class TestShaderEffect : public QQuickOpenGLShaderEffect class TestShaderEffect : public QQuickShaderEffect
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QVariant source READ dummyRead NOTIFY dummyChanged) Q_PROPERTY(QVariant source READ dummyRead NOTIFY dummyChanged)