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 <QString>
10#include <QtQuick3DRuntimeRender/private/qssglayerrenderdata_p.h>
11#include <QThreadPool>
12#include "qssgrendercontextcore.h"
13#if QT_CONFIG(opengl)
14#include <QOffscreenSurface>
15#endif // QT_CONFIG(opengl)
16
18
20{
24 // Use a local threadpool to be able to set highest thread priority on the bake thread
27 bool waitingForInvoke = false;
28};
29
32{
33 d->ctx = ctx;
36}
37
39{
40 delete d;
41}
42
44{
46 return d->currentStatus;
47
48 auto &env = d->ctx.env;
49 auto &settings = d->ctx.settings;
50 auto &callbacks = d->ctx.callbacks;
51
53 // We need to prepare for lightmap baking by doing another frame so that
54 // we can reload all meshes to use the original one and NOT the baked one.
55 // When disableLightmaps is set on the layer, the mesh loader will always load the
56 // original mesh and not the lightmap mesh.
59
60#if QT_CONFIG(opengl)
61 d->waitingForInvoke = true;
62 QMetaObject::invokeMethod(qApp, [this]() {
65 d->waitingForInvoke = false;
66 },
68#else
70#endif
71 } else if (d->currentStatus == Status::Running) {
77
78 // bakedLightingModels contains all models with
79 // usedInBakedLighting: true. These, together with lights that
80 // have a bakeMode set to either Indirect or All, form the
81 // lightmapped scene. A lightmap is stored persistently only
82 // for models that have their lightmapKey set.
84 for (int i = 0, ie = bakedLightingModels.size(); i != ie; ++i)
86
92 qDebug("Lightmap baking/denoising done, exiting application");
94 }
95 return Status::Finished;
96 }
97
99 cb->debugMarkBegin("Quick3D lightmap baking/denoising");
100
102
103 const auto bakeTask = [this, callbacks, settings] {
104#if QT_CONFIG(thread)
106#endif // QT_CONFIG(thread)
108
111
112#if QT_CONFIG(opengl)
113 d->waitingForInvoke = true;
114 QMetaObject::invokeMethod(qApp, [this]() {
115 delete d->fallbackSurface;
116 d->fallbackSurface = nullptr;
118 d->waitingForInvoke = false;
119 }, Qt::QueuedConnection);
120#else
122#endif
124 qDebug("Lightmap baking/denoising done, exiting application");
125 QMetaObject::invokeMethod(qApp, "quit");
126 }
127 };
128
129#if QT_CONFIG(thread)
131#else
132 bakeTask();
133#endif // QT_CONFIG(thread)
134
135 // Wait until lightmapper is finished initializing
137 cb->debugMarkEnd();
138 }
139
140 return d->currentStatus;
141}
142
144
145#else // QT_QUICK3D_HAS_LIGHTMAPPER
146
148
149QSSGLightmapBaker::QSSGLightmapBaker(const QSSGLightmapBaker::Context &ctx)
150{
151 qWarning("QSSGLightmapBaker: This build has no lightmap baking support.");
152#if defined(qApp)
153 if (ctx.settings.quitWhenFinished)
154 QMetaObject::invokeMethod(qApp, "quit");
155#else
156 Q_UNUSED(ctx);
157#endif
158}
159
161
166
167QT_END_NAMESPACE
168
169#endif // QT_QUICK3D_HAS_LIGHTMAPPER
Combined button and popup list for selecting options.