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
5
6#ifdef QT_QUICK3D_HAS_LIGHTMAPPER
7#include <QString>
8#include <QtQuick3DRuntimeRender/private/qssglayerrenderdata_p.h>
9#include <QThreadPool>
10#include "qssgrendercontextcore.h"
11#if QT_CONFIG(opengl)
12#include <QOffscreenSurface>
13#endif // QT_CONFIG(opengl)
14
16
18{
22 // Use a local threadpool to be able to set highest thread priority on the bake thread
25 bool waitingForInvoke = false;
26};
27
30{
31 d->ctx = ctx;
34}
35
37{
38 delete d;
39}
40
42{
44 return d->currentStatus;
45
46 auto &env = d->ctx.env;
47 auto &settings = d->ctx.settings;
48 auto &callbacks = d->ctx.callbacks;
49
51 // We need to prepare for lightmap baking by doing another frame so that
52 // we can reload all meshes to use the original one and NOT the baked one.
53 // When disableLightmaps is set on the layer, the mesh loader will always load the
54 // original mesh and not the lightmap mesh.
57
58#if QT_CONFIG(opengl)
59 d->waitingForInvoke = true;
60 QMetaObject::invokeMethod(qApp, [this]() {
63 d->waitingForInvoke = false;
64 },
66#else
68#endif
69 } else if (d->currentStatus == Status::Running) {
75
76 // bakedLightingModels contains all models with
77 // usedInBakedLighting: true. These, together with lights that
78 // have a bakeMode set to either Indirect or All, form the
79 // lightmapped scene. A lightmap is stored persistently only
80 // for models that have their lightmapKey set.
82 for (int i = 0, ie = bakedLightingModels.size(); i != ie; ++i)
84
90 qDebug("Lightmap baking/denoising done, exiting application");
92 }
93 return Status::Finished;
94 }
95
97 cb->debugMarkBegin("Quick3D lightmap baking/denoising");
98
103
106
107#if QT_CONFIG(opengl)
108 d->waitingForInvoke = true;
109 QMetaObject::invokeMethod(qApp, [this]() {
110 delete d->fallbackSurface;
111 d->fallbackSurface = nullptr;
113 d->waitingForInvoke = false;
114 },
116#else
118#endif
120 qDebug("Lightmap baking/denoising done, exiting application");
121 QMetaObject::invokeMethod(qApp, "quit");
122 }
123 });
124
125 // Wait until lightmapper is finished initializing
127 cb->debugMarkEnd();
128 }
129
130 return d->currentStatus;
131}
132
134
135#else // QT_QUICK3D_HAS_LIGHTMAPPER
136
138
139QSSGLightmapBaker::QSSGLightmapBaker(const QSSGLightmapBaker::Context &ctx)
140{
141 qWarning("QSSGLightmapBaker: This build has no lightmap baking support.");
142#if defined(qApp)
143 if (ctx.settings.quitWhenFinished)
144 QMetaObject::invokeMethod(qApp, "quit");
145#else
146 Q_UNUSED(ctx);
147#endif
148}
149
151
156
157QT_END_NAMESPACE
158
159#endif // QT_QUICK3D_HAS_LIGHTMAPPER