blob: ceb5ccc1cd094eaea101a0bc08365fed493b24c5 [file] [log] [blame]
José Fonseca7ad40262009-09-30 17:17:12 +01001##########################################################################
José Fonseca36e25aa2009-04-13 14:08:08 +01002#
José Fonseca7ad40262009-09-30 17:17:12 +01003# Copyright 2008-2009 VMware, Inc.
4# All Rights Reserved.
José Fonseca36e25aa2009-04-13 14:08:08 +01005#
José Fonseca7ad40262009-09-30 17:17:12 +01006# 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:
José Fonseca36e25aa2009-04-13 14:08:08 +010012#
José Fonseca7ad40262009-09-30 17:17:12 +010013# The above copyright notice and this permission notice shall be included in
14# all copies or substantial portions of the Software.
José Fonseca36e25aa2009-04-13 14:08:08 +010015#
José Fonseca7ad40262009-09-30 17:17:12 +010016# 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
22# THE SOFTWARE.
José Fonseca36e25aa2009-04-13 14:08:08 +010023#
José Fonseca7ad40262009-09-30 17:17:12 +010024##########################################################################/
José Fonseca36e25aa2009-04-13 14:08:08 +010025
26from gl import *
27from windows import *
28
29opengl32 = Dll("opengl32")
José Fonseca2defc982010-11-22 16:59:10 +000030opengl32.functions += basic_functions(DllFunction)
José Fonseca36e25aa2009-04-13 14:08:08 +010031
32HGLRC = Alias("HGLRC", HANDLE)
José Fonsecaf6592d72010-11-21 12:44:41 +000033PROC = Opaque("PROC")
José Fonseca36e25aa2009-04-13 14:08:08 +010034
José Fonseca0fae9702009-04-30 12:42:36 +010035PFD = Flags(DWORD, [
36 "PFD_DOUBLEBUFFER",
37 "PFD_STEREO",
38 "PFD_DRAW_TO_WINDOW",
39 "PFD_DRAW_TO_BITMAP",
40 "PFD_SUPPORT_GDI",
41 "PFD_SUPPORT_OPENGL",
42 "PFD_GENERIC_FORMAT",
43 "PFD_NEED_PALETTE",
44 "PFD_NEED_SYSTEM_PALETTE",
45 "PFD_SWAP_EXCHANGE",
46 "PFD_SWAP_COPY",
47 "PFD_SWAP_LAYER_BUFFERS",
48 "PFD_GENERIC_ACCELERATED",
José Fonsecacd57a402010-04-06 15:09:26 +010049 "PFD_SUPPORT_DIRECTDRAW",
50 "PFD_DEPTH_DONTCARE",
51 "PFD_DOUBLEBUFFER_DONTCARE",
52 "PFD_STEREO_DONTCARE",
José Fonseca0fae9702009-04-30 12:42:36 +010053])
54
José Fonseca36e25aa2009-04-13 14:08:08 +010055PIXELFORMATDESCRIPTOR = Struct("PIXELFORMATDESCRIPTOR", [
56 (WORD, "nSize"),
57 (WORD, "nVersion"),
José Fonseca0fae9702009-04-30 12:42:36 +010058 (PFD, "dwFlags"),
José Fonseca36e25aa2009-04-13 14:08:08 +010059 (BYTE, "iPixelType"),
60 (BYTE, "cColorBits"),
61 (BYTE, "cRedBits"),
62 (BYTE, "cRedShift"),
63 (BYTE, "cGreenBits"),
64 (BYTE, "cGreenShift"),
65 (BYTE, "cBlueBits"),
66 (BYTE, "cBlueShift"),
67 (BYTE, "cAlphaBits"),
68 (BYTE, "cAlphaShift"),
69 (BYTE, "cAccumBits"),
70 (BYTE, "cAccumRedBits"),
71 (BYTE, "cAccumGreenBits"),
72 (BYTE, "cAccumBlueBits"),
73 (BYTE, "cAccumAlphaBits"),
74 (BYTE, "cDepthBits"),
75 (BYTE, "cStencilBits"),
76 (BYTE, "cAuxBuffers"),
77 (BYTE, "iLayerType"),
78 (BYTE, "bReserved"),
79 (DWORD, "dwLayerMask"),
80 (DWORD, "dwVisibleMask"),
81 (DWORD, "dwDamageMask"),
82])
83
84POINTFLOAT = Struct("POINTFLOAT", [
85 (FLOAT, "x"),
86 (FLOAT, "y"),
87])
88
89GLYPHMETRICSFLOAT = Struct("GLYPHMETRICSFLOAT", [
90 (FLOAT, "gmfBlackBoxX"),
91 (FLOAT, "gmfBlackBoxY"),
92 (POINTFLOAT, "gmfptGlyphOrigin"),
93 (FLOAT, "gmfCellIncX"),
94 (FLOAT, "gmfCellIncY"),
95])
96LPGLYPHMETRICSFLOAT = Pointer(GLYPHMETRICSFLOAT)
97
98COLORREF = Alias("COLORREF", DWORD)
José Fonseca0fae9702009-04-30 12:42:36 +010099
100
José Fonseca36e25aa2009-04-13 14:08:08 +0100101LAYERPLANEDESCRIPTOR = Struct("LAYERPLANEDESCRIPTOR", [
102 (WORD, "nSize"),
103 (WORD, "nVersion"),
104 (DWORD, "dwFlags"),
105 (BYTE, "iPixelType"),
106 (BYTE, "cColorBits"),
107 (BYTE, "cRedBits"),
108 (BYTE, "cRedShift"),
109 (BYTE, "cGreenBits"),
110 (BYTE, "cGreenShift"),
111 (BYTE, "cBlueBits"),
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"),
124 (BYTE, "bReserved"),
125 (COLORREF, "crTransparent"),
126])
127LPLAYERPLANEDESCRIPTOR = Pointer(LAYERPLANEDESCRIPTOR)
128
José Fonseca2d034632010-02-13 11:51:49 +0000129WGLSWAP = Struct("WGLSWAP", [
130 (HDC, "hdc"),
131 (UINT, "uiFlags"),
132])
133
José Fonseca36e25aa2009-04-13 14:08:08 +0100134opengl32.functions += [
José Fonseca3c2c9292009-05-04 12:16:30 +0100135 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", []),
140 DllFunction(HDC, "wglGetCurrentDC", []),
José Fonseca3c2c9292009-05-04 12:16:30 +0100141 DllFunction(PROC, "wglGetDefaultProcAddress", [(LPCSTR, "lpszProc")]),
142 DllFunction(Int, "wglChoosePixelFormat", [(HDC, "hdc"), (Pointer(Const(PIXELFORMATDESCRIPTOR)), "ppfd")]),
José Fonsecac9096f02010-11-22 13:02:26 +0000143 DllFunction(Int, "wglDescribePixelFormat", [(HDC, "hdc"), (Int, "iPixelFormat"), (UINT, "nBytes"), Out(Pointer(PIXELFORMATDESCRIPTOR), "ppfd")]),
José Fonseca3c2c9292009-05-04 12:16:30 +0100144 DllFunction(Int, "wglGetPixelFormat", [(HDC, "hdc")]),
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")]),
José Fonsecac9096f02010-11-22 13:02:26 +0000153 DllFunction(BOOL , "wglDescribeLayerPlane", [(HDC, "hdc"), (Int, "iPixelFormat"), (Int, "iLayerPlane"), (UINT, "nBytes"), Out(Pointer(LAYERPLANEDESCRIPTOR), "plpd")]),
José Fonseca2defc982010-11-22 16:59:10 +0000154 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")]),
José Fonseca3c2c9292009-05-04 12:16:30 +0100156 DllFunction(BOOL , "wglRealizeLayerPalette", [(HDC, "hdc"), (Int, "iLayerPlane"), (BOOL, "bRealize")]),
157 DllFunction(BOOL , "wglSwapLayerBuffers", [(HDC, "hdc"), (UINT, "fuPlanes")]),
José Fonseca2defc982010-11-22 16:59:10 +0000158 DllFunction(DWORD, "wglSwapMultipleBuffers", [(UINT, "n"), (Array(Const(WGLSWAP), "n"), "ps")]),
José Fonseca36e25aa2009-04-13 14:08:08 +0100159]
160
José Fonsecac77023d2009-05-04 12:53:50 +0100161
162class WglGetProcAddressFunction(DllFunction):
163
164 def __init__(self, type, name, args):
165 DllFunction.__init__(self, type, name, args)
166 self.functions = []
167
168 def wrap_decl(self):
169 for function in self.functions:
170 function.wrap_decl()
171 DllFunction.wrap_decl(self)
172
173 def wrap_impl(self):
174 for function in self.functions:
175 function.wrap_impl()
176 DllFunction.wrap_impl(self)
177
178 def post_call_impl(self):
José Fonseca355a8fa2009-05-04 22:34:38 +0100179 print ' if(result) {'
José Fonsecac77023d2009-05-04 12:53:50 +0100180 for function in self.functions:
181 ptype = function.pointer_type()
182 pvalue = function.pointer_value()
José Fonseca355a8fa2009-05-04 22:34:38 +0100183 print ' if(!strcmp("%s", lpszProc)) {' % function.name
184 print ' %s = (%s)result;' % (pvalue, ptype)
185 print ' result = (PROC)&%s;' % function.name;
186 print ' }'
187 print ' }'
José Fonsecac77023d2009-05-04 12:53:50 +0100188
189
190wglgetprocaddress = WglGetProcAddressFunction(PROC, "wglGetProcAddress", [(LPCSTR, "lpszProc")])
191opengl32.functions.append(wglgetprocaddress)
192
193class WglFunction(Function):
194
195 def get_true_pointer(self):
196 ptype = self.pointer_type()
197 pvalue = self.pointer_value()
198 print ' if(!%s)' % (pvalue,)
199 self.fail_impl()
200
José Fonseca7c1d2332009-05-04 22:34:59 +0100201attribute = 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",
220 "WGL_STEREO_EXT",
221 "WGL_PIXEL_TYPE_EXT",
222 "WGL_COLOR_BITS_EXT",
223 "WGL_RED_BITS_EXT",
224 "WGL_RED_SHIFT_EXT",
225 "WGL_GREEN_BITS_EXT",
226 "WGL_GREEN_SHIFT_EXT",
227 "WGL_BLUE_BITS_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",
243 "WGL_SWAP_COPY_EXT",
244 "WGL_SWAP_UNDEFINED_EXT",
245 "WGL_TYPE_RGBA_EXT",
246 "WGL_TYPE_COLORINDEX_EXT",
247])
248
José Fonseca3eb4c942009-11-30 16:03:34 +0000249HPBUFFERARB = Alias("HPBUFFERARB", HANDLE)
250
José Fonseca2defc982010-11-22 16:59:10 +0000251wglgetprocaddress.functions += extended_functions(WglFunction)
252
José Fonsecac77023d2009-05-04 12:53:50 +0100253wglgetprocaddress.functions += [
José Fonseca7c1d2332009-05-04 22:34:59 +0100254 # WGL_ARB_extensions_string
José Fonsecac77023d2009-05-04 12:53:50 +0100255 WglFunction(Const(String), "wglGetExtensionsStringARB", [(HDC, "hdc")]),
José Fonseca3eb4c942009-11-30 16:03:34 +0000256 # WGL_ARB_pbuffer
257 WglFunction(HPBUFFERARB, "wglCreatePbufferARB", [(HDC, "hDC"), (Int, "iPixelFormat"), (Int, "iWidth"), (Int, "iHeight"), (Pointer(Const(Int)), "piAttribList")]),
258 WglFunction(HDC, "wglGetPbufferDCARB", [(HPBUFFERARB, "hPbuffer")]),
259 WglFunction(Int, "wglReleasePbufferDCARB", [(HPBUFFERARB, "hPbuffer"), (HDC, "hDC")]),
260 WglFunction(BOOL, "wglDestroyPbufferARB", [(HPBUFFERARB, "hPbuffer")]),
José Fonseca2defc982010-11-22 16:59:10 +0000261 WglFunction(BOOL, "wglQueryPbufferARB", [(HPBUFFERARB, "hPbuffer"), (Int, "iAttribute"), Out(Pointer(Int), "piValue")]),
José Fonseca1eac39b2009-06-30 19:47:38 +0100262 # WGL_ARB_pixel_format
José Fonseca2defc982010-11-22 16:59:10 +0000263 WglFunction(BOOL, "wglGetPixelFormatAttribivARB", [(HDC, "hdc"), (Int, "iPixelFormat"), (Int, "iLayerPlane"), (UINT, "nAttributes"), (Array(attribute, "nAttributes"), "piAttributes"), Out(Array(Int, "nAttributes"), "piValues")]),
264 WglFunction(BOOL, "wglGetPixelFormatAttribfvARB", [(HDC, "hdc"), (Int, "iPixelFormat"), (Int, "iLayerPlane"), (UINT, "nAttributes"), (Array(attribute, "nAttributes"), "piAttributes"), Out(Array(FLOAT, "nAttributes"), "pfValues")]),
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")]),
José Fonseca7c1d2332009-05-04 22:34:59 +0100266 # WGL_EXT_extensions_string
267 WglFunction(Const(String), "wglGetExtensionsStringEXT", []),
268 # WGL_EXT_pixel_format
José Fonseca2defc982010-11-22 16:59:10 +0000269 WglFunction(BOOL, "wglGetPixelFormatAttribivEXT", [(HDC, "hdc"), (Int, "iPixelFormat"), (Int, "iLayerPlane"), (UINT, "nAttributes"), (Array(attribute, "nAttributes"), "piAttributes"), Out(Array(Int, "nAttributes"), "piValues")]),
270 WglFunction(BOOL, "wglGetPixelFormatAttribfvEXT", [(HDC, "hdc"), (Int, "iPixelFormat"), (Int, "iLayerPlane"), (UINT, "nAttributes"), (Array(attribute, "nAttributes"), "piAttributes"), Out(Array(FLOAT, "nAttributes"), "pfValues")]),
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")]),
José Fonsecac77023d2009-05-04 12:53:50 +0100272]
273
José Fonseca36e25aa2009-04-13 14:08:08 +0100274if __name__ == '__main__':
275 print
276 print '#define _GDI32_'
277 print
278 print '#include <windows.h>'
279 print '#include <tchar.h>'
280 print '#include <GL/gl.h>'
José Fonsecaed9c0162009-05-04 10:51:42 +0100281 print '#include "glext.h"'
282 print '#include "wglext.h"'
José Fonseca36e25aa2009-04-13 14:08:08 +0100283 print
José Fonseca2defc982010-11-22 16:59:10 +0000284 print '#include "glhelpers.hpp"'
José Fonseca36e25aa2009-04-13 14:08:08 +0100285 print '#include "log.hpp"'
286 print
José Fonsecacd57a402010-04-06 15:09:26 +0100287 print '#ifndef PFD_SUPPORT_DIRECTDRAW'
288 print '#define PFD_SUPPORT_DIRECTDRAW 0x00002000'
289 print '#endif'
290 print '#ifndef PFD_SUPPORT_COMPOSITION'
291 print '#define PFD_SUPPORT_COMPOSITION 0x00008000'
292 print '#endif'
293 print
José Fonseca2d034632010-02-13 11:51:49 +0000294 print '#ifdef __MINGW32__'
295 print ''
296 print 'typedef struct _WGLSWAP'
297 print '{'
298 print ' HDC hdc;'
299 print ' UINT uiFlags;'
300 print '} WGLSWAP, *PWGLSWAP, FAR *LPWGLSWAP;'
301 print ''
302 print '#define WGL_SWAPMULTIPLE_MAX 16'
303 print ''
304 print '#endif'
305 print
José Fonseca2272ecd2009-05-04 10:24:12 +0100306 print 'extern "C" {'
307 print
José Fonseca36e25aa2009-04-13 14:08:08 +0100308 wrap()
José Fonseca2272ecd2009-05-04 10:24:12 +0100309 print
310 print '}'