1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * File: glthunk.c
3*4882a593Smuzhiyun * Purpose: cdecl thunk wrapper library for Win32 stdcall OpenGL library
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (c) Jon TURNEY 2009,2013
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
8*4882a593Smuzhiyun * copy of this software and associated documentation files (the "Software"),
9*4882a593Smuzhiyun * to deal in the Software without restriction, including without limitation
10*4882a593Smuzhiyun * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11*4882a593Smuzhiyun * and/or sell copies of the Software, and to permit persons to whom the
12*4882a593Smuzhiyun * Software is furnished to do so, subject to the following conditions:
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * The above copyright notice and this permission notice shall be included in
15*4882a593Smuzhiyun * all copies or substantial portions of the Software.
16*4882a593Smuzhiyun *
17*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20*4882a593Smuzhiyun * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21*4882a593Smuzhiyun * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22*4882a593Smuzhiyun * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23*4882a593Smuzhiyun * DEALINGS IN THE SOFTWARE.
24*4882a593Smuzhiyun */
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun // define USE_OPENGL32 makes gl.h declare gl*() function prototypes with stdcall linkage,
27*4882a593Smuzhiyun // so our generated wrappers will correctly link with the functions in opengl32.dll
28*4882a593Smuzhiyun #define USE_OPENGL32
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #ifdef HAVE_XWIN_CONFIG_H
31*4882a593Smuzhiyun #include <xwin-config.h>
32*4882a593Smuzhiyun #endif
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun #include <X11/Xwindows.h>
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun #define GL_GLEXT_LEGACY
37*4882a593Smuzhiyun #include <GL/gl.h>
38*4882a593Smuzhiyun #undef GL_ARB_imaging
39*4882a593Smuzhiyun #undef GL_VERSION_1_3
40*4882a593Smuzhiyun #include <GL/glext.h>
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun static PROC
glWinResolveHelper(PROC * cache,const char * symbol)43*4882a593Smuzhiyun glWinResolveHelper(PROC * cache, const char *symbol)
44*4882a593Smuzhiyun {
45*4882a593Smuzhiyun PROC proc = NULL;
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun /* If not yet cached, call wglGetProcAddress */
48*4882a593Smuzhiyun if ((*cache) == NULL) {
49*4882a593Smuzhiyun proc = wglGetProcAddress(symbol);
50*4882a593Smuzhiyun if (proc == NULL) {
51*4882a593Smuzhiyun (*cache) = (PROC) - 1;
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun else {
54*4882a593Smuzhiyun (*cache) = proc;
55*4882a593Smuzhiyun }
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun /* Cached wglGetProcAddress failure */
58*4882a593Smuzhiyun else if ((*cache) == (PROC) - 1) {
59*4882a593Smuzhiyun proc = 0;
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun /* Cached wglGetProcAddress result */
62*4882a593Smuzhiyun else {
63*4882a593Smuzhiyun proc = (*cache);
64*4882a593Smuzhiyun }
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun return proc;
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun #define RESOLVE_RET(proctype, symbol, retval) \
70*4882a593Smuzhiyun static PROC cache = NULL; \
71*4882a593Smuzhiyun __stdcall proctype proc = (proctype)glWinResolveHelper(&cache, symbol); \
72*4882a593Smuzhiyun if (proc == NULL) { \
73*4882a593Smuzhiyun return retval; \
74*4882a593Smuzhiyun }
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun #define RESOLVE(proctype, symbol) RESOLVE_RET(proctype, symbol,)
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun #define RESOLVED_PROC(proctype) proc
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun /*
81*4882a593Smuzhiyun Include generated cdecl wrappers for stdcall gl*() functions in opengl32.dll
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun OpenGL 1.2 and upward is treated as extensions, function address must
84*4882a593Smuzhiyun found using wglGetProcAddress(), but also stdcall so still need wrappers...
85*4882a593Smuzhiyun */
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun #include "generated_gl_thunks.ic"
88