XVisualInfo *qglx_findVisualInfo(Display *display, int screen, QSurfaceFormat *format) { Q_ASSERT(format); XVisualInfo *visualInfo = 0; GLXFBConfig config = qglx_findConfig(display,screen,*format); if (config) { visualInfo = glXGetVisualFromFBConfig(display, config); *format = qglx_surfaceFormatFromGLXFBConfig(display, config); } // attempt to fall back to glXChooseVisual bool reduced = true; QSurfaceFormat reducedFormat = *format; while (!visualInfo && reduced) { QVarLengthArray<int, 13> attribs; attribs.append(GLX_RGBA); if (reducedFormat.redBufferSize() > 0) { attribs.append(GLX_RED_SIZE); attribs.append(reducedFormat.redBufferSize()); } if (reducedFormat.greenBufferSize() > 0) { attribs.append(GLX_GREEN_SIZE); attribs.append(reducedFormat.greenBufferSize()); } if (reducedFormat.blueBufferSize() > 0) { attribs.append(GLX_BLUE_SIZE); attribs.append(reducedFormat.blueBufferSize()); } if (reducedFormat.stencilBufferSize() > 0) { attribs.append(GLX_STENCIL_SIZE); attribs.append(reducedFormat.stencilBufferSize()); } if (reducedFormat.depthBufferSize() > 0) { attribs.append(GLX_DEPTH_SIZE); attribs.append(reducedFormat.depthBufferSize()); } if (reducedFormat.swapBehavior() != QSurfaceFormat::SingleBuffer) attribs.append(GLX_DOUBLEBUFFER); attribs.append(XNone); visualInfo = glXChooseVisual(display, screen, attribs.data()); if (visualInfo) *format = reducedFormat; reducedFormat = qglx_reduceSurfaceFormat(reducedFormat, &reduced); } return visualInfo; }
GLXFBConfig qglx_findConfig(Display *display, int screen , const QSurfaceFormat &format, int drawableBit) { bool reduced = true; GLXFBConfig chosenConfig = 0; QSurfaceFormat reducedFormat = format; while (!chosenConfig && reduced) { QVector<int> spec = qglx_buildSpec(reducedFormat, drawableBit); int confcount = 0; GLXFBConfig *configs; configs = glXChooseFBConfig(display, screen,spec.constData(),&confcount); if (confcount) { for (int i = 0; i < confcount; i++) { chosenConfig = configs[i]; // Make sure we try to get an ARGB visual if the format asked for an alpha: if (reducedFormat.hasAlpha()) { int alphaSize; glXGetFBConfigAttrib(display,configs[i],GLX_ALPHA_SIZE,&alphaSize); if (alphaSize > 0) { XVisualInfo *visual = glXGetVisualFromFBConfig(display, chosenConfig); bool hasAlpha = false; #if !defined(QT_NO_XRENDER) XRenderPictFormat *pictFormat = XRenderFindVisualFormat(display, visual->visual); hasAlpha = pictFormat->direct.alphaMask > 0; #else hasAlpha = visual->depth == 32; #endif XFree(visual); if (hasAlpha) break; } } else { break; // Just choose the first in the list if there's no alpha requested } } XFree(configs); } if (!chosenConfig) reducedFormat = qglx_reduceSurfaceFormat(reducedFormat,&reduced); } return chosenConfig; }
GLXFBConfig qglx_findConfig(Display *display, int screen , const QSurfaceFormat &format, int drawableBit) { // Allow forcing LIBGL_ALWAYS_SOFTWARE for Qt 5 applications only. // This is most useful with drivers that only support OpenGL 1. // We need OpenGL 2, but the user probably doesn't want // LIBGL_ALWAYS_SOFTWARE in OpenGL 1 apps. static bool checkedForceSoftwareOpenGL = false; static bool forceSoftwareOpenGL = false; if (!checkedForceSoftwareOpenGL) { // If LIBGL_ALWAYS_SOFTWARE is already set, don't mess with it. // We want to unset LIBGL_ALWAYS_SOFTWARE at the end so it does not // get inherited by other processes, of course only if it wasn't // already set before. if (!qEnvironmentVariableIsEmpty("QT_XCB_FORCE_SOFTWARE_OPENGL") && !qEnvironmentVariableIsSet("LIBGL_ALWAYS_SOFTWARE")) forceSoftwareOpenGL = true; checkedForceSoftwareOpenGL = true; } if (forceSoftwareOpenGL) qputenv("LIBGL_ALWAYS_SOFTWARE", QByteArrayLiteral("1")); bool reduced = true; GLXFBConfig chosenConfig = 0; QSurfaceFormat reducedFormat = format; while (!chosenConfig && reduced) { QVector<int> spec = qglx_buildSpec(reducedFormat, drawableBit); int confcount = 0; GLXFBConfig *configs; configs = glXChooseFBConfig(display, screen,spec.constData(),&confcount); if (confcount) { for (int i = 0; i < confcount; i++) { chosenConfig = configs[i]; // Make sure we try to get an ARGB visual if the format asked for an alpha: if (reducedFormat.hasAlpha()) { int alphaSize; glXGetFBConfigAttrib(display,configs[i],GLX_ALPHA_SIZE,&alphaSize); if (alphaSize > 0) { XVisualInfo *visual = glXGetVisualFromFBConfig(display, chosenConfig); bool hasAlpha = false; #if !defined(QT_NO_XRENDER) XRenderPictFormat *pictFormat = XRenderFindVisualFormat(display, visual->visual); hasAlpha = pictFormat->direct.alphaMask > 0; #else hasAlpha = visual->depth == 32; #endif XFree(visual); if (hasAlpha) break; } } else { break; // Just choose the first in the list if there's no alpha requested } } XFree(configs); } if (!chosenConfig) reducedFormat = qglx_reduceSurfaceFormat(reducedFormat,&reduced); } // unset LIBGL_ALWAYS_SOFTWARE now so other processes don't inherit it if (forceSoftwareOpenGL) qunsetenv("LIBGL_ALWAYS_SOFTWARE"); return chosenConfig; }