1/* 2 * File: glwrap.c 3 * Purpose: Wrapper functions for Win32 OpenGL functions 4 * 5 * Authors: Alexander Gottwald 6 * Jon TURNEY 7 * 8 * Copyright (c) Jon TURNEY 2009 9 * Copyright (c) Alexander Gottwald 2004 10 * 11 * 12 * Permission is hereby granted, free of charge, to any person obtaining a 13 * copy of this software and associated documentation files (the "Software"), 14 * to deal in the Software without restriction, including without limitation 15 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 16 * and/or sell copies of the Software, and to permit persons to whom the 17 * Software is furnished to do so, subject to the following conditions: 18 * 19 * The above copyright notice and this permission notice shall be included in 20 * all copies or substantial portions of the Software. 21 * 22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 25 * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 26 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 27 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 * DEALINGS IN THE SOFTWARE. 29 */ 30 31// define USE_OPENGL32 makes gl.h declare gl*() function prototypes with stdcall linkage, 32// so our generated wrappers will correctly link with the functions in opengl32.dll 33#define USE_OPENGL32 34 35#ifdef HAVE_XWIN_CONFIG_H 36#include <xwin-config.h> 37#endif 38 39#include <X11/Xwindows.h> 40#include <GL/gl.h> 41#include <GL/glext.h> 42#include <glx/glxserver.h> 43#include <glx/glxext.h> 44#include <glx/glapi.h> 45#include <glx/dispatch.h> 46#include <glwindows.h> 47 48static unsigned int glWinIndirectProcCalls = 0; 49static unsigned int glWinDirectProcCalls = 0; 50 51void 52glWinCallDelta(void) 53{ 54 static unsigned int glWinIndirectProcCallsLast = 0; 55 static unsigned int glWinDirectProcCallsLast = 0; 56 if ((glWinIndirectProcCalls != glWinIndirectProcCallsLast) || 57 (glWinDirectProcCalls != glWinDirectProcCallsLast)) 58 { 59 if (glxWinDebugSettings.enableTrace) 60 { 61 ErrorF("after %d direct and %d indirect GL calls\n", 62 glWinDirectProcCalls - glWinDirectProcCallsLast, 63 glWinIndirectProcCalls - glWinIndirectProcCallsLast); 64 } 65 glWinDirectProcCallsLast = glWinDirectProcCalls; 66 glWinIndirectProcCallsLast = glWinIndirectProcCalls; 67 } 68} 69 70static PROC 71glWinResolveHelper(PROC *cache, char *symbol) 72{ 73 PROC proc = NULL; 74 75 /* If not yet cached, call wglGetProcAddress */ 76 if ((*cache) == NULL) 77 { 78 proc = wglGetProcAddress(symbol); 79 if (proc == NULL) 80 { 81 ErrorF("glwrap: Can't resolve \"%s\"\n", symbol); 82 (*cache) = (PROC)-1; 83 } 84 else 85 { 86 ErrorF("glwrap: Resolved \"%s\"\n", symbol); 87 (*cache) = proc; 88 } 89 } 90 /* Cached wglGetProcAddress failure */ 91 else if ((*cache) == (PROC)-1) 92 { 93 proc = 0; 94 } 95 /* Cached wglGetProcAddress result */ 96 else 97 { 98 proc = (*cache); 99 } 100 101 return proc; 102} 103 104#define RESOLVE_RET(proctype, symbol, retval) \ 105 static PROC cache = NULL; \ 106 __stdcall proctype proc = (proctype)glWinResolveHelper(&cache, symbol); \ 107 if (proc == NULL) { \ 108 __glXErrorCallBack(0); \ 109 return retval; \ 110 } \ 111 glWinIndirectProcCalls++; 112 113#define RESOLVE(proctype, symbol) RESOLVE_RET(proctype, symbol,) 114 115#define RESOLVED_PROC(proctype) proc 116 117/* 118 Include generated cdecl wrappers for stdcall gl*() functions in opengl32.dll 119 120 OpenGL 1.2 and upward is treated as extensions, function address must 121 found using wglGetProcAddress(), but also stdcall so still need wrappers... 122 123 Include generated dispatch table setup function 124*/ 125 126#include "generated_gl_wrappers.c" 127 128/* 129 Special non-static wrapper for glGetString for debug output 130*/ 131 132const GLubyte* glGetStringWrapperNonstatic(GLenum name) 133{ 134 return glGetString(name); 135} 136 137/* 138 Special non-static wrapper for glAddSwapHintRectWIN for copySubBuffers 139*/ 140 141typedef void (__stdcall *PFNGLADDSWAPHINTRECTWIN)(GLint x, GLint y, GLsizei width, GLsizei height); 142 143void glAddSwapHintRectWINWrapperNonstatic(GLint x, GLint y, GLsizei width, GLsizei height) 144{ 145 RESOLVE(PFNGLADDSWAPHINTRECTWIN, "glAddSwapHintRectWIN"); 146 proc(x, y, width, height); 147} 148 149