Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgmaterialshader.h
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QSGMATERIALSHADER_H
6#define QSGMATERIALSHADER_H
7
8#include <QtQuick/qtquickglobal.h>
9#include <QtCore/QRect>
10#include <QtGui/QMatrix4x4>
11#include <QtGui/QColor>
12#include <QtQuick/qsgmaterialtype.h>
13
15
16class QSGMaterial;
17class QSGMaterialShaderPrivate;
18class QSGTexture;
19class QRhiResourceUpdateBatch;
20class QRhi;
21class QShader;
22
23class Q_QUICK_EXPORT QSGMaterialShader
24{
25public:
26 class Q_QUICK_EXPORT RenderState {
27 public:
28 enum DirtyState
29 {
30 DirtyMatrix = 0x0001,
31 DirtyOpacity = 0x0002,
32 DirtyCachedMaterialData = 0x0004,
33 DirtyAll = 0xFFFF
34 };
35 Q_DECLARE_FLAGS(DirtyStates, DirtyState)
36
37 inline DirtyStates dirtyStates() const { return m_dirty; }
38
39 inline bool isMatrixDirty() const { return bool(m_dirty & QSGMaterialShader::RenderState::DirtyMatrix); }
40 inline bool isOpacityDirty() const { return bool(m_dirty & QSGMaterialShader::RenderState::DirtyOpacity); }
41
42 float opacity() const;
43 QMatrix4x4 combinedMatrix() const;
44 QMatrix4x4 combinedMatrix(qsizetype index) const;
45 QMatrix4x4 modelViewMatrix() const;
46 QMatrix4x4 projectionMatrix() const;
47 QMatrix4x4 projectionMatrix(qsizetype index) const;
48 qsizetype projectionMatrixCount() const;
49 QRect viewportRect() const;
50 QRect deviceRect() const;
51 float determinant() const;
52 float devicePixelRatio() const;
53
54 QByteArray *uniformData();
55 QRhiResourceUpdateBatch *resourceUpdateBatch();
56 QRhi *rhi();
57
58 private:
59 friend class QSGRenderer;
60 DirtyStates m_dirty;
61 const void *m_data;
62 };
63
64 struct GraphicsPipelineState {
65 enum BlendFactor {
66 Zero,
67 One,
68 SrcColor,
69 OneMinusSrcColor,
70 DstColor,
71 OneMinusDstColor,
72 SrcAlpha,
73 OneMinusSrcAlpha,
74 DstAlpha,
75 OneMinusDstAlpha,
76 ConstantColor,
77 OneMinusConstantColor,
78 ConstantAlpha,
79 OneMinusConstantAlpha,
80 SrcAlphaSaturate,
81 Src1Color,
82 OneMinusSrc1Color,
83 Src1Alpha,
84 OneMinusSrc1Alpha
85 };
86
87 enum class BlendOp {
88 Add,
89 Subtract,
90 ReverseSubtract,
91 Min,
92 Max,
93 };
94
95 enum ColorMaskComponent {
96 R = 1 << 0,
97 G = 1 << 1,
98 B = 1 << 2,
99 A = 1 << 3
100 };
101 Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent)
102
103 enum CullMode {
104 CullNone,
105 CullFront,
106 CullBack
107 };
108
109 enum PolygonMode {
110 Fill,
111 Line,
112 };
113
114 bool blendEnable;
115 BlendFactor srcColor;
116 BlendFactor dstColor;
117 ColorMask colorWrite;
118 QColor blendConstant;
119 CullMode cullMode;
120 PolygonMode polygonMode;
121 bool separateBlendFactors;
122 BlendFactor srcAlpha;
123 BlendFactor dstAlpha;
124 BlendOp opColor;
125 BlendOp opAlpha;
126
127 // This struct is extensible while keeping BC since apps only ever get
128 // a ptr to the struct, it is not created by them.
129 };
130
131 enum Flag {
132 UpdatesGraphicsPipelineState = 0x0001
133 };
134 Q_DECLARE_FLAGS(Flags, Flag)
135
136 enum Stage {
137 VertexStage,
138 FragmentStage,
139 };
140
141 QSGMaterialShader();
142 virtual ~QSGMaterialShader();
143
144 virtual bool updateUniformData(RenderState &state,
145 QSGMaterial *newMaterial, QSGMaterial *oldMaterial);
146
147 virtual void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
148 QSGMaterial *newMaterial, QSGMaterial *oldMaterial);
149
150 virtual bool updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps,
151 QSGMaterial *newMaterial, QSGMaterial *oldMaterial);
152
153 Flags flags() const;
154 void setFlag(Flags flags, bool on = true);
155 void setFlags(Flags flags);
156
157 int combinedImageSamplerCount(int binding) const;
158
159protected:
160 Q_DECLARE_PRIVATE(QSGMaterialShader)
161 QSGMaterialShader(QSGMaterialShaderPrivate &dd);
162
163 // filename is for a file containing a serialized QShader.
164 void setShaderFileName(Stage stage, const QString &filename);
165 void setShaderFileName(Stage stage, const QString &filename, int viewCount);
166
167 void setShader(Stage stage, const QShader &shader);
168
169private:
170 QScopedPointer<QSGMaterialShaderPrivate> d_ptr;
171};
172
173Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterialShader::RenderState::DirtyStates)
174Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterialShader::GraphicsPipelineState::ColorMask)
175Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterialShader::Flags)
176
177QT_END_NAMESPACE
178
179#endif
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:323
const Type * at(uint index) const
char data[sizeof(Type) *PageSize]
QList< AllocatorPage< Type, PageSize > * > pages
void releaseExplicit(uint pageIndex, uint index)
QMultiHash< QList< quint32 >, QRhiShaderResourceBindings * > srbPool
Shader * prepareMaterial(QSGMaterial *material, const QSGGeometry *geometry=nullptr, QSGRendererInterface::RenderMode renderMode=QSGRendererInterface::RenderMode2D, int multiViewCount=0)
QList< quint32 > srbLayoutDescSerializeWorkspace
QHash< GraphicsPipelineStateKey, QRhiGraphicsPipeline * > pipelineCache
ShaderManager(QSGDefaultRenderContext *ctx)
Shader * prepareMaterialNoRewrite(QSGMaterial *material, const QSGGeometry *geometry=nullptr, QSGRendererInterface::RenderMode renderMode=QSGRendererInterface::RenderMode2D, int multiViewCount=0)
void updateRootTransforms(Node *n, Node *root, const QMatrix4x4 &combined)
void registerWithParentRoot(QSGNode *subRoot, QSGNode *parentRoot)
void updateStates(QSGNode *n) override
void updateRootTransforms(Node *n)
virtual void visualize()=0
void setMode(VisualizeMode mode)
virtual void visualizeChangesPrepare(Node *n, uint parentChanges=0)
virtual void prepareVisualize()=0
virtual void releaseResources()=0
QHash< Node *, uint > m_visualizeChangeSet
The QSGMaterialShader class represents a graphics API independent shader program.
const int ZORDER_BUFFER_BINDING
static void qsg_wipeBuffer(Buffer *buffer)
static void rendererToMaterialGraphicsState(QSGMaterialShader::GraphicsPipelineState *dst, GraphicsState *src)
size_t qHash(const GraphicsState &s, size_t seed) noexcept
static QRhiVertexInputLayout calculateVertexInputLayout(const QSGMaterialShader *s, const QSGGeometry *geometry, bool batchable)
static void qsg_addBackOrphanedElements(QDataBuffer< Element * > &orphans, QDataBuffer< Element * > &renderList)
bool operator!=(const GraphicsPipelineStateKey &a, const GraphicsPipelineStateKey &b) noexcept
const float VIEWPORT_MIN_DEPTH
QSGMaterial::Flag QSGMaterial_FullMatrix
bool qsg_sort_batch_decreasing_order(Batch *a, Batch *b)
QDebug operator<<(QDebug d, const Pt &p)
QDebug operator<<(QDebug d, const Rect &r)
bool operator==(const ShaderKey &a, const ShaderKey &b) noexcept
bool operator==(const GraphicsPipelineStateKey &a, const GraphicsPipelineStateKey &b) noexcept
bool operator!=(const ShaderKey &a, const ShaderKey &b) noexcept
static void qsg_wipeBatch(Batch *batch)
static QRhiSampler * newSampler(QRhi *rhi, const QSGSamplerDescription &desc)
QRhiVertexInputAttribute::Format qsg_vertexInputFormat(const QSGGeometry::Attribute &a)
QRhiGraphicsPipeline::Topology qsg_topology(int geomDrawMode, QRhi *rhi)
QMatrix4x4 qsg_matrixForRoot(Node *node)
bool qsg_sort_batch_increasing_order(Batch *a, Batch *b)
static void qsg_addOrphanedElements(QDataBuffer< Element * > &orphans, const QDataBuffer< Element * > &renderList)
void qsg_setMultiViewFlagsOnMaterial(QSGMaterial *material, int multiViewCount)
const float VIEWPORT_MAX_DEPTH
int qsg_positionAttribute(QSGGeometry *g)
static int size_of_type(int type)
static bool isTranslate(const QMatrix4x4 &m)
static int qsg_countNodesInBatches(const QDataBuffer< Batch * > &batches)
static float calculateElementZOrder(const Element *e, qreal zRange)
static int qsg_fixIndexCount(int iCount, int drawMode)
bool qsg_sort_element_increasing_order(Element *a, Element *b)
static void materialToRendererGraphicsState(GraphicsState *dst, QSGMaterialShader::GraphicsPipelineState *src)
static bool needsBlendConstant(QRhiGraphicsPipeline::BlendFactor f)
const int VERTEX_BUFFER_BINDING
const uint DYNAMIC_VERTEX_INDEX_BUFFER_THRESHOLD
bool hasMaterialWithBlending(QSGGeometryNode *n)
static int qsg_countNodesInBatch(const Batch *batch)
bool operator==(const GraphicsState &a, const GraphicsState &b) noexcept
QRhiCommandBuffer::IndexFormat qsg_indexFormat(const QSGGeometry *geometry)
bool operator!=(const GraphicsState &a, const GraphicsState &b) noexcept
bool qsg_sort_element_decreasing_order(Element *a, Element *b)
size_t qHash(const ShaderKey &k, size_t seed) noexcept
void qsg_dumpShadowRoots(BatchRootInfo *i, int indent)
void qsg_dumpShadowRoots(Node *n)
static bool isScale(const QMatrix4x4 &m)
static bool is2DSafe(const QMatrix4x4 &m)
size_t qHash(const GraphicsPipelineStateKey &k, size_t seed) noexcept
Int aligned(Int v, Int byteAlign)
const quint32 DEFAULT_BUFFER_POOL_SIZE_LIMIT
Combined button and popup list for selecting options.
Q_DECLARE_TYPEINFO(QDateTime::Data, Q_RELOCATABLE_TYPE)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582
#define DECLARE_DEBUG_VAR(variable)
#define QSGNODE_DIRTY_PARENT
QT_BEGIN_NAMESPACE int qt_sg_envInt(const char *name, int defaultValue)
#define SHADOWNODE_TRAVERSE(NODE)
#define QSGNODE_TRAVERSE(NODE)
Q_DECLARE_TYPEINFO(QSGBatchRenderer::DrawSet, Q_PRIMITIVE_TYPE)
Q_DECLARE_TYPEINFO(QSGBatchRenderer::GraphicsState, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(QSGBatchRenderer::GraphicsPipelineStateKey, Q_RELOCATABLE_TYPE)
#define QSG_RENDERER_COORD_LIMIT
Q_DECLARE_TYPEINFO(QSGBatchRenderer::RenderPassState, Q_RELOCATABLE_TYPE)
bool geometryWasChanged(QSGGeometryNode *gn)
BatchCompatibility isMaterialCompatible(Element *e) const
StencilClipState stencilClipState
QDataBuffer< DrawSet > drawSets
DrawSet(int v, int z, int i)
QRhiGraphicsPipeline * depthPostPassPs
QRhiShaderResourceBindings * srb
QRhiGraphicsPipeline * ps
void setNode(QSGGeometryNode *n)
static GraphicsPipelineStateKey create(const GraphicsState &state, const ShaderManagerShader *sms, const QRhiRenderPassDescriptor *rpDesc, const QRhiShaderResourceBindings *srb)
QSGGeometry::DrawingMode drawMode
QSGNode::NodeType type() const
BatchRootInfo * rootInfo() const
QSGNode::DirtyState dirtyState
ClipBatchRootInfo * clipInfo() const
RenderNodeElement * renderNodeElement() const
bool hasChild(Node *child) const
void map(const QMatrix4x4 &mat)
void set(float nx, float ny)
void operator|=(const Pt &pt)
void set(float left, float top, float right, float bottom)
void map(const QMatrix4x4 &m)
bool intersects(const Rect &r)
void operator|=(const Rect &r)
const QMatrix4x4 * projectionMatrix() const override
const QRegion * clipRegion() const override
QRhiDepthStencilClearValue dsClear
QSGRendererInterface::RenderMode renderMode
QVarLengthArray< QRhiShaderStage, 2 > stages
QRhiShaderResourceBindings * srb
QDataBuffer< StencilDrawCall > drawCalls