aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2020-04-06 14:18:18 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2020-04-07 17:08:39 +0200
commitfd4f121fcaccc671f942b8542e3c8f9eaedc7942 (patch)
treef15d4230c2e84eeb56268198cf5f4080166eb1b6 /src
parentaafd78d0340a971bfc72ac1ce5adaf8a175265af (diff)
Remove QSGSimpleMaterial
And port the graph example to QSGMaterial and the RHI. We will not anymore add a direct OpenGL path (that would mean using QSGMaterialShader) for the example because the upcoming purge renders that useless anyway. Task-number: QTBUG-82988 Change-Id: I137575ed5df45b6bfc34a11d73dc5100945081c5 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quick/CMakeLists.txt1
-rw-r--r--src/quick/items/qquickitem.cpp2
-rw-r--r--src/quick/scenegraph/coreapi/qsgmaterialshader.cpp4
-rw-r--r--src/quick/scenegraph/coreapi/qsgnode.cpp2
-rw-r--r--src/quick/scenegraph/scenegraph.pri2
-rw-r--r--src/quick/scenegraph/util/qsgsimplematerial.cpp254
-rw-r--r--src/quick/scenegraph/util/qsgsimplematerial.h219
7 files changed, 2 insertions, 482 deletions
diff --git a/src/quick/CMakeLists.txt b/src/quick/CMakeLists.txt
index 24d015f576..88ddc4e257 100644
--- a/src/quick/CMakeLists.txt
+++ b/src/quick/CMakeLists.txt
@@ -131,7 +131,6 @@ qt_add_module(Quick
scenegraph/util/qsgninepatchnode.cpp scenegraph/util/qsgninepatchnode.h
scenegraph/util/qsgplaintexture.cpp scenegraph/util/qsgplaintexture_p.h
scenegraph/util/qsgrectanglenode.cpp scenegraph/util/qsgrectanglenode.h
- scenegraph/util/qsgsimplematerial.cpp scenegraph/util/qsgsimplematerial.h
scenegraph/util/qsgsimplerectnode.cpp scenegraph/util/qsgsimplerectnode.h
scenegraph/util/qsgsimpletexturenode.cpp scenegraph/util/qsgsimpletexturenode.h
scenegraph/util/qsgtexturematerial.cpp scenegraph/util/qsgtexturematerial.h scenegraph/util/qsgtexturematerial_p.h
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index 707f149baf..a1f8fd35d8 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -3802,7 +3802,7 @@ void QQuickItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeo
\note All classes with QSG prefix should be used solely on the scene graph's
rendering thread. See \l {Scene Graph and Rendering} for more information.
- \sa QSGMaterial, QSGSimpleMaterial, QSGGeometryNode, QSGGeometry,
+ \sa QSGMaterial, QSGGeometryNode, QSGGeometry,
QSGFlatColorMaterial, QSGTextureMaterial, QSGNode::markDirty(), {Graphics Resource Handling}
*/
diff --git a/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp b/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp
index 9049dd5826..64956e2ca4 100644
--- a/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp
+++ b/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp
@@ -69,10 +69,6 @@ const char *QSGMaterialShaderPrivate::loadShaderSource(QOpenGLShader::ShaderType
\inmodule QtQuick
\ingroup qtquick-scenegraph-materials
- The QSGMaterialShader API is relatively low-level. A more convenient API,
- which provides almost all the same features, is available through
- QSGSimpleMaterialShader.
-
\warning This class is only functional when running with the legacy OpenGL
renderer of the Qt Quick scenegraph.
diff --git a/src/quick/scenegraph/coreapi/qsgnode.cpp b/src/quick/scenegraph/coreapi/qsgnode.cpp
index a35629d874..e22ffa10d2 100644
--- a/src/quick/scenegraph/coreapi/qsgnode.cpp
+++ b/src/quick/scenegraph/coreapi/qsgnode.cpp
@@ -850,7 +850,7 @@ void QSGBasicGeometryNode::setGeometry(QSGGeometry *geometry)
\note All classes with QSG prefix should be used solely on the scene graph's
rendering thread. See \l {Scene Graph and Rendering} for more information.
- \sa QSGGeometry, QSGMaterial, QSGSimpleMaterial
+ \sa QSGGeometry, QSGMaterial
*/
diff --git a/src/quick/scenegraph/scenegraph.pri b/src/quick/scenegraph/scenegraph.pri
index 56dda508c6..494ff7276e 100644
--- a/src/quick/scenegraph/scenegraph.pri
+++ b/src/quick/scenegraph/scenegraph.pri
@@ -55,7 +55,6 @@ HEADERS += \
$$PWD/util/qsgsimpletexturenode.h \
$$PWD/util/qsgtextureprovider.h \
$$PWD/util/qsgflatcolormaterial.h \
- $$PWD/util/qsgsimplematerial.h \
$$PWD/util/qsgtexturematerial.h \
$$PWD/util/qsgtexturematerial_p.h \
$$PWD/util/qsgvertexcolormaterial.h \
@@ -70,7 +69,6 @@ SOURCES += \
$$PWD/util/qsgsimpletexturenode.cpp \
$$PWD/util/qsgtextureprovider.cpp \
$$PWD/util/qsgflatcolormaterial.cpp \
- $$PWD/util/qsgsimplematerial.cpp \
$$PWD/util/qsgtexturematerial.cpp \
$$PWD/util/qsgvertexcolormaterial.cpp \
$$PWD/util/qsgrectanglenode.cpp \
diff --git a/src/quick/scenegraph/util/qsgsimplematerial.cpp b/src/quick/scenegraph/util/qsgsimplematerial.cpp
deleted file mode 100644
index 1064caccc7..0000000000
--- a/src/quick/scenegraph/util/qsgsimplematerial.cpp
+++ /dev/null
@@ -1,254 +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$
-**
-****************************************************************************/
-
-/*!
- \class QSGSimpleMaterialShader
-
- \brief The QSGSimpleMaterialShader class provides a convenient way of
- building custom OpenGL-based materials for the scene graph.
-
- \inmodule QtQuick
- \ingroup qtquick-scenegraph-materials
-
- \warning This utility class is only functional when running with the legacy
- OpenGL renderer of the Qt Quick scenegraph. Its usage is not recommended in
- new application code.
-
- Where the QSGMaterial and QSGMaterialShader API requires a bit of
- boilerplate code to create a functioning material, the
- QSGSimpleMaterialShader tries to hide some of this through the use
- of templates.
-
- QSGSimpleMaterialShader::vertexShader() and
- QSGSimpleMaterialShader::fragmentShader() are used to specify the
- actual shader source code. The names of the vertex attributes
- should be listed in the QSGSimpleMaterialShader::attributes()
-
- QSGSimpleMaterialShader::updateState() is used to push the material
- state to the OpenGL shader program.
-
- The actual OpenGL shader program is accessible through the
- QSGSimpleMaterialShader::program() function.
-
- Each QSGSimpleMaterialShader implementation operates on a unique
- state struct. The state struct must be declared using the
- \c {QSG_DECLARE_SIMPLE_SHADER} macro.
-
- Here is a simple example of a custom solid-color:
-
- \code
- struct Color
- {
- float r, g, b, a;
- };
-
- class MinimalShader : public QSGSimpleMaterialShader<Color>
- {
- QSG_DECLARE_SIMPLE_SHADER(MinimalShader, Color)
- public:
-
- const char *vertexShader() const {
- return
- "attribute highp vec4 vertex; \n"
- "uniform highp mat4 qt_Matrix; \n"
- "void main() { \n"
- " gl_Position = qt_Matrix * vertex; \n"
- "}";
- }
-
- const char *fragmentShader() const {
- return
- "uniform lowp float qt_Opacity; \n"
- "uniform lowp vec4 color; \n"
- "void main() { \n"
- " gl_FragColor = color * qt_Opacity; \n"
- "}";
- }
-
- QList<QByteArray> attributes() const {
- return QList<QByteArray>() << "vertex";
- }
-
- void updateState(const Color *color, const Color *) {
- program()->setUniformValue("color", color->r, color->g, color->b, color->a);
- }
-
- };
- \endcode
-
- Instances of materials using this shader can be created using the
- createMaterial() function which will be defined by the
- QSG_DECLARE_SIMPLE_SHADER macro.
-
- \code
- QSGSimpleMaterial<Color> *material = MinimalShader::createMaterial();
- material->state()->r = 1;
- material->state()->g = 0;
- material->state()->b = 0;
- material->state()->a = 1;
-
- node->setMaterial(material);
- \endcode
-
- The scene graph will often try to find materials that have the
- same or at least similar state so that these can be batched
- together inside the renderer, which gives better performance. To
- specify sortable material states, use
- QSG_DECLARE_SIMPLE_COMPARABLE_SHADER instead of
- QSG_DECLARE_SIMPLE_SHADER. The state struct must then also define
- the function:
-
- \code
- int compare(const Type *other) const;
- \endcode
-
- \warning The QSGSimpleMaterialShader relies on template
- instantiation to create a QSGMaterialType which the scene graph
- renderer internally uses to identify this shader. For this reason,
- the unique QSGSimpleMaterialShader implementation must be
- instantiated with a unique C++ type.
-
- \note All classes with QSG prefix should be used solely on the scene graph's
- rendering thread. See \l {Scene Graph and Rendering} for more information.
-
- \sa {Scene Graph - Simple Material}
- */
-
-/*!
- \macro QSG_DECLARE_SIMPLE_SHADER(Shader, State)
- \relates QSGSimpleMaterialShader
-
- This macro is used to declare a QSGMaterialType and a \c
- createMaterial() function for \a Shader with the given \a State.
- */
-
-/*!
- \macro QSG_DECLARE_SIMPLE_COMPARABLE_SHADER(Shader, State)
- \relates QSGSimpleMaterialShader
-
- This macro is used to declare a QSGMaterialType and a \c
- createMaterial() function for \a Shader with the given \a State,
- where the \a State class must define a compare function on the
- form:
-
- \code
- int compare(const State *other) const;
- \endcode
-*/
-
-
-/*!
- \fn template <typename State> char const *const *QSGSimpleMaterialShader<State>::attributeNames() const
- \internal
- */
-
-/*!
- \fn template <typename State> void QSGSimpleMaterialShader<State>::initialize()
- \internal
- */
-
-/*!
- \fn template <typename State> void QSGSimpleMaterialShader<State>::resolveUniforms()
-
- Reimplement this function to resolve the location of named uniforms
- in the shader program.
-
- This function is called when the material shader is initialized.
- */
-
-/*!
- \fn template <typename State> const char *QSGSimpleMaterialShader<State>::uniformMatrixName() const
-
- Returns the name for the transform matrix uniform of this item.
- The default value is \c qt_Matrix.
- */
-
-/*!
- \fn template <typename State> const char *QSGSimpleMaterialShader<State>::uniformOpacityName() const
-
- Returns the name for the opacity uniform of this item.
- The default value is \c qt_Opacity.
- */
-
-/*!
- \fn template <typename State> void QSGSimpleMaterialShader<State>::updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
- \internal
- */
-
-
-/*!
- \fn template <typename State> QList<QByteArray> QSGSimpleMaterialShader<State>::attributes() const
-
- Returns a list of names, declaring the vertex attributes in the
- vertex shader.
-*/
-
-/*!
- \fn template <typename State> void QSGSimpleMaterialShader<State>::updateState(const State *newState, const State *oldState)
-
- Called whenever the state of this shader should be updated from
- \a oldState to \a newState, typical for each new set of
- geometries being drawn.
-
- Both the old and the new state are passed in so that the
- implementation can compare and minimize the state changes when
- applicable.
-*/
-
-/*!
- \class QSGSimpleMaterial
-
- \inmodule QtQuick
- \ingroup qtquick-scenegraph-materials
-
- \brief The QSGSimpleMaterial class is a template generated class
- used to store the state used with a QSGSimpleMateralShader.
-
- The state of the material is accessible through the template
- generated state() function.
-
- \inmodule QtQuick
-
- \note All classes with QSG prefix should be used solely on the scene graph's
- rendering thread. See \l {Scene Graph and Rendering} for more information.
-
- \sa QSGSimpleMaterialShader
-*/
-
-
diff --git a/src/quick/scenegraph/util/qsgsimplematerial.h b/src/quick/scenegraph/util/qsgsimplematerial.h
deleted file mode 100644
index 79180ca8e2..0000000000
--- a/src/quick/scenegraph/util/qsgsimplematerial.h
+++ /dev/null
@@ -1,219 +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 QSGSIMPLEMATERIAL_H
-#define QSGSIMPLEMATERIAL_H
-
-#include <QtQuick/qsgmaterial.h>
-
-QT_BEGIN_NAMESPACE
-
-template <typename State>
-class QSGSimpleMaterialShader : public QSGMaterialShader
-{
-public:
- void initialize() override {
- QSGMaterialShader::initialize();
-#if QT_CONFIG(opengl)
- m_id_matrix = program()->uniformLocation(uniformMatrixName());
- if (m_id_matrix < 0) {
- qFatal("QSGSimpleMaterialShader does not implement 'uniform highp mat4 %s;' in its vertex shader",
- uniformMatrixName());
- }
-
- const char *opacity = uniformOpacityName();
- if (opacity) {
- m_id_opacity = program()->uniformLocation(uniformOpacityName());
- if (m_id_opacity < 0) {
- qFatal("QSGSimpleMaterialShader does not implement 'uniform lowp float %s' in its fragment shader",
- uniformOpacityName());
- }
- } else {
- m_id_opacity = -1;
- }
-#endif
- resolveUniforms();
- }
-
- // ### Qt 6: make both virtual and fix docs
- const char *uniformMatrixName() const { return "qt_Matrix"; }
- const char *uniformOpacityName() const { return "qt_Opacity"; }
-
- void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
-
- virtual void updateState(const State *newState, const State *oldState) = 0;
-
- virtual void resolveUniforms() {}
-
- virtual QList<QByteArray> attributes() const = 0;
-
- char const *const *attributeNames() const override
- {
- if (m_attribute_pointers.size())
- return m_attribute_pointers.constData();
-
- QList<QByteArray> names = attributes();
-
- // Calculate the total number of bytes needed, so we don't get rellocs and
- // bad pointers while copying over the individual names.
- // Add an extra byte pr entry for the '\0' char.
- int total = 0;
- for (int i=0; i<names.size(); ++i)
- total += names.at(i).size() + 1;
- m_attribute_name_data.reserve(total);
-
- // Copy over the names
- for (int i=0; i<names.size(); ++i) {
- m_attribute_pointers << m_attribute_name_data.constData() + m_attribute_name_data.size();
- m_attribute_name_data.append(names.at(i));
- m_attribute_name_data.append('\0');
- }
-
- // Append the "null" terminator
- m_attribute_pointers << 0;
-
- return m_attribute_pointers.constData();
- }
-
-private:
- int m_id_matrix;
- int m_id_opacity;
-
- mutable QByteArray m_attribute_name_data;
- mutable QVector<const char *> m_attribute_pointers;
-};
-
-#define QSG_DECLARE_SIMPLE_SHADER(Shader, State) \
-static QSGMaterialShader *createShader() \
-{ \
- return new Shader; \
-} \
-public: \
-static QSGSimpleMaterial<State> *createMaterial() \
-{ \
- return new QSGSimpleMaterial<State>(createShader); \
-}
-
-
-typedef QSGMaterialShader *(*PtrShaderCreateFunc)();
-
-
-template <typename State>
-class QSGSimpleMaterial : public QSGMaterial
-{
-public:
-#ifndef Q_CLANG_QDOC
- QSGSimpleMaterial(const State &aState, PtrShaderCreateFunc func)
- : m_state(aState)
- , m_func(func)
- {
- }
-
- QSGSimpleMaterial(PtrShaderCreateFunc func)
- : m_func(func)
- {
- }
-
- QSGMaterialShader *createShader() const override { return m_func(); }
- QSGMaterialType *type() const override { return &m_type; }
-
- State *state() { return &m_state; }
- const State *state() const { return &m_state; }
-#endif
-
-private:
- static QSGMaterialType m_type;
- State m_state;
- PtrShaderCreateFunc m_func;
-};
-
-#define QSG_DECLARE_SIMPLE_COMPARABLE_SHADER(Shader, State) \
-static QSGMaterialShader *createShader() \
-{ \
- return new Shader; \
-} \
-public: \
-static QSGSimpleMaterialComparableMaterial<State> *createMaterial() \
-{ \
- return new QSGSimpleMaterialComparableMaterial<State>(createShader); \
-}
-
-template <typename State>
-class QSGSimpleMaterialComparableMaterial : public QSGSimpleMaterial<State>
-{
-
-public:
- QSGSimpleMaterialComparableMaterial(const State &state, PtrShaderCreateFunc func)
- : QSGSimpleMaterial<State>(state, func) {}
-
- QSGSimpleMaterialComparableMaterial(PtrShaderCreateFunc func)
- : QSGSimpleMaterial<State>(func) {}
-
- int compare(const QSGMaterial *other) const override {
- return QSGSimpleMaterialComparableMaterial<State>::state()->compare(static_cast<const QSGSimpleMaterialComparableMaterial<State> *>(other)->state());
- }
-};
-
-
-template <typename State>
-QSGMaterialType QSGSimpleMaterial<State>::m_type;
-
-
-template <typename State>
-Q_INLINE_TEMPLATE void QSGSimpleMaterialShader<State>::updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
-{
-#if QT_CONFIG(opengl)
- if (state.isMatrixDirty())
- program()->setUniformValue(m_id_matrix, state.combinedMatrix());
- if (state.isOpacityDirty() && m_id_opacity >= 0)
- program()->setUniformValue(m_id_opacity, state.opacity());
-#else
- Q_UNUSED(state)
-#endif
- State *ns = static_cast<QSGSimpleMaterial<State> *>(newMaterial)->state();
- State *old = nullptr;
- if (oldMaterial)
- old = static_cast<QSGSimpleMaterial<State> *>(oldMaterial)->state();
- updateState(ns, old);
-}
-
-QT_END_NAMESPACE
-
-
-#endif