summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/rhi/qrhigles2.cpp34
-rw-r--r--src/gui/rhi/qrhigles2_p_p.h2
2 files changed, 24 insertions, 12 deletions
diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp
index 4512acb969..aa1144a996 100644
--- a/src/gui/rhi/qrhigles2.cpp
+++ b/src/gui/rhi/qrhigles2.cpp
@@ -501,21 +501,33 @@ QRhiGles2::QRhiGles2(QRhiGles2InitParams *params, QRhiGles2NativeHandles *import
}
}
+static inline QSurface *currentSurfaceForCurrentContext(QOpenGLContext *ctx)
+{
+ if (QOpenGLContext::currentContext() != ctx)
+ return nullptr;
+
+ QSurface *currentSurface = ctx->surface();
+ if (!currentSurface)
+ return nullptr;
+
+ if (currentSurface->surfaceClass() == QSurface::Window && !currentSurface->surfaceHandle())
+ return nullptr;
+
+ return currentSurface;
+}
+
bool QRhiGles2::ensureContext(QSurface *surface) const
{
- bool nativeWindowGone = false;
- if (surface && surface->surfaceClass() == QSurface::Window && !surface->surfaceHandle()) {
+ if (!surface) {
+ if (currentSurfaceForCurrentContext(ctx))
+ return true;
surface = fallbackSurface;
- nativeWindowGone = true;
- }
-
- if (!surface)
+ } else if (surface->surfaceClass() == QSurface::Window && !surface->surfaceHandle()) {
surface = fallbackSurface;
-
- if (needsMakeCurrent)
- needsMakeCurrent = false;
- else if (!nativeWindowGone && QOpenGLContext::currentContext() == ctx && (surface == fallbackSurface || ctx->surface() == surface))
+ } else if (!needsMakeCurrentDueToSwap && currentSurfaceForCurrentContext(ctx) == surface) {
return true;
+ }
+ needsMakeCurrentDueToSwap = false;
if (!ctx->makeCurrent(surface)) {
if (ctx->isValid()) {
@@ -1788,7 +1800,7 @@ QRhi::FrameOpResult QRhiGles2::endFrame(QRhiSwapChain *swapChain, QRhi::EndFrame
if (swapChainD->surface && !flags.testFlag(QRhi::SkipPresent)) {
ctx->swapBuffers(swapChainD->surface);
- needsMakeCurrent = true;
+ needsMakeCurrentDueToSwap = true;
} else {
f->glFlush();
}
diff --git a/src/gui/rhi/qrhigles2_p_p.h b/src/gui/rhi/qrhigles2_p_p.h
index c3297f488d..6ee6af8fc5 100644
--- a/src/gui/rhi/qrhigles2_p_p.h
+++ b/src/gui/rhi/qrhigles2_p_p.h
@@ -902,7 +902,7 @@ public:
QSurface *fallbackSurface = nullptr;
QWindow *maybeWindow = nullptr;
QOpenGLContext *maybeShareContext = nullptr;
- mutable bool needsMakeCurrent = false;
+ mutable bool needsMakeCurrentDueToSwap = false;
QOpenGLExtensions *f = nullptr;
uint vao = 0;
struct Caps {