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
qsgrenderer_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QSGRENDERER_P_H
6#define QSGRENDERER_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
20#include "qsgnode.h"
21#include "qsgmaterial.h"
22
23#include <QtQuick/private/qsgcontext_p.h>
24
26
27class QSGNodeUpdater;
28class QRhiRenderTarget;
29class QRhiCommandBuffer;
30class QRhiRenderPassDescriptor;
31class QRhiResourceUpdateBatch;
32
33class Q_QUICK_EXPORT QSGRenderTarget
34{
35public:
36 QSGRenderTarget() { }
37
38 QSGRenderTarget(QRhiRenderTarget *rt,
39 QRhiRenderPassDescriptor *rpDesc,
40 QRhiCommandBuffer *cb)
41 : rt(rt), rpDesc(rpDesc), cb(cb) { }
42
43 explicit QSGRenderTarget(QPaintDevice *paintDevice)
44 : paintDevice(paintDevice) { }
45
46 QRhiRenderTarget *rt = nullptr;
47 // Store the rp descriptor obj separately, it can (even if often it won't)
48 // be different from rt->renderPassDescriptor(); e.g. one user is the 2D
49 // integration in Quick 3D which will use a different, but compatible rp.
50 QRhiRenderPassDescriptor *rpDesc = nullptr;
51 QRhiCommandBuffer *cb = nullptr;
52
53 QPaintDevice *paintDevice = nullptr;
54
55 int multiViewCount = 0;
56};
57
58class Q_QUICK_EXPORT QSGRenderer : public QSGAbstractRenderer
59{
60public:
61 QSGRenderer(QSGRenderContext *context);
62 virtual ~QSGRenderer();
63
64 // Accessed by QSGMaterial[Rhi]Shader::RenderState.
65 QMatrix4x4 currentProjectionMatrix(int index) const { return m_current_projection_matrix[index]; }
66 QMatrix4x4 currentModelViewMatrix() const { return m_current_model_view_matrix; }
67 QMatrix4x4 currentCombinedMatrix(int index) const { return m_current_projection_matrix[index] * m_current_model_view_matrix; }
68 qreal currentOpacity() const { return m_current_opacity; }
69 qreal determinant() const { return m_current_determinant; }
70
71 void setDevicePixelRatio(qreal ratio) { m_device_pixel_ratio = ratio; }
72 qreal devicePixelRatio() const { return m_device_pixel_ratio; }
73 QSGRenderContext *context() const { return m_context; }
74
75 bool isMirrored() const;
76 void renderScene() override;
77 void prepareSceneInline() override;
78 void renderSceneInline() override;
79 void nodeChanged(QSGNode *node, QSGNode::DirtyState state) override;
80
81 QSGNodeUpdater *nodeUpdater() const;
82 void setNodeUpdater(QSGNodeUpdater *updater);
83 inline QSGMaterialShader::RenderState state(QSGMaterialShader::RenderState::DirtyStates dirty) const;
84 virtual void setVisualizationMode(const QByteArray &) { }
85 virtual bool hasVisualizationModeWithContinuousUpdate() const { return false; }
86 virtual void releaseCachedResources() { }
87
88 void clearChangedFlag() { m_changed_emitted = false; }
89
90 // Accessed by QSGMaterialShader::RenderState.
91 QByteArray *currentUniformData() const { return m_current_uniform_data; }
92 QRhiResourceUpdateBatch *currentResourceUpdateBatch() const { return m_current_resource_update_batch; }
93 QRhi *currentRhi() const { return m_rhi; }
94
95 void setRenderTarget(const QSGRenderTarget &rt) { m_rt = rt; }
96 const QSGRenderTarget &renderTarget() const { return m_rt; }
97
98 void setRenderPassRecordingCallbacks(QSGRenderContext::RenderPassCallback start,
99 QSGRenderContext::RenderPassCallback end,
100 void *userData)
101 {
102 m_renderPassRecordingCallbacks.start = start;
103 m_renderPassRecordingCallbacks.end = end;
104 m_renderPassRecordingCallbacks.userData = userData;
105 }
106
107protected:
108 virtual void render() = 0;
109
110 virtual void prepareInline();
111 virtual void renderInline();
112
113 virtual void preprocess();
114
115 void addNodesToPreprocess(QSGNode *node);
116 void removeNodesToPreprocess(QSGNode *node);
117
118 QVarLengthArray<QMatrix4x4, 1> m_current_projection_matrix; // includes adjustment, where applicable, so can be treated as Y up in NDC always
119 QVarLengthArray<QMatrix4x4, 1> m_current_projection_matrix_native_ndc; // Vulkan has Y down in normalized device coordinates, others Y up...
120 QMatrix4x4 m_current_model_view_matrix;
121 qreal m_current_opacity;
122 qreal m_current_determinant;
123 qreal m_device_pixel_ratio;
124
125 QSGRenderContext *m_context;
126
127 QByteArray *m_current_uniform_data;
128 QRhiResourceUpdateBatch *m_current_resource_update_batch;
129 QRhi *m_rhi;
130 QSGRenderTarget m_rt;
131 struct {
132 QSGRenderContext::RenderPassCallback start = nullptr;
133 QSGRenderContext::RenderPassCallback end = nullptr;
134 void *userData = nullptr;
135 } m_renderPassRecordingCallbacks;
136
137private:
138 QSGNodeUpdater *m_node_updater;
139
140 QSet<QSGNode *> m_nodes_to_preprocess;
141 QSet<QSGNode *> m_nodes_dont_preprocess;
142
143 uint m_changed_emitted : 1;
144 uint m_is_rendering : 1;
145 uint m_is_preprocessing : 1;
146};
147
148QSGMaterialShader::RenderState QSGRenderer::state(QSGMaterialShader::RenderState::DirtyStates dirty) const
149{
150 QSGMaterialShader::RenderState s;
151 s.m_dirty = dirty;
152 s.m_data = this;
153 return s;
154}
155
156
157class Q_QUICK_EXPORT QSGNodeDumper : public QSGNodeVisitor {
158
159public:
160 static void dump(QSGNode *n);
161
162 QSGNodeDumper() {}
163 void visitNode(QSGNode *n) override;
164 void visitChildren(QSGNode *n) override;
165
166private:
167 int m_indent = 0;
168};
169
170QT_END_NAMESPACE
171
172#endif
The QSGNodeDumper class provides a way of dumping a scene grahp to the console.
The renderer class is the abstract baseclass used for rendering the QML scene graph.
Combined button and popup list for selecting options.
static QT_BEGIN_NAMESPACE int qt_material_count
\group qtquick-scenegraph-materials \title Qt Quick Scene Graph Material Classes
static void qt_print_material_count()