1/****************************************************************************
2**
3** Copyright (C) 2019 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QSGMATERIALRHISHADER_H
41#define QSGMATERIALRHISHADER_H
42
43#include <QtQuick/qtquickglobal.h>
44#include <QtCore/QRect>
45#include <QtGui/QMatrix4x4>
46#include <QtGui/QColor>
47#include <QtQuick/qsgmaterialshader.h>
48
49QT_BEGIN_NAMESPACE
50
51class QSGMaterial;
52class QSGMaterialRhiShaderPrivate;
53class QSGTexture;
54class QRhiResourceUpdateBatch;
55class QRhi;
56class QShader;
57
58class Q_QUICK_EXPORT QSGMaterialRhiShader : public QSGMaterialShader // ### Qt 6: remove inheritance
59{
60public:
61 class Q_QUICK_EXPORT RenderState {
62 public:
63 using DirtyStates = QSGMaterialShader::RenderState::DirtyStates;
64
65 inline DirtyStates dirtyStates() const { return m_dirty; }
66
67 inline bool isMatrixDirty() const { return m_dirty & QSGMaterialShader::RenderState::DirtyMatrix; }
68 inline bool isOpacityDirty() const { return m_dirty & QSGMaterialShader::RenderState::DirtyOpacity; }
69
70 float opacity() const;
71 QMatrix4x4 combinedMatrix() const;
72 QMatrix4x4 modelViewMatrix() const;
73 QMatrix4x4 projectionMatrix() const;
74 QRect viewportRect() const;
75 QRect deviceRect() const;
76 float determinant() const;
77 float devicePixelRatio() const;
78
79 QByteArray *uniformData();
80 QRhiResourceUpdateBatch *resourceUpdateBatch();
81 QRhi *rhi();
82
83 private:
84 friend class QSGRenderer;
85 DirtyStates m_dirty;
86 const void *m_data;
87 };
88
89 struct Q_QUICK_EXPORT GraphicsPipelineState {
90 enum BlendFactor {
91 Zero,
92 One,
93 SrcColor,
94 OneMinusSrcColor,
95 DstColor,
96 OneMinusDstColor,
97 SrcAlpha,
98 OneMinusSrcAlpha,
99 DstAlpha,
100 OneMinusDstAlpha,
101 ConstantColor,
102 OneMinusConstantColor,
103 ConstantAlpha,
104 OneMinusConstantAlpha,
105 SrcAlphaSaturate,
106 Src1Color,
107 OneMinusSrc1Color,
108 Src1Alpha,
109 OneMinusSrc1Alpha
110 };
111
112 enum ColorMaskComponent {
113 R = 1 << 0,
114 G = 1 << 1,
115 B = 1 << 2,
116 A = 1 << 3
117 };
118 Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent)
119
120 enum CullMode {
121 CullNone,
122 CullFront,
123 CullBack
124 };
125
126 bool blendEnable;
127 BlendFactor srcColor;
128 BlendFactor dstColor;
129 ColorMask colorWrite;
130 QColor blendConstant;
131 CullMode cullMode;
132 // This struct is extensible while keeping BC since apps only ever get
133 // a ptr to the struct, it is not created by them.
134 };
135
136 enum Flag {
137 UpdatesGraphicsPipelineState = 0x0001
138 };
139 Q_DECLARE_FLAGS(Flags, Flag)
140
141 enum Stage {
142 VertexStage,
143 FragmentStage,
144 };
145
146 QSGMaterialRhiShader();
147 virtual ~QSGMaterialRhiShader();
148
149 virtual bool updateUniformData(RenderState &state,
150 QSGMaterial *newMaterial, QSGMaterial *oldMaterial);
151
152 virtual void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
153 QSGMaterial *newMaterial, QSGMaterial *oldMaterial);
154
155 virtual bool updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps,
156 QSGMaterial *newMaterial, QSGMaterial *oldMaterial);
157
158 Flags flags() const;
159 void setFlag(Flags flags, bool on = true);
160
161 // dummy impl for base class pure virtual, never called
162 char const *const *attributeNames() const override;
163
164protected:
165 Q_DECLARE_PRIVATE(QSGMaterialRhiShader)
166 QSGMaterialRhiShader(QSGMaterialRhiShaderPrivate &dd);
167
168 // filename is for a file containing a serialized QShader.
169 void setShaderFileName(Stage stage, const QString &filename);
170
171 void setShader(Stage stage, const QShader &shader);
172
173private:
174 QScopedPointer<QSGMaterialRhiShaderPrivate> d_ptr;
175};
176
177Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterialRhiShader::GraphicsPipelineState::ColorMask)
178Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterialRhiShader::Flags)
179
180QT_END_NAMESPACE
181
182#endif
183

source code of qtdeclarative/src/quick/scenegraph/coreapi/qsgmaterialrhishader.h