mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-26 20:28:49 -05:00
Made GLX extension management global instead of per-window.
This commit is contained in:
parent
9614b9b22f
commit
f77c8f8b21
218
src/x11_opengl.c
218
src/x11_opengl.c
|
@ -37,73 +37,6 @@
|
|||
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
|
||||
// NOTE: Do not call this unless we have found GLX 1.3+ or GLX_SGIX_fbconfig
|
||||
|
@ -113,10 +46,10 @@ static int getFBConfigAttrib(_GLFWwindow* window, GLXFBConfig fbconfig, int attr
|
|||
{
|
||||
int value;
|
||||
|
||||
if (window->GLX.SGIX_fbconfig)
|
||||
if (_glfwLibrary.GLX.SGIX_fbconfig)
|
||||
{
|
||||
window->GLX.GetFBConfigAttribSGIX(_glfwLibrary.X11.display,
|
||||
fbconfig, attrib, &value);
|
||||
_glfwLibrary.GLX.GetFBConfigAttribSGIX(_glfwLibrary.X11.display,
|
||||
fbconfig, attrib, &value);
|
||||
}
|
||||
else
|
||||
glXGetFBConfigAttrib(_glfwLibrary.X11.display, fbconfig, attrib, &value);
|
||||
|
@ -139,7 +72,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
|||
|
||||
if (_glfwLibrary.GLX.majorVersion == 1 && _glfwLibrary.GLX.minorVersion < 3)
|
||||
{
|
||||
if (!window->GLX.SGIX_fbconfig)
|
||||
if (!_glfwLibrary.GLX.SGIX_fbconfig)
|
||||
{
|
||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
|
||||
"X11/GLX: GLXFBConfig support not found");
|
||||
|
@ -147,12 +80,12 @@ 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,
|
||||
_glfwLibrary.X11.screen,
|
||||
NULL,
|
||||
&count);
|
||||
fbconfigs = _glfwLibrary.GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display,
|
||||
_glfwLibrary.X11.screen,
|
||||
NULL,
|
||||
&count);
|
||||
if (!count)
|
||||
{
|
||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
|
||||
|
@ -220,7 +153,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
|||
result[*found].auxBuffers = getFBConfigAttrib(window, fbconfigs[i], GLX_AUX_BUFFERS);
|
||||
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);
|
||||
else
|
||||
result[*found].samples = 0;
|
||||
|
@ -258,12 +191,12 @@ static void refreshContextParams(_GLFWwindow* window, GLXFBConfigID fbconfigID)
|
|||
|
||||
int attribs[] = { GLX_FBCONFIG_ID, fbconfigID, None };
|
||||
|
||||
if (window->GLX.SGIX_fbconfig)
|
||||
if (_glfwLibrary.GLX.SGIX_fbconfig)
|
||||
{
|
||||
fbconfig = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display,
|
||||
_glfwLibrary.X11.screen,
|
||||
attribs,
|
||||
&dummy);
|
||||
fbconfig = _glfwLibrary.GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display,
|
||||
_glfwLibrary.X11.screen,
|
||||
attribs,
|
||||
&dummy);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -304,7 +237,7 @@ static void refreshContextParams(_GLFWwindow* window, GLXFBConfigID fbconfigID)
|
|||
window->stereo = getFBConfigAttrib(window, *fbconfig, GLX_STEREO) ? GL_TRUE : GL_FALSE;
|
||||
|
||||
// Get FSAA buffer sample count
|
||||
if (window->GLX.ARB_multisample)
|
||||
if (_glfwLibrary.GLX.ARB_multisample)
|
||||
window->samples = getFBConfigAttrib(window, *fbconfig, GLX_SAMPLES);
|
||||
else
|
||||
window->samples = 0;
|
||||
|
@ -340,12 +273,12 @@ static int createContext(_GLFWwindow* window,
|
|||
setGLXattrib(attribs, index, GLX_FBCONFIG_ID, (int) fbconfigID);
|
||||
setGLXattrib(attribs, index, None, None);
|
||||
|
||||
if (window->GLX.SGIX_fbconfig)
|
||||
if (_glfwLibrary.GLX.SGIX_fbconfig)
|
||||
{
|
||||
fbconfig = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display,
|
||||
_glfwLibrary.X11.screen,
|
||||
attribs,
|
||||
&dummy);
|
||||
fbconfig = _glfwLibrary.GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display,
|
||||
_glfwLibrary.X11.screen,
|
||||
attribs,
|
||||
&dummy);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -364,10 +297,10 @@ static int createContext(_GLFWwindow* window,
|
|||
}
|
||||
|
||||
// Retrieve the corresponding visual
|
||||
if (window->GLX.SGIX_fbconfig)
|
||||
if (_glfwLibrary.GLX.SGIX_fbconfig)
|
||||
{
|
||||
window->GLX.visual = window->GLX.GetVisualFromFBConfigSGIX(_glfwLibrary.X11.display,
|
||||
*fbconfig);
|
||||
window->GLX.visual = _glfwLibrary.GLX.GetVisualFromFBConfigSGIX(_glfwLibrary.X11.display,
|
||||
*fbconfig);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -384,7 +317,7 @@ static int createContext(_GLFWwindow* window,
|
|||
return GL_FALSE;
|
||||
}
|
||||
|
||||
if (window->GLX.ARB_create_context)
|
||||
if (_glfwLibrary.GLX.ARB_create_context)
|
||||
{
|
||||
index = 0;
|
||||
|
||||
|
@ -416,7 +349,7 @@ static int createContext(_GLFWwindow* window,
|
|||
{
|
||||
int flags = 0;
|
||||
|
||||
if (!window->GLX.ARB_create_context_profile)
|
||||
if (!_glfwLibrary.GLX.ARB_create_context_profile)
|
||||
{
|
||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||
"X11/GLX: An OpenGL profile requested but "
|
||||
|
@ -425,7 +358,7 @@ static int createContext(_GLFWwindow* window,
|
|||
}
|
||||
|
||||
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,
|
||||
"X11/GLX: OpenGL ES 2.x profile requested but "
|
||||
|
@ -447,7 +380,7 @@ static int createContext(_GLFWwindow* window,
|
|||
{
|
||||
int strategy;
|
||||
|
||||
if (!window->GLX.ARB_create_context_robustness)
|
||||
if (!_glfwLibrary.GLX.ARB_create_context_robustness)
|
||||
{
|
||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
|
||||
"X11/GLX: An OpenGL robustness strategy was "
|
||||
|
@ -476,25 +409,25 @@ static int createContext(_GLFWwindow* window,
|
|||
XSetErrorHandler(errorHandler);
|
||||
|
||||
window->GLX.context =
|
||||
window->GLX.CreateContextAttribsARB(_glfwLibrary.X11.display,
|
||||
*fbconfig,
|
||||
share,
|
||||
True,
|
||||
attribs);
|
||||
_glfwLibrary.GLX.CreateContextAttribsARB(_glfwLibrary.X11.display,
|
||||
*fbconfig,
|
||||
share,
|
||||
True,
|
||||
attribs);
|
||||
|
||||
// We are done, so unset the error handler again (see above)
|
||||
XSetErrorHandler(NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (window->GLX.SGIX_fbconfig)
|
||||
if (_glfwLibrary.GLX.SGIX_fbconfig)
|
||||
{
|
||||
window->GLX.context =
|
||||
window->GLX.CreateContextWithConfigSGIX(_glfwLibrary.X11.display,
|
||||
*fbconfig,
|
||||
GLX_RGBA_TYPE,
|
||||
share,
|
||||
True);
|
||||
_glfwLibrary.GLX.CreateContextWithConfigSGIX(_glfwLibrary.X11.display,
|
||||
*fbconfig,
|
||||
GLX_RGBA_TYPE,
|
||||
share,
|
||||
True);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -576,6 +509,65 @@ int _glfwInitOpenGL(void)
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -607,8 +599,6 @@ int _glfwCreateContext(_GLFWwindow* window,
|
|||
{
|
||||
_GLFWfbconfig closest;
|
||||
|
||||
initGLXExtensions(window);
|
||||
|
||||
// Choose the best available fbconfig
|
||||
{
|
||||
unsigned int fbcount;
|
||||
|
@ -693,14 +683,14 @@ void _glfwPlatformSwapInterval(int interval)
|
|||
{
|
||||
_GLFWwindow* window = _glfwLibrary.currentWindow;
|
||||
|
||||
if (window->GLX.EXT_swap_control)
|
||||
if (_glfwLibrary.GLX.EXT_swap_control)
|
||||
{
|
||||
window->GLX.SwapIntervalEXT(_glfwLibrary.X11.display,
|
||||
window->X11.handle,
|
||||
interval);
|
||||
_glfwLibrary.GLX.SwapIntervalEXT(_glfwLibrary.X11.display,
|
||||
window->X11.handle,
|
||||
interval);
|
||||
}
|
||||
else if (window->GLX.SGI_swap_control)
|
||||
window->GLX.SwapIntervalSGI(interval);
|
||||
else if (_glfwLibrary.GLX.SGI_swap_control)
|
||||
_glfwLibrary.GLX.SwapIntervalSGI(interval);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -116,23 +116,6 @@ typedef struct _GLFWcontextGLX
|
|||
GLXContext context; // OpenGL rendering context
|
||||
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;
|
||||
|
||||
|
||||
|
@ -256,6 +239,23 @@ typedef struct _GLFWlibraryGLX
|
|||
// Server-side GLX version
|
||||
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)
|
||||
void* libGL; // dlopen handle for libGL.so
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user