1 ##########################################################################
3 # Copyright 2008-2009 VMware, Inc.
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 ##########################################################################/
29 opengl32 = Dll("opengl32")
30 opengl32.functions += basic_functions(DllFunction)
32 HGLRC = Alias("HGLRC", HANDLE)
44 "PFD_NEED_SYSTEM_PALETTE",
47 "PFD_SWAP_LAYER_BUFFERS",
48 "PFD_GENERIC_ACCELERATED",
49 "PFD_SUPPORT_DIRECTDRAW",
51 "PFD_DOUBLEBUFFER_DONTCARE",
52 "PFD_STEREO_DONTCARE",
55 PIXELFORMATDESCRIPTOR = Struct("PIXELFORMATDESCRIPTOR", [
64 (BYTE, "cGreenShift"),
68 (BYTE, "cAlphaShift"),
70 (BYTE, "cAccumRedBits"),
71 (BYTE, "cAccumGreenBits"),
72 (BYTE, "cAccumBlueBits"),
73 (BYTE, "cAccumAlphaBits"),
75 (BYTE, "cStencilBits"),
76 (BYTE, "cAuxBuffers"),
79 (DWORD, "dwLayerMask"),
80 (DWORD, "dwVisibleMask"),
81 (DWORD, "dwDamageMask"),
84 POINTFLOAT = Struct("POINTFLOAT", [
89 GLYPHMETRICSFLOAT = Struct("GLYPHMETRICSFLOAT", [
90 (FLOAT, "gmfBlackBoxX"),
91 (FLOAT, "gmfBlackBoxY"),
92 (POINTFLOAT, "gmfptGlyphOrigin"),
93 (FLOAT, "gmfCellIncX"),
94 (FLOAT, "gmfCellIncY"),
96 LPGLYPHMETRICSFLOAT = Pointer(GLYPHMETRICSFLOAT)
98 COLORREF = Alias("COLORREF", DWORD)
101 LAYERPLANEDESCRIPTOR = Struct("LAYERPLANEDESCRIPTOR", [
105 (BYTE, "iPixelType"),
106 (BYTE, "cColorBits"),
109 (BYTE, "cGreenBits"),
110 (BYTE, "cGreenShift"),
112 (BYTE, "cBlueShift"),
113 (BYTE, "cAlphaBits"),
114 (BYTE, "cAlphaShift"),
115 (BYTE, "cAccumBits"),
116 (BYTE, "cAccumRedBits"),
117 (BYTE, "cAccumGreenBits"),
118 (BYTE, "cAccumBlueBits"),
119 (BYTE, "cAccumAlphaBits"),
120 (BYTE, "cDepthBits"),
121 (BYTE, "cStencilBits"),
122 (BYTE, "cAuxBuffers"),
123 (BYTE, "iLayerPlane"),
125 (COLORREF, "crTransparent"),
127 LPLAYERPLANEDESCRIPTOR = Pointer(LAYERPLANEDESCRIPTOR)
129 WGLSWAP = Struct("WGLSWAP", [
134 opengl32.functions += [
135 DllFunction(BOOL, "wglCopyContext", [(HGLRC, "hglrcSrc"), (HGLRC, "hglrcDst"), (UINT, "mask")]),
136 DllFunction(HGLRC, "wglCreateContext", [(HDC, "hdc")]),
137 DllFunction(HGLRC, "wglCreateLayerContext", [(HDC, "hdc"), (Int, "iLayerPlane")]),
138 DllFunction(BOOL, "wglDeleteContext", [(HGLRC, "hglrc")]),
139 DllFunction(HGLRC, "wglGetCurrentContext", [], sideeffects=False),
140 DllFunction(HDC, "wglGetCurrentDC", [], sideeffects=False),
141 DllFunction(PROC, "wglGetDefaultProcAddress", [(LPCSTR, "lpszProc")], sideeffects=False),
142 DllFunction(Int, "wglChoosePixelFormat", [(HDC, "hdc"), (Pointer(Const(PIXELFORMATDESCRIPTOR)), "ppfd")]),
143 DllFunction(Int, "wglDescribePixelFormat", [(HDC, "hdc"), (Int, "iPixelFormat"), (UINT, "nBytes"), Out(Pointer(PIXELFORMATDESCRIPTOR), "ppfd")]),
144 DllFunction(Int, "wglGetPixelFormat", [(HDC, "hdc")], sideeffects=False),
145 DllFunction(BOOL, "wglSetPixelFormat", [(HDC, "hdc"), (Int, "iPixelFormat"), (Pointer(Const(PIXELFORMATDESCRIPTOR)), "ppfd")]),
146 DllFunction(BOOL, "wglMakeCurrent", [(HDC, "hdc"), (HGLRC, "hglrc")]),
147 DllFunction(BOOL, "wglShareLists", [(HGLRC, "hglrc1"), (HGLRC, "hglrc2")]),
148 DllFunction(BOOL, "wglUseFontBitmapsA", [(HDC, "hdc"), (DWORD, "first"), (DWORD, "count"), (DWORD, "listBase")]),
149 DllFunction(BOOL, "wglUseFontBitmapsW", [(HDC, "hdc"), (DWORD, "first"), (DWORD, "count"), (DWORD, "listBase")]),
150 DllFunction(BOOL, "wglSwapBuffers", [(HDC, "hdc")]),
151 DllFunction(BOOL, "wglUseFontOutlinesA", [(HDC, "hdc"), (DWORD, "first"), (DWORD, "count"), (DWORD, "listBase"), (FLOAT, "deviation"), (FLOAT, "extrusion"), (Int, "format"), (LPGLYPHMETRICSFLOAT, "lpgmf")]),
152 DllFunction(BOOL, "wglUseFontOutlinesW", [(HDC, "hdc"), (DWORD, "first"), (DWORD, "count"), (DWORD, "listBase"), (FLOAT, "deviation"), (FLOAT, "extrusion"), (Int, "format"), (LPGLYPHMETRICSFLOAT, "lpgmf")]),
153 DllFunction(BOOL , "wglDescribeLayerPlane", [(HDC, "hdc"), (Int, "iPixelFormat"), (Int, "iLayerPlane"), (UINT, "nBytes"), Out(Pointer(LAYERPLANEDESCRIPTOR), "plpd")]),
154 DllFunction(Int , "wglSetLayerPaletteEntries", [(HDC, "hdc"), (Int, "iLayerPlane"), (Int, "iStart"), (Int, "cEntries"), (Array(Const(COLORREF), "cEntries"), "pcr")]),
155 DllFunction(Int , "wglGetLayerPaletteEntries", [(HDC, "hdc"), (Int, "iLayerPlane"), (Int, "iStart"), (Int, "cEntries"), Out(Array(COLORREF, "cEntries"), "pcr")], sideeffects=False),
156 DllFunction(BOOL , "wglRealizeLayerPalette", [(HDC, "hdc"), (Int, "iLayerPlane"), (BOOL, "bRealize")]),
157 DllFunction(BOOL , "wglSwapLayerBuffers", [(HDC, "hdc"), (UINT, "fuPlanes")]),
158 DllFunction(DWORD, "wglSwapMultipleBuffers", [(UINT, "n"), (Array(Const(WGLSWAP), "n"), "ps")]),
162 class WglGetProcAddressFunction(DllFunction):
164 def __init__(self, type, name, args **kwargs):
165 DllFunction.__init__(self, type, name, args **kwargs)
169 for function in self.functions:
171 DllFunction.wrap_decl(self)
174 for function in self.functions:
176 DllFunction.wrap_impl(self)
178 def post_call_impl(self):
179 print ' if(result) {'
180 for function in self.functions:
181 ptype = function.pointer_type()
182 pvalue = function.pointer_value()
183 print ' if(!strcmp("%s", lpszProc)) {' % function.name
184 print ' %s = (%s)result;' % (pvalue, ptype)
185 print ' result = (PROC)&%s;' % function.name;
190 wglgetprocaddress = WglGetProcAddressFunction(PROC, "wglGetProcAddress", [(LPCSTR, "lpszProc")])
191 opengl32.functions.append(wglgetprocaddress)
193 class WglFunction(Function):
195 def get_true_pointer(self):
196 ptype = self.pointer_type()
197 pvalue = self.pointer_value()
198 print ' if(!%s)' % (pvalue,)
201 attribute = FakeEnum(Int, [
202 "WGL_NUMBER_PIXEL_FORMATS_EXT",
203 "WGL_DRAW_TO_WINDOW_EXT",
204 "WGL_DRAW_TO_BITMAP_EXT",
205 "WGL_ACCELERATION_EXT",
206 "WGL_NEED_PALETTE_EXT",
207 "WGL_NEED_SYSTEM_PALETTE_EXT",
208 "WGL_SWAP_LAYER_BUFFERS_EXT",
209 "WGL_SWAP_METHOD_EXT",
210 "WGL_NUMBER_OVERLAYS_EXT",
211 "WGL_NUMBER_UNDERLAYS_EXT",
212 "WGL_TRANSPARENT_EXT",
213 "WGL_TRANSPARENT_VALUE_EXT",
214 "WGL_SHARE_DEPTH_EXT",
215 "WGL_SHARE_STENCIL_EXT",
216 "WGL_SHARE_ACCUM_EXT",
217 "WGL_SUPPORT_GDI_EXT",
218 "WGL_SUPPORT_OPENGL_EXT",
219 "WGL_DOUBLE_BUFFER_EXT",
221 "WGL_PIXEL_TYPE_EXT",
222 "WGL_COLOR_BITS_EXT",
225 "WGL_GREEN_BITS_EXT",
226 "WGL_GREEN_SHIFT_EXT",
228 "WGL_BLUE_SHIFT_EXT",
229 "WGL_ALPHA_BITS_EXT",
230 "WGL_ALPHA_SHIFT_EXT",
231 "WGL_ACCUM_BITS_EXT",
232 "WGL_ACCUM_RED_BITS_EXT",
233 "WGL_ACCUM_GREEN_BITS_EXT",
234 "WGL_ACCUM_BLUE_BITS_EXT",
235 "WGL_ACCUM_ALPHA_BITS_EXT",
236 "WGL_DEPTH_BITS_EXT",
237 "WGL_STENCIL_BITS_EXT",
238 "WGL_AUX_BUFFERS_EXT",
239 "WGL_NO_ACCELERATION_EXT",
240 "WGL_GENERIC_ACCELERATION_EXT",
241 "WGL_FULL_ACCELERATION_EXT",
242 "WGL_SWAP_EXCHANGE_EXT",
244 "WGL_SWAP_UNDEFINED_EXT",
246 "WGL_TYPE_COLORINDEX_EXT",
249 HPBUFFERARB = Alias("HPBUFFERARB", HANDLE)
251 wglgetprocaddress.functions += extended_functions(WglFunction)
253 wglgetprocaddress.functions += [
254 # WGL_ARB_extensions_string
255 WglFunction(Const(String), "wglGetExtensionsStringARB", [(HDC, "hdc")], sideeffects=False),
257 WglFunction(HPBUFFERARB, "wglCreatePbufferARB", [(HDC, "hDC"), (Int, "iPixelFormat"), (Int, "iWidth"), (Int, "iHeight"), (Pointer(Const(Int)), "piAttribList")]),
258 WglFunction(HDC, "wglGetPbufferDCARB", [(HPBUFFERARB, "hPbuffer")], sideeffects=False),
259 WglFunction(Int, "wglReleasePbufferDCARB", [(HPBUFFERARB, "hPbuffer"), (HDC, "hDC")]),
260 WglFunction(BOOL, "wglDestroyPbufferARB", [(HPBUFFERARB, "hPbuffer")]),
261 WglFunction(BOOL, "wglQueryPbufferARB", [(HPBUFFERARB, "hPbuffer"), (Int, "iAttribute"), Out(Pointer(Int), "piValue")]),
262 # WGL_ARB_pixel_format
263 WglFunction(BOOL, "wglGetPixelFormatAttribivARB", [(HDC, "hdc"), (Int, "iPixelFormat"), (Int, "iLayerPlane"), (UINT, "nAttributes"), (Array(attribute, "nAttributes"), "piAttributes"), Out(Array(Int, "nAttributes"), "piValues")], sideeffects=False),
264 WglFunction(BOOL, "wglGetPixelFormatAttribfvARB", [(HDC, "hdc"), (Int, "iPixelFormat"), (Int, "iLayerPlane"), (UINT, "nAttributes"), (Array(attribute, "nAttributes"), "piAttributes"), Out(Array(FLOAT, "nAttributes"), "pfValues")], sideeffects=False),
265 WglFunction(BOOL, "wglChoosePixelFormatARB", [(HDC, "hdc"), (Pointer(Const(Int)), "piAttribIList"), (Pointer(Const(FLOAT)), "pfAttribFList"), (UINT, "nMaxFormats"), Out(Array(Int, "nMaxFormats"), "piFormats"), Out(Pointer(UINT), "nNumFormats")]),
266 # WGL_EXT_extensions_string
267 WglFunction(Const(String), "wglGetExtensionsStringEXT", [], sideeffects=False),
268 # WGL_EXT_pixel_format
269 WglFunction(BOOL, "wglGetPixelFormatAttribivEXT", [(HDC, "hdc"), (Int, "iPixelFormat"), (Int, "iLayerPlane"), (UINT, "nAttributes"), (Array(attribute, "nAttributes"), "piAttributes"), Out(Array(Int, "nAttributes"), "piValues")], sideeffects=False),
270 WglFunction(BOOL, "wglGetPixelFormatAttribfvEXT", [(HDC, "hdc"), (Int, "iPixelFormat"), (Int, "iLayerPlane"), (UINT, "nAttributes"), (Array(attribute, "nAttributes"), "piAttributes"), Out(Array(FLOAT, "nAttributes"), "pfValues")], sideeffects=False),
271 WglFunction(BOOL, "wglChoosePixelFormatEXT", [(HDC, "hdc"), (Pointer(Const(Int)), "piAttribIList"), (Pointer(Const(FLOAT)), "pfAttribFList"), (UINT, "nMaxFormats"), Out(Array(Int, "nMaxFormats"), "piFormats"), Out(Pointer(UINT), "nNumFormats")]),
274 if __name__ == '__main__':
276 print '#define _GDI32_'
278 print '#include <windows.h>'
279 print '#include <tchar.h>'
280 print '#include <GL/gl.h>'
281 print '#include "glext.h"'
282 print '#include "wglext.h"'
284 print '#include "glhelpers.hpp"'
285 print '#include "log.hpp"'
287 print '#ifndef PFD_SUPPORT_DIRECTDRAW'
288 print '#define PFD_SUPPORT_DIRECTDRAW 0x00002000'
290 print '#ifndef PFD_SUPPORT_COMPOSITION'
291 print '#define PFD_SUPPORT_COMPOSITION 0x00008000'
294 print '#ifdef __MINGW32__'
296 print 'typedef struct _WGLSWAP'
299 print ' UINT uiFlags;'
300 print '} WGLSWAP, *PWGLSWAP, FAR *LPWGLSWAP;'
302 print '#define WGL_SWAPMULTIPLE_MAX 16'