57 QOpenGLContext *qtGlobalShareContext = QOpenGLContext::globalShareContext();
58 GLXContext globalShareContext =
nullptr;
59 if (qtGlobalShareContext) {
60 qDebug(KWIN_X11STANDALONE) <<
"Global share context format:" << qtGlobalShareContext->format();
61 const auto nativeHandle = qtGlobalShareContext->nativeInterface<QNativeInterface::QGLXContext>();
63 globalShareContext = nativeHandle->nativeContext();
65 qCDebug(KWIN_X11STANDALONE) <<
"Invalid QOpenGLContext::globalShareContext()";
69 if (!globalShareContext) {
70 qCWarning(KWIN_X11STANDALONE) <<
"QOpenGLContext::globalShareContext() is required";
74 GLXContext handle =
nullptr;
77 if (backend->
hasExtension(QByteArrayLiteral(
"GLX_ARB_create_context"))) {
78 const bool have_robustness = backend->
hasExtension(QByteArrayLiteral(
"GLX_ARB_create_context_robustness"));
79 const bool haveVideoMemoryPurge = backend->
hasExtension(QByteArrayLiteral(
"GLX_NV_robustness_video_memory_purge"));
81 std::vector<GlxContextAttributeBuilder> candidates;
83 if (have_robustness) {
84 if (haveVideoMemoryPurge) {
89 candidates.emplace_back(std::move(purgeMemoryCore));
94 candidates.emplace_back(std::move(robustCore));
98 candidates.emplace_back(std::move(core));
100 if (have_robustness) {
101 if (haveVideoMemoryPurge) {
105 candidates.emplace_back(std::move(purgeMemoryLegacy));
109 candidates.emplace_back(std::move(robustLegacy));
113 candidates.emplace_back(std::move(legacy));
114 for (
auto it = candidates.begin(); it != candidates.end(); it++) {
115 const auto attribs = it->build();
116 handle = glXCreateContextAttribsARB(backend->
display(), fbconfig, globalShareContext,
true, attribs.data());
118 qCDebug(KWIN_X11STANDALONE) <<
"Created GLX context with attributes:" << &(*it);
124 handle = glXCreateNewContext(backend->
display(), fbconfig, GLX_RGBA_TYPE, globalShareContext,
true);
127 qCDebug(KWIN_X11STANDALONE) <<
"Failed to create an OpenGL context.";
131 if (!glXIsDirect(backend->
display(), handle)) {
134 if (!glXMakeCurrent(backend->
display(), glxWindow, handle)) {
135 glXDestroyContext(backend->
display(), handle);
138 auto ret = std::make_unique<GlxContext>(backend->
display(), glxWindow, handle);
139 if (!ret->checkSupported()) {
void setVersion(int major, int minor=0)
void setResetOnVideoMemoryPurge(bool reset)
static std::unique_ptr< GlxContext > create(GlxBackend *backend, GLXFBConfig fbconfig, GLXWindow glxWindow)
GlxContext(::Display *display, GLXWindow window, GLXContext handle)
bool hasOpenglExtension(QByteArrayView name) const