void Widget::printFormat(const QSurfaceFormat &format) { m_output->append(tr("OpenGL version: %1.%2").arg(format.majorVersion()).arg(format.minorVersion())); for (size_t i = 0; i < sizeof(profiles) / sizeof(Profile); ++i) if (profiles[i].profile == format.profile()) { m_output->append(tr("Profile: %1").arg(QString::fromLatin1(profiles[i].str))); break; } QString opts; for (size_t i = 0; i < sizeof(options) / sizeof(Option); ++i) if (format.testOption(options[i].option)) opts += QString::fromLatin1(options[i].str) + QLatin1Char(' '); m_output->append(tr("Options: %1").arg(opts)); for (size_t i = 0; i < sizeof(renderables) / sizeof(Renderable); ++i) if (renderables[i].renderable == format.renderableType()) { m_output->append(tr("Renderable type: %1").arg(QString::fromLatin1(renderables[i].str))); break; } m_output->append(tr("Depth buffer size: %1").arg(QString::number(format.depthBufferSize()))); m_output->append(tr("Stencil buffer size: %1").arg(QString::number(format.stencilBufferSize()))); m_output->append(tr("Samples: %1").arg(QString::number(format.samples()))); m_output->append(tr("Red buffer size: %1").arg(QString::number(format.redBufferSize()))); m_output->append(tr("Green buffer size: %1").arg(QString::number(format.greenBufferSize()))); m_output->append(tr("Blue buffer size: %1").arg(QString::number(format.blueBufferSize()))); m_output->append(tr("Alpha buffer size: %1").arg(QString::number(format.alphaBufferSize()))); m_output->append(tr("Swap interval: %1").arg(QString::number(format.swapInterval()))); }
QSurfaceFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config, const QSurfaceFormat &referenceFormat) { QSurfaceFormat format; EGLint redSize = 0; EGLint greenSize = 0; EGLint blueSize = 0; EGLint alphaSize = 0; EGLint depthSize = 0; EGLint stencilSize = 0; EGLint sampleCount = 0; EGLint renderableType = 0; eglGetConfigAttrib(display, config, EGL_RED_SIZE, &redSize); eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &greenSize); eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &blueSize); eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &alphaSize); eglGetConfigAttrib(display, config, EGL_DEPTH_SIZE, &depthSize); eglGetConfigAttrib(display, config, EGL_STENCIL_SIZE, &stencilSize); eglGetConfigAttrib(display, config, EGL_SAMPLES, &sampleCount); eglGetConfigAttrib(display, config, EGL_RENDERABLE_TYPE, &renderableType); if (referenceFormat.renderableType() == QSurfaceFormat::OpenVG && (renderableType & EGL_OPENVG_BIT)) format.setRenderableType(QSurfaceFormat::OpenVG); #ifdef EGL_VERSION_1_4 else if (referenceFormat.renderableType() == QSurfaceFormat::OpenGL && (renderableType & EGL_OPENGL_BIT)) format.setRenderableType(QSurfaceFormat::OpenGL); else if (referenceFormat.renderableType() == QSurfaceFormat::DefaultRenderableType #ifndef QT_NO_OPENGL && QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL #endif && (renderableType & EGL_OPENGL_BIT)) format.setRenderableType(QSurfaceFormat::OpenGL); #endif else format.setRenderableType(QSurfaceFormat::OpenGLES); format.setRedBufferSize(redSize); format.setGreenBufferSize(greenSize); format.setBlueBufferSize(blueSize); format.setAlphaBufferSize(alphaSize); format.setDepthBufferSize(depthSize); format.setStencilBufferSize(stencilSize); format.setSamples(sampleCount); format.setStereo(false); // EGL doesn't support stereo buffers format.setSwapInterval(referenceFormat.swapInterval()); // Clear the EGL error state because some of the above may // have errored out because the attribute is not applicable // to the surface type. Such errors don't matter. eglGetError(); return format; }