[waffle] [PATCH 6/7] glx: fetch the libGL function pointers at glx_platform_create
Emil Velikov
emil.l.velikov at gmail.com
Mon Nov 10 07:56:38 PST 2014
Thus way with a follow up commit we can use them and eliminate the
link dependency from waffle.
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
src/waffle/glx/glx_platform.c | 45 +++++++++++++++++++++++++++++++++++++++++++
src/waffle/glx/glx_platform.h | 25 ++++++++++++++++++++----
2 files changed, 66 insertions(+), 4 deletions(-)
diff --git a/src/waffle/glx/glx_platform.c b/src/waffle/glx/glx_platform.c
index 804c275..ae0cf46 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,6 +83,37 @@ 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;
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;
};
--
2.1.3
More information about the waffle
mailing list