Separated window GLX state into separate struct.

This commit is contained in:
Camilla Berglund 2010-09-09 20:36:23 +02:00
parent 8a04910a45
commit 3228755895
3 changed files with 83 additions and 73 deletions

View File

@ -191,6 +191,7 @@ typedef struct _GLFWwindow
PFNGLGETSTRINGIPROC GetStringi; PFNGLGETSTRINGIPROC GetStringi;
_GLFW_PLATFORM_WINDOW_STATE; _GLFW_PLATFORM_WINDOW_STATE;
_GLFW_PLATFORM_CONTEXT_STATE;
} _GLFWwindow; } _GLFWwindow;

View File

@ -163,6 +163,7 @@ typedef const GLubyte* (APIENTRY *PFNGLGETSTRINGIPROC)(GLenum, GLuint);
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11 #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11
#define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryX11 X11 #define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryX11 X11
#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX
@ -171,26 +172,13 @@ typedef const GLubyte* (APIENTRY *PFNGLGETSTRINGIPROC)(GLenum, GLuint);
//======================================================================== //========================================================================
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Window structure // OpenGL context structure
//------------------------------------------------------------------------ //------------------------------------------------------------------------
typedef struct _GLFWwindowX11 typedef struct _GLFWcontextGLX
{ {
// Platform specific window resources
Colormap colormap; // Window colormap
Window window; // Window
Window root; // Root window for screen
int screen; // Screen ID
XVisualInfo* visual; // Visual for selected GLXFBConfig
GLXFBConfigID fbconfigID; // ID of selected GLXFBConfig GLXFBConfigID fbconfigID; // ID of selected GLXFBConfig
GLXContext context; // OpenGL rendering context GLXContext context; // OpenGL rendering context
Atom wmDeleteWindow; // WM_DELETE_WINDOW atom XVisualInfo* visual; // Visual for selected GLXFBConfig
Atom wmPing; // _NET_WM_PING atom
Atom wmState; // _NET_WM_STATE atom
Atom wmStateFullscreen; // _NET_WM_STATE_FULLSCREEN atom
Atom wmActiveWindow; // _NET_ACTIVE_WINDOW atom
Cursor cursor; // Invisible cursor for hidden cursor
int mouseMoved, cursorPosX, cursorPosY;
// GLX extensions // GLX extensions
PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI; PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI;
@ -204,6 +192,27 @@ typedef struct _GLFWwindowX11
GLboolean has_GLX_ARB_multisample; GLboolean has_GLX_ARB_multisample;
GLboolean has_GLX_ARB_create_context; GLboolean has_GLX_ARB_create_context;
GLboolean has_GLX_ARB_create_context_profile; GLboolean has_GLX_ARB_create_context_profile;
} _GLFWcontextGLX;
//------------------------------------------------------------------------
// Window structure
//------------------------------------------------------------------------
typedef struct _GLFWwindowX11
{
// Platform specific window resources
Colormap colormap; // Window colormap
Window window; // Window
Window root; // Root window for screen
int screen; // Screen ID
Atom wmDeleteWindow; // WM_DELETE_WINDOW atom
Atom wmPing; // _NET_WM_PING atom
Atom wmState; // _NET_WM_STATE atom
Atom wmStateFullscreen; // _NET_WM_STATE_FULLSCREEN atom
Atom wmActiveWindow; // _NET_ACTIVE_WINDOW atom
Cursor cursor; // Invisible cursor for hidden cursor
int mouseMoved, cursorPosX, cursorPosY;
// Various platform specific internal variables // Various platform specific internal variables
GLboolean hasEWMH; // True if window manager supports EWMH GLboolean hasEWMH; // True if window manager supports EWMH

View File

@ -390,9 +390,9 @@ static int getFBConfigAttrib(_GLFWwindow* window, GLXFBConfig fbconfig, int attr
{ {
int value; int value;
if (window->X11.has_GLX_SGIX_fbconfig) if (window->GLX.has_GLX_SGIX_fbconfig)
{ {
window->X11.GetFBConfigAttribSGIX(_glfwLibrary.X11.display, window->GLX.GetFBConfigAttribSGIX(_glfwLibrary.X11.display,
fbconfig, attrib, &value); fbconfig, attrib, &value);
} }
else else
@ -416,16 +416,16 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
if (_glfwLibrary.X11.glxMajor == 1 && _glfwLibrary.X11.glxMinor < 3) if (_glfwLibrary.X11.glxMajor == 1 && _glfwLibrary.X11.glxMinor < 3)
{ {
if (!window->X11.has_GLX_SGIX_fbconfig) if (!window->GLX.has_GLX_SGIX_fbconfig)
{ {
fprintf(stderr, "GLXFBConfigs are not supported by the X server\n"); fprintf(stderr, "GLXFBConfigs are not supported by the X server\n");
return NULL; return NULL;
} }
} }
if (window->X11.has_GLX_SGIX_fbconfig) if (window->GLX.has_GLX_SGIX_fbconfig)
{ {
fbconfigs = window->X11.ChooseFBConfigSGIX(_glfwLibrary.X11.display, fbconfigs = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display,
window->X11.screen, window->X11.screen,
NULL, NULL,
&count); &count);
@ -489,7 +489,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->X11.has_GLX_ARB_multisample) if (window->GLX.has_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;
@ -526,12 +526,12 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G
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->X11.has_GLX_SGIX_fbconfig) if (window->GLX.has_GLX_SGIX_fbconfig)
{ {
fbconfig = window->X11.ChooseFBConfigSGIX(_glfwLibrary.X11.display, fbconfig = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display,
window->X11.screen, window->X11.screen,
attribs, attribs,
&dummy); &dummy);
} }
else else
{ {
@ -549,18 +549,18 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G
} }
// Retrieve the corresponding visual // Retrieve the corresponding visual
if (window->X11.has_GLX_SGIX_fbconfig) if (window->GLX.has_GLX_SGIX_fbconfig)
{ {
window->X11.visual = window->X11.GetVisualFromFBConfigSGIX(_glfwLibrary.X11.display, window->GLX.visual = window->GLX.GetVisualFromFBConfigSGIX(_glfwLibrary.X11.display,
*fbconfig); *fbconfig);
} }
else else
{ {
window->X11.visual = glXGetVisualFromFBConfig(_glfwLibrary.X11.display, window->GLX.visual = glXGetVisualFromFBConfig(_glfwLibrary.X11.display,
*fbconfig); *fbconfig);
} }
if (window->X11.visual == NULL) if (window->GLX.visual == NULL)
{ {
XFree(fbconfig); XFree(fbconfig);
@ -568,7 +568,7 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G
return GL_FALSE; return GL_FALSE;
} }
if (window->X11.has_GLX_ARB_create_context) if (window->GLX.has_GLX_ARB_create_context)
{ {
index = 0; index = 0;
@ -595,7 +595,7 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G
if (wndconfig->glProfile) if (wndconfig->glProfile)
{ {
if (!window->X11.has_GLX_ARB_create_context_profile) if (!window->GLX.has_GLX_ARB_create_context_profile)
{ {
fprintf(stderr, "OpenGL profile requested but GLX_ARB_create_context_profile " fprintf(stderr, "OpenGL profile requested but GLX_ARB_create_context_profile "
"is unavailable\n"); "is unavailable\n");
@ -612,7 +612,7 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G
setGLXattrib(attribs, index, None, None); setGLXattrib(attribs, index, None, None);
window->X11.context = window->X11.CreateContextAttribsARB(_glfwLibrary.X11.display, window->GLX.context = window->GLX.CreateContextAttribsARB(_glfwLibrary.X11.display,
*fbconfig, *fbconfig,
NULL, NULL,
True, True,
@ -620,9 +620,9 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G
} }
else else
{ {
if (window->X11.has_GLX_SGIX_fbconfig) if (window->GLX.has_GLX_SGIX_fbconfig)
{ {
window->X11.context = window->X11.CreateContextWithConfigSGIX(_glfwLibrary.X11.display, window->GLX.context = window->GLX.CreateContextWithConfigSGIX(_glfwLibrary.X11.display,
*fbconfig, *fbconfig,
GLX_RGBA_TYPE, GLX_RGBA_TYPE,
NULL, NULL,
@ -630,7 +630,7 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G
} }
else else
{ {
window->X11.context = glXCreateNewContext(_glfwLibrary.X11.display, window->GLX.context = glXCreateNewContext(_glfwLibrary.X11.display,
*fbconfig, *fbconfig,
GLX_RGBA_TYPE, GLX_RGBA_TYPE,
NULL, NULL,
@ -640,13 +640,13 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, G
XFree(fbconfig); XFree(fbconfig);
if (window->X11.context == NULL) if (window->GLX.context == NULL)
{ {
fprintf(stderr, "Unable to create OpenGL context\n"); fprintf(stderr, "Unable to create OpenGL context\n");
return GL_FALSE; return GL_FALSE;
} }
window->X11.fbconfigID = fbconfigID; window->GLX.fbconfigID = fbconfigID;
return GL_TRUE; return GL_TRUE;
} }
@ -662,47 +662,47 @@ static void initGLXExtensions(_GLFWwindow* window)
{ {
if (_glfwPlatformExtensionSupported("GLX_SGI_swap_control")) if (_glfwPlatformExtensionSupported("GLX_SGI_swap_control"))
{ {
window->X11.SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC) window->GLX.SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)
_glfwPlatformGetProcAddress("glXSwapIntervalSGI"); _glfwPlatformGetProcAddress("glXSwapIntervalSGI");
if (window->X11.SwapIntervalSGI) if (window->GLX.SwapIntervalSGI)
window->X11.has_GLX_SGI_swap_control = GL_TRUE; window->GLX.has_GLX_SGI_swap_control = GL_TRUE;
} }
if (_glfwPlatformExtensionSupported("GLX_SGIX_fbconfig")) if (_glfwPlatformExtensionSupported("GLX_SGIX_fbconfig"))
{ {
window->X11.GetFBConfigAttribSGIX = (PFNGLXGETFBCONFIGATTRIBSGIXPROC) window->GLX.GetFBConfigAttribSGIX = (PFNGLXGETFBCONFIGATTRIBSGIXPROC)
_glfwPlatformGetProcAddress("glXGetFBConfigAttribSGIX"); _glfwPlatformGetProcAddress("glXGetFBConfigAttribSGIX");
window->X11.ChooseFBConfigSGIX = (PFNGLXCHOOSEFBCONFIGSGIXPROC) window->GLX.ChooseFBConfigSGIX = (PFNGLXCHOOSEFBCONFIGSGIXPROC)
_glfwPlatformGetProcAddress("glXChooseFBConfigSGIX"); _glfwPlatformGetProcAddress("glXChooseFBConfigSGIX");
window->X11.CreateContextWithConfigSGIX = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) window->GLX.CreateContextWithConfigSGIX = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC)
_glfwPlatformGetProcAddress("glXCreateContextWithConfigSGIX"); _glfwPlatformGetProcAddress("glXCreateContextWithConfigSGIX");
window->X11.GetVisualFromFBConfigSGIX = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) window->GLX.GetVisualFromFBConfigSGIX = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC)
_glfwPlatformGetProcAddress("glXGetVisualFromFBConfigSGIX"); _glfwPlatformGetProcAddress("glXGetVisualFromFBConfigSGIX");
if (window->X11.GetFBConfigAttribSGIX && if (window->GLX.GetFBConfigAttribSGIX &&
window->X11.ChooseFBConfigSGIX && window->GLX.ChooseFBConfigSGIX &&
window->X11.CreateContextWithConfigSGIX && window->GLX.CreateContextWithConfigSGIX &&
window->X11.GetVisualFromFBConfigSGIX) window->GLX.GetVisualFromFBConfigSGIX)
{ {
window->X11.has_GLX_SGIX_fbconfig = GL_TRUE; window->GLX.has_GLX_SGIX_fbconfig = GL_TRUE;
} }
} }
if (_glfwPlatformExtensionSupported("GLX_ARB_multisample")) if (_glfwPlatformExtensionSupported("GLX_ARB_multisample"))
window->X11.has_GLX_ARB_multisample = GL_TRUE; window->GLX.has_GLX_ARB_multisample = GL_TRUE;
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context")) if (_glfwPlatformExtensionSupported("GLX_ARB_create_context"))
{ {
window->X11.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) window->GLX.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)
_glfwPlatformGetProcAddress("glXCreateContextAttribsARB"); _glfwPlatformGetProcAddress("glXCreateContextAttribsARB");
if (window->X11.CreateContextAttribsARB) if (window->GLX.CreateContextAttribsARB)
window->X11.has_GLX_ARB_create_context = GL_TRUE; window->GLX.has_GLX_ARB_create_context = GL_TRUE;
} }
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_profile")) if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_profile"))
window->X11.has_GLX_ARB_create_context_profile = GL_TRUE; window->GLX.has_GLX_ARB_create_context_profile = GL_TRUE;
} }
@ -723,7 +723,7 @@ static GLboolean createWindow(_GLFWwindow* window,
window->X11.colormap = XCreateColormap(_glfwLibrary.X11.display, window->X11.colormap = XCreateColormap(_glfwLibrary.X11.display,
window->X11.root, window->X11.root,
window->X11.visual->visual, window->GLX.visual->visual,
AllocNone); AllocNone);
// Create the actual window // Create the actual window
@ -751,9 +751,9 @@ static GLboolean createWindow(_GLFWwindow* window,
0, 0, // Upper left corner of this window on root 0, 0, // Upper left corner of this window on root
window->width, window->height, window->width, window->height,
0, // Border width 0, // Border width
window->X11.visual->depth, // Color depth window->GLX.visual->depth, // Color depth
InputOutput, InputOutput,
window->X11.visual->visual, window->GLX.visual->visual,
wamask, wamask,
&wa &wa
); );
@ -1392,7 +1392,7 @@ int _glfwPlatformMakeWindowCurrent(_GLFWwindow* window)
{ {
glXMakeCurrent(_glfwLibrary.X11.display, glXMakeCurrent(_glfwLibrary.X11.display,
window->X11.window, window->X11.window,
window->X11.context); window->GLX.context);
} }
else else
glXMakeCurrent(_glfwLibrary.X11.display, None, NULL); glXMakeCurrent(_glfwLibrary.X11.display, None, NULL);
@ -1408,18 +1408,18 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window)
if (window->mode == GLFW_FULLSCREEN) if (window->mode == GLFW_FULLSCREEN)
leaveFullscreenMode(window); leaveFullscreenMode(window);
if (window->X11.context) if (window->GLX.context)
{ {
// Release and destroy the context // Release and destroy the context
glXMakeCurrent(_glfwLibrary.X11.display, None, NULL); glXMakeCurrent(_glfwLibrary.X11.display, None, NULL);
glXDestroyContext(_glfwLibrary.X11.display, window->X11.context); glXDestroyContext(_glfwLibrary.X11.display, window->GLX.context);
window->X11.context = NULL; window->GLX.context = NULL;
} }
if (window->X11.visual) if (window->GLX.visual)
{ {
XFree(window->X11.visual); XFree(window->GLX.visual);
window->X11.visual = NULL; window->GLX.visual = NULL;
} }
if (window->X11.window) if (window->X11.window)
@ -1568,8 +1568,8 @@ void _glfwPlatformSwapInterval(int interval)
{ {
_GLFWwindow* window = _glfwLibrary.currentWindow; _GLFWwindow* window = _glfwLibrary.currentWindow;
if (window->X11.has_GLX_SGI_swap_control) if (window->GLX.has_GLX_SGI_swap_control)
window->X11.SwapIntervalSGI(interval); window->GLX.SwapIntervalSGI(interval);
} }
@ -1590,11 +1590,11 @@ void _glfwPlatformRefreshWindowParams(void)
#endif #endif
_GLFWwindow* window = _glfwLibrary.currentWindow; _GLFWwindow* window = _glfwLibrary.currentWindow;
int attribs[] = { GLX_FBCONFIG_ID, window->X11.fbconfigID, None }; int attribs[] = { GLX_FBCONFIG_ID, window->GLX.fbconfigID, None };
if (window->X11.has_GLX_SGIX_fbconfig) if (window->GLX.has_GLX_SGIX_fbconfig)
{ {
fbconfig = window->X11.ChooseFBConfigSGIX(_glfwLibrary.X11.display, fbconfig = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display,
window->X11.screen, window->X11.screen,
attribs, attribs,
&dummy); &dummy);
@ -1637,7 +1637,7 @@ void _glfwPlatformRefreshWindowParams(void)
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->X11.has_GLX_ARB_multisample) if (window->GLX.has_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;