3 * Purpose: GL shim which redirects to a specified DLL
5 * Copyright (c) Jon TURNEY 2013
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
27 A GL shim which redirects to a specified DLL
29 XWin is statically linked with this, rather than the system libGL, so that
30 GL calls can be directed to mesa cygGL-1.dll, or cygnativeGLthunk.dll
31 (which contains cdecl-to-stdcall thunks to the native openGL32.dll)
34 #ifdef HAVE_XWIN_CONFIG_H
35 #include <xwin-config.h>
38 #define GL_GLEXT_LEGACY
44 #include <X11/Xwindows.h>
46 #include "glwindows.h"
47 #include <glx/glxserver.h>
49 static HMODULE hMod
= NULL
;
52 Implement the __glGetProcAddress function by just using GetProcAddress() on the selected DLL
54 void *glXGetProcAddressARB(const char *symbol
)
58 /* Default to the mesa GL implementation if one hasn't been selected yet */
60 glWinSelectImplementation(0);
62 proc
= GetProcAddress(hMod
, symbol
);
64 if (glxWinDebugSettings
.enableGLcallTrace
)
65 ErrorF("glXGetProcAddressARB: Resolved '%s' in %p to %p\n", symbol
, hMod
, proc
);
71 Select a GL implementation DLL
73 int glWinSelectImplementation(int native
)
78 dllname
= "cygnativeGLthunk.dll";
81 dllname
= "cygGL-1.dll";
84 hMod
= LoadLibraryEx(dllname
, NULL
, 0);
86 ErrorF("glWinSelectGLimplementation: Could not load '%s'\n", dllname
);
90 ErrorF("glWinSelectGLimplementation: Loaded '%s'\n", dllname
);
92 /* Connect __glGetProcAddress() to our implementation of glXGetProcAddressARB() above */
93 __glXsetGetProcAddress((glx_gpa_proc
)glXGetProcAddressARB
);
98 #define RESOLVE_RET(proctype, symbol, retval) \
99 proctype proc = (proctype)glXGetProcAddressARB(symbol); \
100 if (proc == NULL) return retval;
102 #define RESOLVE(proctype, symbol) RESOLVE_RET(proctype, symbol,)
103 #define RESOLVED_PROC proc
105 /* Include generated shims for direct linkage to GL functions which are in the ABI */
106 #include "generated_gl_shim.c"
109 Special wrapper for glAddSwapHintRectWIN for copySubBuffers
111 Only used with native GL if the GL_WIN_swap_hint extension is present, so we enable
112 GLX_MESA_copy_sub_buffer
114 typedef void (__stdcall
* PFNGLADDSWAPHINTRECTWIN
) (GLint x
, GLint y
,
119 glAddSwapHintRectWINWrapper(GLint x
, GLint y
, GLsizei width
,
122 RESOLVE(PFNGLADDSWAPHINTRECTWIN
, "glAddSwapHintRectWIN");
123 RESOLVED_PROC(x
, y
, width
, height
);