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