diff options
29 files changed, 658 insertions, 480 deletions
diff --git a/examples/quick/scenegraph/rendernode/main.qml b/examples/quick/scenegraph/rendernode/main.qml index bae77aabd3..c647aab88d 100644 --- a/examples/quick/scenegraph/rendernode/main.qml +++ b/examples/quick/scenegraph/rendernode/main.qml @@ -38,7 +38,7 @@ ** ****************************************************************************/ -import QtQuick 2.8 // for RendererInfo +import QtQuick 2.8 import SceneGraphRendering 2.0 Item { @@ -89,8 +89,8 @@ Item { anchors.right: renderer.right anchors.margins: 20 wrapMode: Text.WordWrap - property int api: RendererInfo.api - text: "Custom rendering via the graphics API " + (api === RendererInfo.OpenGL ? "OpenGL" : (api === RendererInfo.Direct3D12 ? "Direct3D 12" : "")) + property int api: GraphicsInfo.api + text: "Custom rendering via the graphics API " + (api === GraphicsInfo.OpenGL ? "OpenGL" : (api === GraphicsInfo.Direct3D12 ? "Direct3D 12" : "")) color: "yellow" } } diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12engine.cpp b/src/plugins/scenegraph/d3d12/qsgd3d12engine.cpp index 9c2bb68bbe..14137f062c 100644 --- a/src/plugins/scenegraph/d3d12/qsgd3d12engine.cpp +++ b/src/plugins/scenegraph/d3d12/qsgd3d12engine.cpp @@ -545,6 +545,21 @@ void *QSGD3D12Engine::getResource(Resource resource) const return d->getResource(resource); } +QSGRendererInterface::ShaderType QSGD3D12Engine::shaderType() const +{ + return HLSL; +} + +QSGRendererInterface::ShaderCompilationTypes QSGD3D12Engine::shaderCompilationType() const +{ + return OfflineCompilation; +} + +QSGRendererInterface::ShaderSourceTypes QSGD3D12Engine::shaderSourceType() const +{ + return ShaderByteCode; +} + static inline quint32 alignedSize(quint32 size, quint32 byteAlign) { return (size + byteAlign - 1) & ~(byteAlign - 1); diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12engine_p.h b/src/plugins/scenegraph/d3d12/qsgd3d12engine_p.h index 07f2d360c8..2ebe1e733a 100644 --- a/src/plugins/scenegraph/d3d12/qsgd3d12engine_p.h +++ b/src/plugins/scenegraph/d3d12/qsgd3d12engine_p.h @@ -375,6 +375,9 @@ public: // QSGRendererInterface GraphicsApi graphicsApi() const override; void *getResource(Resource resource) const override; + ShaderType shaderType() const override; + ShaderCompilationTypes shaderCompilationType() const override; + ShaderSourceTypes shaderSourceType() const override; private: QSGD3D12EnginePrivate *d; diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode.cpp b/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode.cpp index b5c0b1d903..f77719f876 100644 --- a/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode.cpp +++ b/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode.cpp @@ -770,21 +770,6 @@ void QSGD3D12ShaderEffectNode::preprocess() } } -QSGGuiThreadShaderEffectManager::ShaderType QSGD3D12GuiThreadShaderEffectManager::shaderType() const -{ - return HLSL; -} - -int QSGD3D12GuiThreadShaderEffectManager::shaderCompilationType() const -{ - return OfflineCompilation; -} - -int QSGD3D12GuiThreadShaderEffectManager::shaderSourceType() const -{ - return ShaderByteCode; -} - bool QSGD3D12GuiThreadShaderEffectManager::hasSeparateSamplerAndTextureObjects() const { return true; diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode_p.h b/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode_p.h index 41d366abda..edeaba899b 100644 --- a/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode_p.h +++ b/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode_p.h @@ -155,10 +155,6 @@ private: class QSGD3D12GuiThreadShaderEffectManager : public QSGGuiThreadShaderEffectManager { public: - ShaderType shaderType() const override; - int shaderCompilationType() const override; - int shaderSourceType() const override; - bool hasSeparateSamplerAndTextureObjects() const override; QString log() const override; diff --git a/src/quick/items/items.pri b/src/quick/items/items.pri index eee11e9d75..0c7dc97a2c 100644 --- a/src/quick/items/items.pri +++ b/src/quick/items/items.pri @@ -78,7 +78,7 @@ HEADERS += \ $$PWD/qquickgenericshadereffect_p.h \ $$PWD/qquickrendercontrol.h \ $$PWD/qquickrendercontrol_p.h \ - $$PWD/qquickrendererinfo_p.h \ + $$PWD/qquickgraphicsinfo_p.h \ $$PWD/qquickitemgrabresult.h SOURCES += \ @@ -133,7 +133,7 @@ SOURCES += \ $$PWD/qquickshadereffect.cpp \ $$PWD/qquickgenericshadereffect.cpp \ $$PWD/qquickrendercontrol.cpp \ - $$PWD/qquickrendererinfo.cpp \ + $$PWD/qquickgraphicsinfo.cpp \ $$PWD/qquickitemgrabresult.cpp # Items that depend on OpenGL Renderer diff --git a/src/quick/items/qquickgenericshadereffect.cpp b/src/quick/items/qquickgenericshadereffect.cpp index cad3520ed1..47272a2eac 100644 --- a/src/quick/items/qquickgenericshadereffect.cpp +++ b/src/quick/items/qquickgenericshadereffect.cpp @@ -202,33 +202,6 @@ QQuickShaderEffect::Status QQuickGenericShaderEffect::status() const return QQuickShaderEffect::Status(mgr->status()); } -QQuickShaderEffect::ShaderType QQuickGenericShaderEffect::shaderType() const -{ - QSGGuiThreadShaderEffectManager *mgr = shaderEffectManager(); - if (!mgr) - return QQuickShaderEffect::ShaderType(0); - - return QQuickShaderEffect::ShaderType(mgr->shaderType()); -} - -QQuickShaderEffect::ShaderCompilationType QQuickGenericShaderEffect::shaderCompilationType() const -{ - QSGGuiThreadShaderEffectManager *mgr = shaderEffectManager(); - if (!mgr) - return QQuickShaderEffect::ShaderCompilationType(0); - - return QQuickShaderEffect::ShaderCompilationType(mgr->shaderCompilationType()); -} - -QQuickShaderEffect::ShaderSourceType QQuickGenericShaderEffect::shaderSourceType() const -{ - QSGGuiThreadShaderEffectManager *mgr = shaderEffectManager(); - if (!mgr) - return QQuickShaderEffect::ShaderSourceType(0); - - return QQuickShaderEffect::ShaderSourceType(mgr->shaderSourceType()); -} - void QQuickGenericShaderEffect::handleEvent(QEvent *event) { if (event->type() == QEvent::DynamicPropertyChange) { @@ -381,9 +354,6 @@ void QQuickGenericShaderEffect::backendChanged() disconnect(m_item->window(), SIGNAL(sceneGraphInitialized()), this, SLOT(backendChanged())); emit m_item->logChanged(); emit m_item->statusChanged(); - emit m_item->shaderTypeChanged(); - emit m_item->shaderCompilationTypeChanged(); - emit m_item->shaderSourceTypeChanged(); } void QQuickGenericShaderEffect::disconnectSignals(Shader shaderType) diff --git a/src/quick/items/qquickgenericshadereffect_p.h b/src/quick/items/qquickgenericshadereffect_p.h index 2af7d1156a..ab17a7fb87 100644 --- a/src/quick/items/qquickgenericshadereffect_p.h +++ b/src/quick/items/qquickgenericshadereffect_p.h @@ -90,10 +90,6 @@ public: bool supportsAtlasTextures() const { return m_supportsAtlasTextures; } void setSupportsAtlasTextures(bool supports); - QQuickShaderEffect::ShaderType shaderType() const; - QQuickShaderEffect::ShaderCompilationType shaderCompilationType() const; - QQuickShaderEffect::ShaderSourceType shaderSourceType() const; - void handleEvent(QEvent *); void handleGeometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); QSGNode *handleUpdatePaintNode(QSGNode *, QQuickItem::UpdatePaintNodeData *); diff --git a/src/quick/items/qquickgraphicsinfo.cpp b/src/quick/items/qquickgraphicsinfo.cpp new file mode 100644 index 0000000000..2dbad82acf --- /dev/null +++ b/src/quick/items/qquickgraphicsinfo.cpp @@ -0,0 +1,306 @@ +/**************************************************************************** +** +** 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 "qquickgraphicsinfo_p.h" +#include "qquickwindow.h" +#include "qquickitem.h" +#include <QtGui/qopenglcontext.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype GraphicsInfo + \instantiates QQuickGraphicsInfo + \inqmlmodule QtQuick + \ingroup qtquick-visual + \since 5.8 + \since QtQuick 2.8 + \brief Provides information about the used Qt Quick backend + + The GraphicsInfo attached type provides information about the scenegraph + backend used to render the contents of the associated window. + + If the item to which the properties are attached is not currently + associated with any window, the properties are set to default values. When + the associated window changes, the properties will update. + */ + +QQuickGraphicsInfo::QQuickGraphicsInfo(QQuickItem *item) + : QObject(item) + , m_window(0) + , m_api(Unknown) + , m_shaderType(UnknownShadingLanguage) + , m_shaderCompilationType(ShaderCompilationType(0)) + , m_shaderSourceType(ShaderSourceType(0)) + , m_majorVersion(2) + , m_minorVersion(0) + , m_profile(NoProfile) + , m_renderableType(SurfaceFormatUnspecified) +{ + connect(item, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(setWindow(QQuickWindow*))); + setWindow(item->window()); +} + +QQuickGraphicsInfo *QQuickGraphicsInfo::qmlAttachedProperties(QObject *object) +{ + if (QQuickItem *item = qobject_cast<QQuickItem *>(object)) + return new QQuickGraphicsInfo(item); + + return nullptr; +} + +/*! + \qmlproperty enumeration QtQuick::GraphicsInfo::api + + This property describes the graphics API that is currently in use. + + The possible values are: + \list + \li GraphicsInfo.Unknown - the default value when no active scenegraph is associated with the item + \li GraphicsInfo.Software - Qt Quick's software renderer based on QPainter with the raster paint engine + \li GraphicsInfo.OpenGL - OpenGL or OpenGL ES + \li GraphicsInfo.Direct3D12 - Direct3D 12 + \endlist + */ + +/*! + \qmlproperty enumeration QtQuick::GraphicsInfo::shaderType + + This property contains the shading language supported by the Qt Quick + backend the application is using. + + \list + \li GraphicsInfo.UnknownShadingLanguage - Not yet known due to no window and scenegraph associated + \li GraphicsInfo.GLSL - GLSL or GLSL ES + \li GraphicsInfo.HLSL - HLSL + \endlist + + \note The value is only up-to-date once the item is associated with a + window and the window's scenegraph has initialized. Bindings relying on the + value have to keep this in mind since the value may change from + GraphicsInfo.UnknownShadingLanguage to the actual value after component + initialization is complete. This is particularly relevant for ShaderEffect + items inside ShaderEffectSource items set as property values. + + \since 5.8 + \since QtQuick 2.8 + + \sa shaderCompilationType, shaderSourceType +*/ + +/*! + \qmlproperty enumeration QtQuick::GraphicsInfo::shaderCompilationType + + This property contains a bitmask of the shader compilation approaches + supported by the Qt Quick backend the application is using. + + \list + \li GraphicsInfo.RuntimeCompilation + \li GraphicsInfo.OfflineCompilation + \endlist + + With OpenGL the value is GraphicsInfo.RuntimeCompilation, which corresponds + to the traditional way of using ShaderEffect. Non-OpenGL backends are + expected to focus more on GraphicsInfo.OfflineCompilation, however. + + \note The value is only up-to-date once the item is associated with a + window and the window's scenegraph has initialized. Bindings relying on the + value have to keep this in mind since the value may change from \c 0 to the + actual bitmask after component initialization is complete. This is + particularly relevant for ShaderEffect items inside ShaderEffectSource + items set as property values. + + \since 5.8 + \since QtQuick 2.8 + + \sa shaderType, shaderSourceType +*/ + +/*! + \qmlproperty enumeration QtQuick::GraphicsInfo::shaderSourceType + + This property contains a bitmask of the supported ways of providing shader + sources. + + \list + \li GraphicsInfo.ShaderSourceString + \li GraphicsInfo.ShaderSourceFile + \li GraphicsInfo.ShaderByteCode + \endlist + + With OpenGL the value is GraphicsInfo.ShaderSourceString, which corresponds + to the traditional way of inlining GLSL source code into QML. Other, + non-OpenGL Qt Quick backends may however decide not to support inlined + shader sources, or even shader sources at all. In this case shaders are + expected to be pre-compiled into formats like SPIR-V or D3D shader + bytecode. + + \note The value is only up-to-date once the item is associated with a + window and the window's scenegraph has initialized. Bindings relying on the + value have to keep this in mind since the value may change from \c 0 to the + actual bitmask after component initialization is complete. This is + particularly relevant for ShaderEffect items inside ShaderEffectSource + items set as property values. + + \since 5.8 + \since QtQuick 2.8 + + \sa shaderType, shaderCompilationType +*/ + +/*! + \qmlproperty int QtQuick::GraphicsInfo::majorVersion + + This property holds the major version of the graphics API in use. + + With OpenGL the default version is \c 2.0. + + \sa minorVersion, profile + */ + +/*! + \qmlproperty int QtQuick::GraphicsInfo::minorVersion + + This property holds the minor version of the graphics API in use. + + With OpenGL the default version is \c 2.0. + + \sa majorVersion, profile + */ + +/*! + \qmlproperty enumeration QtQuick::GraphicsInfo::profile + + This property holds the configured OpenGL context profile. + + The possible values are: + \list + \li GraphicsInfo.NoProfile (default) - OpenGL version is lower than 3.2 or OpenGL is not in use. + \li GraphicsInfo.CoreProfile - Functionality deprecated in OpenGL version 3.0 is not available. + \li GraphicsInfo.CompatibilityProfile - Functionality from earlier OpenGL versions is available. + \endlist + + Reusable QML components will typically use this property in bindings in order to + choose between core and non core profile compatible shader sources. + + \sa majorVersion, minorVersion, QSurfaceFormat + */ + +/*! + \qmlproperty enumeration QtQuick::GraphicsInfo::renderableType + + This property holds the renderable type. The value has no meaning for APIs + other than OpenGL. + + The possible values are: + \list + \li GraphicsInfo.SurfaceFormatUnspecified (default) - Unspecified rendering method + \li GraphicsInfo.SurfaceFormatOpenGL - Desktop OpenGL or other graphics API + \li GraphicsInfo.SurfaceFormatOpenGLES - OpenGL ES + \endlist + + \sa QSurfaceFormat + */ + +void QQuickGraphicsInfo::updateInfo() +{ + const bool sgReady = m_window && m_window->isSceneGraphInitialized(); + + if (sgReady) { + QSGRendererInterface *rif = m_window->rendererInterface(); + if (rif) { + GraphicsApi newAPI = GraphicsApi(rif->graphicsApi()); + if (m_api != newAPI) { + m_api = newAPI; + emit apiChanged(); + m_shaderType = ShaderType(rif->shaderType()); + emit shaderTypeChanged(); + m_shaderCompilationType = ShaderCompilationType(int(rif->shaderCompilationType())); + emit shaderCompilationTypeChanged(); + m_shaderSourceType = ShaderSourceType(int(rif->shaderSourceType())); + emit shaderSourceTypeChanged(); + } + } + } + + QSurfaceFormat format = QSurfaceFormat::defaultFormat(); +#ifndef QT_NO_OPENGL + if (sgReady) { + QOpenGLContext *context = m_window->openglContext(); + if (context) + format = context->format(); + } +#endif + if (m_majorVersion != format.majorVersion()) { + m_majorVersion = format.majorVersion(); + emit majorVersionChanged(); + } + if (m_minorVersion != format.minorVersion()) { + m_minorVersion = format.minorVersion(); + emit minorVersionChanged(); + } + ContextProfile profile = static_cast<ContextProfile>(format.profile()); + if (m_profile != profile) { + m_profile = profile; + emit profileChanged(); + } + RenderableType renderableType = static_cast<RenderableType>(format.renderableType()); + if (m_renderableType != renderableType) { + m_renderableType = renderableType; + emit renderableTypeChanged(); + } +} + +void QQuickGraphicsInfo::setWindow(QQuickWindow *window) +{ + if (m_window != window) { + if (m_window) { + disconnect(m_window, SIGNAL(sceneGraphInitialized()), this, SLOT(updateInfo())); + disconnect(m_window, SIGNAL(sceneGraphInvalidated()), this, SLOT(updateInfo())); + } + if (window) { + connect(window, SIGNAL(sceneGraphInitialized()), this, SLOT(updateInfo())); + connect(window, SIGNAL(sceneGraphInvalidated()), this, SLOT(updateInfo())); + } + m_window = window; + } + updateInfo(); +} + +QT_END_NAMESPACE diff --git a/src/quick/items/qquickgraphicsinfo_p.h b/src/quick/items/qquickgraphicsinfo_p.h new file mode 100644 index 0000000000..0cbfbbddba --- /dev/null +++ b/src/quick/items/qquickgraphicsinfo_p.h @@ -0,0 +1,166 @@ +/**************************************************************************** +** +** 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 QQUICKGRAPHICSINFO_P_H +#define QQUICKGRAPHICSINFO_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 <QtCore/qobject.h> +#include <QtCore/qpointer.h> +#include <QtQml/qqml.h> +#include <QtGui/qsurfaceformat.h> +#include <QtQuick/qsgrendererinterface.h> + +QT_BEGIN_NAMESPACE + +class QQuickItem; +class QQuickWindow; + +class QQuickGraphicsInfo : public QObject +{ + Q_OBJECT + Q_PROPERTY(GraphicsApi api READ api NOTIFY apiChanged FINAL) + Q_PROPERTY(ShaderType shaderType READ shaderType NOTIFY shaderTypeChanged FINAL) + Q_PROPERTY(ShaderCompilationType shaderCompilationType READ shaderCompilationType NOTIFY shaderCompilationTypeChanged FINAL) + Q_PROPERTY(ShaderSourceType shaderSourceType READ shaderSourceType NOTIFY shaderSourceTypeChanged FINAL) + + Q_PROPERTY(int majorVersion READ majorVersion NOTIFY majorVersionChanged FINAL) + Q_PROPERTY(int minorVersion READ minorVersion NOTIFY minorVersionChanged FINAL) + Q_PROPERTY(ContextProfile profile READ profile NOTIFY profileChanged FINAL) + Q_PROPERTY(RenderableType renderableType READ renderableType NOTIFY renderableTypeChanged FINAL) + +public: + enum GraphicsApi { + Unknown = QSGRendererInterface::Unknown, + Software = QSGRendererInterface::Software, + OpenGL = QSGRendererInterface::OpenGL, + Direct3D12 = QSGRendererInterface::Direct3D12 + }; + Q_ENUM(GraphicsApi) + + enum ShaderType { + UnknownShadingLanguage = QSGRendererInterface::UnknownShadingLanguage, + GLSL = QSGRendererInterface::GLSL, + HLSL = QSGRendererInterface::HLSL + }; + Q_ENUM(ShaderType) + + enum ShaderCompilationType { + RuntimeCompilation = QSGRendererInterface::RuntimeCompilation, + OfflineCompilation = QSGRendererInterface::OfflineCompilation + }; + Q_ENUM(ShaderCompilationType) + + enum ShaderSourceType { + ShaderSourceString = QSGRendererInterface::ShaderSourceString, + ShaderSourceFile = QSGRendererInterface::ShaderSourceFile, + ShaderByteCode = QSGRendererInterface::ShaderByteCode + }; + Q_ENUM(ShaderSourceType) + + enum ContextProfile { + NoProfile = QSurfaceFormat::NoProfile, + CoreProfile = QSurfaceFormat::CoreProfile, + CompatibilityProfile = QSurfaceFormat::CompatibilityProfile + }; + Q_ENUM(ContextProfile) + + enum RenderableType { + SurfaceFormatUnspecified = QSurfaceFormat::DefaultRenderableType, + SurfaceFormatOpenGL = QSurfaceFormat::OpenGL, + SurfaceFormatOpenGLES = QSurfaceFormat::OpenGLES + }; + Q_ENUM(RenderableType) + + QQuickGraphicsInfo(QQuickItem *item = 0); + + static QQuickGraphicsInfo *qmlAttachedProperties(QObject *object); + + GraphicsApi api() const { return m_api; } + ShaderType shaderType() const { return m_shaderType; } + ShaderCompilationType shaderCompilationType() const { return m_shaderCompilationType; } + ShaderSourceType shaderSourceType() const { return m_shaderSourceType; } + + int majorVersion() const { return m_majorVersion; } + int minorVersion() const { return m_minorVersion; } + ContextProfile profile() const { return m_profile; } + RenderableType renderableType() const { return m_renderableType; } + +Q_SIGNALS: + void apiChanged(); + void shaderTypeChanged(); + void shaderCompilationTypeChanged(); + void shaderSourceTypeChanged(); + + void majorVersionChanged(); + void minorVersionChanged(); + void profileChanged(); + void renderableTypeChanged(); + +private Q_SLOTS: + void updateInfo(); + void setWindow(QQuickWindow *window); + +private: + QPointer<QQuickWindow> m_window; + GraphicsApi m_api; + ShaderType m_shaderType; + ShaderCompilationType m_shaderCompilationType; + ShaderSourceType m_shaderSourceType; + int m_majorVersion; + int m_minorVersion; + ContextProfile m_profile; + RenderableType m_renderableType; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPEINFO(QQuickGraphicsInfo, QML_HAS_ATTACHED_PROPERTIES) + +#endif // QQUICKGRAPHICSINFO_P_H diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp index e5b82e1102..8ed7f2bb05 100644 --- a/src/quick/items/qquickitemsmodule.cpp +++ b/src/quick/items/qquickitemsmodule.cpp @@ -80,7 +80,7 @@ # include "qquickanimatedsprite_p.h" # include "qquickopenglinfo_p.h" #endif -#include "qquickrendererinfo_p.h" +#include "qquickgraphicsinfo_p.h" #include "qquickshadereffect_p.h" #include "qquickshadereffectmesh_p.h" #include "qquickdrag_p.h" @@ -294,8 +294,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) qmlRegisterUncreatableType<QQuickMouseEvent, 7>(uri, 2, 7, nullptr, QQuickMouseEvent::tr("MouseEvent is only available within handlers in MouseArea")); - qmlRegisterType<QQuickShaderEffect, 2>(uri, 2, 8, "ShaderEffect"); - qmlRegisterUncreatableType<QQuickRendererInfo>(uri, 2, 8,"RendererInfo", QQuickRendererInfo::tr("RendererInfo is only available via attached properties")); + qmlRegisterUncreatableType<QQuickGraphicsInfo>(uri, 2, 8,"GraphicsInfo", QQuickGraphicsInfo::tr("GraphicsInfo is only available via attached properties")); qmlRegisterType<QQuickBorderImageMesh>("QtQuick", 2, 8, "BorderImageMesh"); } diff --git a/src/quick/items/qquickopenglinfo.cpp b/src/quick/items/qquickopenglinfo.cpp index b380a93e76..4bb13b84aa 100644 --- a/src/quick/items/qquickopenglinfo.cpp +++ b/src/quick/items/qquickopenglinfo.cpp @@ -61,6 +61,10 @@ QT_BEGIN_NAMESPACE format. When it becomes associated with a surface, all properties will update. + \deprecated + + \warning This type is deprecated. Use GraphicsInfo instead. + \sa ShaderEffect */ QQuickOpenGLInfo::QQuickOpenGLInfo(QQuickItem *item) diff --git a/src/quick/items/qquickrendererinfo.cpp b/src/quick/items/qquickrendererinfo.cpp deleted file mode 100644 index b31cfd7f94..0000000000 --- a/src/quick/items/qquickrendererinfo.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** -** -** 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 "qquickrendererinfo_p.h" -#include "qquickwindow.h" -#include "qquickitem.h" -#include <qsgrendererinterface.h> - -QT_BEGIN_NAMESPACE - -/*! - \qmltype RendererInfo - \instantiates QQuickRendererInfo - \inqmlmodule QtQuick - \ingroup qtquick-effects - \since 5.8 - \since QtQuick 2.8 - \brief Provides information about the used Qt Quick backend - - The RendererInfo attached type provides information about the scenegraph - backend used to render the contents of the associated window. - - If the item to which the properties are attached is not currently - associated with any window, the properties are set to default values. When - the associated window changes, the properties will update. - - \sa OpenGLInfo, ShaderEffect - */ - -QQuickRendererInfo::QQuickRendererInfo(QQuickItem *item) - : QObject(item) - , m_window(0) - , m_api(Unknown) -{ - connect(item, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(setWindow(QQuickWindow*))); - setWindow(item->window()); -} - -QQuickRendererInfo *QQuickRendererInfo::qmlAttachedProperties(QObject *object) -{ - if (QQuickItem *item = qobject_cast<QQuickItem *>(object)) - return new QQuickRendererInfo(item); - - return nullptr; -} - -/*! - \qmlproperty enumeration QtQuick::RendererInfo::api - - This property describes the graphics API that is currently in use. - - The possible values are: - \list - \li RendererInfo.Unknown - the default value when no active scenegraph is associated with the item - \li RendererInfo.Software - Qt Quick's software renderer based on QPainter with the raster paint engine - \li RendererInfo.OpenGL - OpenGL or OpenGL ES - \li RendererInfo.Direct3D12 - Direct3D 12 - \endlist - */ - -void QQuickRendererInfo::updateInfo() -{ - GraphicsApi newAPI = Unknown; - - if (m_window && m_window->isSceneGraphInitialized()) { - QSGRendererInterface *rif = m_window->rendererInterface(); - if (rif) - newAPI = GraphicsApi(rif->graphicsApi()); // this function is safe to call on the gui/main thread too - } - - if (m_api != newAPI) { - m_api = newAPI; - emit apiChanged(); - } -} - -void QQuickRendererInfo::setWindow(QQuickWindow *window) -{ - if (m_window != window) { - if (m_window) { - disconnect(m_window, SIGNAL(sceneGraphInitialized()), this, SLOT(updateInfo())); - disconnect(m_window, SIGNAL(sceneGraphInvalidated()), this, SLOT(updateInfo())); - } - if (window) { - connect(window, SIGNAL(sceneGraphInitialized()), this, SLOT(updateInfo())); - connect(window, SIGNAL(sceneGraphInvalidated()), this, SLOT(updateInfo())); - } - m_window = window; - } - updateInfo(); -} - -QT_END_NAMESPACE diff --git a/src/quick/items/qquickrendererinfo_p.h b/src/quick/items/qquickrendererinfo_p.h deleted file mode 100644 index d0298baa21..0000000000 --- a/src/quick/items/qquickrendererinfo_p.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** 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 QQUICKRENDERERINFO_P_H -#define QQUICKRENDERERINFO_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 <QtCore/qobject.h> -#include <QtCore/qpointer.h> -#include <QtQml/qqml.h> - -QT_BEGIN_NAMESPACE - -class QQuickItem; -class QQuickWindow; - -class QQuickRendererInfo : public QObject -{ - Q_OBJECT - Q_PROPERTY(GraphicsApi api READ api NOTIFY apiChanged FINAL) - -public: - // must match QSGRendererInterface - enum GraphicsApi { - Unknown, - Software, - OpenGL, - Direct3D12 - }; - Q_ENUM(GraphicsApi) - - QQuickRendererInfo(QQuickItem *item = 0); - - static QQuickRendererInfo *qmlAttachedProperties(QObject *object); - - GraphicsApi api() const { return m_api; } - -Q_SIGNALS: - void apiChanged(); - -private Q_SLOTS: - void updateInfo(); - void setWindow(QQuickWindow *window); - -private: - QPointer<QQuickWindow> m_window; - GraphicsApi m_api; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPEINFO(QQuickRendererInfo, QML_HAS_ATTACHED_PROPERTIES) - -#endif // QQUICKRENDERERINFO_P_H diff --git a/src/quick/items/qquickshadereffect.cpp b/src/quick/items/qquickshadereffect.cpp index 1fbc9c201f..f7fc7880ed 100644 --- a/src/quick/items/qquickshadereffect.cpp +++ b/src/quick/items/qquickshadereffect.cpp @@ -174,7 +174,7 @@ QT_BEGIN_NAMESPACE Direct3D backends provide ShaderEffect support with HLSL. The Direct3D 12 backend requires using at least Shader Model 5.0 both for vertex and pixel - shaders. When necessary, the \l shaderType property can be used to decide + shaders. When necessary, GraphicsInfo.shaderType can be used to decide at runtime what kind of value to assign to \l fragmentShader or \l vertexShader. @@ -212,8 +212,8 @@ QT_BEGIN_NAMESPACE Unlike with OpenGL, runtime compilation of shader source code may not be supported. Backends for modern APIs are likely to prefer offline compilation and shipping pre-compiled bytecode with applications instead of - inlined shader source strings. See the \l shaderSourceType and - \l shaderCompilationType properties. + inlined shader source strings. To check what is expected at runtime, use the + GraphicsInfo.shaderSourceType and GraphicsInfo.shaderCompilationType properties. \table 70% \row @@ -399,7 +399,7 @@ QQuickShaderEffect::QQuickShaderEffect(QQuickItem *parent) \c{float4 position : SV_POSITION} (names can differ since linking is done based on the semantics). - \sa vertexShader, shaderType, shaderCompilationType, shaderSourceType + \sa vertexShader, GraphicsInfo */ QByteArray QQuickShaderEffect::fragmentShader() const @@ -438,7 +438,7 @@ void QQuickShaderEffect::setFragmentShader(const QByteArray &code) enough to use the standard \c TEXCOORD0 semantic, for example \c{float2 coord : TEXCOORD0}. - \sa fragmentShader, shaderType, shaderCompilationType, shaderSourceType + \sa fragmentShader, GraphicsInfo */ QByteArray QQuickShaderEffect::vertexShader() const @@ -652,118 +652,6 @@ QQuickShaderEffect::Status QQuickShaderEffect::status() const return m_impl->status(); } -/*! - \qmlproperty enumeration QtQuick::ShaderEffect::shaderType - - This property contains the shading language supported by the current Qt - Quick backend the application is using. - - \list - \li ShaderEffect.UnknownShadingLanguage - Not yet known due to no window and scenegraph associated - \li ShaderEffect.GLSL - GLSL or GLSL ES - \li ShaderEffect.HLSL - HLSL - \endlist - - \note The value is only up-to-date once the item is associated with a - window and the window's scenegraph has initialized. Bindings relying on the - value have to keep this in mind since the value may change from - ShaderEffect.UnknownShadingLanguage to the actual value after component - initialization is complete. This is particularly relevant for ShaderEffect - items inside ShaderEffectSource items set as property values. - - \since 5.8 - \since QtQuick 2.8 - - \sa shaderCompilationType, shaderSourceType, vertexShader, fragmentShader -*/ - -QQuickShaderEffect::ShaderType QQuickShaderEffect::shaderType() const -{ -#ifndef QT_NO_OPENGL - if (m_glImpl) - return GLSL; -#endif - return m_impl->shaderType(); -} - -/*! - \qmlproperty enumeration QtQuick::ShaderEffect::shaderCompilationType - - This property contains a bitmask of the shader compilation approaches - supported by the current Qt Quick backend the application is using. - - \list - \li ShaderEffect.RuntimeCompilation - \li ShaderEffect.OfflineCompilation - \endlist - - With OpenGL the value is ShaderEffect.RuntimeCompilation, which corresponds - to the traditional way of using ShaderEffect. Non-OpenGL backends are - expected to focus more on ShaderEffect.OfflineCompilation, however. - - \note The value is only up-to-date once the item is associated with a - window and the window's scenegraph has initialized. Bindings relying on the - value have to keep this in mind since the value may change from \c 0 to the - actual bitmask after component initialization is complete. This is - particularly relevant for ShaderEffect items inside ShaderEffectSource - items set as property values. - - \since 5.8 - \since QtQuick 2.8 - - \sa shaderType, shaderSourceType, vertexShader, fragmentShader -*/ - -QQuickShaderEffect::ShaderCompilationType QQuickShaderEffect::shaderCompilationType() const -{ -#ifndef QT_NO_OPENGL - if (m_glImpl) - return RuntimeCompilation; -#endif - return m_impl->shaderCompilationType(); -} - -/*! - \qmlproperty enumeration QtQuick::ShaderEffect::shaderSourceType - - This property contains a bitmask of the supported ways of providing shader - sources. - - \list - \li ShaderEffect.ShaderSourceString - \li ShaderEffect.ShaderSourceFile - \li ShaderEffect.ShaderByteCode - \endlist - - With OpenGL the value is ShaderEffect.ShaderSourceString, which corresponds - to the traditional way of inlining GLSL source code into QML. Other, - non-OpenGL Qt Quick backends may however decide not to support inlined - shader sources, or even shader sources at all. In this case shaders are - expected to be pre-compiled into formats like SPIR-V or D3D shader - bytecode. - - \note The value is only up-to-date once the item is associated with a - window and the window's scenegraph has initialized. Bindings relying on the - value have to keep this in mind since the value may change from \c 0 to the - actual bitmask after component initialization is complete. This is - particularly relevant for ShaderEffect items inside ShaderEffectSource - items set as property values. - - \since 5.8 - \since QtQuick 2.8 - - \sa shaderType, shaderCompilationType, vertexShader, fragmentShader -*/ - -QQuickShaderEffect::ShaderSourceType QQuickShaderEffect::shaderSourceType() const -{ -#ifndef QT_NO_OPENGL - if (m_glImpl) - return ShaderSourceString; -#endif - return m_impl->shaderSourceType(); -} - bool QQuickShaderEffect::event(QEvent *e) { #ifndef QT_NO_OPENGL diff --git a/src/quick/items/qquickshadereffect_p.h b/src/quick/items/qquickshadereffect_p.h index 0410514c36..62d7e6fe5f 100644 --- a/src/quick/items/qquickshadereffect_p.h +++ b/src/quick/items/qquickshadereffect_p.h @@ -70,9 +70,6 @@ class Q_QUICK_PRIVATE_EXPORT QQuickShaderEffect : public QQuickItem Q_PROPERTY(QString log READ log NOTIFY logChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(bool supportsAtlasTextures READ supportsAtlasTextures WRITE setSupportsAtlasTextures NOTIFY supportsAtlasTexturesChanged REVISION 1) - Q_PROPERTY(ShaderType shaderType READ shaderType NOTIFY shaderTypeChanged REVISION 2) - Q_PROPERTY(ShaderCompilationType shaderCompilationType READ shaderCompilationType NOTIFY shaderCompilationTypeChanged REVISION 2) - Q_PROPERTY(ShaderSourceType shaderSourceType READ shaderSourceType NOTIFY shaderSourceTypeChanged REVISION 2) public: enum CullMode { @@ -89,26 +86,6 @@ public: }; Q_ENUM(Status) - enum ShaderType { - UnknownShadingLanguage, - GLSL, - HLSL - }; - Q_ENUM(ShaderType) - - enum ShaderCompilationType { - RuntimeCompilation = 0x01, - OfflineCompilation = 0x02 - }; - Q_ENUM(ShaderCompilationType) - - enum ShaderSourceType { - ShaderSourceString = 0x01, - ShaderSourceFile = 0x02, - ShaderByteCode = 0x04 - }; - Q_ENUM(ShaderSourceType) - QQuickShaderEffect(QQuickItem *parent = 0); QByteArray fragmentShader() const; @@ -132,10 +109,6 @@ public: QString log() const; Status status() const; - ShaderType shaderType() const; - ShaderCompilationType shaderCompilationType() const; - ShaderSourceType shaderSourceType() const; - bool isComponentComplete() const; QString parseLog(); @@ -148,9 +121,6 @@ Q_SIGNALS: void logChanged(); void statusChanged(); void supportsAtlasTexturesChanged(); - void shaderTypeChanged(); - void shaderCompilationTypeChanged(); - void shaderSourceTypeChanged(); protected: bool event(QEvent *e) override; diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext.cpp index fe9ad67901..dee1ac8954 100644 --- a/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext.cpp +++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext.cpp @@ -179,4 +179,19 @@ QSGRendererInterface::GraphicsApi QSGSoftwareContext::graphicsApi() const return Software; } +QSGRendererInterface::ShaderType QSGSoftwareContext::shaderType() const +{ + return UnknownShadingLanguage; +} + +QSGRendererInterface::ShaderCompilationTypes QSGSoftwareContext::shaderCompilationType() const +{ + return 0; +} + +QSGRendererInterface::ShaderSourceTypes QSGSoftwareContext::shaderSourceType() const +{ + return 0; +} + QT_END_NAMESPACE diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext_p.h b/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext_p.h index 023a33cbd5..992f6f5677 100644 --- a/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext_p.h +++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext_p.h @@ -96,6 +96,9 @@ public: QSGRendererInterface *rendererInterface(QSGRenderContext *renderContext) override; GraphicsApi graphicsApi() const override; + ShaderType shaderType() const override; + ShaderCompilationTypes shaderCompilationType() const override; + ShaderSourceTypes shaderSourceType() const override; }; QT_END_NAMESPACE diff --git a/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp b/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp index 2920a187e2..ffde9d8930 100644 --- a/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp +++ b/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp @@ -63,7 +63,7 @@ QT_BEGIN_NAMESPACE */ /*! - \enum QSGRenderNode::GraphicsApi + \enum QSGRendererInterface::GraphicsApi \value Unknown An unknown graphics API is in use \value Software The Qt Quick 2D Renderer is in use \value OpenGL OpenGL ES 2.0 or higher @@ -73,7 +73,7 @@ QT_BEGIN_NAMESPACE */ /*! - \enum QSGRenderNode::Resource + \enum QSGRendererInterface::Resource \value Device The graphics device \value CommandQueue The graphics command queue used by the scenergaph \value CommandList The command list or buffer used by the scenegraph @@ -84,7 +84,7 @@ QSGRendererInterface::~QSGRendererInterface() } /*! - \fn QSGRenderNode::GraphicsApi QSGRenderNode::graphicsApi() const + \fn QSGRendererInterface::GraphicsApi QSGRendererInterface::graphicsApi() const Returns the graphics API that is in use by the Qt Quick scenegraph. @@ -125,4 +125,45 @@ void *QSGRendererInterface::getResource(const char *resource) const return nullptr; } +/*! + \fn QSGRendererInterface::ShaderType QSGRendererInterface::shaderType() const + + \return the shading language supported by the Qt Quick backend the + application is using. + + \note This function can be called on any thread. However, the renderer + interface's lifetime may be tied to the render thread and therefore calling + this function from other threads during the process of application shutdown + or QQuickWindow closing is likely to become invalid. + + \sa QtQuick::GraphicsInfo + */ + +/*! + \fn QSGRendererInterface::ShaderCompilationTypes QSGRendererInterface::shaderCompilationType() const + + \return a bitmask of the shader compilation approaches supported by the Qt + Quick backend the application is using. + + \note This function can be called on any thread. However, the renderer + interface's lifetime may be tied to the render thread and therefore calling + this function from other threads during the process of application shutdown + or QQuickWindow closing is likely to become invalid. + + \sa QtQuick::GraphicsInfo + */ + +/*! + \fn QSGRendererInterface::ShaderSourceTypes QSGRendererInterface::shaderSourceType() const + + \return a bitmask of the supported ways of providing shader sources. + + \note This function can be called on any thread. However, the renderer + interface's lifetime may be tied to the render thread and therefore calling + this function from other threads during the process of application shutdown + or QQuickWindow closing is likely to become invalid. + + \sa QtQuick::GraphicsInfo + */ + QT_END_NAMESPACE diff --git a/src/quick/scenegraph/coreapi/qsgrendererinterface.h b/src/quick/scenegraph/coreapi/qsgrendererinterface.h index 75b79336fd..234a061d0e 100644 --- a/src/quick/scenegraph/coreapi/qsgrendererinterface.h +++ b/src/quick/scenegraph/coreapi/qsgrendererinterface.h @@ -60,14 +60,40 @@ public: CommandList }; + enum ShaderType { + UnknownShadingLanguage, + GLSL, + HLSL + }; + + enum ShaderCompilationType { + RuntimeCompilation = 0x01, + OfflineCompilation = 0x02 + }; + Q_DECLARE_FLAGS(ShaderCompilationTypes, ShaderCompilationType) + + enum ShaderSourceType { + ShaderSourceString = 0x01, + ShaderSourceFile = 0x02, + ShaderByteCode = 0x04 + }; + Q_DECLARE_FLAGS(ShaderSourceTypes, ShaderSourceType) + virtual ~QSGRendererInterface(); virtual GraphicsApi graphicsApi() const = 0; virtual void *getResource(Resource resource) const; virtual void *getResource(const char *resource) const; + + virtual ShaderType shaderType() const = 0; + virtual ShaderCompilationTypes shaderCompilationType() const = 0; + virtual ShaderSourceTypes shaderSourceType() const = 0; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QSGRendererInterface::ShaderCompilationTypes) +Q_DECLARE_OPERATORS_FOR_FLAGS(QSGRendererInterface::ShaderSourceTypes) + QT_END_NAMESPACE #endif diff --git a/src/quick/scenegraph/qsgadaptationlayer_p.h b/src/quick/scenegraph/qsgadaptationlayer_p.h index 0df42c2aa8..8fdcf7af64 100644 --- a/src/quick/scenegraph/qsgadaptationlayer_p.h +++ b/src/quick/scenegraph/qsgadaptationlayer_p.h @@ -228,31 +228,12 @@ class Q_QUICK_PRIVATE_EXPORT QSGGuiThreadShaderEffectManager : public QObject Q_OBJECT public: - // Enum values must match ShaderEffect. - enum ShaderType { - UnknownShadingLanguage, - GLSL, - HLSL - }; - enum ShaderCompilationType { - RuntimeCompilation = 0x01, - OfflineCompilation = 0x02 - }; - enum ShaderSourceType { - ShaderSourceString = 0x01, - ShaderSourceFile = 0x02, - ShaderByteCode = 0x04 - }; enum Status { Compiled, Uncompiled, Error }; - virtual ShaderType shaderType() const = 0; - virtual int shaderCompilationType() const = 0; - virtual int shaderSourceType() const = 0; - virtual bool hasSeparateSamplerAndTextureObjects() const = 0; virtual QString log() const = 0; diff --git a/src/quick/scenegraph/qsgdefaultcontext.cpp b/src/quick/scenegraph/qsgdefaultcontext.cpp index 46127544a0..f9978e816c 100644 --- a/src/quick/scenegraph/qsgdefaultcontext.cpp +++ b/src/quick/scenegraph/qsgdefaultcontext.cpp @@ -251,4 +251,19 @@ QSGRendererInterface::GraphicsApi QSGDefaultContext::graphicsApi() const return OpenGL; } +QSGRendererInterface::ShaderType QSGDefaultContext::shaderType() const +{ + return GLSL; +} + +QSGRendererInterface::ShaderCompilationTypes QSGDefaultContext::shaderCompilationType() const +{ + return RuntimeCompilation; +} + +QSGRendererInterface::ShaderSourceTypes QSGDefaultContext::shaderSourceType() const +{ + return ShaderSourceString; +} + QT_END_NAMESPACE diff --git a/src/quick/scenegraph/qsgdefaultcontext_p.h b/src/quick/scenegraph/qsgdefaultcontext_p.h index d14d9d6812..6686ab98a0 100644 --- a/src/quick/scenegraph/qsgdefaultcontext_p.h +++ b/src/quick/scenegraph/qsgdefaultcontext_p.h @@ -79,6 +79,9 @@ public: bool isDistanceFieldEnabled() const; GraphicsApi graphicsApi() const override; + ShaderType shaderType() const override; + ShaderCompilationTypes shaderCompilationType() const override; + ShaderSourceTypes shaderSourceType() const override; private: QMutex m_mutex; diff --git a/tests/auto/quick/qquickgraphicsinfo/data/basic.qml b/tests/auto/quick/qquickgraphicsinfo/data/basic.qml new file mode 100644 index 0000000000..6ff3b82cec --- /dev/null +++ b/tests/auto/quick/qquickgraphicsinfo/data/basic.qml @@ -0,0 +1,14 @@ +import QtQuick 2.8 + +Item { + property int api: GraphicsInfo.api + + property int shaderType: GraphicsInfo.shaderType + property int shaderCompilationType: GraphicsInfo.shaderCompilationType + property int shaderSourceType: GraphicsInfo.shaderSourceType + + property int majorVersion: GraphicsInfo.majorVersion + property int minorVersion: GraphicsInfo.minorVersion + property int profile: GraphicsInfo.profile + property int renderableType: GraphicsInfo.renderableType +} diff --git a/tests/auto/quick/qquickrendererinfo/qquickrendererinfo.pro b/tests/auto/quick/qquickgraphicsinfo/qquickgraphicsinfo.pro index 4f55b79961..a4296ad9a2 100644 --- a/tests/auto/quick/qquickrendererinfo/qquickrendererinfo.pro +++ b/tests/auto/quick/qquickgraphicsinfo/qquickgraphicsinfo.pro @@ -1,6 +1,6 @@ CONFIG += testcase -TARGET = tst_qquickrendererinfo -SOURCES += tst_qquickrendererinfo.cpp +TARGET = tst_qquickgraphicsinfo +SOURCES += tst_qquickgraphicsinfo.cpp TESTDATA = data/* include(../../shared/util.pri) diff --git a/tests/auto/quick/qquickrendererinfo/tst_qquickrendererinfo.cpp b/tests/auto/quick/qquickgraphicsinfo/tst_qquickgraphicsinfo.cpp index 5e2da76333..256fa43d2e 100644 --- a/tests/auto/quick/qquickrendererinfo/tst_qquickrendererinfo.cpp +++ b/tests/auto/quick/qquickgraphicsinfo/tst_qquickgraphicsinfo.cpp @@ -35,7 +35,12 @@ #include "../../shared/util.h" -class tst_QQuickRendererInfo : public QQmlDataTest +#ifndef QT_NO_OPENGL +#include <QtGui/qopenglcontext.h> +#include <QtGui/qsurfaceformat.h> +#endif + +class tst_QQuickGraphicsInfo : public QQmlDataTest { Q_OBJECT @@ -43,7 +48,7 @@ private slots: void testProperties(); }; -void tst_QQuickRendererInfo::testProperties() +void tst_QQuickGraphicsInfo::testProperties() { QQuickView view; view.setSource(QUrl::fromLocalFile("data/basic.qml")); @@ -61,8 +66,20 @@ void tst_QQuickRendererInfo::testProperties() const int expectedAPI = rif ? rif->graphicsApi() : QSGRendererInterface::Unknown; QCOMPARE(obj->property("api").toInt(), expectedAPI); + +#ifndef QT_NO_OPENGL + if (expectedAPI == QSGRendererInterface::OpenGL) { + QCOMPARE(obj->property("shaderType").toInt(), int(QSGRendererInterface::GLSL)); + QVERIFY(view.openglContext()); + QSurfaceFormat format = view.openglContext()->format(); + QCOMPARE(obj->property("majorVersion").toInt(), format.majorVersion()); + QCOMPARE(obj->property("minorVersion").toInt(), format.minorVersion()); + QCOMPARE(obj->property("profile").toInt(), static_cast<int>(format.profile())); + QCOMPARE(obj->property("renderableType").toInt(), static_cast<int>(format.renderableType())); + } +#endif } -QTEST_MAIN(tst_QQuickRendererInfo) +QTEST_MAIN(tst_QQuickGraphicsInfo) -#include "tst_qquickrendererinfo.moc" +#include "tst_qquickgraphicsinfo.moc" diff --git a/tests/auto/quick/qquickrendererinfo/data/basic.qml b/tests/auto/quick/qquickrendererinfo/data/basic.qml deleted file mode 100644 index b7dbbb9ac9..0000000000 --- a/tests/auto/quick/qquickrendererinfo/data/basic.qml +++ /dev/null @@ -1,5 +0,0 @@ -import QtQuick 2.8 - -Item { - property int api: RendererInfo.api -} diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro index fecd1aea58..70e5b8ef6a 100644 --- a/tests/auto/quick/quick.pro +++ b/tests/auto/quick/quick.pro @@ -57,6 +57,7 @@ QUICKTESTS = \ qquickflickable \ qquickflipable \ qquickfocusscope \ + qquickgraphicsinfo \ qquickgridview \ qquickimage \ qquickitem \ @@ -71,7 +72,6 @@ QUICKTESTS = \ qquickpincharea \ qquickpositioners \ qquickrectangle \ - qquickrendererinfo \ qquickrepeater \ qquickshortcut \ qquicktext \ diff --git a/tests/manual/nodetypes/Effects.qml b/tests/manual/nodetypes/Effects.qml index 4503c49df1..0d16cd1c84 100644 --- a/tests/manual/nodetypes/Effects.qml +++ b/tests/manual/nodetypes/Effects.qml @@ -38,7 +38,7 @@ ** ****************************************************************************/ -// Use QtQuick 2.8 to get shaderType and the other new properties +// Use QtQuick 2.8 to get GraphicsInfo and the other new properties import QtQuick 2.8 Item { @@ -95,9 +95,9 @@ Item { property string hlslVertexShaderByteCode: "qrc:/vs_wobble.cso" property string hlslPixelShaderByteCode: "qrc:/ps_wobble.cso" - vertexShader: customVertexShader ? (shaderType === ShaderEffect.HLSL ? hlslVertexShaderByteCode : (shaderType === ShaderEffect.GLSL ? glslVertexShader : "")) : "" + vertexShader: customVertexShader ? (GraphicsInfo.shaderType === GraphicsInfo.HLSL ? hlslVertexShaderByteCode : (GraphicsInfo.shaderType === GraphicsInfo.GLSL ? glslVertexShader : "")) : "" - fragmentShader: shaderType === ShaderEffect.HLSL ? hlslPixelShaderByteCode : (shaderType === ShaderEffect.GLSL ? glslFragmentShader : "") + fragmentShader: GraphicsInfo.shaderType === GraphicsInfo.HLSL ? hlslPixelShaderByteCode : (GraphicsInfo.shaderType === GraphicsInfo.GLSL ? glslFragmentShader : "") } Image { @@ -157,10 +157,10 @@ Item { height: eff2.height property variant delta: Qt.size(1.0 / width, 0.0) property variant source: effectSource2 - fragmentShader: shaderType === ShaderEffect.HLSL ? "qrc:/ps_shadow1.cso" : (shaderType === ShaderEffect.GLSL ? eff2.glslShaderPass1 : "") + fragmentShader: GraphicsInfo.shaderType === GraphicsInfo.HLSL ? "qrc:/ps_shadow1.cso" : (GraphicsInfo.shaderType === GraphicsInfo.GLSL ? eff2.glslShaderPass1 : "") } } - fragmentShader: shaderType === ShaderEffect.HLSL ? "qrc:/ps_shadow1.cso" : (shaderType === ShaderEffect.GLSL ? eff2.glslShaderPass1: "") + fragmentShader: GraphicsInfo.shaderType === GraphicsInfo.HLSL ? "qrc:/ps_shadow1.cso" : (GraphicsInfo.shaderType === GraphicsInfo.GLSL ? eff2.glslShaderPass1: "") } } property real angle: 0 @@ -168,7 +168,7 @@ Item { NumberAnimation on angle { loops: Animation.Infinite; from: 0; to: Math.PI * 2; duration: 6000 } property variant delta: Qt.size(offset.x / width, offset.y / height) property real darkness: 0.5 - fragmentShader: shaderType === ShaderEffect.HLSL ? "qrc:/ps_shadow2.cso" : (shaderType === ShaderEffect.GLSL ? glslShaderPass2 : "") + fragmentShader: GraphicsInfo.shaderType === GraphicsInfo.HLSL ? "qrc:/ps_shadow2.cso" : (GraphicsInfo.shaderType === GraphicsInfo.GLSL ? glslShaderPass2 : "") } Column { @@ -176,11 +176,10 @@ Item { Text { color: "yellow" font.pointSize: 24 - text: "Shader effect is " + (eff.shaderType === ShaderEffect.HLSL ? "HLSL" : (eff.shaderType === ShaderEffect.GLSL ? "GLSL" : "UNKNOWN")) + " based"; + text: "Shader effect is " + (GraphicsInfo.shaderType === GraphicsInfo.HLSL ? "HLSL" : (GraphicsInfo.shaderType === GraphicsInfo.GLSL ? "GLSL" : "UNKNOWN")) + " based"; } Text { - // check the inner shader effect's properties as those only get updated later on, once a window gets associated - text: innerEff.shaderType + " " + innerEff.shaderCompilationType + " " + innerEff.shaderSourceType + text: GraphicsInfo.shaderType + " " + GraphicsInfo.shaderCompilationType + " " + GraphicsInfo.shaderSourceType } } } |