Qt 6.x
The Qt SDK
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
4#ifndef QSGRENDERER_P_H
5#define QSGRENDERER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
19#include "qsgnode.h"
20#include "qsgmaterial.h"
21
22#include <QtQuick/private/qsgcontext_p.h>
23
25
26class QSGNodeUpdater;
31
32Q_QUICK_PRIVATE_EXPORT bool qsg_test_and_clear_fatal_render_error();
33Q_QUICK_PRIVATE_EXPORT void qsg_set_fatal_renderer_error();
34
35class Q_QUICK_PRIVATE_EXPORT QSGRenderTarget
36{
37public:
39
43 : rt(rt), rpDesc(rpDesc), cb(cb) { }
44
45 explicit QSGRenderTarget(QPaintDevice *paintDevice)
46 : paintDevice(paintDevice) { }
47
48 QRhiRenderTarget *rt = nullptr;
49 // Store the rp descriptor obj separately, it can (even if often it won't)
50 // be different from rt->renderPassDescriptor(); e.g. one user is the 2D
51 // integration in Quick 3D which will use a different, but compatible rp.
52 QRhiRenderPassDescriptor *rpDesc = nullptr;
54
55 QPaintDevice *paintDevice = nullptr;
56};
57
58class Q_QUICK_PRIVATE_EXPORT QSGRenderer : public QSGAbstractRenderer
59{
60public:
62 virtual ~QSGRenderer();
63
64 // Accessed by QSGMaterial[Rhi]Shader::RenderState.
65 QMatrix4x4 currentProjectionMatrix() const { return m_current_projection_matrix; }
66 QMatrix4x4 currentModelViewMatrix() const { return m_current_model_view_matrix; }
67 QMatrix4x4 currentCombinedMatrix() const { return m_current_projection_matrix * 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
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 QMatrix4x4 m_current_projection_matrix; // includes adjustment, where applicable, so can be treated as Y up in NDC always
119 QMatrix4x4 m_current_projection_matrix_native_ndc; // Vulkan has Y down in normalized device coordinates, others Y up...
124
126
131 struct {
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{
151 s.m_dirty = dirty;
152 s.m_data = this;
153 return s;
154}
155
156
157class Q_QUICK_PRIVATE_EXPORT QSGNodeDumper : public QSGNodeVisitor {
158
159public:
160 static void dump(QSGNode *n);
161
163 void visitNode(QSGNode *n) override;
164 void visitChildren(QSGNode *n) override;
165
166private:
167 int m_indent = 0;
168};
169
170#ifndef QT_NO_DEBUG
171extern bool _q_sg_leak_check;
172#endif
173
175
176#endif
\inmodule QtCore
Definition qbytearray.h:57
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
\inmodule QtGui
Definition qrhi.h:1614
\inmodule QtGui
Definition qrhi.h:1119
\inmodule QtGui
Definition qrhi.h:1135
\inmodule QtGui
Definition qrhi.h:1694
\inmodule QtGui
Definition qrhi.h:1767
QSGAbstractRenderer gives access to the scene graph nodes and rendering.
Encapsulates the current rendering state during a call to QSGMaterialShader::updateUniformData() and ...
The QSGNodeDumper class provides a way of dumping a scene grahp to the console.
The QSGNodeVisitor class is a helper class for traversing the scene graph.
Definition qsgnode.h:297
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
Definition qsgnode.h:37
void(*)(void *) RenderPassCallback
QSGRenderTarget(QRhiRenderTarget *rt, QRhiRenderPassDescriptor *rpDesc, QRhiCommandBuffer *cb)
QSGRenderTarget(QPaintDevice *paintDevice)
The renderer class is the abstract baseclass used for rendering the QML scene graph.
QMatrix4x4 m_current_projection_matrix_native_ndc
virtual void render()=0
void setRenderTarget(const QSGRenderTarget &rt)
qreal m_device_pixel_ratio
QByteArray * currentUniformData() const
QMatrix4x4 m_current_projection_matrix
virtual bool hasVisualizationModeWithContinuousUpdate() const
QRhi * currentRhi() const
qreal m_current_opacity
QMatrix4x4 currentProjectionMatrix() const
QRhiResourceUpdateBatch * currentResourceUpdateBatch() const
const QSGRenderTarget & renderTarget() const
QRhiResourceUpdateBatch * m_current_resource_update_batch
qreal currentOpacity() const
QMatrix4x4 m_current_model_view_matrix
QByteArray * m_current_uniform_data
void setRenderPassRecordingCallbacks(QSGRenderContext::RenderPassCallback start, QSGRenderContext::RenderPassCallback end, void *userData)
QSGMaterialShader::RenderState state(QSGMaterialShader::RenderState::DirtyStates dirty) const
QSGRenderContext * context() const
void clearChangedFlag()
qreal devicePixelRatio() const
qreal m_current_determinant
QSGRenderContext * m_context
QMatrix4x4 currentCombinedMatrix() const
void setDevicePixelRatio(qreal ratio)
qreal determinant() const
QSGRenderTarget m_rt
virtual void setVisualizationMode(const QByteArray &)
virtual void releaseCachedResources()
QMatrix4x4 currentModelViewMatrix() const
Definition qset.h:18
else opt state
[0]
Combined button and popup list for selecting options.
static void * context
GLuint GLuint end
GLuint start
GLfloat n
GLdouble s
[6]
Definition qopenglext.h:235
bool _q_sg_leak_check
Q_QUICK_PRIVATE_EXPORT void qsg_set_fatal_renderer_error()
Q_QUICK_PRIVATE_EXPORT bool qsg_test_and_clear_fatal_render_error()
static QString dump(const QByteArray &)
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
unsigned int uint
Definition qtypes.h:29
double qreal
Definition qtypes.h:92