static int determineMesaGLX(void) { #ifdef GLX_VERSION_1_1 const char *vendor, *version, *ch; vendor = glXGetClientString(__glutDisplay, GLX_VENDOR); if (!strcmp(vendor, "Brian Paul")) { version = glXGetClientString(__glutDisplay, GLX_VERSION); for (ch = version; *ch != ' ' && *ch != '\0'; ch++); for (; *ch == ' ' && *ch != '\0'; ch++); #define MESA_NAME "Mesa " /* Trailing space is intentional. */ if (!strncmp(MESA_NAME, ch, sizeof(MESA_NAME) - 1)) { return 1; } } #else /* Recent versions for Mesa should support GLX 1.1 and therefore glXGetClientString. If we get into this case, we would be compiling against a true OpenGL not supporting GLX 1.1, and the resulting compiled library won't work well with Mesa then. */ #endif return 0; }
/*< private >*/ void _gdk_x11_gl_print_glx_info (Display *xdisplay, int screen_num) { static gboolean done = FALSE; if (!done) { g_message (" -- Server GLX_VENDOR : %s", glXQueryServerString (xdisplay, screen_num, GLX_VENDOR)); g_message (" -- Server GLX_VERSION : %s", glXQueryServerString (xdisplay, screen_num, GLX_VERSION)); g_message (" -- Server GLX_EXTENSIONS : %s", glXQueryServerString (xdisplay, screen_num, GLX_EXTENSIONS)); g_message (" -- Client GLX_VENDOR : %s", glXGetClientString (xdisplay, GLX_VENDOR)); g_message (" -- Client GLX_VERSION : %s", glXGetClientString (xdisplay, GLX_VERSION)); g_message (" -- Client GLX_EXTENSIONS : %s", glXGetClientString (xdisplay, GLX_EXTENSIONS)); done = TRUE; } }
// // Constructor // CRegistry::CRegistry( bool WindowSystem ): m_VersionStr( NULL ), m_ExtensionsStr( NULL ) { if (WindowSystem) { #ifdef _WIN32 if (!wglGetExtensionsStringARB) throw Sys::CException( this, "::CRegistry() : Failed to obtain wglGetExtensionsStringARB entry point." ); HDC DC = wglGetCurrentDC(); if (!DC) throw Sys::CException( this, "::CRegistry() : Invalid current DC." ); m_ExtensionsStr = wglGetExtensionsStringARB( DC ); #elif defined (__linux__) Display *Dpy = glXGetCurrentDisplay(); if (!Dpy) throw Sys::CException( this, "::CRegistry() : Invalid current Display." ); m_ExtensionsString = glXGetClientString( Dpy, GLX_EXTENSIONS ); #endif // _WIN32 } else { m_VersionStr = reinterpret_cast<const char *>( glGetString( GL_VERSION ) ); m_ExtensionsStr = reinterpret_cast<const char *>( glGetString( GL_EXTENSIONS ) ); } TokenizeString(); }
void* QGLXContext::getProcAddress(const QString& procName) { Q_XCB_NOOP(m_screen->connection()); typedef void *(*qt_glXGetProcAddressARB)(const GLubyte *); static qt_glXGetProcAddressARB glXGetProcAddressARB = 0; static bool resolved = false; if (resolved && !glXGetProcAddressARB) return 0; if (!glXGetProcAddressARB) { QList<QByteArray> glxExt = QByteArray(glXGetClientString(DISPLAY_FROM_XCB(m_screen), GLX_EXTENSIONS)).split(' '); if (glxExt.contains("GLX_ARB_get_proc_address")) { #if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) void *handle = dlopen(NULL, RTLD_LAZY); if (handle) { glXGetProcAddressARB = (qt_glXGetProcAddressARB) dlsym(handle, "glXGetProcAddressARB"); dlclose(handle); } if (!glXGetProcAddressARB) #endif { extern const QString qt_gl_library_name(); // QLibrary lib(qt_gl_library_name()); QLibrary lib(QLatin1String("GL")); glXGetProcAddressARB = (qt_glXGetProcAddressARB) lib.resolve("glXGetProcAddressARB"); } } resolved = true; } if (!glXGetProcAddressARB) return 0; return glXGetProcAddressARB(reinterpret_cast<const GLubyte *>(procName.toLatin1().data())); }
static gboolean _has_texture_from_pixmap (Display *display) { int screen; const char *server_extensions; const char *client_extensions; gboolean ret = FALSE; screen = DefaultScreen (display); server_extensions = glXQueryServerString (display, screen, GLX_EXTENSIONS); if (!_has_extension (server_extensions, "GLX_EXT_texture_from_pixmap")) goto out; client_extensions = glXGetClientString (display, GLX_EXTENSIONS); if (!_has_extension (client_extensions, "GLX_EXT_texture_from_pixmap")) goto out; ret = TRUE; out: return ret; }
void *QGLContext::getProcAddress(const QString &proc) const { typedef void *(*qt_glXGetProcAddressARB)(const GLubyte *); static qt_glXGetProcAddressARB glXGetProcAddressARB = 0; static bool resolved = false; if (resolved && !glXGetProcAddressARB) return 0; if (!glXGetProcAddressARB) { QString glxExt = QString(QLatin1String(glXGetClientString(QX11Info::display(), GLX_EXTENSIONS))); if (glxExt.contains(QLatin1String("GLX_ARB_get_proc_address"))) { #if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) void *handle = dlopen(NULL, RTLD_LAZY); if (handle) { glXGetProcAddressARB = (qt_glXGetProcAddressARB) dlsym(handle, "glXGetProcAddressARB"); dlclose(handle); } if (!glXGetProcAddressARB) #endif { extern const QString qt_gl_library_name(); QLibrary lib(qt_gl_library_name()); glXGetProcAddressARB = (qt_glXGetProcAddressARB) lib.resolve("glXGetProcAddressARB"); } } resolved = true; } if (!glXGetProcAddressARB) return 0; return glXGetProcAddressARB(reinterpret_cast<const GLubyte *>(proc.toLatin1().data())); }
JNIEXPORT jint JNICALL GLX_NATIVE(glXGetClientString) (JNIEnv *env, jclass that, jint arg0, jint arg1) { jint rc = 0; GLX_NATIVE_ENTER(env, that, glXGetClientString_FUNC); rc = (jint)glXGetClientString(arg0, arg1); GLX_NATIVE_EXIT(env, that, glXGetClientString_FUNC); return rc; }
static void screenInfo( Display *dpy, int scrnum, QString &infotext ) { const char *serverVendor = glXQueryServerString( dpy, scrnum, GLX_VENDOR ); const char *serverVersion = glXQueryServerString( dpy, scrnum, GLX_VERSION ); const char *serverExtensions = glXQueryServerString( dpy, scrnum, GLX_EXTENSIONS ); const char *clientVendor = glXGetClientString( dpy, GLX_VENDOR ); const char *clientVersion = glXGetClientString( dpy, GLX_VERSION ); const char *clientExtensions = glXGetClientString( dpy, GLX_EXTENSIONS ); const char *glxExtensions = glXQueryExtensionsString( dpy, scrnum ); const char *glVendor = (const char *) glGetString( GL_VENDOR ); const char *glRenderer = (const char *) glGetString( GL_RENDERER ); const char *glVersion = (const char *) glGetString( GL_VERSION ); const char *glExtensions = (const char *) glGetString( GL_EXTENSIONS ); const char *gluVersion = (const char *) gluGetString( (GLenum) GLU_VERSION ); const char *gluExtensions = (const char *) gluGetString( (GLenum) GLU_EXTENSIONS ); infotext.sprintf( "%sServer GLX vendor string: %s\n", infotext.ascii(), serverVendor ); infotext.sprintf( "%sServer GLX version string: %s\n", infotext.ascii(), serverVersion ); infotext.sprintf( "%sServer GLX extensions:\n", infotext.ascii() ); infotext += QString( serverExtensions ).replace( ' ', '\n' ) + "\n\n"; infotext.sprintf( "%sClient GLX vendor string: %s\n", infotext.ascii(), clientVendor ); infotext.sprintf( "%sClient GLX version string: %s\n", infotext.ascii(), clientVersion ); infotext.sprintf( "%sClient GLX extensions:\n", infotext.ascii() ); infotext += QString( clientExtensions ).replace( ' ', '\n' ) + "\n\n"; infotext.sprintf( "%sGLX extensions:\n", infotext.ascii() ); infotext += QString( glxExtensions ).replace( ' ', '\n' ) + "\n\n"; infotext.sprintf( "%sOpenGL vendor string: %s\n", infotext.ascii(), glVendor ); infotext.sprintf( "%sOpenGL renderer string: %s\n", infotext.ascii(), glRenderer ); infotext.sprintf( "%sOpenGL version string: %s\n", infotext.ascii(), glVersion ); infotext.sprintf( "%sOpenGL extensions:\n", infotext.ascii() ); infotext += QString( glExtensions ).replace( ' ', '\n' ) + "\n\n"; infotext.sprintf( "%sGLU version: %s\n", infotext.ascii(), gluVersion ); infotext.sprintf( "%sGLU extensions:\n", infotext.ascii() ); infotext += QString( gluExtensions ).replace( ' ', '\n' ) + "\n\n"; }
//================================================================ int GLB_Query () { //================================================================ /// GLB_Query display OpenGL-vendorstring (used by GUI_gl__) char const *p1, *p2; p1 = glXGetClientString (GLB_display, GLX_VENDOR); if(!p1) return -1; p2 = glXGetClientString(GLB_display, GLX_VERSION); printf("OpenGL Vendor %s Version %s\n",p1,p2); // p1 = glXGetClientString(GLB_display, GLX_EXTENSIONS); // printf("Extensions: %s\n",p1); return 0; }
GLboolean glxewGetExtension (const char* name) { const GLubyte* start; const GLubyte* end; if (glXGetCurrentDisplay == NULL) return GL_FALSE; start = (const GLubyte*)glXGetClientString(glXGetCurrentDisplay(), GLX_EXTENSIONS); if (0 == start) return GL_FALSE; end = start + _glewStrLen(start); return _glewSearchExtension(name, start, end); }
static int GLXExtensionSupported(Display *dpy, const char *extension) { const char *s; s = glXQueryExtensionsString(dpy, DefaultScreen(dpy)); if(s != NULL && check_ext_string(s, extension)) return 1; s = glXGetClientString(dpy, GLX_EXTENSIONS); if(s != NULL && check_ext_string(s, extension)) return 1; return 0; }
TAO_BEGIN bool enableVSyncX11(QWidget *widget, bool enable) // ---------------------------------------------------------------------------- // Enable or disable VSync, return true on success // ---------------------------------------------------------------------------- { static bool resolved = false; typedef int (*setSwapIntervalFunc)(int interval); static setSwapIntervalFunc set_fn = NULL; if (!resolved) { #if QT_VERSION < 0x050000 const char *ext = glXGetClientString(widget->x11Info().display(), GLX_EXTENSIONS); QString extensions(ext); if (extensions.contains("GLX_MESA_swap_control")) { set_fn = (setSwapIntervalFunc) glXGetProcAddress((const GLubyte*) "glXSwapIntervalMESA"); } else if (extensions.contains("GLX_SGI_swap_control")) { set_fn = (setSwapIntervalFunc) glXGetProcAddress((const GLubyte*) "glXSwapIntervalSGI"); } #else // QT5 has no easy access to the X11 dpy (void) widget; set_fn = (setSwapIntervalFunc) glXGetProcAddress((const GLubyte*) "glXSwapIntervalMESA"); if (!set_fn) set_fn = (setSwapIntervalFunc) glXGetProcAddress((const GLubyte*) "glXSwapIntervalSGI"); #endif // QT5 resolved = true; } if (set_fn) { int swapInterval = enable ? 1 : 0; if (!set_fn(swapInterval)) return true; } return false; }
void QGLContext::swapBuffers() const { Q_D(const QGLContext); if (!d->valid) return; if (!deviceIsPixmap()) { int interval = d->glFormat.swapInterval(); if (interval > 0) { typedef int (*qt_glXGetVideoSyncSGI)(uint *); typedef int (*qt_glXWaitVideoSyncSGI)(int, int, uint *); static qt_glXGetVideoSyncSGI glXGetVideoSyncSGI = 0; static qt_glXWaitVideoSyncSGI glXWaitVideoSyncSGI = 0; static bool resolved = false; if (!resolved) { QString glxExt = QString(QLatin1String(glXGetClientString(QX11Info::display(), GLX_EXTENSIONS))); if (glxExt.contains(QLatin1String("GLX_SGI_video_sync"))) { #if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) void *handle = dlopen(NULL, RTLD_LAZY); if (handle) { glXGetVideoSyncSGI = (qt_glXGetVideoSyncSGI) dlsym(handle, "glXGetVideoSyncSGI"); glXWaitVideoSyncSGI = (qt_glXWaitVideoSyncSGI) dlsym(handle, "glXWaitVideoSyncSGI"); dlclose(handle); } if (!glXGetVideoSyncSGI) #endif { extern const QString qt_gl_library_name(); QLibrary lib(qt_gl_library_name()); glXGetVideoSyncSGI = (qt_glXGetVideoSyncSGI) lib.resolve("glXGetVideoSyncSGI"); glXWaitVideoSyncSGI = (qt_glXWaitVideoSyncSGI) lib.resolve("glXWaitVideoSyncSGI"); } } resolved = true; } if (glXGetVideoSyncSGI && glXWaitVideoSyncSGI) { uint counter; if (!glXGetVideoSyncSGI(&counter)) glXWaitVideoSyncSGI(interval + 1, (counter + interval) % (interval + 1), &counter); } } glXSwapBuffers(qt_x11Info(d->paintDevice)->display(), static_cast<QWidget *>(d->paintDevice)->winId()); } }
DECLEXPORT(EGLDisplay) eglGetDisplay(EGLNativeDisplayType hDisplay) { Display *pDisplay; if (!testValidDisplay(hDisplay)) return EGL_NO_DISPLAY; if (!clearEGLError()) /* Set up our tls. */ return EGL_NO_DISPLAY; if (hDisplay != EGL_DEFAULT_DISPLAY) pDisplay = hDisplay; else { pthread_once(&g_defaultDisplayOnce, defaultDisplayInitOnce); pDisplay = g_pDefaultDisplay; } if (pDisplay && !strcmp(glXGetClientString(pDisplay, GLX_VENDOR), "Chromium")) return (EGLDisplay) pDisplay; return EGL_NO_DISPLAY; }
static bool test_glx_version(void) { int version = epoxy_glx_version(dpy, 0); const char *version_string; int ret; int server_major, server_minor; int client_major, client_minor; int server, client, expected; if (version < 13) { fprintf(stderr, "Reported GLX version %d, should be at least 13 " "according to Linux GL ABI\n", version); return false; } version_string = glXQueryServerString(dpy, 0, GLX_VERSION); ret = sscanf(version_string, "%d.%d", &server_major, &server_minor); assert(ret == 2); server = server_major * 10 + server_minor; version_string = glXGetClientString(dpy, GLX_VERSION); ret = sscanf(version_string, "%d.%d", &client_major, &client_minor); assert(ret == 2); client = client_major * 10 + client_minor; if (client < server) expected = client; else expected = server; if (version != expected) { fprintf(stderr, "Reported GLX version %d, should be %d (%s)\n", version, expected, version_string); return false; } return true; }
static int GLXExtensionSupported(Display *dpy, const char *extension) { const char *extensionsString, *client_extensions, *pos; extensionsString = glXQueryExtensionsString(dpy, DefaultScreen(dpy)); client_extensions = glXGetClientString(dpy, GLX_EXTENSIONS); pos = strstr(extensionsString, extension); if (pos != NULL && (pos == extensionsString || pos[-1] == ' ') && (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0')) return 1; pos = strstr(client_extensions, extension); if (pos != NULL && (pos == extensionsString || pos[-1] == ' ') && (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0')) return 1; return 0; }
GLenum glxewContextInit (GLXEW_CONTEXT_ARG_DEF_LIST) { int major, minor; const GLubyte* extStart; const GLubyte* extEnd; /* initialize core GLX 1.2 */ if (_glewInit_GLX_VERSION_1_2(GLEW_CONTEXT_ARG_VAR_INIT)) return GLEW_ERROR_GLX_VERSION_11_ONLY; /* initialize flags */ CONST_CAST(GLXEW_VERSION_1_0) = GL_TRUE; CONST_CAST(GLXEW_VERSION_1_1) = GL_TRUE; CONST_CAST(GLXEW_VERSION_1_2) = GL_TRUE; CONST_CAST(GLXEW_VERSION_1_3) = GL_TRUE; CONST_CAST(GLXEW_VERSION_1_4) = GL_TRUE; /* query GLX version */ glXQueryVersion(glXGetCurrentDisplay(), &major, &minor); if (major == 1 && minor <= 3) { switch (minor) { case 3: CONST_CAST(GLXEW_VERSION_1_4) = GL_FALSE; break; case 2: CONST_CAST(GLXEW_VERSION_1_4) = GL_FALSE; CONST_CAST(GLXEW_VERSION_1_3) = GL_FALSE; break; default: return GLEW_ERROR_GLX_VERSION_11_ONLY; break; } } /* query GLX extension string */ extStart = 0; if (glXGetCurrentDisplay != NULL) extStart = (const GLubyte*)glXGetClientString(glXGetCurrentDisplay(), GLX_EXTENSIONS); if (extStart == 0) extStart = (const GLubyte *)""; extEnd = extStart + _glewStrLen(extStart);
void glx_features() { #ifdef GLLOADER_GLX char const * str = glXGetClientString(glXGetCurrentDisplay(), GLX_EXTENSIONS); if (str != NULL) { std::vector<std::string> glx_exts = split(str); glx_exts.erase(std::remove(glx_exts.begin(), glx_exts.end(), ""), glx_exts.end()); features_.insert(features_.end(), glx_exts.begin(), glx_exts.end()); int major, minor; glx_version(major, minor); int const ver_code = major * 10 + minor; if (ver_code >= 10) { features_.push_back("GLX_VERSION_1_0"); } if (ver_code >= 11) { features_.push_back("GLX_VERSION_1_1"); } if (ver_code >= 12) { features_.push_back("GLX_VERSION_1_2"); } if (ver_code >= 13) { features_.push_back("GLX_VERSION_1_3"); } if (ver_code >= 14) { features_.push_back("GLX_VERSION_1_4"); } } #endif // GLLOADER_GLX }
int main( int argc, char **argv ) { Display *display; int err, event, server_major, server_minor, client_major, client_minor; if ( argc > 1 ) display = XOpenDisplay( argv[1] ); else display = XOpenDisplay( "" ); if ( !display ) { fprintf( stderr, "FATAL: Can't connect to X Server\n" ); fprintf( stdout, "fatal\n" ); exit(0); } if ( glXQueryExtension( display, &err, &event ) ) { sscanf( glXQueryServerString( display, 0, GLX_VERSION ), "%d.%d", &server_major, &server_minor ); sscanf( glXGetClientString( display, GLX_VERSION ), "%d.%d", &client_major, &client_minor ); if ( server_major != client_major || server_minor != client_minor ) { fprintf( stdout, "glx_mismatch\n" ); } else fprintf( stdout, "success\n" ); } else fprintf( stdout, "no_glx_found\n" ); XCloseDisplay( display ); return 1; }
static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) { GLXFBConfig* fbconfigs; _GLFWfbconfig* result; int i, count = 0; const char* vendor; GLboolean trustWindowBit = GL_TRUE; *found = 0; if (_glfwLibrary.GLX.majorVersion == 1 && _glfwLibrary.GLX.minorVersion < 3) { if (!_glfwLibrary.GLX.SGIX_fbconfig) { _glfwSetError(GLFW_API_UNAVAILABLE, "GLX: GLXFBConfig support not found"); return NULL; } } vendor = glXGetClientString(_glfwLibrary.X11.display, GLX_VENDOR); if (strcmp(vendor, "Chromium") == 0) { // HACK: This is a (hopefully temporary) workaround for Chromium // (VirtualBox GL) not setting the window bit on any GLXFBConfigs trustWindowBit = GL_FALSE; } if (_glfwLibrary.GLX.SGIX_fbconfig) { fbconfigs = _glfwLibrary.GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, _glfwLibrary.X11.screen, NULL, &count); if (!count) { _glfwSetError(GLFW_API_UNAVAILABLE, "GLX: No GLXFBConfigs returned"); return NULL; } } else { fbconfigs = glXGetFBConfigs(_glfwLibrary.X11.display, _glfwLibrary.X11.screen, &count); if (!count) { _glfwSetError(GLFW_API_UNAVAILABLE, "GLX: No GLXFBConfigs returned"); return NULL; } } result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count); if (!result) { _glfwSetError(GLFW_OUT_OF_MEMORY, NULL); return NULL; } for (i = 0; i < count; i++) { _GLFWfbconfig* f = result + *found; if (!getFBConfigAttrib(window, fbconfigs[i], GLX_DOUBLEBUFFER) || !getFBConfigAttrib(window, fbconfigs[i], GLX_VISUAL_ID)) { // Only consider double-buffered GLXFBConfigs with associated visuals continue; } if (!(getFBConfigAttrib(window, fbconfigs[i], GLX_RENDER_TYPE) & GLX_RGBA_BIT)) { // Only consider RGBA GLXFBConfigs continue; } if (!(getFBConfigAttrib(window, fbconfigs[i], GLX_DRAWABLE_TYPE) & GLX_WINDOW_BIT)) { if (trustWindowBit) { // Only consider window GLXFBConfigs continue; } } f->redBits = getFBConfigAttrib(window, fbconfigs[i], GLX_RED_SIZE); f->greenBits = getFBConfigAttrib(window, fbconfigs[i], GLX_GREEN_SIZE); f->blueBits = getFBConfigAttrib(window, fbconfigs[i], GLX_BLUE_SIZE); f->alphaBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ALPHA_SIZE); f->depthBits = getFBConfigAttrib(window, fbconfigs[i], GLX_DEPTH_SIZE); f->stencilBits = getFBConfigAttrib(window, fbconfigs[i], GLX_STENCIL_SIZE); f->accumRedBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_RED_SIZE); f->accumGreenBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_GREEN_SIZE); f->accumBlueBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_BLUE_SIZE); f->accumAlphaBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_ALPHA_SIZE); f->auxBuffers = getFBConfigAttrib(window, fbconfigs[i], GLX_AUX_BUFFERS); f->stereo = getFBConfigAttrib(window, fbconfigs[i], GLX_STEREO); if (_glfwLibrary.GLX.ARB_multisample) f->samples = getFBConfigAttrib(window, fbconfigs[i], GLX_SAMPLES); else f->samples = 0; if (_glfwLibrary.GLX.ARB_framebuffer_sRGB) f->sRGB = getFBConfigAttrib(window, fbconfigs[i], GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB); else f->sRGB = GL_FALSE; f->platformID = (GLFWintptr) getFBConfigAttrib(window, fbconfigs[i], GLX_FBCONFIG_ID); (*found)++; } XFree(fbconfigs); return result; }
void print_screen_info(Display *dpy, int scrnum) { Window win; int attribSingle[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, None }; int attribDouble[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, None }; XSetWindowAttributes attr; unsigned long mask; Window root; GLXContext ctx; XVisualInfo *visinfo; int width = 100, height = 100; root = RootWindow(dpy, scrnum); visinfo = glXChooseVisual(dpy, scrnum, attribSingle); if (!visinfo) { visinfo = glXChooseVisual(dpy, scrnum, attribDouble); if (!visinfo) { fprintf(stderr, "Error: couldn't find RGB GLX visual\n"); return; } } attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | ExposureMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; win = XCreateWindow(dpy, root, 0, 0, width, height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr); ctx = glXCreateContext( dpy, visinfo, NULL, True ); if (!ctx) { fprintf(stderr, "Error: glXCreateContext failed\n"); XDestroyWindow(dpy, win); return; } if (glXMakeCurrent(dpy, win, ctx)) { const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR); const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION); const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS); const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR); const char *clientVersion = glXGetClientString(dpy, GLX_VERSION); const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS); const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum); const char *glVendor = (const char *) glGetString(GL_VENDOR); const char *glRenderer = (const char *) glGetString(GL_RENDERER); const char *glVersion = (const char *) glGetString(GL_VERSION); const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS); printf("display: %s screen:%d\n", DisplayString(dpy), scrnum); printf("direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No"); printf("server glx vendor string: %s\n", serverVendor); printf("server glx version string: %s\n", serverVersion); printf("server glx extensions:\n"); print_extension_list(serverExtensions); printf("client glx vendor string: %s\n", clientVendor); printf("client glx version string: %s\n", clientVersion); printf("client glx extensions:\n"); print_extension_list(clientExtensions); printf("GLX extensions:\n"); print_extension_list(glxExtensions); printf("OpenGL vendor string: %s\n", glVendor); printf("OpenGL renderer string: %s\n", glRenderer); printf("OpenGL version string: %s\n", glVersion); printf("OpenGL extensions:\n"); print_extension_list(glExtensions); } else { fprintf(stderr, "Error: glXMakeCurrent failed\n"); } glXDestroyContext(dpy, ctx); XDestroyWindow(dpy, win); }
void GLX_EXT_import_context_setup(void) { const char *const names[] = { "glXGetCurrentDisplayEXT", "glXQueryContextInfoEXT", "glXGetContextIDEXT", "glXImportContextEXT", "glXFreeContextEXT" }; __GLXextFuncPtr *procedures[ARRAY_SIZE(names)] = { (__GLXextFuncPtr *) & __piglit_glXGetCurrentDisplayEXT, (__GLXextFuncPtr *) & __piglit_glXQueryContextInfoEXT, (__GLXextFuncPtr *) & __piglit_glXGetContextIDEXT, (__GLXextFuncPtr *) & __piglit_glXImportContextEXT, (__GLXextFuncPtr *) & __piglit_glXFreeContextEXT }; const char *vendor; dpy = piglit_get_glx_display(); /* NVIDIA incorrectly only list the extension in the client * extenstions list. If the extension is available for applications * to use, it is supposed to be included in the list returned by * glXQueryExtensionsString. * * The glXImportContextEXT manual page is somewhat clear on this * topic: * * "If _glxextstring(EXT_import_context) is included in the string * returned by glXQueryExtensionsString, when called with argument * GLX_EXTENSIONS, extension EXT_import_context is supported." * * The text is a little weird because the only parameters to * glXQueryExtensionsString are the display and the screen. */ vendor = glXGetClientString(dpy, GLX_VENDOR); if (strcmp("NVIDIA Corporation", vendor) == 0) { const char *const client_extensions = glXGetClientString(dpy, GLX_EXTENSIONS); if (!piglit_is_extension_in_string(client_extensions, "GLX_EXT_import_context")) { fprintf(stderr, "Test requires GLX_EXT_import_context.\n"); piglit_report_result(PIGLIT_SKIP); } } else { piglit_require_glx_extension(dpy, "GLX_EXT_import_context"); } piglit_glx_get_all_proc_addresses(procedures, names, ARRAY_SIZE(names)); visinfo = piglit_get_glx_visual(dpy); directCtx = glXCreateContext(dpy, visinfo, NULL, True); if (directCtx == NULL) { fprintf(stderr, "Could not create initial direct-rendering context.\n"); piglit_report_result(PIGLIT_FAIL); } if (!glXIsDirect(dpy, directCtx)) { glXDestroyContext(dpy, directCtx); directCtx = NULL; } indirectCtx = glXCreateContext(dpy, visinfo, NULL, False); if (indirectCtx == NULL) { fprintf(stderr, "Could not create initial indirect-rendering " "context.\n"); piglit_report_result(PIGLIT_FAIL); } piglit_glx_get_error(dpy, NULL); old_handler = XSetErrorHandler(x_error_handler); }
void GraphicsManager::updatePlanformExtensions() { SDL_SysWMinfo info; SDL_VERSION(&info.version); if (SDL::getWindowWMInfo(mainGraphics->getWindow(), &info)) { #ifdef WIN32 if (!mwglGetExtensionsString) return; HDC hdc = GetDC(info.window); if (hdc) { const char *const extensions = mwglGetExtensionsString(hdc); if (extensions) { logger->log1("wGL extensions:"); logger->log1(extensions); splitToStringSet(mPlatformExtensions, extensions, ' '); } } #elif defined USE_X11 Display *const display = info.info.x11.display; if (display) { Screen *const screen = XDefaultScreenOfDisplay(display); if (!screen) return; const int screenNum = XScreenNumberOfScreen(screen); const char *const extensions = glXQueryExtensionsString( display, screenNum); if (extensions) { logger->log1("glx extensions:"); logger->log1(extensions); splitToStringSet(mPlatformExtensions, extensions, ' '); } glXQueryVersion(display, &mPlatformMajor, &mPlatformMinor); if (checkPlatformVersion(1, 1)) { const char *const vendor1 = glXQueryServerString( display, screenNum, GLX_VENDOR); if (vendor1) logger->log("glx server vendor: %s", vendor1); const char *const version1 = glXQueryServerString( display, screenNum, GLX_VERSION); if (version1) logger->log("glx server version: %s", version1); const char *const extensions1 = glXQueryServerString( display, screenNum, GLX_EXTENSIONS); if (extensions1) { logger->log1("glx server extensions:"); logger->log1(extensions1); } const char *const vendor2 = glXGetClientString( display, GLX_VENDOR); if (vendor2) logger->log("glx client vendor: %s", vendor2); const char *const version2 = glXGetClientString( display, GLX_VERSION); if (version2) logger->log("glx client version: %s", version2); const char *const extensions2 = glXGetClientString( display, GLX_EXTENSIONS); if (extensions2) { logger->log1("glx client extensions:"); logger->log1(extensions2); } } logger->log("width=%d", DisplayWidth(display, screenNum)); } #endif } }
// Return the GLXFBConfig most closely matching the specified hints // static GLFWbool chooseGLXFBConfig(const _GLFWfbconfig* desired, GLXFBConfig* result) { GLXFBConfig* nativeConfigs; _GLFWfbconfig* usableConfigs; const _GLFWfbconfig* closest; int i, nativeCount, usableCount; const char* vendor; GLFWbool trustWindowBit = GLFW_TRUE; // HACK: This is a (hopefully temporary) workaround for Chromium // (VirtualBox GL) not setting the window bit on any GLXFBConfigs vendor = glXGetClientString(_glfw.x11.display, GLX_VENDOR); if (strcmp(vendor, "Chromium") == 0) trustWindowBit = GLFW_FALSE; nativeConfigs = glXGetFBConfigs(_glfw.x11.display, _glfw.x11.screen, &nativeCount); if (!nativeCount) { _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: No GLXFBConfigs returned"); return GLFW_FALSE; } usableConfigs = calloc(nativeCount, sizeof(_GLFWfbconfig)); usableCount = 0; for (i = 0; i < nativeCount; i++) { const GLXFBConfig n = nativeConfigs[i]; _GLFWfbconfig* u = usableConfigs + usableCount; // Only consider RGBA GLXFBConfigs if (!(getGLXFBConfigAttrib(n, GLX_RENDER_TYPE) & GLX_RGBA_BIT)) continue; // Only consider window GLXFBConfigs if (!(getGLXFBConfigAttrib(n, GLX_DRAWABLE_TYPE) & GLX_WINDOW_BIT)) { if (trustWindowBit) continue; } u->redBits = getGLXFBConfigAttrib(n, GLX_RED_SIZE); u->greenBits = getGLXFBConfigAttrib(n, GLX_GREEN_SIZE); u->blueBits = getGLXFBConfigAttrib(n, GLX_BLUE_SIZE); u->alphaBits = getGLXFBConfigAttrib(n, GLX_ALPHA_SIZE); u->depthBits = getGLXFBConfigAttrib(n, GLX_DEPTH_SIZE); u->stencilBits = getGLXFBConfigAttrib(n, GLX_STENCIL_SIZE); u->accumRedBits = getGLXFBConfigAttrib(n, GLX_ACCUM_RED_SIZE); u->accumGreenBits = getGLXFBConfigAttrib(n, GLX_ACCUM_GREEN_SIZE); u->accumBlueBits = getGLXFBConfigAttrib(n, GLX_ACCUM_BLUE_SIZE); u->accumAlphaBits = getGLXFBConfigAttrib(n, GLX_ACCUM_ALPHA_SIZE); u->auxBuffers = getGLXFBConfigAttrib(n, GLX_AUX_BUFFERS); if (getGLXFBConfigAttrib(n, GLX_STEREO)) u->stereo = GLFW_TRUE; if (getGLXFBConfigAttrib(n, GLX_DOUBLEBUFFER)) u->doublebuffer = GLFW_TRUE; if (_glfw.glx.ARB_multisample) u->samples = getGLXFBConfigAttrib(n, GLX_SAMPLES); if (_glfw.glx.ARB_framebuffer_sRGB || _glfw.glx.EXT_framebuffer_sRGB) u->sRGB = getGLXFBConfigAttrib(n, GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB); u->handle = (uintptr_t) n; usableCount++; } closest = _glfwChooseFBConfig(desired, usableConfigs, usableCount); if (closest) *result = (GLXFBConfig) closest->handle; XFree(nativeConfigs); free(usableConfigs); return closest != NULL; }
void GlTraceFilterModel::checkExtensions() { const GLubyte *extensionString, *versionString; int supportedMajor, supportedMinor; QGLWidget w; w.makeCurrent(); extensionString = glGetString(GL_EXTENSIONS); versionString = glGetString(GL_VERSION); supportedMajor = versionString[0] - '0'; supportedMinor = versionString[2] - '0'; QByteArray extensions = QByteArray( reinterpret_cast<const char*>(extensionString)); #ifdef GLSLDB_WIN PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0; wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB"); if(wglGetExtensionsStringARB) { extensions.append(' '); extensions.append(QByteArray(reinterpret_cast<const char*>(wglGetExtensionsStringARB(wglGetCurrentDC())))); } #elif defined(GLSLDB_LINUX) int supportedXMajor, supportedXMinor; const char *versionXString; versionXString = glXQueryServerString(XOpenDisplay(NULL), 0, GLX_VERSION); supportedXMajor = versionXString[0] - '0'; supportedXMinor = versionXString[2] - '0'; extensions.append(' '); extensions.append( QByteArray( reinterpret_cast<const char*>(glXQueryServerString( XOpenDisplay(NULL), 0, GLX_EXTENSIONS)))); extensions.append(' '); extensions.append( QByteArray( reinterpret_cast<const char*>(glXGetClientString( XOpenDisplay(NULL), GLX_EXTENSIONS)))); extensions.append(' '); extensions.append( QByteArray( reinterpret_cast<const char*>(glXQueryExtensionsString( XOpenDisplay(NULL), 0)))); #elif defined(GLSLDB_OSX) #warning "FIXME: any OSX specific extensions wee need to add here?" #endif QList<QByteArray> extList = extensions.split(' '); for (int i = 0; i < this->rootItem->childCount(); i++) { GlTraceFilterItem *item = this->rootItem->child(i); if (strstr(item->function->extname, "GL_VERSION_") == item->function->extname) { int major, minor; major = item->function->extname[11] - '0'; minor = item->function->extname[13] - '0'; if (major < supportedMajor || (major == supportedMajor && minor <= supportedMinor)) { item->isSupported = true; } else { item->isSupported = false; } } #if defined(_WIN32) else if (strstr(item->function->extname, "WGL_VERSION_") == item->function->extname) { item->isSupported = true; } #elif defined(GLSLDB_LINUX) else if (strstr(item->function->extname, "GLX_VERSION_") == item->function->extname) { int major, minor; major = item->function->extname[12] - '0'; minor = item->function->extname[14] - '0'; if (major < supportedXMajor || (major == supportedXMajor && minor <= supportedXMinor)) { item->isSupported = true; } else { item->isSupported = false; } } #elif defined(GLSLDB_OSX) #warning "FIXME: any OSX specific extensions wee need to add here?" #endif else { item->isSupported = extList.contains(item->function->extname); } } }
static void print_screen_info(Display *dpy, int scrnum, Bool allowDirect, GLboolean limits) { Window win; int attribSingle[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, None }; int attribDouble[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, None }; XSetWindowAttributes attr; unsigned long mask; Window root; GLXContext ctx; XVisualInfo *visinfo; int width = 100, height = 100; root = RootWindow(dpy, scrnum); visinfo = glXChooseVisual(dpy, scrnum, attribSingle); if (!visinfo) { visinfo = glXChooseVisual(dpy, scrnum, attribDouble); if (!visinfo) { fprintf(stderr, "Error: couldn't find RGB GLX visual\n"); return; } } attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | ExposureMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; win = XCreateWindow(dpy, root, 0, 0, width, height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr); ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect ); if (!ctx) { fprintf(stderr, "Error: glXCreateContext failed\n"); XDestroyWindow(dpy, win); return; } if (glXMakeCurrent(dpy, win, ctx)) { const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR); const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION); const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS); const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR); const char *clientVersion = glXGetClientString(dpy, GLX_VERSION); const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS); const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum); const char *glVendor = (const char *) glGetString(GL_VENDOR); const char *glRenderer = (const char *) glGetString(GL_RENDERER); const char *glVersion = (const char *) glGetString(GL_VERSION); const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS); int glxVersionMajor; int glxVersionMinor; char *displayName = NULL; char *colon = NULL, *period = NULL; #ifdef DO_GLU const char *gluVersion = (const char *) gluGetString(GLU_VERSION); const char *gluExtensions = (const char *) gluGetString(GLU_EXTENSIONS); #endif if (! glXQueryVersion( dpy, & glxVersionMajor, & glxVersionMinor )) { fprintf(stderr, "Error: glXQueryVersion failed\n"); exit(1); } /* Strip the screen number from the display name, if present. */ if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) { fprintf(stderr, "Error: malloc() failed\n"); exit(1); } strcpy(displayName, DisplayString(dpy)); colon = strrchr(displayName, ':'); if (colon) { period = strchr(colon, '.'); if (period) *period = '\0'; } printf("display: %s screen: %d\n", displayName, scrnum); free(displayName); printf("direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No"); printf("server glx vendor string: %s\n", serverVendor); printf("server glx version string: %s\n", serverVersion); printf("server glx extensions:\n"); print_extension_list(serverExtensions); printf("client glx vendor string: %s\n", clientVendor); printf("client glx version string: %s\n", clientVersion); printf("client glx extensions:\n"); print_extension_list(clientExtensions); printf("GLX version: %u.%u\n", glxVersionMajor, glxVersionMinor); printf("GLX extensions:\n"); print_extension_list(glxExtensions); printf("OpenGL vendor string: %s\n", glVendor); printf("OpenGL renderer string: %s\n", glRenderer); printf("OpenGL version string: %s\n", glVersion); printf("OpenGL extensions:\n"); print_extension_list(glExtensions); if (limits) print_limits(); #ifdef DO_GLU printf("glu version: %s\n", gluVersion); printf("glu extensions:\n"); print_extension_list(gluExtensions); #endif } else { fprintf(stderr, "Error: glXMakeCurrent failed\n"); } glXDestroyContext(dpy, ctx); XDestroyWindow(dpy, win); }
static int setup(int width, int height) { #if USE_OSMESA const size_t size = width * height * 4; pbuffer = malloc(size); memset(pbuffer, 0x21, size); context = OSMesaCreateContextExt(GL_RGBA, 24, 0, 0, 0); OSMesaMakeCurrent(context, (void *)pbuffer, GL_UNSIGNED_BYTE, width, height); return 0; #elif USE_CGL /* OpenGL PBuffer initialization: OSX specific */ CGLPixelFormatAttribute pfattr[] = { kCGLPFAPBuffer, (CGLPixelFormatAttribute)0 }; CGLPixelFormatObj pixformat; GLint npixels; int e; e = CGLChoosePixelFormat(pfattr, &pixformat, &npixels); if (e != kCGLNoError) { fprintf(stderr, "CGLChoosePixelFormat failed, err %d\n", e); return e; } e = CGLCreateContext(pixformat, 0, &context); if (e != kCGLNoError) { fprintf(stderr, "CGLChoosePixelFormat failed, err %d\n", e); return e; } e = CGLDestroyPixelFormat(pixformat); if (e != kCGLNoError) { fprintf(stderr, "CGLDestroyPixelFormat failed, err %d\n", e); return e; } e = CGLSetCurrentContext(context); if (e != kCGLNoError) { fprintf(stderr, "CGLSetCurrentContext failed, err %d\n", e); return e; } e = CGLCreatePBuffer(width, height, GL_TEXTURE_2D, GL_RGB, 0, &pbuffer); if (e != kCGLNoError) { fprintf(stderr, "CGLCreatePBuffer failed, err %d\n", e); return e; } e = CGLSetPBuffer(context, pbuffer, 0, 0, 0); if (e != kCGLNoError) { fprintf(stderr, "CGLSetPBuffer failed, err %d\n", e); return e; } return (int)kCGLNoError; #elif USE_GLX int result = (-1); char *glxversion; int screen; GLXFBConfig *fbConfigs = NULL; GLXFBConfig chosenFBConfig; GLXFBConfig fbconfig = 0; GLXPbuffer pbuffer = None; int nConfigs; int fbconfigid; int fbAttribs[] = { GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_DEPTH_SIZE, 1, GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT | GLX_PBUFFER_BIT, None }; int pbAttribs[] = { GLX_PBUFFER_WIDTH, 0, GLX_PBUFFER_HEIGHT, 0, GLX_LARGEST_PBUFFER, False, GLX_PRESERVED_CONTENTS, False, None }; /* Open the X display */ display = XOpenDisplay(NULL); if (!display) { fprintf(stderr, "Error: couldn't open default X display.\n"); goto end; } /* Get default screen */ screen = DefaultScreen(display); glxversion = (char *) glXGetClientString(display, GLX_VERSION); if (!(strstr(glxversion, "1.3") || strstr(glxversion, "1.4"))) { goto end; } glxversion = (char *) glXQueryServerString(display, screen, GLX_VERSION); if (!(strstr(glxversion, "1.3") || strstr(glxversion, "1.4"))) { goto end; } /* Create Pbuffer */ pbAttribs[1] = width; pbAttribs[3] = height; fbConfigs = glXChooseFBConfig(display, screen, fbAttribs, &nConfigs); if (0 == nConfigs || !fbConfigs) { fprintf(stderr, "Error: glxChooseFBConfig failed\n"); XFree(fbConfigs); goto end; } chosenFBConfig = fbConfigs[0]; glXGetFBConfigAttrib(display, chosenFBConfig, GLX_FBCONFIG_ID, &fbconfigid); /* Create the pbuffer using first fbConfig in the list that works. */ pbuffer = glXCreatePbuffer(display, chosenFBConfig, pbAttribs); if (pbuffer) { fbconfig = chosenFBConfig; } XFree(fbConfigs); if (pbuffer == None) { fprintf(stderr, "Error: couldn't create pbuffer\n"); goto end; } /* Create GLX context */ context = glXCreateNewContext(display, fbconfig, GLX_RGBA_TYPE, NULL, True); if (!context) { fprintf(stderr, "Error: Couldn't create GLXContext\n"); goto end; } /* Bind context to pbuffer */ if (!glXMakeCurrent(display, pbuffer, context)) { fprintf(stderr, "Error: glXMakeCurrent failed\n"); goto end; } result = 0; end: if (fbConfigs) XFree(fbConfigs); if (display) XCloseDisplay(display); return result; #else /* TODO: pbuffer initialization */ return 0; #endif }
bool QGLContext::chooseContext(const QGLContext* shareContext) { Q_D(QGLContext); const QX11Info *xinfo = qt_x11Info(d->paintDevice); Display* disp = xinfo->display(); d->vi = chooseVisual(); if (!d->vi) return false; if (deviceIsPixmap() && (((XVisualInfo*)d->vi)->depth != xinfo->depth() || ((XVisualInfo*)d->vi)->screen != xinfo->screen())) { XFree(d->vi); XVisualInfo appVisInfo; memset(&appVisInfo, 0, sizeof(XVisualInfo)); appVisInfo.visualid = XVisualIDFromVisual((Visual *) xinfo->visual()); appVisInfo.screen = xinfo->screen(); int nvis; d->vi = XGetVisualInfo(disp, VisualIDMask | VisualScreenMask, &appVisInfo, &nvis); if (!d->vi) return false; int useGL; glXGetConfig(disp, (XVisualInfo*)d->vi, GLX_USE_GL, &useGL); if (!useGL) return false; //# Chickening out already... } int res; glXGetConfig(disp, (XVisualInfo*)d->vi, GLX_LEVEL, &res); d->glFormat.setPlane(res); glXGetConfig(disp, (XVisualInfo*)d->vi, GLX_DOUBLEBUFFER, &res); d->glFormat.setDoubleBuffer(res); glXGetConfig(disp, (XVisualInfo*)d->vi, GLX_DEPTH_SIZE, &res); d->glFormat.setDepth(res); if (d->glFormat.depth()) d->glFormat.setDepthBufferSize(res); glXGetConfig(disp, (XVisualInfo*)d->vi, GLX_RGBA, &res); d->glFormat.setRgba(res); glXGetConfig(disp, (XVisualInfo*)d->vi, GLX_RED_SIZE, &res); d->glFormat.setRedBufferSize(res); glXGetConfig(disp, (XVisualInfo*)d->vi, GLX_GREEN_SIZE, &res); d->glFormat.setGreenBufferSize(res); glXGetConfig(disp, (XVisualInfo*)d->vi, GLX_BLUE_SIZE, &res); d->glFormat.setBlueBufferSize(res); glXGetConfig(disp, (XVisualInfo*)d->vi, GLX_ALPHA_SIZE, &res); d->glFormat.setAlpha(res); if (d->glFormat.alpha()) d->glFormat.setAlphaBufferSize(res); glXGetConfig(disp, (XVisualInfo*)d->vi, GLX_ACCUM_RED_SIZE, &res); d->glFormat.setAccum(res); if (d->glFormat.accum()) d->glFormat.setAccumBufferSize(res); glXGetConfig(disp, (XVisualInfo*)d->vi, GLX_STENCIL_SIZE, &res); d->glFormat.setStencil(res); if (d->glFormat.stencil()) d->glFormat.setStencilBufferSize(res); glXGetConfig(disp, (XVisualInfo*)d->vi, GLX_STEREO, &res); d->glFormat.setStereo(res); glXGetConfig(disp, (XVisualInfo*)d->vi, GLX_SAMPLE_BUFFERS_ARB, &res); d->glFormat.setSampleBuffers(res); if (d->glFormat.sampleBuffers()) { glXGetConfig(disp, (XVisualInfo*)d->vi, GLX_SAMPLES_ARB, &res); d->glFormat.setSamples(res); } Bool direct = format().directRendering() ? True : False; if (shareContext && (!shareContext->isValid() || !shareContext->d_func()->cx)) { qWarning("QGLContext::chooseContext(): Cannot share with invalid context"); shareContext = 0; } // 1. Sharing between rgba and color-index will give wrong colors. // 2. Contexts cannot be shared btw. direct/non-direct renderers. // 3. Pixmaps cannot share contexts that are set up for direct rendering. // 4. If the contexts are not created on the same screen, they can't be shared if (shareContext && (format().rgba() != shareContext->format().rgba() || (deviceIsPixmap() && glXIsDirect(disp, (GLXContext)shareContext->d_func()->cx)) || (shareContext->d_func()->screen != xinfo->screen()))) { shareContext = 0; } d->cx = 0; if (shareContext) { d->cx = glXCreateContext(disp, (XVisualInfo *)d->vi, (GLXContext)shareContext->d_func()->cx, direct); d->screen = ((XVisualInfo*)d->vi)->screen; if (d->cx) { QGLContext *share = const_cast<QGLContext *>(shareContext); d->sharing = true; share->d_func()->sharing = true; } } if (!d->cx) { d->cx = glXCreateContext(disp, (XVisualInfo *)d->vi, NULL, direct); d->screen = ((XVisualInfo*)d->vi)->screen; } if (!d->cx) return false; d->glFormat.setDirectRendering(glXIsDirect(disp, (GLXContext)d->cx)); if (deviceIsPixmap()) { #if defined(GLX_MESA_pixmap_colormap) && defined(QGL_USE_MESA_EXT) d->gpm = glXCreateGLXPixmapMESA(disp, (XVisualInfo *)d->vi, qt_x11Handle(d->paintDevice), qt_gl_choose_cmap(disp, (XVisualInfo *)d->vi)); #else d->gpm = (quint32)glXCreateGLXPixmap(disp, (XVisualInfo *)d->vi, qt_x11Handle(d->paintDevice)); #endif if (!d->gpm) return false; } QString glxExt = QString(QLatin1String(glXGetClientString(QX11Info::display(), GLX_EXTENSIONS))); if (glxExt.contains(QLatin1String("GLX_SGI_video_sync"))) { if (d->glFormat.swapInterval() == -1) d->glFormat.setSwapInterval(0); } else { d->glFormat.setSwapInterval(-1); } return true; }
void PBuffer::initialise() { /// Smaller dimensions are not sane if(mWidth < 64) mWidth = 64; if(mHeight < 64) mHeight = 64; Display *dpy = GLEngine::getInstance().getDisplay(); GLXContext context = GLEngine::getInstance().getSharedContext(); int screen = DefaultScreen(dpy); /// Find out which extension to use for floating point /// Possible floating point extensions, in order of preference #define RTF_NONE 0 #define RTF_NV 1 /** GLX_NV_float_buffer */ #define RTF_ATI 2 /** GLX_ATI_pixel_format_float */ #define RTF_ARB 3 /** GLX_ARB_fbconfig_float */ int floatBuffer = RTF_NONE; if(mIsFloat) { /// Query supported float buffer extensions /// Choose the best one std::stringstream ext; std::string instr; ext << glXQueryExtensionsString(dpy, screen) << " " << glXGetClientString(dpy, GLX_EXTENSIONS); while(ext >> instr) { if(instr == "GLX_NV_float_buffer" && floatBuffer<RTF_NV) floatBuffer = RTF_NV; if(instr == "GLX_ATI_pixel_format_float" && floatBuffer<RTF_ATI) floatBuffer = RTF_ATI; if(instr == "GLX_ARB_fbconfig_float" && floatBuffer<RTF_ARB) floatBuffer = RTF_ARB; } if(floatBuffer == RTF_NONE) { GPGPU_EXCEPT(ERR_RENDERSYSTEM, "Floating point rendertargets not supported on this hardware"); } } /// Make the buffer int attribs[50]; int attrib = 0; if (floatBuffer == RTF_ATI) { attribs[attrib++] = GLX_RENDER_TYPE; attribs[attrib++] = GLX_RGBA_FLOAT_ATI_BIT; } else if (floatBuffer == RTF_ARB) { attribs[attrib++] = GLX_RENDER_TYPE; attribs[attrib++] = GLX_RGBA_FLOAT_BIT; } else { attribs[attrib++] = GLX_RENDER_TYPE; attribs[attrib++] = GLX_RGBA_BIT; } attribs[attrib++] = GLX_DRAWABLE_TYPE; attribs[attrib++] = GLX_PBUFFER_BIT; attribs[attrib++] = GLX_STENCIL_SIZE; attribs[attrib++] = 8; attribs[attrib++] = GLX_DEPTH_SIZE; attribs[attrib++] = 24; attribs[attrib++] = GLX_RED_SIZE; attribs[attrib++] = mBitDepth; attribs[attrib++] = GLX_GREEN_SIZE; attribs[attrib++] = mBitDepth; attribs[attrib++] = GLX_BLUE_SIZE; attribs[attrib++] = mBitDepth; attribs[attrib++] = GLX_ALPHA_SIZE; attribs[attrib++] = mBitDepth; if (floatBuffer == RTF_NV) { attribs[attrib++] = GLX_FLOAT_COMPONENTS_NV; attribs[attrib++] = 1; } attribs[attrib++] = None; GLXFBConfig * fbConfigs; int nConfigs; fbConfigs = glXChooseFBConfig(dpy, screen, attribs, &nConfigs); if (nConfigs == 0 || !fbConfigs) GPGPU_EXCEPT(ERR_RENDERSYSTEM, "RenderTexture::Initialize() creation error: Couldn't find a suitable pixel format"); /// Determine the type of context to create int renderType = GLX_RGBA_TYPE; if(floatBuffer == RTF_ARB) { renderType = GLX_RGBA_FLOAT_TYPE; } /// Pick the first returned format that will return a pbuffer for (int i = 0; i < nConfigs; i++) { // Check colour format int redSize, greenSize, blueSize, alphaSize; glXGetFBConfigAttrib(dpy, fbConfigs[i], GLX_RED_SIZE, &redSize); glXGetFBConfigAttrib(dpy, fbConfigs[i], GLX_GREEN_SIZE, &greenSize); glXGetFBConfigAttrib(dpy, fbConfigs[i], GLX_BLUE_SIZE, &blueSize); glXGetFBConfigAttrib(dpy, fbConfigs[i], GLX_ALPHA_SIZE, &alphaSize); if(redSize == mBitDepth && greenSize == mBitDepth && blueSize == mBitDepth && alphaSize == mBitDepth) { attrib = 0; attribs[attrib++] = GLX_PBUFFER_WIDTH; attribs[attrib++] = mWidth; // Get from texture? attribs[attrib++] = GLX_PBUFFER_HEIGHT; attribs[attrib++] = mHeight; // Get from texture? attribs[attrib++] = GLX_PRESERVED_CONTENTS; attribs[attrib++] = 1; attribs[attrib++] = None; mPBuffer = glXCreatePbuffer(dpy, fbConfigs[i], attribs); if (mPBuffer) { mContext = glXCreateNewContext(dpy, fbConfigs[i], renderType, context, True); break; } } } if (!mPBuffer) GPGPU_EXCEPT(ERR_RENDERSYSTEM, "RenderTexture::Initialize() pbuffer creation error: No exact match found"); if (!mContext) GPGPU_EXCEPT(ERR_RENDERSYSTEM, "RenderTexture::Initialize() creation error: glXCreateContext() failed"); /// Read final size int _iWidth, _iHeight; glXQueryDrawable(dpy, mPBuffer, GLX_WIDTH, (GLuint *) & _iWidth); glXQueryDrawable(dpy, mPBuffer, GLX_HEIGHT, (GLuint *) & _iHeight); mWidth = _iWidth; mHeight = _iHeight; }
void *QGLContext::tryVisual( const QGLFormat& f, int bufDepth ) { int spec[40]; int i = 0; spec[i++] = GLX_LEVEL; spec[i++] = f.plane(); #if defined(GLX_VERSION_1_1) && defined(GLX_EXT_visual_info) static bool useTranspExt = FALSE; static bool useTranspExtChecked = FALSE; if ( f.plane() && !useTranspExtChecked && d->paintDevice ) { QCString estr( glXQueryExtensionsString( d->paintDevice->x11Display(), d->paintDevice->x11Screen() ) ); useTranspExt = estr.contains( "GLX_EXT_visual_info" ); //# (A bit simplistic; that could theoretically be a substring) if ( useTranspExt ) { QCString cstr( glXGetClientString( d->paintDevice->x11Display(), GLX_VENDOR ) ); useTranspExt = !cstr.contains( "Xi Graphics" ); // bug workaround if ( useTranspExt ) { // bug workaround - some systems (eg. FireGL) refuses to return an overlay // visual if the GLX_TRANSPARENT_TYPE_EXT attribute is specfied, even if // the implementation supports transparent overlays int tmpSpec[] = { GLX_LEVEL, f.plane(), GLX_TRANSPARENT_TYPE_EXT, f.rgba() ? GLX_TRANSPARENT_RGB_EXT : GLX_TRANSPARENT_INDEX_EXT, None }; XVisualInfo * vinf = glXChooseVisual( d->paintDevice->x11Display(), d->paintDevice->x11Screen(), tmpSpec ); if ( !vinf ) { useTranspExt = FALSE; } } } useTranspExtChecked = TRUE; } if ( f.plane() && useTranspExt ) { // Required to avoid non-transparent overlay visual(!) on some systems spec[i++] = GLX_TRANSPARENT_TYPE_EXT; spec[i++] = f.rgba() ? GLX_TRANSPARENT_RGB_EXT : GLX_TRANSPARENT_INDEX_EXT; } #endif if ( f.doubleBuffer() ) spec[i++] = GLX_DOUBLEBUFFER; if ( f.depth() ) { spec[i++] = GLX_DEPTH_SIZE; spec[i++] = 1; } if ( f.stereo() ) { spec[i++] = GLX_STEREO; } if ( f.stencil() ) { spec[i++] = GLX_STENCIL_SIZE; spec[i++] = 1; } if ( f.rgba() ) { spec[i++] = GLX_RGBA; spec[i++] = GLX_RED_SIZE; spec[i++] = 1; spec[i++] = GLX_GREEN_SIZE; spec[i++] = 1; spec[i++] = GLX_BLUE_SIZE; spec[i++] = 1; if ( f.alpha() ) { spec[i++] = GLX_ALPHA_SIZE; spec[i++] = 1; } if ( f.accum() ) { spec[i++] = GLX_ACCUM_RED_SIZE; spec[i++] = 1; spec[i++] = GLX_ACCUM_GREEN_SIZE; spec[i++] = 1; spec[i++] = GLX_ACCUM_BLUE_SIZE; spec[i++] = 1; if ( f.alpha() ) { spec[i++] = GLX_ACCUM_ALPHA_SIZE; spec[i++] = 1; } } } else { spec[i++] = GLX_BUFFER_SIZE; spec[i++] = bufDepth; } spec[i] = None; return glXChooseVisual( d->paintDevice->x11Display(), d->paintDevice->x11Screen(), spec ); }