Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
33Q_QUICK_EXPORT void qsg_set_fatal_renderer_error();
34
35class Q_QUICK_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 int multiViewCount = 0;
58};
59
60class Q_QUICK_EXPORT QSGRenderer : public QSGAbstractRenderer
61{
62public:
64 virtual ~QSGRenderer();
65
66 // Accessed by QSGMaterial[Rhi]Shader::RenderState.
67 QMatrix4x4 currentProjectionMatrix(int index) const { return m_current_projection_matrix[index]; }
68 QMatrix4x4 currentModelViewMatrix() const { return m_current_model_view_matrix; }
69 QMatrix4x4 currentCombinedMatrix(int index) const { return m_current_projection_matrix[index] * m_current_model_view_matrix; }
70 qreal currentOpacity() const { return m_current_opacity; }
71 qreal determinant() const { return m_current_determinant; }
72
73 void setDevicePixelRatio(qreal ratio) { m_device_pixel_ratio = ratio; }
74 qreal devicePixelRatio() const { return m_device_pixel_ratio; }
75 QSGRenderContext *context() const { return m_context; }
76
77 bool isMirrored() const;
78 void renderScene() override;
79 void prepareSceneInline() override;
80 void renderSceneInline() override;
81 void nodeChanged(QSGNode *node, QSGNode::DirtyState state) override;
82
83 QSGNodeUpdater *nodeUpdater() const;
84 void setNodeUpdater(QSGNodeUpdater *updater);
85 inline QSGMaterialShader::RenderState state(QSGMaterialShader::RenderState::DirtyStates dirty) const;
86 virtual void setVisualizationMode(const QByteArray &) { }
87 virtual bool hasVisualizationModeWithContinuousUpdate() const { return false; }
88 virtual void releaseCachedResources() { }
89
90 void clearChangedFlag() { m_changed_emitted = false; }
91
92 // Accessed by QSGMaterialShader::RenderState.
93 QByteArray *currentUniformData() const { return m_current_uniform_data; }
94 QRhiResourceUpdateBatch *currentResourceUpdateBatch() const { return m_current_resource_update_batch; }
95 QRhi *currentRhi() const { return m_rhi; }
96
97 void setRenderTarget(const QSGRenderTarget &rt) { m_rt = rt; }
98 const QSGRenderTarget &renderTarget() const { return m_rt; }
99
102 void *userData)
103 {
104 m_renderPassRecordingCallbacks.start = start;
105 m_renderPassRecordingCallbacks.end = end;
106 m_renderPassRecordingCallbacks.userData = userData;
107 }
108
109protected:
110 virtual void render() = 0;
111
112 virtual void prepareInline();
113 virtual void renderInline();
114
115 virtual void preprocess();
116
117 void addNodesToPreprocess(QSGNode *node);
118 void removeNodesToPreprocess(QSGNode *node);
119
120 QVarLengthArray<QMatrix4x4, 1> m_current_projection_matrix; // includes adjustment, where applicable, so can be treated as Y up in NDC always
121 QVarLengthArray<QMatrix4x4, 1> m_current_projection_matrix_native_ndc; // Vulkan has Y down in normalized device coordinates, others Y up...
126
128
133 struct {
136 void *userData = nullptr;
137 } m_renderPassRecordingCallbacks;
138
139private:
140 QSGNodeUpdater *m_node_updater;
141
142 QSet<QSGNode *> m_nodes_to_preprocess;
143 QSet<QSGNode *> m_nodes_dont_preprocess;
144
145 uint m_changed_emitted : 1;
146 uint m_is_rendering : 1;
147 uint m_is_preprocessing : 1;
148};
149
150QSGMaterialShader::RenderState QSGRenderer::state(QSGMaterialShader::RenderState::DirtyStates dirty) const
151{
153 s.m_dirty = dirty;
154 s.m_data = this;
155 return s;
156}
157
158
159class Q_QUICK_EXPORT QSGNodeDumper : public QSGNodeVisitor {
160
161public:
162 static void dump(QSGNode *n);
163
165 void visitNode(QSGNode *n) override;
166 void visitChildren(QSGNode *n) override;
167
168private:
169 int m_indent = 0;
170};
171
173
174#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:1651
\inmodule QtGui
Definition qrhi.h:1142
\inmodule QtGui
Definition qrhi.h:1158
\inmodule QtGui
Definition qrhi.h:1731
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1804
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:294
\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.
virtual void render()=0
void setRenderTarget(const QSGRenderTarget &rt)
qreal m_device_pixel_ratio
QByteArray * currentUniformData() const
virtual bool hasVisualizationModeWithContinuousUpdate() const
QRhi * currentRhi() const
qreal m_current_opacity
QVarLengthArray< QMatrix4x4, 1 > m_current_projection_matrix_native_ndc
QRhiResourceUpdateBatch * currentResourceUpdateBatch() const
const QSGRenderTarget & renderTarget() const
QRhiResourceUpdateBatch * m_current_resource_update_batch
QMatrix4x4 currentCombinedMatrix(int index) const
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
QMatrix4x4 currentProjectionMatrix(int index) const
void clearChangedFlag()
qreal devicePixelRatio() const
qreal m_current_determinant
QSGRenderContext * m_context
QVarLengthArray< QMatrix4x4, 1 > m_current_projection_matrix
void setDevicePixelRatio(qreal ratio)
qreal determinant() const
QSGRenderTarget m_rt
virtual void setVisualizationMode(const QByteArray &)
virtual void releaseCachedResources()
QMatrix4x4 currentModelViewMatrix() const
else opt state
[0]
Combined button and popup list for selecting options.
static void * context
GLuint index
[2]
GLuint GLuint end
GLuint start
GLfloat n
GLdouble s
[6]
Definition qopenglext.h:235
Q_QUICK_EXPORT void qsg_set_fatal_renderer_error()
Q_QUICK_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:34
double qreal
Definition qtypes.h:187