mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 04:24:47 +02:00
Merge pull request #9163 from jherico/gl_context_preservation
Preserve and restore the GL context when resizing QML surfaces
This commit is contained in:
commit
bc9f2b4007
3 changed files with 46 additions and 28 deletions
|
@ -69,3 +69,15 @@ QThread* RENDER_THREAD = nullptr;
|
|||
bool isRenderThread() {
|
||||
return QThread::currentThread() == RENDER_THREAD;
|
||||
}
|
||||
|
||||
namespace gl {
|
||||
void withSavedContext(const std::function<void()>& f) {
|
||||
// Save the original GL context, because creating a QML surface will create a new context
|
||||
QOpenGLContext * savedContext = QOpenGLContext::currentContext();
|
||||
QSurface * savedSurface = savedContext ? savedContext->surface() : nullptr;
|
||||
f();
|
||||
if (savedContext) {
|
||||
savedContext->makeCurrent(savedSurface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#ifndef hifi_GLHelpers_h
|
||||
#define hifi_GLHelpers_h
|
||||
|
||||
#include <functional>
|
||||
#include <QJsonObject>
|
||||
|
||||
// 16 bits of depth precision
|
||||
|
@ -34,4 +35,8 @@ int glVersionToInteger(QString glVersion);
|
|||
|
||||
bool isRenderThread();
|
||||
|
||||
namespace gl {
|
||||
void withSavedContext(const std::function<void()>& f);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -467,7 +467,7 @@ void OffscreenQmlSurface::resize(const QSize& newSize_, bool forceResize) {
|
|||
}
|
||||
|
||||
qCDebug(glLogging) << "Offscreen UI resizing to " << newSize.width() << "x" << newSize.height();
|
||||
|
||||
gl::withSavedContext([&] {
|
||||
_canvas->makeCurrent();
|
||||
|
||||
// Release hold on the textures of the old size
|
||||
|
@ -501,6 +501,7 @@ void OffscreenQmlSurface::resize(const QSize& newSize_, bool forceResize) {
|
|||
}
|
||||
|
||||
_canvas->doneCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
QQuickItem* OffscreenQmlSurface::getRootItem() {
|
||||
|
|
Loading…
Reference in a new issue