3 # $Id: gltable.py,v 1.2 2000/05/11 17:44:42 brianp Exp $
5 # Mesa 3-D graphics library
8 # Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
10 # Permission is hereby granted, free of charge, to any person obtaining a
11 # copy of this software and associated documentation files (the "Software"),
12 # to deal in the Software without restriction, including without limitation
13 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 # and/or sell copies of the Software, and to permit persons to whom the
15 # Software is furnished to do so, subject to the following conditions:
17 # The above copyright notice and this permission notice shall be included
18 # in all copies or substantial portions of the Software.
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 # BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
24 # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 # Generate the glapitable.h file.
31 # gltable.py >glapitable.h
34 # The gl.spec file from the SI must be in the current directory.
36 # Brian Paul 3 February 2000
44 # This table maps types from the gl.spec file to the OpenGL C types.
47 'AttribMask' : 'GLbitfield',
48 'Boolean' : 'GLboolean',
49 'CheckedFloat32' : 'GLfloat',
50 'CheckedInt32' : 'GLint',
51 'ClampedColorF' : 'GLclampf',
52 'ClampedFloat32' : 'GLclampf',
53 'ClampedFloat64' : 'GLclampd',
54 'ClampedStencilValue' : 'GLint',
55 'ClearBufferMask' : 'GLbitfield',
56 'ClientAttribMask' : 'GLbitfield',
58 'ColorD' : 'GLdouble',
61 'ColorIndexValueD' : 'GLdouble',
62 'ColorIndexValueF' : 'GLfloat',
63 'ColorIndexValueI' : 'GLint',
64 'ColorIndexValueS' : 'GLshort',
65 'ColorIndexValueUB' : 'GLubyte',
67 'ColorUB' : 'GLubyte',
69 'ColorUS' : 'GLushort',
71 'CoordD' : 'GLdouble',
74 'FeedbackElement' : 'GLfloat',
75 'Float32' : 'GLfloat',
76 'Float64' : 'GLdouble',
77 'Float32Pointer' : 'GLfloat',
78 'Float64Pointer' : 'GLdouble',
82 'LineStipple' : 'GLushort',
84 'MaskedColorIndexValueF' : 'GLfloat',
85 'MaskedColorIndexValueI' : 'GLuint',
86 'MaskedStencilValue' : 'GLuint',
87 'PixelInternalFormat' : 'GLenum',
88 'SelectName' : 'GLuint',
90 'StencilValue' : 'GLint',
91 'String' : 'const GLubyte *',
92 'TexelInternalFormat' : 'GLint',
93 'TextureComponentCount' : 'GLint',
96 'UInt16' : 'GLushort',
99 'VoidPointer' : 'GLvoid *',
106 # Return C-style argument type string.
107 # Input: t = a type like ListMode, Int16, CoordF, etc.
108 # pointerQual = '' or '*'
109 # constQual = '' or 'const '
110 # Return: a string like "const GLubyte *'
112 def ActualType(t
, pointerQual
, constQual
):
113 if TypeTable
.has_key(t
):
117 if pointerQual
== '':
120 s
= constQual
+ type + ' ' + pointerQual
127 # Convert a Python list of arguments into a string.
129 def ArgListToString(argList
):
134 result
= result
+ pair
[0] + ' ' + pair
[1]
136 result
= result
+ ', '
146 # Return a dispatch table entry, like "void (*Enable)(GLenum cap);"
148 def MakeTableEntry(retType
, funcName
, argList
, offset
):
150 s
= s
+ ActualType(retType
, '', '')
154 s
= s
+ ArgListToString(argList
)
163 def GroupFromCategory(category
):
178 if baseCats
.count(category
) > 0:
181 return 'GL_' + category
186 def PrintGroup(group
):
196 # Parse gl.spec to generate all the function pointers in the dispatch struct.
198 def PrintTableEntries():
199 functionPattern
= re
.compile('^[a-zA-Z0-9]+\(')
200 functionNamePattern
= re
.compile('^[a-zA-Z0-9]+')
210 for line
in f
.readlines():
212 m
= functionPattern
.match(line
)
215 n
= functionNamePattern
.findall(line
)
220 m
= string
.split(line
)
231 if len(m
) >= 5 and m
[4] == 'array':
236 paramType
= ActualType(m
[2], pointerQual
, constQual
)
238 argList
.append( (paramType
, paramName
) )
242 if m
[0] == 'category':
244 group
= GroupFromCategory(category
)
245 if group
!= prevGroup
:
250 # end of function spec
253 #print 'WARNING: skipping', funcName
256 funcOffset
= int(m
[1])
257 if funcOffset
> maxOffset
:
258 maxOffset
= funcOffset
259 #PrintProto(returnType, funcName, argList)
260 s
= MakeTableEntry(returnType
, funcName
, argList
, funcOffset
)
262 table
[funcOffset
] = s
;
268 # Now dump the table, this effectively does the sort by offset number
269 for i
in range(0, maxOffset
+ 1):
278 print '/* DO NOT EDIT - This file generated automatically with gltable.py script */'
279 print '#ifndef _GLAPI_TABLE_H_'
280 print '#define _GLAPI_TABLE_H_'
282 print '#include <GL/gl.h>'
284 print 'struct _glapi_table'