xref: /OK3568_Linux_fs/external/xserver/hw/xwin/glx/glthunk.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * File: glthunk.c
3  * Purpose: cdecl thunk wrapper library for Win32 stdcall OpenGL library
4  *
5  * Copyright (c) Jon TURNEY 2009,2013
6  *
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:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
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.
24  */
25 
26 // define USE_OPENGL32 makes gl.h declare gl*() function prototypes with stdcall linkage,
27 // so our generated wrappers will correctly link with the functions in opengl32.dll
28 #define USE_OPENGL32
29 
30 #ifdef HAVE_XWIN_CONFIG_H
31 #include <xwin-config.h>
32 #endif
33 
34 #include <X11/Xwindows.h>
35 
36 #define GL_GLEXT_LEGACY
37 #include <GL/gl.h>
38 #undef GL_ARB_imaging
39 #undef GL_VERSION_1_3
40 #include <GL/glext.h>
41 
42 static PROC
glWinResolveHelper(PROC * cache,const char * symbol)43 glWinResolveHelper(PROC * cache, const char *symbol)
44 {
45     PROC proc = NULL;
46 
47     /* If not yet cached, call wglGetProcAddress */
48     if ((*cache) == NULL) {
49         proc = wglGetProcAddress(symbol);
50         if (proc == NULL) {
51             (*cache) = (PROC) - 1;
52         }
53         else {
54             (*cache) = proc;
55         }
56     }
57     /* Cached wglGetProcAddress failure */
58     else if ((*cache) == (PROC) - 1) {
59         proc = 0;
60     }
61     /* Cached wglGetProcAddress result */
62     else {
63         proc = (*cache);
64     }
65 
66     return proc;
67 }
68 
69 #define RESOLVE_RET(proctype, symbol, retval) \
70     static PROC cache = NULL; \
71     __stdcall proctype proc = (proctype)glWinResolveHelper(&cache, symbol); \
72     if (proc == NULL) { \
73         return retval; \
74     }
75 
76 #define RESOLVE(proctype, symbol) RESOLVE_RET(proctype, symbol,)
77 
78 #define RESOLVED_PROC(proctype) proc
79 
80 /*
81   Include generated cdecl wrappers for stdcall gl*() functions in opengl32.dll
82 
83   OpenGL 1.2 and upward is treated as extensions, function address must
84   found using wglGetProcAddress(), but also stdcall so still need wrappers...
85 */
86 
87 #include "generated_gl_thunks.ic"
88