wip - import hostgl from abi v0 and adapt to abi v1/GL.library ABI
[AROS.git] / arch / all-hosted / libs / hostgl / x11_hostlib.c
blob5853dec11f6435ca995f574cbd2c955c0ff1ea80
1 #include <aros/config.h>
3 #include <aros/symbolsets.h>
5 #include "hostgl_renderer_config.h"
6 #include "x11_hostlib.h"
8 #include <proto/hostlib.h>
10 #include LC_LIBDEFS_FILE
12 #define DEBUG 0
13 #include <aros/debug.h>
15 void *x11_handle = NULL;
16 struct x11_func x11_func;
18 static const char *x11_func_names[] =
20 "XOpenDisplay",
21 "XCloseDisplay",
22 "XFree",
23 #if defined(RENDERER_SEPARATE_X_WINDOW)
24 "XCreateColormap",
25 "XCreateWindow",
26 "XDestroyWindow",
27 "XFlush",
28 "XMapWindow",
29 #endif
30 NULL
33 APTR HostLibBase;
35 void *x11_hostlib_load_so(const char *sofile, const char **names, void **funcptr)
37 void *handle;
38 char *err;
39 const char *name;
40 int i = 0;
42 D(bug("[HostGL] loading %d functions from %s\n", nfuncs, sofile));
44 if ((handle = HostLib_Open(sofile, &err)) == NULL)
46 kprintf("[HostGL] couldn't open '%s': %s\n", sofile, err);
47 return NULL;
50 while((name = names[i]) != NULL)
52 funcptr[i] = HostLib_GetPointer(handle, name, &err);
53 D(bug("%s(%x)\n", names[i], funcptr[i]));
54 if (err != NULL)
56 kprintf("[HostGL] couldn't get symbol '%s' from '%s': %s\n", names[i], sofile, err);
57 HostLib_Close(handle, NULL);
58 return NULL;
60 i++;
63 D(bug("[x11] done\n"));
65 return handle;
68 static int x11_hostlib_init(LIBBASETYPEPTR LIBBASE)
70 D(bug("[HostGL] X11 hostlib init\n"));
72 if ((HostLibBase = OpenResource("hostlib.resource")) == NULL)
74 kprintf("[HostGL] couldn't open hostlib.resource\n");
75 return FALSE;
78 if ((x11_handle = x11_hostlib_load_so(X11_SOFILE, x11_func_names, (void **) &x11_func)) == NULL)
80 HostLib_Close(x11_handle, NULL);
81 return FALSE;
84 return TRUE;
87 static int x11_hostlib_expunge(LIBBASETYPEPTR LIBBASE)
89 D(bug("[HostGL] X11 hostlib expunge\n"));
91 if (x11_handle != NULL)
92 HostLib_Close(x11_handle, NULL);
94 return TRUE;
97 ADD2INITLIB(x11_hostlib_init, 0)
98 ADD2EXPUNGELIB(x11_hostlib_expunge, 0)