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