diff options
author | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-09-16 14:12:54 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-10-10 08:36:47 +0200 |
commit | 1f040d401d322cec9dc56c93e78899a429cb6e5a (patch) | |
tree | a604b60b9964f098dd07e66204abd7b564e5f3d8 /src/platformsupport/eglconvenience | |
parent | 881ceeff428c377d02ae3881beccdbb028385075 (diff) |
eglfs: Add support for systems without pbuffer support
Use a small native window and window surface in case the hooks indicate
that pbuffer support is not available.
Change-Id: I6515309041f0e1e2f5321d59941f35d6ee16dca7
Reviewed-by: Louai Al-Khanji <louai.al-khanji@digia.com>
Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
Diffstat (limited to 'src/platformsupport/eglconvenience')
-rw-r--r-- | src/platformsupport/eglconvenience/qeglplatformcontext.cpp | 46 | ||||
-rw-r--r-- | src/platformsupport/eglconvenience/qeglplatformcontext_p.h | 3 |
2 files changed, 33 insertions, 16 deletions
diff --git a/src/platformsupport/eglconvenience/qeglplatformcontext.cpp b/src/platformsupport/eglconvenience/qeglplatformcontext.cpp index 1a1e298935..07ef202195 100644 --- a/src/platformsupport/eglconvenience/qeglplatformcontext.cpp +++ b/src/platformsupport/eglconvenience/qeglplatformcontext.cpp @@ -187,7 +187,7 @@ void QEGLPlatformContext::init(const QSurfaceFormat &format, QPlatformOpenGLCont q_printEglConfig(m_eglDisplay, m_eglConfig); } - updateFormatFromGL(); + // Cannot just call updateFormatFromGL() since it relies on virtuals. Defer it to initialize(). } void QEGLPlatformContext::adopt(const QVariant &nativeHandle, QPlatformOpenGLContext *share) @@ -238,18 +238,13 @@ void QEGLPlatformContext::adopt(const QVariant &nativeHandle, QPlatformOpenGLCon updateFormatFromGL(); } -void QEGLPlatformContext::updateFormatFromGL() +void QEGLPlatformContext::initialize() { -#ifndef QT_NO_OPENGL - // Have to save & restore to prevent QOpenGLContext::currentContext() from becoming - // inconsistent after QOpenGLContext::create(). - EGLDisplay prevDisplay = eglGetCurrentDisplay(); - if (prevDisplay == EGL_NO_DISPLAY) // when no context is current - prevDisplay = m_eglDisplay; - EGLContext prevContext = eglGetCurrentContext(); - EGLSurface prevSurfaceDraw = eglGetCurrentSurface(EGL_DRAW); - EGLSurface prevSurfaceRead = eglGetCurrentSurface(EGL_READ); + updateFormatFromGL(); +} +EGLSurface QEGLPlatformContext::createTemporaryOffscreenSurface() +{ // Make the context current to ensure the GL version query works. This needs a surface too. const EGLint pbufferAttributes[] = { EGL_WIDTH, 1, @@ -257,15 +252,34 @@ void QEGLPlatformContext::updateFormatFromGL() EGL_LARGEST_PBUFFER, EGL_FALSE, EGL_NONE }; + // Cannot just pass m_eglConfig because it may not be suitable for pbuffers. Instead, // do what QEGLPbuffer would do: request a config with the same attributes but with // PBUFFER_BIT set. EGLConfig config = q_configFromGLFormat(m_eglDisplay, m_format, false, EGL_PBUFFER_BIT); - EGLSurface pbuffer = eglCreatePbufferSurface(m_eglDisplay, config, pbufferAttributes); - if (pbuffer == EGL_NO_SURFACE) - return; - if (eglMakeCurrent(m_eglDisplay, pbuffer, pbuffer, m_eglContext)) { + return eglCreatePbufferSurface(m_eglDisplay, config, pbufferAttributes); +} + +void QEGLPlatformContext::destroyTemporaryOffscreenSurface(EGLSurface surface) +{ + eglDestroySurface(m_eglDisplay, surface); +} + +void QEGLPlatformContext::updateFormatFromGL() +{ +#ifndef QT_NO_OPENGL + // Have to save & restore to prevent QOpenGLContext::currentContext() from becoming + // inconsistent after QOpenGLContext::create(). + EGLDisplay prevDisplay = eglGetCurrentDisplay(); + if (prevDisplay == EGL_NO_DISPLAY) // when no context is current + prevDisplay = m_eglDisplay; + EGLContext prevContext = eglGetCurrentContext(); + EGLSurface prevSurfaceDraw = eglGetCurrentSurface(EGL_DRAW); + EGLSurface prevSurfaceRead = eglGetCurrentSurface(EGL_READ); + + EGLSurface tempSurface = createTemporaryOffscreenSurface(); + if (eglMakeCurrent(m_eglDisplay, tempSurface, tempSurface, m_eglContext)) { if (m_format.renderableType() == QSurfaceFormat::OpenGL || m_format.renderableType() == QSurfaceFormat::OpenGLES) { const GLubyte *s = glGetString(GL_VERSION); @@ -303,7 +317,7 @@ void QEGLPlatformContext::updateFormatFromGL() } eglMakeCurrent(prevDisplay, prevSurfaceDraw, prevSurfaceRead, prevContext); } - eglDestroySurface(m_eglDisplay, pbuffer); + destroyTemporaryOffscreenSurface(tempSurface); #endif // QT_NO_OPENGL } diff --git a/src/platformsupport/eglconvenience/qeglplatformcontext_p.h b/src/platformsupport/eglconvenience/qeglplatformcontext_p.h index 7825c7b3d7..b922584554 100644 --- a/src/platformsupport/eglconvenience/qeglplatformcontext_p.h +++ b/src/platformsupport/eglconvenience/qeglplatformcontext_p.h @@ -59,6 +59,7 @@ public: EGLConfig *config = 0, const QVariant &nativeHandle = QVariant()); ~QEGLPlatformContext(); + void initialize(); bool makeCurrent(QPlatformSurface *surface); void doneCurrent(); void swapBuffers(QPlatformSurface *surface); @@ -74,6 +75,8 @@ public: protected: virtual EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) = 0; + virtual EGLSurface createTemporaryOffscreenSurface(); + virtual void destroyTemporaryOffscreenSurface(EGLSurface surface); private: void init(const QSurfaceFormat &format, QPlatformOpenGLContext *share); |