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
qssglightmapbaker.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5
7
8#ifdef QT_QUICK3D_HAS_LIGHTMAPPER
9#include <QGuiApplication>
10#include <QString>
11#include <QtQuick3DRuntimeRender/private/qssglayerrenderdata_p.h>
12#include <QThreadPool>
13#include "qssgrendercontextcore.h"
14#if QT_CONFIG(opengl)
15#include <QOffscreenSurface>
16#endif // QT_CONFIG(opengl)
17
19
21{
25 // Use a local threadpool to be able to set highest thread priority on the bake thread
28 bool waitingForInvoke = false;
29};
30
33{
34 d->ctx = ctx;
37}
38
40{
41 delete d;
42}
43
45{
47 return d->currentStatus;
48
49 auto &env = d->ctx.env;
50 auto &settings = d->ctx.settings;
51 auto &callbacks = d->ctx.callbacks;
52
54 // We need to prepare for lightmap baking by doing another frame so that
55 // we can reload all meshes to use the original one and NOT the baked one.
56 // When disableLightmaps is set on the layer, the mesh loader will always load the
57 // original mesh and not the lightmap mesh.
60
61#if QT_CONFIG(opengl)
62 d->waitingForInvoke = true;
63 QMetaObject::invokeMethod(qApp, [this]() {
66 d->waitingForInvoke = false;
67 },
69#else
71#endif
72 } else if (d->currentStatus == Status::Running) {
78
79 // bakedLightingModels contains all models with
80 // usedInBakedLighting: true. These, together with lights that
81 // have a bakeMode set to either Indirect or All, form the
82 // lightmapped scene. A lightmap is stored persistently only
83 // for models that have their lightmapKey set.
85 for (int i = 0, ie = bakedLightingModels.size(); i != ie; ++i)
87
93 qDebug("Lightmap baking/denoising done, exiting application");
95 }
96 return Status::Finished;
97 }
98
100 cb->debugMarkBegin("Quick3D lightmap baking/denoising");
101
103
104 const auto bakeTask = [this, callbacks, settings] {
105#if QT_CONFIG(thread)
107#endif // QT_CONFIG(thread)
109
112
113#if QT_CONFIG(opengl)
114 d->waitingForInvoke = true;
115 QMetaObject::invokeMethod(qApp, [this]() {
116 delete d->fallbackSurface;
117 d->fallbackSurface = nullptr;
119 d->waitingForInvoke = false;
120 }, Qt::QueuedConnection);
121#else
123#endif
125 qDebug("Lightmap baking/denoising done, exiting application");
126 QMetaObject::invokeMethod(qApp, "quit");
127 }
128 };
129
130#if QT_CONFIG(thread)
132#else
133 bakeTask();
134#endif // QT_CONFIG(thread)
135
136 // Wait until lightmapper is finished initializing
138 cb->debugMarkEnd();
139 }
140
141 return d->currentStatus;
142}
143
145
146#else // QT_QUICK3D_HAS_LIGHTMAPPER
147
149
150QSSGLightmapBaker::QSSGLightmapBaker(const QSSGLightmapBaker::Context &ctx)
151{
152 qWarning("QSSGLightmapBaker: This build has no lightmap baking support.");
153#if defined(qApp)
154 if (ctx.settings.quitWhenFinished)
155 QMetaObject::invokeMethod(qApp, "quit");
156#else
157 Q_UNUSED(ctx);
158#endif
159}
160
162
167
168QT_END_NAMESPACE
169
170#endif // QT_QUICK3D_HAS_LIGHTMAPPER
Combined button and popup list for selecting options.