Skip to content

Commit a734c95

Browse files
committed
ProjectLoader: Use the correct context for rendering
1 parent d05b880 commit a734c95

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/projectloader.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,24 @@ void ProjectLoader::timerEvent(QTimerEvent *event)
210210
return;
211211

212212
if (m_engine) {
213+
QOpenGLContext *oldCtx = QOpenGLContext::currentContext();
214+
QSurface *oldSurface = nullptr;
215+
216+
if (!m_glCtx)
217+
m_glCtx = oldCtx;
218+
219+
if (m_glCtx) {
220+
if (!m_surface)
221+
m_surface = m_glCtx->surface();
222+
223+
oldSurface = oldCtx->surface();
224+
225+
if (oldCtx != m_glCtx) {
226+
oldCtx->doneCurrent();
227+
m_glCtx->makeCurrent(m_surface);
228+
}
229+
}
230+
213231
for (Monitor *monitor : m_unpositionedMonitors)
214232
monitor->autoPosition(m_engine->monitors());
215233

@@ -230,6 +248,13 @@ void ProjectLoader::timerEvent(QTimerEvent *event)
230248
m_renderTimer.restart();
231249
} else
232250
m_renderFpsCounter++;
251+
252+
if (m_glCtx) {
253+
if (oldCtx != m_glCtx) {
254+
m_glCtx->doneCurrent();
255+
oldCtx->makeCurrent(oldSurface);
256+
}
257+
}
233258
}
234259

235260
event->accept();

src/projectloader.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
Q_MOC_INCLUDE("spritemodel.h");
1313
Q_MOC_INCLUDE("monitormodel.h");
1414

15+
class QSurface;
16+
class QOpenGLContext;
17+
1518
namespace scratchcpprender
1619
{
1720

@@ -185,6 +188,8 @@ class ProjectLoader : public QObject
185188
std::atomic<unsigned int> m_downloadedAssets = 0;
186189
std::atomic<unsigned int> m_assetCount = 0;
187190
std::atomic<bool> m_stopLoading = false;
191+
QOpenGLContext *m_glCtx = nullptr;
192+
QSurface *m_surface = nullptr;
188193
};
189194

190195
} // namespace scratchcpprender

0 commit comments

Comments
 (0)