diff options
author | Chad Versace <chad@kiwitree.net> | 2014-11-23 22:12:19 -0800 |
---|---|---|
committer | Chad Versace <chad@kiwitree.net> | 2014-11-23 22:12:19 -0800 |
commit | 763f94542d150b5cf546257909641d7a429dc6f5 (patch) | |
tree | b61a45246fc54a3bd96b7b3bdcf5041ea1322675 | |
parent | 1149861bfaf6da0a8ce88aaf02f8a7626fa0f31d (diff) | |
parent | 91605807cede960924c54b6972f0e03c126d048e (diff) |
Merge branch 'evelikov/remove-libgbm-libgl-libdeps-v2'
* cooking/evelikov/remove-libgbm-libgl-libdeps-v2:
glx: drop explicit linking against libGL.so
glx: fetch the libGL function pointers at glx_platform_create
pkg/archlinux: demote libgbm to (make|opt)depend
gbm: drop explicit linking against libgbm.so (v2)
gbm: fetch the libgbm function pointers at wgbm_platform_init
pkg/archlinux: waffle does not link against libegl
pkg/archlinux: use configure autodetection
Conflicts:
src/waffle/gbm/wgbm_display.c
Minor conflict due to 9a4f7c0, the libglapi workaround.
-rw-r--r-- | cmake/Modules/WafflePrintConfigurationSummary.cmake | 2 | ||||
-rw-r--r-- | pkg/archlinux/waffle-1.4.1/PKGBUILD | 6 | ||||
-rw-r--r-- | pkg/archlinux/waffle-git/PKGBUILD | 12 | ||||
-rw-r--r-- | src/waffle/CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/waffle/gbm/wgbm_display.c | 11 | ||||
-rw-r--r-- | src/waffle/gbm/wgbm_platform.c | 43 | ||||
-rw-r--r-- | src/waffle/gbm/wgbm_platform.h | 17 | ||||
-rw-r--r-- | src/waffle/gbm/wgbm_window.c | 23 | ||||
-rw-r--r-- | src/waffle/gbm/wgbm_window.h | 1 | ||||
-rw-r--r-- | src/waffle/glx/glx_config.c | 7 | ||||
-rw-r--r-- | src/waffle/glx/glx_context.c | 7 | ||||
-rw-r--r-- | src/waffle/glx/glx_display.c | 5 | ||||
-rw-r--r-- | src/waffle/glx/glx_platform.c | 57 | ||||
-rw-r--r-- | src/waffle/glx/glx_platform.h | 25 | ||||
-rw-r--r-- | src/waffle/glx/glx_window.c | 4 | ||||
-rw-r--r-- | src/waffle/glx/glx_window.h | 2 | ||||
-rw-r--r-- | src/waffle/glx/glx_wrappers.h | 50 |
17 files changed, 205 insertions, 73 deletions
diff --git a/cmake/Modules/WafflePrintConfigurationSummary.cmake b/cmake/Modules/WafflePrintConfigurationSummary.cmake index 869788c..1f38db5 100644 --- a/cmake/Modules/WafflePrintConfigurationSummary.cmake +++ b/cmake/Modules/WafflePrintConfigurationSummary.cmake @@ -57,7 +57,6 @@ if(waffle_has_egl) endif() if(waffle_has_glx) message(" gl_INCLUDE_DIRS: ${gl_INCLUDE_DIRS}") - message(" gl_LDFLAGS: ${gl_LDFLAGS}") endif() if(waffle_has_wayland) message(" wayland-client_INCLUDE_DIRS: ${wayland-client_INCLUDE_DIRS}") @@ -71,7 +70,6 @@ if(waffle_has_x11) endif() if(waffle_has_gbm) message(" gbm_INCLUDE_DIRS: ${gbm_INCLUDE_DIRS}") - message(" gbm_LDFLAGS: ${gbm_LDFLAGS}") endif() message("") message("Build type:") diff --git a/pkg/archlinux/waffle-1.4.1/PKGBUILD b/pkg/archlinux/waffle-1.4.1/PKGBUILD index e877ddc..5426e4b 100644 --- a/pkg/archlinux/waffle-1.4.1/PKGBUILD +++ b/pkg/archlinux/waffle-1.4.1/PKGBUILD @@ -2,7 +2,7 @@ pkgname='waffle' pkgver='1.4.1' -pkgrel=1 +pkgrel=2 pkgdesc='a library for choosing window system and OpenGL API at runtime' arch=('i686' 'x86_64') url='http://www.waffle-gl.org' @@ -34,10 +34,6 @@ build() { -DCMAKE_INSTALL_PREFIX=/usr \ -DCMAKE_INSTALL_LIBDIR=/usr/lib \ -DCMAKE_BUILD_TYPE=Release \ - -Dwaffle_has_gbm=1 \ - -Dwaffle_has_glx=1 \ - -Dwaffle_has_x11_egl=1 \ - -Dwaffle_has_wayland=1 \ -Dwaffle_build_manpages=1 \ -Dwaffle_build_htmldocs=1 \ -Dwaffle_build_examples=0 diff --git a/pkg/archlinux/waffle-git/PKGBUILD b/pkg/archlinux/waffle-git/PKGBUILD index b5a6d96..932595c 100644 --- a/pkg/archlinux/waffle-git/PKGBUILD +++ b/pkg/archlinux/waffle-git/PKGBUILD @@ -12,8 +12,6 @@ provides=(waffle) conflicts=(waffle) depends=( 'libgl' # for glx - 'libegl' - 'libgbm' 'libx11' 'libxcb' 'wayland' @@ -22,6 +20,9 @@ makedepends=( 'cmake' 'xcb-proto' + 'libegl' + 'libgbm' + # for building the docs. 'libxslt' 'docbook-xsl' @@ -43,10 +44,6 @@ build() { -DCMAKE_INSTALL_PREFIX=/usr \ -DCMAKE_INSTALL_LIBDIR=/usr/lib \ -DCMAKE_BUILD_TYPE=Release \ - -Dwaffle_has_glx=1 \ - -Dwaffle_has_x11_egl=1 \ - -Dwaffle_has_wayland=1 \ - -Dwaffle_has_gbm=1 \ -Dwaffle_build_manpages=1 \ -Dwaffle_build_htmldocs=1 \ -Dwaffle_build_examples=0 @@ -54,6 +51,9 @@ build() { } package() { + optdepends=('libegl: for x11_egl, gbm or wayland support') + optdepends=('libgbm: for gbm support') + cd "$srcdir/${_unpackdir}" make DESTDIR="$pkgdir/" install install -m755 -d "$pkgdir/usr/share/licenses/$pkgname" diff --git a/src/waffle/CMakeLists.txt b/src/waffle/CMakeLists.txt index 5c63c47..358ea6c 100644 --- a/src/waffle/CMakeLists.txt +++ b/src/waffle/CMakeLists.txt @@ -38,11 +38,6 @@ list(APPEND waffle_libdeps ) if(waffle_on_linux) - if(waffle_has_glx) - list(APPEND waffle_libdeps - ${gl_LDFLAGS} - ) - endif() if(waffle_has_wayland) list(APPEND waffle_libdeps ${wayland-client_LDFLAGS} @@ -56,7 +51,6 @@ if(waffle_on_linux) endif() if(waffle_has_gbm) list(APPEND waffle_libdeps - ${gbm_LDFLAGS} ${libudev_LDFLAGS} ) endif() diff --git a/src/waffle/gbm/wgbm_display.c b/src/waffle/gbm/wgbm_display.c index 22a8e8a..76e6c32 100644 --- a/src/waffle/gbm/wgbm_display.c +++ b/src/waffle/gbm/wgbm_display.c @@ -23,14 +23,12 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#define __GBM__ 1 #define _GNU_SOURCE #include <dlfcn.h> #include <stdlib.h> #include <unistd.h> -#include <gbm.h> #include <libudev.h> #include <fcntl.h> #include <sys/types.h> @@ -46,6 +44,8 @@ bool wgbm_display_destroy(struct wcore_display *wc_self) { struct wgbm_display *self = wgbm_display(wc_self); + struct wcore_platform *wc_plat = wc_self->platform; + struct wgbm_platform *plat = wgbm_platform(wegl_platform(wc_plat)); bool ok = true; int fd; @@ -56,8 +56,8 @@ wgbm_display_destroy(struct wcore_display *wc_self) ok &= wegl_display_teardown(&self->wegl); if (self->gbm_device) { - fd = gbm_device_get_fd(self->gbm_device); - gbm_device_destroy(self->gbm_device); + fd = plat->gbm_device_get_fd(self->gbm_device); + plat->gbm_device_destroy(self->gbm_device); close(fd); } @@ -120,6 +120,7 @@ wgbm_display_connect(struct wcore_platform *wc_plat, const char *name) { struct wgbm_display *self; + struct wgbm_platform *plat = wgbm_platform(wegl_platform(wc_plat)); bool ok = true; int fd; @@ -139,7 +140,7 @@ wgbm_display_connect(struct wcore_platform *wc_plat, } dlopen("libglapi.so.0", RTLD_LAZY | RTLD_GLOBAL); - self->gbm_device = gbm_create_device(fd); + self->gbm_device = plat->gbm_create_device(fd); if (!self->gbm_device) { wcore_errorf(WAFFLE_ERROR_UNKNOWN, "gbm_create_device failed"); goto error; diff --git a/src/waffle/gbm/wgbm_platform.c b/src/waffle/gbm/wgbm_platform.c index 4c224ac..981c366 100644 --- a/src/waffle/gbm/wgbm_platform.c +++ b/src/waffle/gbm/wgbm_platform.c @@ -23,10 +23,10 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#define __GBM__ 1 #define _POSIX_C_SOURCE 200112 // glib feature macro for unsetenv() #include <stdlib.h> +#include <dlfcn.h> #include "wcore_error.h" @@ -42,6 +42,8 @@ #include "wgbm_platform.h" #include "wgbm_window.h" +static const char *libgbm_filename = "libgbm.so.1"; + static const struct wcore_platform_vtbl wgbm_platform_vtbl; static bool @@ -49,6 +51,7 @@ wgbm_platform_destroy(struct wcore_platform *wc_self) { struct wgbm_platform *self = wgbm_platform(wegl_platform(wc_self)); bool ok = true; + int error = 0; if (!self) return true; @@ -58,6 +61,16 @@ wgbm_platform_destroy(struct wcore_platform *wc_self) if (self->linux) ok &= linux_platform_destroy(self->linux); + if (self->gbmHandle) { + error = dlclose(self->gbmHandle); + if (error) { + ok &= false; + wcore_errorf(WAFFLE_ERROR_UNKNOWN, + "dlclose(\"%s\") failed: %s", + libgbm_filename, dlerror()); + } + } + ok &= wegl_platform_teardown(&self->wegl); free(self); return ok; @@ -77,6 +90,34 @@ wgbm_platform_create(void) if (!ok) goto error; + self->gbmHandle = dlopen(libgbm_filename, RTLD_LAZY | RTLD_LOCAL); + if (!self->gbmHandle) { + wcore_errorf(WAFFLE_ERROR_FATAL, + "dlopen(\"%s\") failed: %s", + libgbm_filename, dlerror()); + goto error; + } + +#define RETRIEVE_GBM_SYMBOL(function) \ + self->function = dlsym(self->gbmHandle, #function); \ + if (!self->function) { \ + wcore_errorf(WAFFLE_ERROR_FATAL, \ + "dlsym(\"%s\", \"" #function "\") failed: %s", \ + libgbm_filename, dlerror()); \ + goto error; \ + } + + RETRIEVE_GBM_SYMBOL(gbm_create_device); + RETRIEVE_GBM_SYMBOL(gbm_device_get_fd); + RETRIEVE_GBM_SYMBOL(gbm_device_destroy); + + RETRIEVE_GBM_SYMBOL(gbm_surface_create); + RETRIEVE_GBM_SYMBOL(gbm_surface_destroy); + + RETRIEVE_GBM_SYMBOL(gbm_surface_lock_front_buffer); + RETRIEVE_GBM_SYMBOL(gbm_surface_release_buffer); +#undef RETRIEVE_GBM_SYMBOL + self->linux = linux_platform_create(); if (!self->linux) goto error; diff --git a/src/waffle/gbm/wgbm_platform.h b/src/waffle/gbm/wgbm_platform.h index 11a5867..259eb19 100644 --- a/src/waffle/gbm/wgbm_platform.h +++ b/src/waffle/gbm/wgbm_platform.h @@ -27,6 +27,7 @@ #include <stdbool.h> #include <stdlib.h> +#include <gbm.h> #undef linux @@ -38,6 +39,22 @@ struct linux_platform; struct wgbm_platform { struct wegl_platform wegl; struct linux_platform *linux; + + // GBM function pointers + void *gbmHandle; + + struct gbm_device *(*gbm_create_device)(int fd); + int (*gbm_device_get_fd)(struct gbm_device *gbm); + void (*gbm_device_destroy)(struct gbm_device *gbm); + + struct gbm_surface *(*gbm_surface_create)(struct gbm_device *gbm, + uint32_t width, uint32_t height, + uint32_t format, uint32_t flags); + void (*gbm_surface_destroy)(struct gbm_surface *surface); + + struct gbm_bo *(*gbm_surface_lock_front_buffer)(struct gbm_surface *surface); + void (*gbm_surface_release_buffer)(struct gbm_surface *surface, + struct gbm_bo *bo); }; DEFINE_CONTAINER_CAST_FUNC(wgbm_platform, diff --git a/src/waffle/gbm/wgbm_window.c b/src/waffle/gbm/wgbm_window.c index bce32a4..edac449 100644 --- a/src/waffle/gbm/wgbm_window.c +++ b/src/waffle/gbm/wgbm_window.c @@ -23,8 +23,6 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#define __GBM__ 1 - #include <stdlib.h> #include <string.h> @@ -38,11 +36,14 @@ #include "wgbm_config.h" #include "wgbm_display.h" +#include "wgbm_platform.h" #include "wgbm_window.h" bool wgbm_window_destroy(struct wcore_window *wc_self) { + struct wcore_platform *wc_plat = wc_self->display->platform; + struct wgbm_platform *plat = wgbm_platform(wegl_platform(wc_plat)); struct wgbm_window *self = wgbm_window(wc_self); bool ok = true; @@ -50,7 +51,7 @@ wgbm_window_destroy(struct wcore_window *wc_self) return ok; ok &= wegl_window_teardown(&self->wegl); - gbm_surface_destroy(self->gbm_surface); + plat->gbm_surface_destroy(self->gbm_surface); free(self); return ok; } @@ -61,8 +62,9 @@ wgbm_window_create(struct wcore_platform *wc_plat, int width, int height) { - struct wgbm_window *self; struct wgbm_display *dpy = wgbm_display(wc_config->display); + struct wgbm_platform *plat = wgbm_platform(wegl_platform(wc_plat)); + struct wgbm_window *self; uint32_t gbm_format; bool ok = true; @@ -72,9 +74,9 @@ wgbm_window_create(struct wcore_platform *wc_plat, gbm_format = wgbm_config_get_gbm_format(&wc_config->attrs); assert(gbm_format != 0); - self->gbm_surface = gbm_surface_create(dpy->gbm_device, width, height, - gbm_format, - GBM_BO_USE_RENDERING); + self->gbm_surface = plat->gbm_surface_create(dpy->gbm_device, + width, height, gbm_format, + GBM_BO_USE_RENDERING); if (!self->gbm_surface) { wcore_errorf(WAFFLE_ERROR_UNKNOWN, "gbm_surface_create failed"); @@ -104,15 +106,18 @@ wgbm_window_show(struct wcore_window *wc_self) bool wgbm_window_swap_buffers(struct wcore_window *wc_self) { + struct wcore_platform *wc_plat = wc_self->display->platform; + struct wgbm_platform *plat = wgbm_platform(wegl_platform(wc_plat)); + if (!wegl_window_swap_buffers(wc_self)) return false; struct wgbm_window *self = wgbm_window(wc_self); - struct gbm_bo *bo = gbm_surface_lock_front_buffer(self->gbm_surface); + struct gbm_bo *bo = plat->gbm_surface_lock_front_buffer(self->gbm_surface); if (!bo) return false; - gbm_surface_release_buffer(self->gbm_surface, bo); + plat->gbm_surface_release_buffer(self->gbm_surface, bo); return true; } diff --git a/src/waffle/gbm/wgbm_window.h b/src/waffle/gbm/wgbm_window.h index 0a895db..729612b 100644 --- a/src/waffle/gbm/wgbm_window.h +++ b/src/waffle/gbm/wgbm_window.h @@ -30,6 +30,7 @@ #include "wegl_window.h" struct wcore_platform; +struct gbm_surface; struct wgbm_window { struct gbm_surface *gbm_surface; diff --git a/src/waffle/glx/glx_config.c b/src/waffle/glx/glx_config.c index bad3531..f47e705 100644 --- a/src/waffle/glx/glx_config.c +++ b/src/waffle/glx/glx_config.c @@ -168,6 +168,7 @@ glx_config_choose(struct wcore_platform *wc_plat, { struct glx_config *self; struct glx_display *dpy = glx_display(wc_dpy); + struct glx_platform *plat = glx_platform(wc_plat); GLXFBConfig *configs = NULL; int num_configs = 0; @@ -220,7 +221,7 @@ glx_config_choose(struct wcore_platform *wc_plat, }; // Set glx_fbconfig. - configs = wrapped_glXChooseFBConfig(dpy->x11.xlib, + configs = wrapped_glXChooseFBConfig(plat, dpy->x11.xlib, dpy->x11.screen, attrib_list, &num_configs); @@ -233,7 +234,7 @@ glx_config_choose(struct wcore_platform *wc_plat, self->glx_fbconfig = configs[0]; // Set glx_fbconfig_id. - ok = !wrapped_glXGetFBConfigAttrib(dpy->x11.xlib, + ok = !wrapped_glXGetFBConfigAttrib(plat, dpy->x11.xlib, self->glx_fbconfig, GLX_FBCONFIG_ID, &self->glx_fbconfig_id); @@ -243,7 +244,7 @@ glx_config_choose(struct wcore_platform *wc_plat, } // Set xcb_visual_id. - vi = wrapped_glXGetVisualFromFBConfig(dpy->x11.xlib, + vi = wrapped_glXGetVisualFromFBConfig(plat, dpy->x11.xlib, self->glx_fbconfig); if (!vi) { wcore_errorf(WAFFLE_ERROR_UNKNOWN, diff --git a/src/waffle/glx/glx_context.c b/src/waffle/glx/glx_context.c index 62573dc..57db2ba 100644 --- a/src/waffle/glx/glx_context.c +++ b/src/waffle/glx/glx_context.c @@ -45,6 +45,7 @@ glx_context_destroy(struct wcore_context *wc_self) { struct glx_context *self; struct glx_display *dpy; + struct glx_platform *platform; bool ok = true; if (!wc_self) @@ -52,9 +53,10 @@ glx_context_destroy(struct wcore_context *wc_self) self = glx_context(wc_self); dpy = glx_display(wc_self->display); + platform = glx_platform(wc_self->display->platform); if (self->glx) - wrapped_glXDestroyContext(dpy->x11.xlib, self->glx); + wrapped_glXDestroyContext(platform, dpy->x11.xlib, self->glx); ok &= wcore_context_teardown(wc_self); free(self); @@ -182,7 +184,8 @@ glx_context_create_native(struct glx_config *config, } } else { - ctx = wrapped_glXCreateNewContext(dpy->x11.xlib, + ctx = wrapped_glXCreateNewContext(platform, + dpy->x11.xlib, config->glx_fbconfig, GLX_RGBA_TYPE, real_share_ctx, diff --git a/src/waffle/glx/glx_display.c b/src/waffle/glx/glx_display.c index 184438f..567d442 100644 --- a/src/waffle/glx/glx_display.c +++ b/src/waffle/glx/glx_display.c @@ -51,8 +51,9 @@ glx_display_destroy(struct wcore_display *wc_self) static bool glx_display_set_extensions(struct glx_display *self) { - - const char *s = wrapped_glXQueryExtensionsString(self->x11.xlib, + struct glx_platform *platform = glx_platform(self->wcore.platform); + const char *s = wrapped_glXQueryExtensionsString(platform, + self->x11.xlib, self->x11.screen); if (!s) { wcore_errorf(WAFFLE_ERROR_UNKNOWN, diff --git a/src/waffle/glx/glx_platform.c b/src/waffle/glx/glx_platform.c index 804c275..4fb2eed 100644 --- a/src/waffle/glx/glx_platform.c +++ b/src/waffle/glx/glx_platform.c @@ -24,6 +24,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <stdlib.h> +#include <dlfcn.h> #include "wcore_error.h" @@ -36,6 +37,8 @@ #include "glx_window.h" #include "glx_wrappers.h" +static const char *libGL_filename = "libGL.so.1"; + static const struct wcore_platform_vtbl glx_platform_vtbl; static bool @@ -43,6 +46,7 @@ glx_platform_destroy(struct wcore_platform *wc_self) { struct glx_platform *self = glx_platform(wc_self); bool ok = true; + int error = 0; if (!self) return true; @@ -50,6 +54,16 @@ glx_platform_destroy(struct wcore_platform *wc_self) if (self->linux) ok &= linux_platform_destroy(self->linux); + if (self->glxHandle) { + error = dlclose(self->glxHandle); + if (error) { + ok &= false; + wcore_errorf(WAFFLE_ERROR_UNKNOWN, + "dlclose(\"%s\") failed: %s", + libGL_filename, dlerror()); + } + } + ok &= wcore_platform_teardown(wc_self); free(self); return ok; @@ -69,11 +83,42 @@ glx_platform_create(void) if (!ok) goto error; + self->glxHandle = dlopen(libGL_filename, RTLD_LAZY | RTLD_LOCAL); + if (!self->glxHandle) { + wcore_errorf(WAFFLE_ERROR_FATAL, + "dlopen(\"%s\") failed: %s", + libGL_filename, dlerror()); + goto error; + } + +#define RETRIEVE_GLX_SYMBOL(function) \ + self->function = dlsym(self->glxHandle, #function); \ + if (!self->function) { \ + wcore_errorf(WAFFLE_ERROR_FATAL, \ + "dlsym(\"%s\", \"" #function "\") failed: %s", \ + libGL_filename, dlerror()); \ + goto error; \ + } + + RETRIEVE_GLX_SYMBOL(glXCreateNewContext); + RETRIEVE_GLX_SYMBOL(glXDestroyContext); + RETRIEVE_GLX_SYMBOL(glXMakeCurrent); + + RETRIEVE_GLX_SYMBOL(glXQueryExtensionsString); + RETRIEVE_GLX_SYMBOL(glXGetProcAddress); + + RETRIEVE_GLX_SYMBOL(glXGetVisualFromFBConfig); + RETRIEVE_GLX_SYMBOL(glXGetFBConfigAttrib); + RETRIEVE_GLX_SYMBOL(glXChooseFBConfig); + + RETRIEVE_GLX_SYMBOL(glXSwapBuffers); +#undef RETRIEVE_GLX_SYMBOL + self->linux = linux_platform_create(); if (!self->linux) goto error; - self->glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddress((const uint8_t*) "glXCreateContextAttribsARB"); + self->glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) self->glXGetProcAddress((const uint8_t*) "glXCreateContextAttribsARB"); self->wcore.vtbl = &glx_platform_vtbl; return &self->wcore; @@ -89,12 +134,13 @@ glx_platform_make_current(struct wcore_platform *wc_self, struct wcore_window *wc_window, struct wcore_context *wc_ctx) { - bool ok; + struct glx_platform *self = glx_platform(wc_self); Display *dpy = glx_display(wc_dpy)->x11.xlib; GLXDrawable win = wc_window ? glx_window(wc_window)->x11.xcb : 0; GLXContext ctx = wc_ctx ? glx_context(wc_ctx)->glx : NULL; - - ok = wrapped_glXMakeCurrent(dpy, win, ctx); + bool ok; + + ok = wrapped_glXMakeCurrent(self, dpy, win, ctx); if (!ok) { wcore_errorf(WAFFLE_ERROR_UNKNOWN, "glXMakeCurrent failed"); } @@ -106,7 +152,8 @@ static void* glx_platform_get_proc_address(struct wcore_platform *wc_self, const char *name) { - return glXGetProcAddress((const GLubyte*) name); + struct glx_platform *self = glx_platform(wc_self); + return self->glXGetProcAddress((const GLubyte*) name); } static bool diff --git a/src/waffle/glx/glx_platform.h b/src/waffle/glx/glx_platform.h index 58519e8..36ddff6 100644 --- a/src/waffle/glx/glx_platform.h +++ b/src/waffle/glx/glx_platform.h @@ -26,12 +26,8 @@ #pragma once #include <GL/glx.h> -#include <X11/Xlib.h> -#include <xcb/xcb.h> #undef linux -#include "waffle_glx.h" - #include "wcore_platform.h" #include "wcore_util.h" @@ -41,6 +37,27 @@ struct glx_platform { struct wcore_platform wcore; struct linux_platform *linux; + // glX function pointers + void *glxHandle; + + GLXContext (*glXCreateNewContext)(Display *dpy, GLXFBConfig config, + int renderType, GLXContext shareList, + Bool direct); + void (*glXDestroyContext)(Display *dpy, GLXContext ctx); + Bool (*glXMakeCurrent)(Display *dpy, GLXDrawable drawable, GLXContext ctx); + + const char *(*glXQueryExtensionsString)(Display *dpy, int screen); + void *(*glXGetProcAddress)(const GLubyte *procname); + + XVisualInfo *(*glXGetVisualFromFBConfig)(Display *dpy, GLXFBConfig config); + int (*glXGetFBConfigAttrib)(Display *dpy, GLXFBConfig config, + int attribute, int *value); + GLXFBConfig *(*glXChooseFBConfig)(Display *dpy, int screen, + const int *attribList, int *nitems); + + void (*glXSwapBuffers)(Display *dpy, GLXDrawable drawable); + + PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB; }; diff --git a/src/waffle/glx/glx_window.c b/src/waffle/glx/glx_window.c index 702ed3f..34fa784 100644 --- a/src/waffle/glx/glx_window.c +++ b/src/waffle/glx/glx_window.c @@ -25,6 +25,7 @@ #include <stdlib.h> #include <string.h> +#include <xcb/xcb.h> #include "wcore_error.h" @@ -100,8 +101,9 @@ glx_window_swap_buffers(struct wcore_window *wc_self) { struct glx_window *self = glx_window(wc_self); struct glx_display *dpy = glx_display(wc_self->display); + struct glx_platform *plat = glx_platform(wc_self->display->platform); - wrapped_glXSwapBuffers(dpy->x11.xlib, self->x11.xcb); + wrapped_glXSwapBuffers(plat, dpy->x11.xlib, self->x11.xcb); return true; } diff --git a/src/waffle/glx/glx_window.h b/src/waffle/glx/glx_window.h index 4cf44e3..5aed497 100644 --- a/src/waffle/glx/glx_window.h +++ b/src/waffle/glx/glx_window.h @@ -27,8 +27,6 @@ #include <stdbool.h> -#include <xcb/xcb.h> - #include "wcore_window.h" #include "wcore_util.h" diff --git a/src/waffle/glx/glx_wrappers.h b/src/waffle/glx/glx_wrappers.h index 5f53332..1411c86 100644 --- a/src/waffle/glx/glx_wrappers.h +++ b/src/waffle/glx/glx_wrappers.h @@ -45,19 +45,22 @@ #include "x11_wrappers.h" static inline GLXFBConfig* -wrapped_glXChooseFBConfig(Display *dpy, int screen, +wrapped_glXChooseFBConfig(struct glx_platform *platform, + Display *dpy, int screen, const int *attribList, int *nitems) { X11_SAVE_ERROR_HANDLER - GLXFBConfig *configs = glXChooseFBConfig(dpy, screen, attribList, nitems); + GLXFBConfig *configs = platform->glXChooseFBConfig(dpy, screen, + attribList, nitems); X11_RESTORE_ERROR_HANDLER return configs; } static inline GLXContext -wrapped_glXCreateContextAttribsARB( - struct glx_platform *platform, Display *dpy, GLXFBConfig config, - GLXContext share_context, Bool direct, const int *attrib_list) +wrapped_glXCreateContextAttribsARB(struct glx_platform *platform, + Display *dpy, GLXFBConfig config, + GLXContext share_context, Bool direct, + const int *attrib_list) { X11_SAVE_ERROR_HANDLER GLXContext ctx = platform->glXCreateContextAttribsARB( @@ -67,65 +70,72 @@ wrapped_glXCreateContextAttribsARB( } static inline GLXContext -wrapped_glXCreateNewContext(Display *dpy, GLXFBConfig config, int renderType, +wrapped_glXCreateNewContext(struct glx_platform *platform, + Display *dpy, GLXFBConfig config, int renderType, GLXContext shareList, Bool direct) { X11_SAVE_ERROR_HANDLER - GLXContext ctx = glXCreateNewContext(dpy, config, renderType, shareList, - direct); + GLXContext ctx = platform->glXCreateNewContext(dpy, config, renderType, + shareList, direct); X11_RESTORE_ERROR_HANDLER return ctx; } static inline int -wrapped_glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config, +wrapped_glXGetFBConfigAttrib(struct glx_platform *platform, + Display *dpy, GLXFBConfig config, int attribute, int *value) { X11_SAVE_ERROR_HANDLER - int error = glXGetFBConfigAttrib(dpy, config, attribute, value); + int error = platform->glXGetFBConfigAttrib(dpy, config, attribute, value); X11_RESTORE_ERROR_HANDLER return error; } static inline XVisualInfo* -wrapped_glXGetVisualFromFBConfig(Display *dpy, GLXFBConfig config) +wrapped_glXGetVisualFromFBConfig(struct glx_platform *platform, + Display *dpy, GLXFBConfig config) { X11_SAVE_ERROR_HANDLER - XVisualInfo *vi = glXGetVisualFromFBConfig(dpy, config); + XVisualInfo *vi = platform->glXGetVisualFromFBConfig(dpy, config); X11_RESTORE_ERROR_HANDLER return vi; } static inline void -wrapped_glXDestroyContext(Display *dpy, GLXContext ctx) +wrapped_glXDestroyContext(struct glx_platform *platform, + Display *dpy, GLXContext ctx) { X11_SAVE_ERROR_HANDLER - glXDestroyContext(dpy, ctx); + platform->glXDestroyContext(dpy, ctx); X11_RESTORE_ERROR_HANDLER } static inline Bool -wrapped_glXMakeCurrent(Display *dpy, GLXDrawable drawable, GLXContext ctx) +wrapped_glXMakeCurrent(struct glx_platform *platform, + Display *dpy, GLXDrawable drawable, GLXContext ctx) { X11_SAVE_ERROR_HANDLER - Bool ok = glXMakeCurrent(dpy, drawable, ctx); + Bool ok = platform->glXMakeCurrent(dpy, drawable, ctx); X11_RESTORE_ERROR_HANDLER return ok; } static inline const char* -wrapped_glXQueryExtensionsString(Display *dpy, int screen) +wrapped_glXQueryExtensionsString(struct glx_platform *platform, + Display *dpy, int screen) { X11_SAVE_ERROR_HANDLER - const char *s = glXQueryExtensionsString(dpy, screen); + const char *s = platform->glXQueryExtensionsString(dpy, screen); X11_RESTORE_ERROR_HANDLER return s; } static inline void -wrapped_glXSwapBuffers(Display *dpy, GLXDrawable drawable) +wrapped_glXSwapBuffers(struct glx_platform *platform, + Display *dpy, GLXDrawable drawable) { X11_SAVE_ERROR_HANDLER - glXSwapBuffers(dpy, drawable); + platform->glXSwapBuffers(dpy, drawable); X11_RESTORE_ERROR_HANDLER } |