From 962497bdc902974912f48f32f15cc5a65fd5abdc Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 15 Oct 2015 20:10:24 +0200 Subject: [PATCH] Use GLXWindow renderables on X11 Fixes #507. --- README.md | 1 + src/glx_context.c | 24 +++++++++++++++++++++--- src/glx_context.h | 8 ++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0ce69e97..8e860707 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ used by the tests and examples and are not required to build the library. - [Cocoa] Removed support for OS X 10.6 - [X11] Bugfix: Monitor connection and disconnection events were not reported - [WGL] Removed dependency on external WGL headers + - [GLX] Replaced legacy renderable with `GLXWindow` - [GLX] Removed dependency on external GLX headers - [EGL] Removed dependency on external EGL headers diff --git a/src/glx_context.c b/src/glx_context.c index e660037d..fa604561 100644 --- a/src/glx_context.c +++ b/src/glx_context.c @@ -188,6 +188,10 @@ int _glfwInitContextAPI(void) 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 = @@ -463,6 +467,14 @@ int _glfwCreateContext(_GLFWwindow* window, return GLFW_FALSE; } + window->glx.window = _glfw_glXCreateWindow(_glfw.x11.display, native, + window->x11.handle, NULL); + if (!window->glx.window) + { + _glfwInputError(GLFW_PLATFORM_ERROR, "GLX: Failed to create window"); + return GLFW_FALSE; + } + return GLFW_TRUE; } @@ -472,6 +484,12 @@ int _glfwCreateContext(_GLFWwindow* window, // void _glfwDestroyContext(_GLFWwindow* window) { + if (window->glx.window) + { + _glfw_glXDestroyWindow(_glfw.x11.display, window->glx.window); + window->glx.window = None; + } + if (window->glx.context) { _glfw_glXDestroyContext(_glfw.x11.display, window->glx.context); @@ -520,7 +538,7 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) if (window) { _glfw_glXMakeCurrent(_glfw.x11.display, - window->x11.handle, + window->glx.window, window->glx.context); } else @@ -531,7 +549,7 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) void _glfwPlatformSwapBuffers(_GLFWwindow* window) { - _glfw_glXSwapBuffers(_glfw.x11.display, window->x11.handle); + _glfw_glXSwapBuffers(_glfw.x11.display, window->glx.window); } void _glfwPlatformSwapInterval(int interval) @@ -541,7 +559,7 @@ void _glfwPlatformSwapInterval(int interval) if (_glfw.glx.EXT_swap_control) { _glfw.glx.SwapIntervalEXT(_glfw.x11.display, - window->x11.handle, + window->glx.window, interval); } else if (_glfw.glx.MESA_swap_control) diff --git a/src/glx_context.h b/src/glx_context.h index a53e70d5..926e0930 100644 --- a/src/glx_context.h +++ b/src/glx_context.h @@ -67,6 +67,7 @@ #define GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0 #define GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098 +typedef XID GLXWindow; typedef XID GLXDrawable; typedef struct __GLXFBConfig* GLXFBConfig; typedef struct __GLXcontext* GLXContext; @@ -88,6 +89,8 @@ typedef int (*PFNGLXSWAPINTERVALSGIPROC)(int); typedef void (*PFNGLXSWAPINTERVALEXTPROC)(Display*,GLXDrawable,int); typedef GLXContext (*PFNGLXCREATECONTEXTATTRIBSARBPROC)(Display*,GLXFBConfig,GLXContext,Bool,const int*); typedef XVisualInfo* (*PFNGLXGETVISUALFROMFBCONFIGPROC)(Display*,GLXFBConfig); +typedef GLXWindow (*PFNGLXCREATEWINDOWPROC)(Display*,GLXFBConfig,Window,const int*); +typedef void (*PFNGLXDESTROYWINDOWPROC)(Display*,GLXWindow); // libGL.so function pointer typedefs #define _glfw_glXGetFBConfigs _glfw.glx.GetFBConfigs @@ -101,6 +104,8 @@ typedef XVisualInfo* (*PFNGLXGETVISUALFROMFBCONFIGPROC)(Display*,GLXFBConfig); #define _glfw_glXQueryExtensionsString _glfw.glx.QueryExtensionsString #define _glfw_glXCreateNewContext _glfw.glx.CreateNewContext #define _glfw_glXGetVisualFromFBConfig _glfw.glx.GetVisualFromFBConfig +#define _glfw_glXCreateWindow _glfw.glx.CreateWindow +#define _glfw_glXDestroyWindow _glfw.glx.DestroyWindow #define _GLFW_PLATFORM_FBCONFIG GLXFBConfig glx #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX glx @@ -112,6 +117,7 @@ typedef XVisualInfo* (*PFNGLXGETVISUALFROMFBCONFIGPROC)(Display*,GLXFBConfig); typedef struct _GLFWcontextGLX { GLXContext context; + GLXWindow window; } _GLFWcontextGLX; @@ -139,6 +145,8 @@ typedef struct _GLFWlibraryGLX PFNGLXQUERYEXTENSIONSSTRINGPROC QueryExtensionsString; PFNGLXCREATENEWCONTEXTPROC CreateNewContext; PFNGLXGETVISUALFROMFBCONFIGPROC GetVisualFromFBConfig; + PFNGLXCREATEWINDOWPROC CreateWindow; + PFNGLXDESTROYWINDOWPROC DestroyWindow; // GLX 1.4 and extension functions PFNGLXGETPROCADDRESSPROC GetProcAddress;