stw: use new stw_get_nop_function() function to avoid Viewperf 12 crashes
[mesa.git] / src / gallium / state_trackers / wgl / stw_getprocaddress.c
1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include <windows.h>
29
30 #define WGL_WGLEXT_PROTOTYPES
31
32 #include <GL/gl.h>
33 #include <GL/wglext.h>
34
35 #include "glapi/glapi.h"
36 #include "stw_device.h"
37 #include "stw_icd.h"
38 #include "stw_nopfuncs.h"
39
40 struct stw_extension_entry
41 {
42 const char *name;
43 PROC proc;
44 };
45
46 #define STW_EXTENSION_ENTRY(P) { #P, (PROC) P }
47
48 static const struct stw_extension_entry stw_extension_entries[] = {
49
50 /* WGL_ARB_extensions_string */
51 STW_EXTENSION_ENTRY( wglGetExtensionsStringARB ),
52
53 /* WGL_ARB_pbuffer */
54 STW_EXTENSION_ENTRY( wglCreatePbufferARB ),
55 STW_EXTENSION_ENTRY( wglGetPbufferDCARB ),
56 STW_EXTENSION_ENTRY( wglReleasePbufferDCARB ),
57 STW_EXTENSION_ENTRY( wglDestroyPbufferARB ),
58 STW_EXTENSION_ENTRY( wglQueryPbufferARB ),
59
60 /* WGL_ARB_pixel_format */
61 STW_EXTENSION_ENTRY( wglChoosePixelFormatARB ),
62 STW_EXTENSION_ENTRY( wglGetPixelFormatAttribfvARB ),
63 STW_EXTENSION_ENTRY( wglGetPixelFormatAttribivARB ),
64
65 /* WGL_EXT_extensions_string */
66 STW_EXTENSION_ENTRY( wglGetExtensionsStringEXT ),
67
68 /* WGL_EXT_swap_interval */
69 STW_EXTENSION_ENTRY( wglGetSwapIntervalEXT ),
70 STW_EXTENSION_ENTRY( wglSwapIntervalEXT ),
71
72 /* WGL_ARB_create_context */
73 STW_EXTENSION_ENTRY( wglCreateContextAttribsARB ),
74
75 { NULL, NULL }
76 };
77
78 PROC APIENTRY
79 DrvGetProcAddress(
80 LPCSTR lpszProc )
81 {
82 const struct stw_extension_entry *entry;
83 PROC p;
84
85 if (!stw_dev)
86 return NULL;
87
88 if (lpszProc[0] == 'w' && lpszProc[1] == 'g' && lpszProc[2] == 'l')
89 for (entry = stw_extension_entries; entry->name; entry++)
90 if (strcmp( lpszProc, entry->name ) == 0)
91 return entry->proc;
92
93 if (lpszProc[0] == 'g' && lpszProc[1] == 'l') {
94 p = (PROC) _glapi_get_proc_address(lpszProc);
95 if (p)
96 return p;
97 }
98
99 /* If we get here, we'd normally just return NULL, but since some apps
100 * (like Viewperf12) crash when they try to use the null pointer, try
101 * returning a pointer to a no-op function instead.
102 */
103 p = stw_get_nop_function(lpszProc);
104 if (p) {
105 debug_printf("wglGetProcAddress(\"%s\") returning no-op function\n",
106 lpszProc);
107 return p;
108 }
109
110 debug_printf("wglGetProcAddress(\"%s\") returning NULL\n", lpszProc);
111 return NULL;
112 }