diff options
Diffstat (limited to 'src/platformsupport/eglconvenience/qeglplatformcontext.cpp')
-rw-r--r-- | src/platformsupport/eglconvenience/qeglplatformcontext.cpp | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/src/platformsupport/eglconvenience/qeglplatformcontext.cpp b/src/platformsupport/eglconvenience/qeglplatformcontext.cpp index 7cc330092e..d7c4fd6764 100644 --- a/src/platformsupport/eglconvenience/qeglplatformcontext.cpp +++ b/src/platformsupport/eglconvenience/qeglplatformcontext.cpp @@ -177,17 +177,17 @@ void QEGLPlatformContext::init(const QSurfaceFormat &format, QPlatformOpenGLCont } if (m_eglContext == EGL_NO_CONTEXT) { - qWarning("QEGLPlatformContext::init: eglError: %x, this: %p \n", eglGetError(), this); + qWarning("QEGLPlatformContext: Failed to create context: %x", eglGetError()); return; } - static const bool printConfig = qgetenv("QT_QPA_EGLFS_DEBUG").toInt(); + static const bool printConfig = qEnvironmentVariableIntValue("QT_QPA_EGLFS_DEBUG"); if (printConfig) { qDebug() << "Created context for format" << format << "with config:"; 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 } @@ -343,7 +357,7 @@ bool QEGLPlatformContext::makeCurrent(QPlatformSurface *surface) eglSwapInterval(eglDisplay(), m_swapInterval); } } else { - qWarning("QEGLPlatformContext::makeCurrent: eglError: %x, this: %p \n", eglGetError(), this); + qWarning("QEGLPlatformContext: eglMakeCurrent failed: %x", eglGetError()); } return ok; @@ -362,7 +376,7 @@ void QEGLPlatformContext::doneCurrent() eglBindAPI(m_api); bool ok = eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); if (!ok) - qWarning("QEGLPlatformContext::doneCurrent(): eglError: %d, this: %p \n", eglGetError(), this); + qWarning("QEGLPlatformContext: eglMakeCurrent failed: %x", eglGetError()); } void QEGLPlatformContext::swapBuffers(QPlatformSurface *surface) @@ -371,7 +385,7 @@ void QEGLPlatformContext::swapBuffers(QPlatformSurface *surface) EGLSurface eglSurface = eglSurfaceForPlatformSurface(surface); bool ok = eglSwapBuffers(m_eglDisplay, eglSurface); if (!ok) - qWarning("QEGLPlatformContext::swapBuffers(): eglError: %d, this: %p \n", eglGetError(), this); + qWarning("QEGLPlatformContext: eglSwapBuffers failed: %x", eglGetError()); } void (*QEGLPlatformContext::getProcAddress(const QByteArray &procName)) () |