From 007d73ef9e64a99e560cc932f519f8cb00121ba8 Mon Sep 17 00:00:00 2001 From: Giulio Camuffo Date: Wed, 13 May 2015 23:04:18 +0300 Subject: Fix threaded OpenGL rendering on Mesa and possibly other EGLs eglBindAPI's docs says "defines the current rendering API for EGL in the thread it is called from". We were instead just calling it in the thread the context was created in, not in the thread used for rendering. Change-Id: Iba8ffe75a6f4f8b9d1bba59c0e7cce34499e9c48 Reviewed-by: Laszlo Agocs --- .../client/wayland-egl/qwaylandglcontext.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp') diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp index a062a2f98..18ed1d61e 100644 --- a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp +++ b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp @@ -260,21 +260,22 @@ QWaylandGLContext::QWaylandGLContext(EGLDisplay eglDisplay, QWaylandDisplay *dis switch (m_format.renderableType()) { case QSurfaceFormat::OpenVG: - eglBindAPI(EGL_OPENVG_API); + m_api = EGL_OPENVG_API; break; #ifdef EGL_VERSION_1_4 # if !defined(QT_OPENGL_ES_2) case QSurfaceFormat::DefaultRenderableType: # endif case QSurfaceFormat::OpenGL: - eglBindAPI(EGL_OPENGL_API); + m_api = EGL_OPENGL_API; break; #endif case QSurfaceFormat::OpenGLES: default: - eglBindAPI(EGL_OPENGL_ES_API); + m_api = EGL_OPENGL_ES_API; break; } + eglBindAPI(m_api); m_context = eglCreateContext(m_eglDisplay, m_config, m_shareEGLContext, eglContextAttrs.constData()); @@ -358,6 +359,15 @@ QWaylandGLContext::~QWaylandGLContext() bool QWaylandGLContext::makeCurrent(QPlatformSurface *surface) { + // in QWaylandGLContext() we called eglBindAPI with the correct value. However, + // eglBindAPI's documentation says: + // "eglBindAPI defines the current rendering API for EGL in the thread it is called from" + // Since makeCurrent() can be called from a different thread than the one we created the + // context in make sure to call eglBindAPI in the correct thread. + if (eglQueryAPI() != m_api) { + eglBindAPI(m_api); + } + QWaylandEglWindow *window = static_cast(surface); EGLSurface eglSurface = window->eglSurface(); -- cgit v1.2.3