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 "gldrv.h"
38 #include "stw_nopfuncs.h"
39
40 #include "util/u_debug.h"
41
42 struct stw_extension_entry
43 {
44 const char *name;
45 PROC proc;
46 };
47
48 #define STW_EXTENSION_ENTRY(P) { #P, (PROC) P }
49
50 static const struct stw_extension_entry stw_extension_entries[] = {
51
52 /* WGL_ARB_extensions_string */
53 STW_EXTENSION_ENTRY( wglGetExtensionsStringARB ),
54
55 /* WGL_ARB_pbuffer */
56 STW_EXTENSION_ENTRY( wglCreatePbufferARB ),
57 STW_EXTENSION_ENTRY( wglGetPbufferDCARB ),
58 STW_EXTENSION_ENTRY( wglReleasePbufferDCARB ),
59 STW_EXTENSION_ENTRY( wglDestroyPbufferARB ),
60 STW_EXTENSION_ENTRY( wglQueryPbufferARB ),
61
62 /* WGL_ARB_pixel_format */
63 STW_EXTENSION_ENTRY( wglChoosePixelFormatARB ),
64 STW_EXTENSION_ENTRY( wglGetPixelFormatAttribfvARB ),
65 STW_EXTENSION_ENTRY( wglGetPixelFormatAttribivARB ),
66
67 /* WGL_EXT_extensions_string */
68 STW_EXTENSION_ENTRY( wglGetExtensionsStringEXT ),
69
70 /* WGL_EXT_swap_control */
71 STW_EXTENSION_ENTRY( wglGetSwapIntervalEXT ),
72 STW_EXTENSION_ENTRY( wglSwapIntervalEXT ),
73
74 /* WGL_ARB_create_context */
75 STW_EXTENSION_ENTRY( wglCreateContextAttribsARB ),
76
77 /* WGL_ARB_render_texture */
78 STW_EXTENSION_ENTRY( wglBindTexImageARB ),
79 STW_EXTENSION_ENTRY( wglReleaseTexImageARB ),
80 STW_EXTENSION_ENTRY( wglSetPbufferAttribARB ),
81
82 /* WGL_ARB_make_current_read */
83 STW_EXTENSION_ENTRY( wglMakeContextCurrentARB ),
84 STW_EXTENSION_ENTRY( wglGetCurrentReadDCARB ),
85 { NULL, NULL }
86 };
87
88 PROC APIENTRY
DrvGetProcAddress(LPCSTR lpszProc)89 DrvGetProcAddress(
90 LPCSTR lpszProc )
91 {
92 const struct stw_extension_entry *entry;
93 PROC p;
94
95 if (!stw_dev)
96 return NULL;
97
98 if (lpszProc[0] == 'w' && lpszProc[1] == 'g' && lpszProc[2] == 'l')
99 for (entry = stw_extension_entries; entry->name; entry++)
100 if (strcmp( lpszProc, entry->name ) == 0)
101 return entry->proc;
102
103 if (lpszProc[0] == 'g' && lpszProc[1] == 'l') {
104 p = (PROC) _glapi_get_proc_address(lpszProc);
105 if (p)
106 return p;
107 }
108
109 /* If we get here, we'd normally just return NULL, but since some apps
110 * (like Viewperf12) crash when they try to use the null pointer, try
111 * returning a pointer to a no-op function instead.
112 */
113 p = stw_get_nop_function(lpszProc);
114 if (p) {
115 debug_printf("wglGetProcAddress(\"%s\") returning no-op function\n",
116 lpszProc);
117 return p;
118 }
119
120 debug_printf("wglGetProcAddress(\"%s\") returning NULL\n", lpszProc);
121 return NULL;
122 }
123