Remove ENABLE_* flags, ctx->_Enabled.
[mesa.git] / src / mesa / glapi / gltable.py
1 #!/usr/bin/env python
2
3 # $Id: gltable.py,v 1.2 2000/05/11 17:44:42 brianp Exp $
4
5 # Mesa 3-D graphics library
6 # Version: 3.3
7 #
8 # Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
9 #
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:
16 #
17 # The above copyright notice and this permission notice shall be included
18 # in all copies or substantial portions of the Software.
19 #
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.
26
27
28 # Generate the glapitable.h file.
29 #
30 # Usage:
31 # gltable.py >glapitable.h
32 #
33 # Dependencies:
34 # The gl.spec file from the SI must be in the current directory.
35 #
36 # Brian Paul 3 February 2000
37
38
39 import string
40 import re
41
42
43 #
44 # This table maps types from the gl.spec file to the OpenGL C types.
45 #
46 TypeTable = {
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',
57 'ColorB' : 'GLbyte',
58 'ColorD' : 'GLdouble',
59 'ColorF' : 'GLfloat',
60 'ColorI' : 'GLint',
61 'ColorIndexValueD' : 'GLdouble',
62 'ColorIndexValueF' : 'GLfloat',
63 'ColorIndexValueI' : 'GLint',
64 'ColorIndexValueS' : 'GLshort',
65 'ColorIndexValueUB' : 'GLubyte',
66 'ColorS' : 'GLshort',
67 'ColorUB' : 'GLubyte',
68 'ColorUI' : 'GLuint',
69 'ColorUS' : 'GLushort',
70 'CoordF' : 'GLfloat',
71 'CoordD' : 'GLdouble',
72 'CoordI' : 'GLint',
73 'CoordS' : 'GLshort',
74 'FeedbackElement' : 'GLfloat',
75 'Float32' : 'GLfloat',
76 'Float64' : 'GLdouble',
77 'Float32Pointer' : 'GLfloat',
78 'Float64Pointer' : 'GLdouble',
79 'Int8' : 'GLbyte',
80 'Int16' : 'GLshort',
81 'Int32' : 'GLint',
82 'LineStipple' : 'GLushort',
83 'List' : 'GLuint',
84 'MaskedColorIndexValueF' : 'GLfloat',
85 'MaskedColorIndexValueI' : 'GLuint',
86 'MaskedStencilValue' : 'GLuint',
87 'PixelInternalFormat' : 'GLenum',
88 'SelectName' : 'GLuint',
89 'SizeI' : 'GLsizei',
90 'StencilValue' : 'GLint',
91 'String' : 'const GLubyte *',
92 'TexelInternalFormat' : 'GLint',
93 'TextureComponentCount' : 'GLint',
94 'WinCoord' : 'GLint',
95 'UInt8' : 'GLubyte',
96 'UInt16' : 'GLushort',
97 'UInt32' : 'GLuint',
98 'Void' : 'GLvoid',
99 'VoidPointer' : 'GLvoid *',
100 'void' : 'void',
101 }
102
103
104
105 #
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 *'
111 #
112 def ActualType(t, pointerQual, constQual):
113 if TypeTable.has_key(t):
114 type = TypeTable[t]
115 else:
116 type = 'GLenum'
117 if pointerQual == '':
118 s = constQual + type
119 else:
120 s = constQual + type + ' ' + pointerQual
121 return s
122 #enddef
123
124
125
126 #
127 # Convert a Python list of arguments into a string.
128 #
129 def ArgListToString(argList):
130 result = ''
131 i = 1
132 n = len(argList)
133 for pair in argList:
134 result = result + pair[0] + ' ' + pair[1]
135 if i < n:
136 result = result + ', '
137 i = i + 1
138
139 if result == '':
140 result = 'void'
141 return result
142 #enddef
143
144
145 #
146 # Return a dispatch table entry, like "void (*Enable)(GLenum cap);"
147 #
148 def MakeTableEntry(retType, funcName, argList, offset):
149 s = ' '
150 s = s + ActualType(retType, '', '')
151 s = s + ' (*'
152 s = s + funcName
153 s = s + ')('
154 s = s + ArgListToString(argList)
155 s = s + '); /* '
156 s = s + str(offset)
157 s = s + ' */'
158 return s
159 #enddef
160
161
162
163 def GroupFromCategory(category):
164 baseCats = [
165 'display-list',
166 'drawing',
167 'drawing-control',
168 'feedback',
169 'framebuf',
170 'misc',
171 'modeling',
172 'pixel-op',
173 'pixel-rw',
174 'state-req',
175 'xform'
176 ]
177
178 if baseCats.count(category) > 0:
179 return 'GL_1_0'
180 else:
181 return 'GL_' + category
182 #endif
183 #endif
184
185
186 def PrintGroup(group):
187 s = ' /* '
188 s = s + group
189 s = s + ' */'
190 print s
191 #enddef
192
193
194
195 #
196 # Parse gl.spec to generate all the function pointers in the dispatch struct.
197 #
198 def PrintTableEntries():
199 functionPattern = re.compile('^[a-zA-Z0-9]+\(')
200 functionNamePattern = re.compile('^[a-zA-Z0-9]+')
201
202 prevGroup = ''
203 funcName = ''
204 returnType = ''
205 argList = [ ]
206 maxOffset = 0
207 table = { }
208
209 f = open('gl.spec')
210 for line in f.readlines():
211
212 m = functionPattern.match(line)
213 if m:
214 # extract funcName
215 n = functionNamePattern.findall(line)
216 funcName = n[0]
217 argList = [ ]
218 #endif
219
220 m = string.split(line)
221 if len(m) > 1:
222 # return datatype
223 if m[0] == 'return':
224 returnType = m[1]
225 #endif
226
227 # function parameter
228 if m[0] == 'param':
229 constQual = ''
230 pointerQual = ''
231 if len(m) >= 5 and m[4] == 'array':
232 pointerQual = '*'
233 if m[3] == 'in':
234 constQual = 'const '
235 paramName = m[1]
236 paramType = ActualType(m[2], pointerQual, constQual)
237
238 argList.append( (paramType, paramName) )
239 #endif
240
241 # # category
242 if m[0] == 'category':
243 category = m[1]
244 group = GroupFromCategory(category)
245 if group != prevGroup:
246 # PrintGroup(group)
247 prevGroup = group
248 #endif
249
250 # end of function spec
251 if m[0] == 'offset':
252 if m[1] == '?':
253 #print 'WARNING: skipping', funcName
254 noop = 0
255 else:
256 funcOffset = int(m[1])
257 if funcOffset > maxOffset:
258 maxOffset = funcOffset
259 #PrintProto(returnType, funcName, argList)
260 s = MakeTableEntry(returnType, funcName, argList, funcOffset)
261 # print s
262 table[funcOffset] = s;
263 #endif
264 #endif
265 #endif
266 #endfor
267
268 # Now dump the table, this effectively does the sort by offset number
269 for i in range(0, maxOffset + 1):
270 if table.has_key(i):
271 print table[i]
272
273 #enddef
274
275
276
277 def PrintHead():
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_'
281 print ''
282 print '#include <GL/gl.h>'
283 print ''
284 print 'struct _glapi_table'
285 print '{'
286 return
287 #endif
288
289
290 def PrintTail():
291 print '};'
292 print ''
293 print '#endif'
294 #endif
295
296
297
298 PrintHead()
299 PrintTableEntries()
300 PrintTail()