]> git.cworth.org Git - apitrace/blob - opengl32.py
Fix glGenBuffersARB spec.
[apitrace] / opengl32.py
1 ##########################################################################
2 #
3 # Copyright 2008-2009 VMware, Inc.
4 # All Rights Reserved.
5 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
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
22 # THE SOFTWARE.
23 #
24 ##########################################################################/
25
26 from gl import *
27 from windows import *
28
29 opengl32 = Dll("opengl32")
30 opengl32.functions += basic_functions(DllFunction)
31
32 HGLRC = Alias("HGLRC", HANDLE)
33 PROC = Opaque("PROC")
34
35 PFD = 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",
49     "PFD_SUPPORT_DIRECTDRAW",
50     "PFD_DEPTH_DONTCARE",
51     "PFD_DOUBLEBUFFER_DONTCARE",
52     "PFD_STEREO_DONTCARE",
53 ])
54
55 PIXELFORMATDESCRIPTOR = Struct("PIXELFORMATDESCRIPTOR", [
56     (WORD, "nSize"),
57     (WORD, "nVersion"),
58     (PFD, "dwFlags"),
59     (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
84 POINTFLOAT = Struct("POINTFLOAT", [
85     (FLOAT, "x"),
86     (FLOAT, "y"),
87 ])
88
89 GLYPHMETRICSFLOAT = Struct("GLYPHMETRICSFLOAT", [
90     (FLOAT, "gmfBlackBoxX"),
91     (FLOAT, "gmfBlackBoxY"),
92     (POINTFLOAT, "gmfptGlyphOrigin"),
93     (FLOAT, "gmfCellIncX"),
94     (FLOAT, "gmfCellIncY"),
95 ])
96 LPGLYPHMETRICSFLOAT = Pointer(GLYPHMETRICSFLOAT)
97
98 COLORREF = Alias("COLORREF", DWORD)
99
100
101 LAYERPLANEDESCRIPTOR = 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 ])
127 LPLAYERPLANEDESCRIPTOR = Pointer(LAYERPLANEDESCRIPTOR)
128
129 WGLSWAP = Struct("WGLSWAP", [
130    (HDC, "hdc"),
131     (UINT, "uiFlags"),
132 ])
133
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")]),
159 ]
160
161
162 class WglGetProcAddressFunction(DllFunction):
163
164     def __init__(self, type, name, args, **kwargs):
165         DllFunction.__init__(self, type, name, args, **kwargs)
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):
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;
186             print '        }'
187         print '    }'
188
189
190 wglgetprocaddress = WglGetProcAddressFunction(PROC, "wglGetProcAddress", [(LPCSTR, "lpszProc")])
191 opengl32.functions.append(wglgetprocaddress)
192
193 class 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
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",
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
249 HPBUFFERARB = Alias("HPBUFFERARB", HANDLE)
250
251 wglgetprocaddress.functions += extended_functions(WglFunction)
252
253 wglgetprocaddress.functions += [
254     # WGL_ARB_extensions_string
255     WglFunction(Const(String), "wglGetExtensionsStringARB", [(HDC, "hdc")], sideeffects=False),
256     # 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")], 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")]),
272 ]
273
274 if __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>'
281     print '#include "glext.h"'
282     print '#include "wglext.h"'
283     print
284     print '#include "glhelpers.hpp"'
285     print '#include "log.hpp"'
286     print
287     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
294     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
306     print 'extern "C" {'
307     print
308     wrap()
309     print
310     print '}'