1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
// Copyright (C) 2008-2012 NVIDIA Corporation.
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "qssgrendercontextcore.h"
#include <QtQuick3DRuntimeRender/private/qssgrendernode_p.h>
#include <QtQuick3DRuntimeRender/private/qssgrenderbuffermanager_p.h>
#include <QtQuick3DRuntimeRender/private/qssgrendershadercache_p.h>
#include <QtQuick3DRuntimeRender/private/qssgrendercamera_p.h>
#include <QtQuick3DRuntimeRender/private/qssgrendershaderlibrarymanager_p.h>
#include <QtQuick3DRuntimeRender/private/qssgrendershadercodegenerator_p.h>
#include <QtQuick3DRuntimeRender/private/qssgrenderdefaultmaterialshadergenerator_p.h>
#include <QtQuick3DRuntimeRender/private/qssgrhicustommaterialsystem_p.h>
#include <QtQuick3DRuntimeRender/private/qssgperframeallocator_p.h>
#include <QtQuick3DRuntimeRender/private/qssgrenderer_p.h>
#include <QtQuick3DRuntimeRender/private/qssgrendererutil_p.h>
#include <QtQuick3DRuntimeRender/private/qssgdebugdrawsystem_p.h>
#include <QtQuick/private/qquickwindow_p.h>
QT_BEGIN_NAMESPACE
/*!
\class QSSGRenderContextInterface
\inmodule QtQuick3D
\since 6.7
\brief Aggregate class for sub-parts of the QtQuick3D rendering engine.
The QSSGRenderContextInterface, and the objects owned by it are always
per-QQuickWindow, and so per scenegraph render thread. Some resources might
be shared, like the shader library, but that's all take care of internally
by the QSSGRenderContextInterface.
\note Some sub-components might not be exposed as semi-public, or their use might require
private headers to be used. In those cases it's likely their APIs have a high likelihood
of being changed in the near future. One the APIs for those class have stabilized they will
be made available with the same guarantee as the rest of the semi-public APIs.
*/
static bool loadPregenratedShaders()
{
return qEnvironmentVariableIntValue("QT_QUICK3D_DISABLE_GENSHADERS") == 0;
}
void QSSGRenderContextInterface::init()
{
if (m_renderer)
QSSGRendererPrivate::setRenderContextInterface(*m_renderer, this);
if (m_bufferManager)
m_bufferManager->setRenderContextInterface(this);
if (m_customMaterialSystem)
m_customMaterialSystem->setRenderContextInterface(this);
if (m_shaderLibraryManager && loadPregenratedShaders())
m_shaderLibraryManager->loadPregeneratedShaderInfo();
}
void QSSGRenderContextInterface::releaseCachedResources()
{
if (m_renderer)
m_renderer->releaseCachedResources();
if (m_shaderCache)
m_shaderCache->releaseCachedResources();
if (m_customMaterialSystem)
m_customMaterialSystem->releaseCachedResources();
if (m_bufferManager)
m_bufferManager->releaseCachedResources();
if (m_rhiContext)
QSSGRhiContextPrivate::get(m_rhiContext.get())->releaseCachedResources();
}
const std::unique_ptr<QSSGPerFrameAllocator> &QSSGRenderContextInterface::perFrameAllocator() const
{
return m_perFrameAllocator;
}
/*!
\internal
*/
QSSGRenderContextInterface::QSSGRenderContextInterface(std::unique_ptr<QSSGBufferManager> bufferManager,
std::unique_ptr<QSSGRenderer> renderer,
std::shared_ptr<QSSGShaderLibraryManager> shaderLibraryManager,
std::unique_ptr<QSSGShaderCache> shaderCache,
std::unique_ptr<QSSGCustomMaterialSystem> customMaterialSystem,
std::unique_ptr<QSSGProgramGenerator> shaderProgramGenerator,
std::unique_ptr<QSSGRhiContext> ctx,
std::unique_ptr<QSSGDebugDrawSystem> debugDrawSystem)
: m_rhiContext(std::move(ctx))
, m_shaderCache(std::move(shaderCache))
, m_bufferManager(std::move(bufferManager))
, m_renderer(std::move(renderer))
, m_shaderLibraryManager(std::move(shaderLibraryManager))
, m_customMaterialSystem(std::move(customMaterialSystem))
, m_shaderProgramGenerator(std::move(shaderProgramGenerator))
, m_debugDrawSystem(std::move(debugDrawSystem))
, m_perFrameAllocator(new QSSGPerFrameAllocator)
{
init();
}
// The shader library is a global object, not per-QQuickWindow, hence not owned
// by the QSSGRenderContextInterface.
static const std::shared_ptr<QSSGShaderLibraryManager> &q3ds_shaderLibraryManager()
{
static auto shaderLibraryManager = std::make_shared<QSSGShaderLibraryManager>();
return shaderLibraryManager;
}
/*!
\internal
*/
QSSGRenderContextInterface::QSSGRenderContextInterface(QRhi *rhi)
: m_rhiContext(new QSSGRhiContext(rhi))
, m_shaderCache(new QSSGShaderCache(*m_rhiContext))
, m_bufferManager(new QSSGBufferManager())
, m_renderer(new QSSGRenderer())
, m_shaderLibraryManager(q3ds_shaderLibraryManager())
, m_customMaterialSystem(new QSSGCustomMaterialSystem())
, m_shaderProgramGenerator(new QSSGProgramGenerator())
, m_debugDrawSystem(new QSSGDebugDrawSystem())
, m_perFrameAllocator(new QSSGPerFrameAllocator)
{
init();
}
/*!
\internal
*/
QSSGRenderContextInterface::~QSSGRenderContextInterface()
{
m_renderer->releaseCachedResources();
}
/*!
\internal
*/
const std::unique_ptr<QSSGRenderer> &QSSGRenderContextInterface::renderer() const
{
return m_renderer;
}
/*!
\internal
*/
const std::unique_ptr<QSSGBufferManager> &QSSGRenderContextInterface::bufferManager() const
{
return m_bufferManager;
}
/*!
\return the context object that wraps QRhi-related settings and helper functionality.
*/
const std::unique_ptr<QSSGRhiContext> &QSSGRenderContextInterface::rhiContext() const
{
return m_rhiContext;
}
/*!
\internal
*/
const std::unique_ptr<QSSGShaderCache> &QSSGRenderContextInterface::shaderCache() const
{
return m_shaderCache;
}
/*!
\internal
*/
const std::shared_ptr<QSSGShaderLibraryManager> &QSSGRenderContextInterface::shaderLibraryManager() const
{
return m_shaderLibraryManager;
}
/*!
\internal
*/
const std::unique_ptr<QSSGCustomMaterialSystem> &QSSGRenderContextInterface::customMaterialSystem() const
{
return m_customMaterialSystem;
}
/*!
\internal
*/
const std::unique_ptr<QSSGProgramGenerator> &QSSGRenderContextInterface::shaderProgramGenerator() const
{
return m_shaderProgramGenerator;
}
/*!
\internal
*/
const std::unique_ptr<QSSGDebugDrawSystem> &QSSGRenderContextInterface::debugDrawSystem() const
{
return m_debugDrawSystem;
}
QRhi *QSSGRenderContextInterface::rhi() const
{
return m_rhiContext->rhi();
}
QT_END_NAMESPACE
|