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
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
42{
43 return qEnvironmentVariableIntValue("QT_QUICK3D_DISABLE_GENSHADERS") == 0;
44}
45
46void QSSGRenderContextInterface::init()
47{
48 if (m_renderer)
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
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 std::unique_ptr<QSSGDebugDrawSystem> debugDrawSystem)
90 : m_rhiContext(std::move(ctx))
91 , m_shaderCache(std::move(shaderCache))
92 , m_bufferManager(std::move(bufferManager))
93 , m_renderer(std::move(renderer))
94 , m_shaderLibraryManager(std::move(shaderLibraryManager))
95 , m_customMaterialSystem(std::move(customMaterialSystem))
96 , m_shaderProgramGenerator(std::move(shaderProgramGenerator))
97 , m_debugDrawSystem(std::move(debugDrawSystem))
98 , m_perFrameAllocator(new QSSGPerFrameAllocator)
99{
100 init();
101}
102
103// The shader library is a global object, not per-QQuickWindow, hence not owned
104// by the QSSGRenderContextInterface.
105static const std::shared_ptr<QSSGShaderLibraryManager> &q3ds_shaderLibraryManager()
106{
107 static auto shaderLibraryManager = std::make_shared<QSSGShaderLibraryManager>();
108 return shaderLibraryManager;
109}
110
115 : m_rhiContext(new QSSGRhiContext(rhi))
116 , m_shaderCache(new QSSGShaderCache(*m_rhiContext))
117 , m_bufferManager(new QSSGBufferManager())
118 , m_renderer(new QSSGRenderer())
119 , m_shaderLibraryManager(q3ds_shaderLibraryManager())
120 , m_customMaterialSystem(new QSSGCustomMaterialSystem())
121 , m_shaderProgramGenerator(new QSSGProgramGenerator())
122 , m_debugDrawSystem(new QSSGDebugDrawSystem())
123 , m_perFrameAllocator(new QSSGPerFrameAllocator)
124{
125 init();
126}
127
132{
133 m_renderer->releaseCachedResources();
134}
135
139const std::unique_ptr<QSSGRenderer> &QSSGRenderContextInterface::renderer() const
140{
141 return m_renderer;
142}
143
147const std::unique_ptr<QSSGBufferManager> &QSSGRenderContextInterface::bufferManager() const
148{
149 return m_bufferManager;
150}
151
155const std::unique_ptr<QSSGRhiContext> &QSSGRenderContextInterface::rhiContext() const
156{
157 return m_rhiContext;
158}
159
163const std::unique_ptr<QSSGShaderCache> &QSSGRenderContextInterface::shaderCache() const
164{
165 return m_shaderCache;
166}
167
171const std::shared_ptr<QSSGShaderLibraryManager> &QSSGRenderContextInterface::shaderLibraryManager() const
172{
173 return m_shaderLibraryManager;
174}
175
179const std::unique_ptr<QSSGCustomMaterialSystem> &QSSGRenderContextInterface::customMaterialSystem() const
180{
181 return m_customMaterialSystem;
182}
183
187const std::unique_ptr<QSSGProgramGenerator> &QSSGRenderContextInterface::shaderProgramGenerator() const
188{
189 return m_shaderProgramGenerator;
190}
191
195const std::unique_ptr<QSSGDebugDrawSystem> &QSSGRenderContextInterface::debugDrawSystem() const
196{
197 return m_debugDrawSystem;
198}
199
200QRhi *QSSGRenderContextInterface::rhi() const
201{
202 return m_rhiContext->rhi();
203}
204
206
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1804
const std::unique_ptr< QSSGRhiContext > & rhiContext() const
const std::unique_ptr< QSSGDebugDrawSystem > & debugDrawSystem() const
const std::unique_ptr< QSSGProgramGenerator > & shaderProgramGenerator() const
const std::unique_ptr< QSSGCustomMaterialSystem > & customMaterialSystem() const
const std::shared_ptr< QSSGShaderLibraryManager > & shaderLibraryManager() const
const std::unique_ptr< QSSGBufferManager > & bufferManager() const
const std::unique_ptr< QSSGRenderer > & renderer() const
const std::unique_ptr< QSSGShaderCache > & shaderCache() const
static void setRenderContextInterface(QSSGRenderer &renderer, QSSGRenderContextInterface *ctx)
static QSSGRhiContextPrivate * get(QSSGRhiContext *q)
\inmodule QtQuick3D
EGLContext ctx
Combined button and popup list for selecting options.
static const std::shared_ptr< QSSGShaderLibraryManager > & q3ds_shaderLibraryManager()
static bool loadPregenratedShaders()
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
QSvgRenderer * renderer
[0]