GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname) { _GLFW_REQUIRE_INIT_OR_RETURN(NULL); if (!_glfwPlatformGetCurrentContext()) { _glfwInputError(GLFW_NO_CURRENT_CONTEXT, NULL); return NULL; } return _glfwPlatformGetProcAddress(procname); }
GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname) { if (!_glfwInitialized) { _glfwInputError(GLFW_NOT_INITIALIZED, NULL); return NULL; } if (!_glfwPlatformGetCurrentContext()) { _glfwInputError(GLFW_NO_CURRENT_CONTEXT, NULL); return NULL; } return _glfwPlatformGetProcAddress(procname); }
GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname) { if (!_glfwInitialized) { _glfwSetError(GLFW_NOT_INITIALIZED, NULL); return NULL; } if (!_glfwLibrary.currentWindow) { _glfwSetError(GLFW_NO_CURRENT_CONTEXT, NULL); return NULL; } return _glfwPlatformGetProcAddress(procname); }
// Initialize GLX // int _glfwInitContextAPI(void) { #ifdef _GLFW_DLOPEN_LIBGL int i; char* libGL_names[ ] = { "libGL.so", "libGL.so.1", "/usr/lib/libGL.so", "/usr/lib/libGL.so.1", NULL }; for (i = 0; libGL_names[i] != NULL; i++) { _glfw.glx.libGL = dlopen(libGL_names[i], RTLD_LAZY | RTLD_GLOBAL); if (_glfw.glx.libGL) break; } if (!_glfw.glx.libGL) { _glfwInputError(GLFW_PLATFORM_ERROR, "GLX: Failed to find libGL"); return GL_FALSE; } #endif if (pthread_key_create(&_glfw.glx.current, NULL) != 0) { _glfwInputError(GLFW_PLATFORM_ERROR, "GLX: Failed to create context TLS"); return GL_FALSE; } // Check if GLX is supported on this display if (!glXQueryExtension(_glfw.x11.display, &_glfw.glx.errorBase, &_glfw.glx.eventBase)) { _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: GLX support not found"); return GL_FALSE; } if (!glXQueryVersion(_glfw.x11.display, &_glfw.glx.versionMajor, &_glfw.glx.versionMinor)) { _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: Failed to query GLX version"); return GL_FALSE; } if (_glfwPlatformExtensionSupported("GLX_EXT_swap_control")) { _glfw.glx.SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC) _glfwPlatformGetProcAddress("glXSwapIntervalEXT"); if (_glfw.glx.SwapIntervalEXT) _glfw.glx.EXT_swap_control = GL_TRUE; } if (_glfwPlatformExtensionSupported("GLX_SGI_swap_control")) { _glfw.glx.SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC) _glfwPlatformGetProcAddress("glXSwapIntervalSGI"); if (_glfw.glx.SwapIntervalSGI) _glfw.glx.SGI_swap_control = GL_TRUE; } if (_glfwPlatformExtensionSupported("GLX_MESA_swap_control")) { _glfw.glx.SwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC) _glfwPlatformGetProcAddress("glXSwapIntervalMESA"); if (_glfw.glx.SwapIntervalMESA) _glfw.glx.MESA_swap_control = GL_TRUE; } if (_glfwPlatformExtensionSupported("GLX_SGIX_fbconfig")) { _glfw.glx.GetFBConfigAttribSGIX = (PFNGLXGETFBCONFIGATTRIBSGIXPROC) _glfwPlatformGetProcAddress("glXGetFBConfigAttribSGIX"); _glfw.glx.ChooseFBConfigSGIX = (PFNGLXCHOOSEFBCONFIGSGIXPROC) _glfwPlatformGetProcAddress("glXChooseFBConfigSGIX"); _glfw.glx.CreateContextWithConfigSGIX = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) _glfwPlatformGetProcAddress("glXCreateContextWithConfigSGIX"); _glfw.glx.GetVisualFromFBConfigSGIX = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) _glfwPlatformGetProcAddress("glXGetVisualFromFBConfigSGIX"); if (_glfw.glx.GetFBConfigAttribSGIX && _glfw.glx.ChooseFBConfigSGIX && _glfw.glx.CreateContextWithConfigSGIX && _glfw.glx.GetVisualFromFBConfigSGIX) { _glfw.glx.SGIX_fbconfig = GL_TRUE; } } if (_glfwPlatformExtensionSupported("GLX_ARB_multisample")) _glfw.glx.ARB_multisample = GL_TRUE; if (_glfwPlatformExtensionSupported("GLX_ARB_framebuffer_sRGB")) _glfw.glx.ARB_framebuffer_sRGB = GL_TRUE; if (_glfwPlatformExtensionSupported("GLX_ARB_create_context")) { _glfw.glx.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) _glfwPlatformGetProcAddress("glXCreateContextAttribsARB"); if (_glfw.glx.CreateContextAttribsARB) _glfw.glx.ARB_create_context = GL_TRUE; } if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_robustness")) _glfw.glx.ARB_create_context_robustness = GL_TRUE; if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_profile")) _glfw.glx.ARB_create_context_profile = GL_TRUE; if (_glfwPlatformExtensionSupported("GLX_EXT_create_context_es2_profile")) _glfw.glx.EXT_create_context_es2_profile = GL_TRUE; return GL_TRUE; }
// Initialize GLX // GLFWbool _glfwInitGLX(void) { int i; const char* sonames[] = { #if defined(__CYGWIN__) "libGL-1.so", #else "libGL.so.1", "libGL.so", #endif NULL }; for (i = 0; sonames[i]; i++) { _glfw.glx.handle = dlopen(sonames[i], RTLD_LAZY | RTLD_GLOBAL); if (_glfw.glx.handle) break; } if (!_glfw.glx.handle) { _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: Failed to load GLX"); return GLFW_FALSE; } _glfw.glx.GetFBConfigs = dlsym(_glfw.glx.handle, "glXGetFBConfigs"); _glfw.glx.GetFBConfigAttrib = dlsym(_glfw.glx.handle, "glXGetFBConfigAttrib"); _glfw.glx.GetClientString = dlsym(_glfw.glx.handle, "glXGetClientString"); _glfw.glx.QueryExtension = dlsym(_glfw.glx.handle, "glXQueryExtension"); _glfw.glx.QueryVersion = dlsym(_glfw.glx.handle, "glXQueryVersion"); _glfw.glx.DestroyContext = dlsym(_glfw.glx.handle, "glXDestroyContext"); _glfw.glx.MakeCurrent = dlsym(_glfw.glx.handle, "glXMakeCurrent"); _glfw.glx.SwapBuffers = dlsym(_glfw.glx.handle, "glXSwapBuffers"); _glfw.glx.QueryExtensionsString = dlsym(_glfw.glx.handle, "glXQueryExtensionsString"); _glfw.glx.CreateNewContext = dlsym(_glfw.glx.handle, "glXCreateNewContext"); _glfw.glx.CreateWindow = dlsym(_glfw.glx.handle, "glXCreateWindow"); _glfw.glx.DestroyWindow = dlsym(_glfw.glx.handle, "glXDestroyWindow"); _glfw.glx.GetProcAddress = dlsym(_glfw.glx.handle, "glXGetProcAddress"); _glfw.glx.GetProcAddressARB = dlsym(_glfw.glx.handle, "glXGetProcAddressARB"); _glfw.glx.GetVisualFromFBConfig = dlsym(_glfw.glx.handle, "glXGetVisualFromFBConfig"); if (!glXQueryExtension(_glfw.x11.display, &_glfw.glx.errorBase, &_glfw.glx.eventBase)) { _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: GLX extension not found"); return GLFW_FALSE; } if (!glXQueryVersion(_glfw.x11.display, &_glfw.glx.major, &_glfw.glx.minor)) { _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: Failed to query GLX version"); return GLFW_FALSE; } if (_glfw.glx.major == 1 && _glfw.glx.minor < 3) { _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: GLX version 1.3 is required"); return GLFW_FALSE; } if (_glfwPlatformExtensionSupported("GLX_EXT_swap_control")) { _glfw.glx.SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC) _glfwPlatformGetProcAddress("glXSwapIntervalEXT"); if (_glfw.glx.SwapIntervalEXT) _glfw.glx.EXT_swap_control = GLFW_TRUE; } if (_glfwPlatformExtensionSupported("GLX_SGI_swap_control")) { _glfw.glx.SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC) _glfwPlatformGetProcAddress("glXSwapIntervalSGI"); if (_glfw.glx.SwapIntervalSGI) _glfw.glx.SGI_swap_control = GLFW_TRUE; } if (_glfwPlatformExtensionSupported("GLX_MESA_swap_control")) { _glfw.glx.SwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC) _glfwPlatformGetProcAddress("glXSwapIntervalMESA"); if (_glfw.glx.SwapIntervalMESA) _glfw.glx.MESA_swap_control = GLFW_TRUE; } if (_glfwPlatformExtensionSupported("GLX_ARB_multisample")) _glfw.glx.ARB_multisample = GLFW_TRUE; if (_glfwPlatformExtensionSupported("GLX_ARB_framebuffer_sRGB")) _glfw.glx.ARB_framebuffer_sRGB = GLFW_TRUE; if (_glfwPlatformExtensionSupported("GLX_EXT_framebuffer_sRGB")) _glfw.glx.EXT_framebuffer_sRGB = GLFW_TRUE; if (_glfwPlatformExtensionSupported("GLX_ARB_create_context")) { _glfw.glx.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) _glfwPlatformGetProcAddress("glXCreateContextAttribsARB"); if (_glfw.glx.CreateContextAttribsARB) _glfw.glx.ARB_create_context = GLFW_TRUE; } if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_robustness")) _glfw.glx.ARB_create_context_robustness = GLFW_TRUE; if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_profile")) _glfw.glx.ARB_create_context_profile = GLFW_TRUE; if (_glfwPlatformExtensionSupported("GLX_EXT_create_context_es2_profile")) _glfw.glx.EXT_create_context_es2_profile = GLFW_TRUE; if (_glfwPlatformExtensionSupported("GLX_ARB_context_flush_control")) _glfw.glx.ARB_context_flush_control = GLFW_TRUE; return GLFW_TRUE; }
// Initialize GLX // int _glfwInitContextAPI(void) { if (!_glfwInitTLS()) return GL_FALSE; #ifdef _GLFW_DLOPEN_LIBGL _glfw.glx.libGL = dlopen("libGL.so.1", RTLD_LAZY | RTLD_GLOBAL); if (!_glfw.glx.libGL) { _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: Failed to find libGL"); return GL_FALSE; } #endif if (!glXQueryExtension(_glfw.x11.display, &_glfw.glx.errorBase, &_glfw.glx.eventBase)) { _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: GLX extension not found"); return GL_FALSE; } if (!glXQueryVersion(_glfw.x11.display, &_glfw.glx.versionMajor, &_glfw.glx.versionMinor)) { _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: Failed to query GLX version"); return GL_FALSE; } if (_glfw.glx.versionMajor == 1 && _glfw.glx.versionMinor < 3) { _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: GLX version 1.3 is required"); return GL_FALSE; } if (_glfwPlatformExtensionSupported("GLX_EXT_swap_control")) { _glfw.glx.SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC) _glfwPlatformGetProcAddress("glXSwapIntervalEXT"); if (_glfw.glx.SwapIntervalEXT) _glfw.glx.EXT_swap_control = GL_TRUE; } if (_glfwPlatformExtensionSupported("GLX_SGI_swap_control")) { _glfw.glx.SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC) _glfwPlatformGetProcAddress("glXSwapIntervalSGI"); if (_glfw.glx.SwapIntervalSGI) _glfw.glx.SGI_swap_control = GL_TRUE; } if (_glfwPlatformExtensionSupported("GLX_MESA_swap_control")) { _glfw.glx.SwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC) _glfwPlatformGetProcAddress("glXSwapIntervalMESA"); if (_glfw.glx.SwapIntervalMESA) _glfw.glx.MESA_swap_control = GL_TRUE; } if (_glfwPlatformExtensionSupported("GLX_ARB_multisample")) _glfw.glx.ARB_multisample = GL_TRUE; if (_glfwPlatformExtensionSupported("GLX_ARB_framebuffer_sRGB")) _glfw.glx.ARB_framebuffer_sRGB = GL_TRUE; if (_glfwPlatformExtensionSupported("GLX_ARB_create_context")) { _glfw.glx.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) _glfwPlatformGetProcAddress("glXCreateContextAttribsARB"); if (_glfw.glx.CreateContextAttribsARB) _glfw.glx.ARB_create_context = GL_TRUE; } if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_robustness")) _glfw.glx.ARB_create_context_robustness = GL_TRUE; if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_profile")) _glfw.glx.ARB_create_context_profile = GL_TRUE; if (_glfwPlatformExtensionSupported("GLX_EXT_create_context_es2_profile")) _glfw.glx.EXT_create_context_es2_profile = GL_TRUE; if (_glfwPlatformExtensionSupported("GLX_ARB_context_flush_control")) _glfw.glx.ARB_context_flush_control = GL_TRUE; return GL_TRUE; }