mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-08 15:49:21 +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() {
|
bool isRenderThread() {
|
||||||
return QThread::currentThread() == RENDER_THREAD;
|
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
|
#ifndef hifi_GLHelpers_h
|
||||||
#define hifi_GLHelpers_h
|
#define hifi_GLHelpers_h
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
// 16 bits of depth precision
|
// 16 bits of depth precision
|
||||||
|
@ -34,4 +35,8 @@ int glVersionToInteger(QString glVersion);
|
||||||
|
|
||||||
bool isRenderThread();
|
bool isRenderThread();
|
||||||
|
|
||||||
|
namespace gl {
|
||||||
|
void withSavedContext(const std::function<void()>& f);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -467,7 +467,7 @@ void OffscreenQmlSurface::resize(const QSize& newSize_, bool forceResize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(glLogging) << "Offscreen UI resizing to " << newSize.width() << "x" << newSize.height();
|
qCDebug(glLogging) << "Offscreen UI resizing to " << newSize.width() << "x" << newSize.height();
|
||||||
|
gl::withSavedContext([&] {
|
||||||
_canvas->makeCurrent();
|
_canvas->makeCurrent();
|
||||||
|
|
||||||
// Release hold on the textures of the old size
|
// Release hold on the textures of the old size
|
||||||
|
@ -501,6 +501,7 @@ void OffscreenQmlSurface::resize(const QSize& newSize_, bool forceResize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_canvas->doneCurrent();
|
_canvas->doneCurrent();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QQuickItem* OffscreenQmlSurface::getRootItem() {
|
QQuickItem* OffscreenQmlSurface::getRootItem() {
|
||||||
|
|
Loading…
Reference in a new issue