summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEmil Velikov <emil.l.velikov@gmail.com>2014-11-10 03:31:43 +0000
committerEmil Velikov <emil.l.velikov@gmail.com>2014-11-13 00:04:05 +0000
commita92ef65cbe8b141276431144e15cc21ac2136bc0 (patch)
treefd52e2e1a4fa696d3176fac2c14609a1f7011b31 /src
parent70350e4f659f80f28b7f69ecd31356b304893722 (diff)
glx: fetch the libGL function pointers at glx_platform_create
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@gmail.com> Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/waffle/glx/glx_platform.c45
-rw-r--r--src/waffle/glx/glx_platform.h25
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;
};