Made GLX extension management global instead of per-window.

This commit is contained in:
Camilla Berglund 2012-04-23 13:08:34 +02:00
parent 9614b9b22f
commit f77c8f8b21
2 changed files with 121 additions and 131 deletions

View File

@ -37,73 +37,6 @@
void (*glXGetProcAddressEXT(const GLubyte* procName))(); void (*glXGetProcAddressEXT(const GLubyte* procName))();
//========================================================================
// Initialize GLX-specific extensions
//========================================================================
static void initGLXExtensions(_GLFWwindow* window)
{
if (_glfwPlatformExtensionSupported("GLX_EXT_swap_control"))
{
window->GLX.SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)
_glfwPlatformGetProcAddress("glXSwapIntervalEXT");
if (window->GLX.SwapIntervalEXT)
window->GLX.EXT_swap_control = GL_TRUE;
}
if (_glfwPlatformExtensionSupported("GLX_SGI_swap_control"))
{
window->GLX.SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)
_glfwPlatformGetProcAddress("glXSwapIntervalSGI");
if (window->GLX.SwapIntervalSGI)
window->GLX.SGI_swap_control = GL_TRUE;
}
if (_glfwPlatformExtensionSupported("GLX_SGIX_fbconfig"))
{
window->GLX.GetFBConfigAttribSGIX = (PFNGLXGETFBCONFIGATTRIBSGIXPROC)
_glfwPlatformGetProcAddress("glXGetFBConfigAttribSGIX");
window->GLX.ChooseFBConfigSGIX = (PFNGLXCHOOSEFBCONFIGSGIXPROC)
_glfwPlatformGetProcAddress("glXChooseFBConfigSGIX");
window->GLX.CreateContextWithConfigSGIX = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC)
_glfwPlatformGetProcAddress("glXCreateContextWithConfigSGIX");
window->GLX.GetVisualFromFBConfigSGIX = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC)
_glfwPlatformGetProcAddress("glXGetVisualFromFBConfigSGIX");
if (window->GLX.GetFBConfigAttribSGIX &&
window->GLX.ChooseFBConfigSGIX &&
window->GLX.CreateContextWithConfigSGIX &&
window->GLX.GetVisualFromFBConfigSGIX)
{
window->GLX.SGIX_fbconfig = GL_TRUE;
}
}
if (_glfwPlatformExtensionSupported("GLX_ARB_multisample"))
window->GLX.ARB_multisample = GL_TRUE;
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context"))
{
window->GLX.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)
_glfwPlatformGetProcAddress("glXCreateContextAttribsARB");
if (window->GLX.CreateContextAttribsARB)
window->GLX.ARB_create_context = GL_TRUE;
}
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_robustness"))
window->GLX.ARB_create_context_robustness = GL_TRUE;
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_profile"))
window->GLX.ARB_create_context_profile = GL_TRUE;
if (_glfwPlatformExtensionSupported("GLX_EXT_create_context_es2_profile"))
window->GLX.EXT_create_context_es2_profile = GL_TRUE;
}
//======================================================================== //========================================================================
// Returns the specified attribute of the specified GLXFBConfig // Returns the specified attribute of the specified GLXFBConfig
// NOTE: Do not call this unless we have found GLX 1.3+ or GLX_SGIX_fbconfig // NOTE: Do not call this unless we have found GLX 1.3+ or GLX_SGIX_fbconfig
@ -113,9 +46,9 @@ static int getFBConfigAttrib(_GLFWwindow* window, GLXFBConfig fbconfig, int attr
{ {
int value; int value;
if (window->GLX.SGIX_fbconfig) if (_glfwLibrary.GLX.SGIX_fbconfig)
{ {
window->GLX.GetFBConfigAttribSGIX(_glfwLibrary.X11.display, _glfwLibrary.GLX.GetFBConfigAttribSGIX(_glfwLibrary.X11.display,
fbconfig, attrib, &value); fbconfig, attrib, &value);
} }
else else
@ -139,7 +72,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
if (_glfwLibrary.GLX.majorVersion == 1 && _glfwLibrary.GLX.minorVersion < 3) if (_glfwLibrary.GLX.majorVersion == 1 && _glfwLibrary.GLX.minorVersion < 3)
{ {
if (!window->GLX.SGIX_fbconfig) if (!_glfwLibrary.GLX.SGIX_fbconfig)
{ {
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, _glfwSetError(GLFW_OPENGL_UNAVAILABLE,
"X11/GLX: GLXFBConfig support not found"); "X11/GLX: GLXFBConfig support not found");
@ -147,9 +80,9 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
} }
} }
if (window->GLX.SGIX_fbconfig) if (_glfwLibrary.GLX.SGIX_fbconfig)
{ {
fbconfigs = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, fbconfigs = _glfwLibrary.GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen, _glfwLibrary.X11.screen,
NULL, NULL,
&count); &count);
@ -220,7 +153,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
result[*found].auxBuffers = getFBConfigAttrib(window, fbconfigs[i], GLX_AUX_BUFFERS); result[*found].auxBuffers = getFBConfigAttrib(window, fbconfigs[i], GLX_AUX_BUFFERS);
result[*found].stereo = getFBConfigAttrib(window, fbconfigs[i], GLX_STEREO); result[*found].stereo = getFBConfigAttrib(window, fbconfigs[i], GLX_STEREO);
if (window->GLX.ARB_multisample) if (_glfwLibrary.GLX.ARB_multisample)
result[*found].samples = getFBConfigAttrib(window, fbconfigs[i], GLX_SAMPLES); result[*found].samples = getFBConfigAttrib(window, fbconfigs[i], GLX_SAMPLES);
else else
result[*found].samples = 0; result[*found].samples = 0;
@ -258,9 +191,9 @@ static void refreshContextParams(_GLFWwindow* window, GLXFBConfigID fbconfigID)
int attribs[] = { GLX_FBCONFIG_ID, fbconfigID, None }; int attribs[] = { GLX_FBCONFIG_ID, fbconfigID, None };
if (window->GLX.SGIX_fbconfig) if (_glfwLibrary.GLX.SGIX_fbconfig)
{ {
fbconfig = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, fbconfig = _glfwLibrary.GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen, _glfwLibrary.X11.screen,
attribs, attribs,
&dummy); &dummy);
@ -304,7 +237,7 @@ static void refreshContextParams(_GLFWwindow* window, GLXFBConfigID fbconfigID)
window->stereo = getFBConfigAttrib(window, *fbconfig, GLX_STEREO) ? GL_TRUE : GL_FALSE; window->stereo = getFBConfigAttrib(window, *fbconfig, GLX_STEREO) ? GL_TRUE : GL_FALSE;
// Get FSAA buffer sample count // Get FSAA buffer sample count
if (window->GLX.ARB_multisample) if (_glfwLibrary.GLX.ARB_multisample)
window->samples = getFBConfigAttrib(window, *fbconfig, GLX_SAMPLES); window->samples = getFBConfigAttrib(window, *fbconfig, GLX_SAMPLES);
else else
window->samples = 0; window->samples = 0;
@ -340,9 +273,9 @@ static int createContext(_GLFWwindow* window,
setGLXattrib(attribs, index, GLX_FBCONFIG_ID, (int) fbconfigID); setGLXattrib(attribs, index, GLX_FBCONFIG_ID, (int) fbconfigID);
setGLXattrib(attribs, index, None, None); setGLXattrib(attribs, index, None, None);
if (window->GLX.SGIX_fbconfig) if (_glfwLibrary.GLX.SGIX_fbconfig)
{ {
fbconfig = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, fbconfig = _glfwLibrary.GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen, _glfwLibrary.X11.screen,
attribs, attribs,
&dummy); &dummy);
@ -364,9 +297,9 @@ static int createContext(_GLFWwindow* window,
} }
// Retrieve the corresponding visual // Retrieve the corresponding visual
if (window->GLX.SGIX_fbconfig) if (_glfwLibrary.GLX.SGIX_fbconfig)
{ {
window->GLX.visual = window->GLX.GetVisualFromFBConfigSGIX(_glfwLibrary.X11.display, window->GLX.visual = _glfwLibrary.GLX.GetVisualFromFBConfigSGIX(_glfwLibrary.X11.display,
*fbconfig); *fbconfig);
} }
else else
@ -384,7 +317,7 @@ static int createContext(_GLFWwindow* window,
return GL_FALSE; return GL_FALSE;
} }
if (window->GLX.ARB_create_context) if (_glfwLibrary.GLX.ARB_create_context)
{ {
index = 0; index = 0;
@ -416,7 +349,7 @@ static int createContext(_GLFWwindow* window,
{ {
int flags = 0; int flags = 0;
if (!window->GLX.ARB_create_context_profile) if (!_glfwLibrary.GLX.ARB_create_context_profile)
{ {
_glfwSetError(GLFW_VERSION_UNAVAILABLE, _glfwSetError(GLFW_VERSION_UNAVAILABLE,
"X11/GLX: An OpenGL profile requested but " "X11/GLX: An OpenGL profile requested but "
@ -425,7 +358,7 @@ static int createContext(_GLFWwindow* window,
} }
if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE && if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE &&
!window->GLX.EXT_create_context_es2_profile) !_glfwLibrary.GLX.EXT_create_context_es2_profile)
{ {
_glfwSetError(GLFW_VERSION_UNAVAILABLE, _glfwSetError(GLFW_VERSION_UNAVAILABLE,
"X11/GLX: OpenGL ES 2.x profile requested but " "X11/GLX: OpenGL ES 2.x profile requested but "
@ -447,7 +380,7 @@ static int createContext(_GLFWwindow* window,
{ {
int strategy; int strategy;
if (!window->GLX.ARB_create_context_robustness) if (!_glfwLibrary.GLX.ARB_create_context_robustness)
{ {
_glfwSetError(GLFW_VERSION_UNAVAILABLE, _glfwSetError(GLFW_VERSION_UNAVAILABLE,
"X11/GLX: An OpenGL robustness strategy was " "X11/GLX: An OpenGL robustness strategy was "
@ -476,7 +409,7 @@ static int createContext(_GLFWwindow* window,
XSetErrorHandler(errorHandler); XSetErrorHandler(errorHandler);
window->GLX.context = window->GLX.context =
window->GLX.CreateContextAttribsARB(_glfwLibrary.X11.display, _glfwLibrary.GLX.CreateContextAttribsARB(_glfwLibrary.X11.display,
*fbconfig, *fbconfig,
share, share,
True, True,
@ -487,10 +420,10 @@ static int createContext(_GLFWwindow* window,
} }
else else
{ {
if (window->GLX.SGIX_fbconfig) if (_glfwLibrary.GLX.SGIX_fbconfig)
{ {
window->GLX.context = window->GLX.context =
window->GLX.CreateContextWithConfigSGIX(_glfwLibrary.X11.display, _glfwLibrary.GLX.CreateContextWithConfigSGIX(_glfwLibrary.X11.display,
*fbconfig, *fbconfig,
GLX_RGBA_TYPE, GLX_RGBA_TYPE,
share, share,
@ -576,6 +509,65 @@ int _glfwInitOpenGL(void)
return GL_FALSE; return GL_FALSE;
} }
if (_glfwPlatformExtensionSupported("GLX_EXT_swap_control"))
{
_glfwLibrary.GLX.SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)
_glfwPlatformGetProcAddress("glXSwapIntervalEXT");
if (_glfwLibrary.GLX.SwapIntervalEXT)
_glfwLibrary.GLX.EXT_swap_control = GL_TRUE;
}
if (_glfwPlatformExtensionSupported("GLX_SGI_swap_control"))
{
_glfwLibrary.GLX.SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)
_glfwPlatformGetProcAddress("glXSwapIntervalSGI");
if (_glfwLibrary.GLX.SwapIntervalSGI)
_glfwLibrary.GLX.SGI_swap_control = GL_TRUE;
}
if (_glfwPlatformExtensionSupported("GLX_SGIX_fbconfig"))
{
_glfwLibrary.GLX.GetFBConfigAttribSGIX = (PFNGLXGETFBCONFIGATTRIBSGIXPROC)
_glfwPlatformGetProcAddress("glXGetFBConfigAttribSGIX");
_glfwLibrary.GLX.ChooseFBConfigSGIX = (PFNGLXCHOOSEFBCONFIGSGIXPROC)
_glfwPlatformGetProcAddress("glXChooseFBConfigSGIX");
_glfwLibrary.GLX.CreateContextWithConfigSGIX = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC)
_glfwPlatformGetProcAddress("glXCreateContextWithConfigSGIX");
_glfwLibrary.GLX.GetVisualFromFBConfigSGIX = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC)
_glfwPlatformGetProcAddress("glXGetVisualFromFBConfigSGIX");
if (_glfwLibrary.GLX.GetFBConfigAttribSGIX &&
_glfwLibrary.GLX.ChooseFBConfigSGIX &&
_glfwLibrary.GLX.CreateContextWithConfigSGIX &&
_glfwLibrary.GLX.GetVisualFromFBConfigSGIX)
{
_glfwLibrary.GLX.SGIX_fbconfig = GL_TRUE;
}
}
if (_glfwPlatformExtensionSupported("GLX_ARB_multisample"))
_glfwLibrary.GLX.ARB_multisample = GL_TRUE;
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context"))
{
_glfwLibrary.GLX.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)
_glfwPlatformGetProcAddress("glXCreateContextAttribsARB");
if (_glfwLibrary.GLX.CreateContextAttribsARB)
_glfwLibrary.GLX.ARB_create_context = GL_TRUE;
}
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_robustness"))
_glfwLibrary.GLX.ARB_create_context_robustness = GL_TRUE;
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_profile"))
_glfwLibrary.GLX.ARB_create_context_profile = GL_TRUE;
if (_glfwPlatformExtensionSupported("GLX_EXT_create_context_es2_profile"))
_glfwLibrary.GLX.EXT_create_context_es2_profile = GL_TRUE;
return GL_TRUE; return GL_TRUE;
} }
@ -607,8 +599,6 @@ int _glfwCreateContext(_GLFWwindow* window,
{ {
_GLFWfbconfig closest; _GLFWfbconfig closest;
initGLXExtensions(window);
// Choose the best available fbconfig // Choose the best available fbconfig
{ {
unsigned int fbcount; unsigned int fbcount;
@ -693,14 +683,14 @@ void _glfwPlatformSwapInterval(int interval)
{ {
_GLFWwindow* window = _glfwLibrary.currentWindow; _GLFWwindow* window = _glfwLibrary.currentWindow;
if (window->GLX.EXT_swap_control) if (_glfwLibrary.GLX.EXT_swap_control)
{ {
window->GLX.SwapIntervalEXT(_glfwLibrary.X11.display, _glfwLibrary.GLX.SwapIntervalEXT(_glfwLibrary.X11.display,
window->X11.handle, window->X11.handle,
interval); interval);
} }
else if (window->GLX.SGI_swap_control) else if (_glfwLibrary.GLX.SGI_swap_control)
window->GLX.SwapIntervalSGI(interval); _glfwLibrary.GLX.SwapIntervalSGI(interval);
} }

View File

@ -116,23 +116,6 @@ typedef struct _GLFWcontextGLX
GLXContext context; // OpenGL rendering context GLXContext context; // OpenGL rendering context
XVisualInfo* visual; // Visual for selected GLXFBConfig XVisualInfo* visual; // Visual for selected GLXFBConfig
// GLX extensions
PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI;
PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT;
PFNGLXGETFBCONFIGATTRIBSGIXPROC GetFBConfigAttribSGIX;
PFNGLXCHOOSEFBCONFIGSGIXPROC ChooseFBConfigSGIX;
PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC CreateContextWithConfigSGIX;
PFNGLXGETVISUALFROMFBCONFIGSGIXPROC GetVisualFromFBConfigSGIX;
PFNGLXCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB;
GLboolean SGIX_fbconfig;
GLboolean SGI_swap_control;
GLboolean EXT_swap_control;
GLboolean ARB_multisample;
GLboolean ARB_create_context;
GLboolean ARB_create_context_profile;
GLboolean ARB_create_context_robustness;
GLboolean EXT_create_context_es2_profile;
} _GLFWcontextGLX; } _GLFWcontextGLX;
@ -256,6 +239,23 @@ typedef struct _GLFWlibraryGLX
// Server-side GLX version // Server-side GLX version
int majorVersion, minorVersion; int majorVersion, minorVersion;
// GLX extensions
PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI;
PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT;
PFNGLXGETFBCONFIGATTRIBSGIXPROC GetFBConfigAttribSGIX;
PFNGLXCHOOSEFBCONFIGSGIXPROC ChooseFBConfigSGIX;
PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC CreateContextWithConfigSGIX;
PFNGLXGETVISUALFROMFBCONFIGSGIXPROC GetVisualFromFBConfigSGIX;
PFNGLXCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB;
GLboolean SGIX_fbconfig;
GLboolean SGI_swap_control;
GLboolean EXT_swap_control;
GLboolean ARB_multisample;
GLboolean ARB_create_context;
GLboolean ARB_create_context_profile;
GLboolean ARB_create_context_robustness;
GLboolean EXT_create_context_es2_profile;
#if defined(_GLFW_DLOPEN_LIBGL) #if defined(_GLFW_DLOPEN_LIBGL)
void* libGL; // dlopen handle for libGL.so void* libGL; // dlopen handle for libGL.so
#endif #endif