static HGLRC createContext(const QOpenGLStaticContext &staticContext, HDC hdc, const QSurfaceFormat &format, const QWindowsOpenGLAdditionalFormat &, HGLRC shared = 0) { enum { attribSize = 11 }; if (!staticContext.hasExtensions()) return 0; int attributes[attribSize]; int attribIndex = 0; qFill(attributes, attributes + attribSize, int(0)); const int requestedVersion = (format.majorVersion() << 8) + format.minorVersion(); if (requestedVersion > 0x0101) { attributes[attribIndex++] = WGL_CONTEXT_MAJOR_VERSION_ARB; attributes[attribIndex++] = format.majorVersion(); attributes[attribIndex++] = WGL_CONTEXT_MINOR_VERSION_ARB; attributes[attribIndex++] = format.minorVersion(); } if (requestedVersion >= 0x0300) { attributes[attribIndex++] = WGL_CONTEXT_FLAGS_ARB; attributes[attribIndex] = 0; if (format.testOption(QSurfaceFormat::DeprecatedFunctions)) attributes[attribIndex] |= WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; if (format.testOption(QSurfaceFormat::DebugContext)) attributes[attribIndex++] |= WGL_CONTEXT_DEBUG_BIT_ARB; attribIndex++; } if (requestedVersion >= 0x0302) { switch (format.profile()) { case QSurfaceFormat::NoProfile: break; case QSurfaceFormat::CoreProfile: attributes[attribIndex++] = WGL_CONTEXT_PROFILE_MASK_ARB; attributes[attribIndex++] = WGL_CONTEXT_CORE_PROFILE_BIT_ARB; break; case QSurfaceFormat::CompatibilityProfile: attributes[attribIndex++] = WGL_CONTEXT_PROFILE_MASK_ARB; attributes[attribIndex++] = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; break; } } if (QWindowsContext::verboseGL) qDebug("%s: Creating context version %d.%d with %d attributes", __FUNCTION__, format.majorVersion(), format.minorVersion(), attribIndex / 2); const HGLRC result = staticContext.wglCreateContextAttribsARB(hdc, shared, attributes); if (!result) qErrnoWarning("%s: wglCreateContextAttribsARB() failed.", __FUNCTION__); return result; }
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()))); }
void QSGContext::renderContextInitialized(QSGRenderContext *renderContext) { Q_D(QSGContext); d->mutex.lock(); if (d->antialiasingMethod == UndecidedAntialiasing) { if (Q_UNLIKELY(qEnvironmentVariableIsSet("QSG_ANTIALIASING_METHOD"))) { const QByteArray aaType = qgetenv("QSG_ANTIALIASING_METHOD"); if (aaType == "msaa") d->antialiasingMethod = MsaaAntialiasing; else if (aaType == "vertex") d->antialiasingMethod = VertexAntialiasing; } if (d->antialiasingMethod == UndecidedAntialiasing) { if (renderContext->openglContext()->format().samples() > 0) d->antialiasingMethod = MsaaAntialiasing; else d->antialiasingMethod = VertexAntialiasing; } } // With OpenGL ES, except for Angle on Windows, use GrayAntialiasing, unless // some value had been requested explicitly. This could not be decided // before without a context. Now the context is ready. if (!d->distanceFieldAntialiasingDecided) { d->distanceFieldAntialiasingDecided = true; #ifndef Q_OS_WIN32 if (renderContext->openglContext()->isOpenGLES()) d->distanceFieldAntialiasing = QSGGlyphNode::GrayAntialiasing; #endif } static bool dumped = false; if (!dumped && QSG_LOG_INFO().isDebugEnabled()) { dumped = true; QSurfaceFormat format = renderContext->openglContext()->format(); QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); qCDebug(QSG_LOG_INFO) << "R/G/B/A Buffers: " << format.redBufferSize() << format.greenBufferSize() << format.blueBufferSize() << format.alphaBufferSize(); qCDebug(QSG_LOG_INFO) << "Depth Buffer: " << format.depthBufferSize(); qCDebug(QSG_LOG_INFO) << "Stencil Buffer: " << format.stencilBufferSize(); qCDebug(QSG_LOG_INFO) << "Samples: " << format.samples(); qCDebug(QSG_LOG_INFO) << "GL_VENDOR: " << (const char *) funcs->glGetString(GL_VENDOR); qCDebug(QSG_LOG_INFO) << "GL_RENDERER: " << (const char *) funcs->glGetString(GL_RENDERER); qCDebug(QSG_LOG_INFO) << "GL_VERSION: " << (const char *) funcs->glGetString(GL_VERSION); QSet<QByteArray> exts = renderContext->openglContext()->extensions(); QByteArray all; foreach (const QByteArray &e, exts) all += ' ' + e; qCDebug(QSG_LOG_INFO) << "GL_EXTENSIONS: " << all.constData(); qCDebug(QSG_LOG_INFO) << "Max Texture Size: " << renderContext->maxTextureSize(); qCDebug(QSG_LOG_INFO) << "Debug context: " << format.testOption(QSurfaceFormat::DebugContext); }
void QEGLPlatformContext::init(const QSurfaceFormat &format, QPlatformOpenGLContext *share) { m_format = q_glFormatFromConfig(m_eglDisplay, m_eglConfig); // m_format now has the renderableType() resolved (it cannot be Default anymore) // but does not yet contain version, profile, options. m_shareContext = share ? static_cast<QEGLPlatformContext *>(share)->m_eglContext : 0; QVector<EGLint> contextAttrs; contextAttrs.append(EGL_CONTEXT_CLIENT_VERSION); contextAttrs.append(format.majorVersion()); const bool hasKHRCreateContext = q_hasEglExtension(m_eglDisplay, "EGL_KHR_create_context"); if (hasKHRCreateContext) { contextAttrs.append(EGL_CONTEXT_MINOR_VERSION_KHR); contextAttrs.append(format.minorVersion()); int flags = 0; // The debug bit is supported both for OpenGL and OpenGL ES. if (format.testOption(QSurfaceFormat::DebugContext)) flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; // The fwdcompat bit is only for OpenGL 3.0+. if (m_format.renderableType() == QSurfaceFormat::OpenGL && format.majorVersion() >= 3 && !format.testOption(QSurfaceFormat::DeprecatedFunctions)) flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR; if (flags) { contextAttrs.append(EGL_CONTEXT_FLAGS_KHR); contextAttrs.append(flags); } // Profiles are OpenGL only and mandatory in 3.2+. The value is silently ignored for < 3.2. if (m_format.renderableType() == QSurfaceFormat::OpenGL) { contextAttrs.append(EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR); contextAttrs.append(format.profile() == QSurfaceFormat::CoreProfile ? EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR : EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR); } } contextAttrs.append(EGL_NONE); switch (m_format.renderableType()) { case QSurfaceFormat::OpenVG: m_api = EGL_OPENVG_API; break; #ifdef EGL_VERSION_1_4 case QSurfaceFormat::OpenGL: m_api = EGL_OPENGL_API; break; #endif // EGL_VERSION_1_4 default: m_api = EGL_OPENGL_ES_API; break; } eglBindAPI(m_api); m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, m_shareContext, contextAttrs.constData()); if (m_eglContext == EGL_NO_CONTEXT && m_shareContext != EGL_NO_CONTEXT) { m_shareContext = 0; m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, 0, contextAttrs.constData()); } if (m_eglContext == EGL_NO_CONTEXT) { qWarning("QEGLPlatformContext: Failed to create context: %x", eglGetError()); return; } 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); } // Cannot just call updateFormatFromGL() since it relies on virtuals. Defer it to initialize(). }