glx: Implement the libglvnd interface.
[mesa.git] / src / glx / glxglvnd.c
1 #include <string.h>
2 #include <X11/Xlib.h>
3
4 #include "glvnd/libglxabi.h"
5
6 #include "glxglvnd.h"
7
8
9 static Bool __glXGLVNDIsScreenSupported(Display *dpy, int screen)
10 {
11 /* TODO: Think of a better heuristic... */
12 return True;
13 }
14
15 static void *__glXGLVNDGetProcAddress(const GLubyte *procName)
16 {
17 return glXGetProcAddressARB(procName);
18 }
19
20 static int FindGLXFunction(const GLubyte *name)
21 {
22 int i;
23
24 for (i = 0; i < DI_FUNCTION_COUNT; i++) {
25 if (strcmp((const char *) name, __glXDispatchTableStrings[i]) == 0)
26 return i;
27 }
28 return -1;
29 }
30
31 static void *__glXGLVNDGetDispatchAddress(const GLubyte *procName)
32 {
33 int internalIndex = FindGLXFunction(procName);
34
35 if (internalIndex >= 0) {
36 return __glXDispatchFunctions[internalIndex];
37 }
38
39 return NULL;
40 }
41
42 static void __glXGLVNDSetDispatchIndex(const GLubyte *procName, int index)
43 {
44 int internalIndex = FindGLXFunction(procName);
45
46 if (internalIndex >= 0)
47 __glXDispatchTableIndices[internalIndex] = index;
48 }
49
50 _X_EXPORT Bool __glx_Main(uint32_t version, const __GLXapiExports *exports,
51 __GLXvendorInfo *vendor, __GLXapiImports *imports)
52 {
53 static Bool initDone = False;
54
55 if (GLX_VENDOR_ABI_GET_MAJOR_VERSION(version) !=
56 GLX_VENDOR_ABI_MAJOR_VERSION ||
57 GLX_VENDOR_ABI_GET_MINOR_VERSION(version) <
58 GLX_VENDOR_ABI_MINOR_VERSION)
59 return False;
60
61 if (!initDone) {
62 initDone = True;
63 __glXGLVNDAPIExports = exports;
64
65 imports->isScreenSupported = __glXGLVNDIsScreenSupported;
66 imports->getProcAddress = __glXGLVNDGetProcAddress;
67 imports->getDispatchAddress = __glXGLVNDGetDispatchAddress;
68 imports->setDispatchIndex = __glXGLVNDSetDispatchIndex;
69 imports->notifyError = NULL;
70 imports->isPatchSupported = NULL;
71 imports->initiatePatch = NULL;
72 }
73
74 return True;
75 }