1 | # Copyright (c) 2001, Stanford University
|
---|
2 | # All rights reserved.
|
---|
3 | #
|
---|
4 | # See the file LICENSE.txt for information on redistributing this software.
|
---|
5 |
|
---|
6 | import sys
|
---|
7 | curver = sys.version_info[0] + sys.version_info[1]/10.0
|
---|
8 | if curver < 2.2:
|
---|
9 | print >>sys.stderr, "Your python is version %g. Chromium requires at least"%(curver)
|
---|
10 | print >>sys.stderr, "version 2.2. Please upgrade your python installation."
|
---|
11 | sys.exit(1)
|
---|
12 |
|
---|
13 | import string;
|
---|
14 | import re;
|
---|
15 |
|
---|
16 | def CopyrightC( ):
|
---|
17 | print """/* Copyright (c) 2001, Stanford University
|
---|
18 | All rights reserved.
|
---|
19 |
|
---|
20 | See the file LICENSE.txt for information on redistributing this software. */
|
---|
21 | """
|
---|
22 |
|
---|
23 | def CopyrightDef( ):
|
---|
24 | print """; Copyright (c) 2001, Stanford University
|
---|
25 | ; All rights reserved.
|
---|
26 | ;
|
---|
27 | ; See the file LICENSE.txt for information on redistributing this software.
|
---|
28 | """
|
---|
29 |
|
---|
30 | def DecoderName( glName ):
|
---|
31 | return "crUnpack" + glName
|
---|
32 |
|
---|
33 | def OpcodeName( glName ):
|
---|
34 | # This is a bit of a hack. We want to implement the glVertexAttrib*NV
|
---|
35 | # functions in terms of the glVertexAttrib*ARB opcodes.
|
---|
36 | m = re.search( "VertexAttrib([1234](ub|b|us|s|ui|i|f|d|)v?)NV", glName )
|
---|
37 | if m:
|
---|
38 | dataType = m.group(1)
|
---|
39 | if dataType == "4ub":
|
---|
40 | dataType = "4Nub"
|
---|
41 | elif dataType == "4ubv":
|
---|
42 | dataType = "4Nubv"
|
---|
43 | glName = "VertexAttrib" + dataType + "ARB"
|
---|
44 | return "CR_" + string.upper( glName ) + "_OPCODE"
|
---|
45 |
|
---|
46 | def ExtendedOpcodeName( glName ):
|
---|
47 | return "CR_" + string.upper( glName ) + "_EXTEND_OPCODE"
|
---|
48 |
|
---|
49 | def PackFunction( glName ):
|
---|
50 | return "crPack" + glName
|
---|
51 |
|
---|
52 | def DoPackFunctionMapping( glName ):
|
---|
53 | return "__glpack_" + glName
|
---|
54 |
|
---|
55 | def DoStateFunctionMapping( glName ):
|
---|
56 | return "__glstate_" + glName
|
---|
57 |
|
---|
58 | def DoImmediateMapping( glName ):
|
---|
59 | return "__glim_" + glName
|
---|
60 |
|
---|
61 |
|
---|
62 |
|
---|
63 | # Annotations are a generalization of Specials (below).
|
---|
64 | # Each line of an annotation file is a set of words.
|
---|
65 | # The first word is a key; the remainder are all annotations
|
---|
66 | # for that key. This is a useful model for grouping keys
|
---|
67 | # (like GL function names) into overlapping subsets, all in
|
---|
68 | # a single file.
|
---|
69 | annotations = {}
|
---|
70 | def LoadAnnotations(filename):
|
---|
71 | table = {}
|
---|
72 | try:
|
---|
73 | f = open(filename, "r")
|
---|
74 | except:
|
---|
75 | annotations[filename] = {}
|
---|
76 | return {}
|
---|
77 |
|
---|
78 | for line in f.readlines():
|
---|
79 | line = line.strip()
|
---|
80 | if line == "" or line[0] == '#':
|
---|
81 | continue
|
---|
82 | subtable = {}
|
---|
83 | words = line.split()
|
---|
84 | for word in words[1:]:
|
---|
85 | subtable[word] = 1
|
---|
86 | table[words[0]] = subtable
|
---|
87 |
|
---|
88 | annotations[filename] = table
|
---|
89 | return table
|
---|
90 |
|
---|
91 | def GetAnnotations( filename, key ):
|
---|
92 | table = {}
|
---|
93 | try:
|
---|
94 | table = annotations[filename]
|
---|
95 | except KeyError:
|
---|
96 | table = LoadAnnotations(filename)
|
---|
97 |
|
---|
98 | try:
|
---|
99 | subtable = table[key]
|
---|
100 | except KeyError:
|
---|
101 | return []
|
---|
102 |
|
---|
103 | keys = subtable.keys()
|
---|
104 | keys.sort()
|
---|
105 | return keys
|
---|
106 |
|
---|
107 | def FindAnnotation( filename, key, subkey ):
|
---|
108 | table = {}
|
---|
109 | try:
|
---|
110 | table = annotations[filename]
|
---|
111 | except KeyError:
|
---|
112 | table = LoadAnnotations(filename)
|
---|
113 |
|
---|
114 | try:
|
---|
115 | subtable = table[key]
|
---|
116 | except KeyError:
|
---|
117 | return 0
|
---|
118 |
|
---|
119 | try:
|
---|
120 | return subtable[subkey]
|
---|
121 | except KeyError:
|
---|
122 | return 0
|
---|
123 |
|
---|
124 |
|
---|
125 |
|
---|
126 | specials = {}
|
---|
127 |
|
---|
128 | def LoadSpecials( filename ):
|
---|
129 | table = {}
|
---|
130 | try:
|
---|
131 | f = open( filename, "r" )
|
---|
132 | except:
|
---|
133 | specials[filename] = {}
|
---|
134 | return {}
|
---|
135 |
|
---|
136 | for line in f.readlines():
|
---|
137 | line = string.strip(line)
|
---|
138 | if line == "" or line[0] == '#':
|
---|
139 | continue
|
---|
140 | table[line] = 1
|
---|
141 |
|
---|
142 | specials[filename] = table
|
---|
143 | return table
|
---|
144 |
|
---|
145 | def FindSpecial( table_file, glName ):
|
---|
146 | table = {}
|
---|
147 | filename = table_file + "_special"
|
---|
148 | try:
|
---|
149 | table = specials[filename]
|
---|
150 | except KeyError:
|
---|
151 | table = LoadSpecials( filename )
|
---|
152 |
|
---|
153 | try:
|
---|
154 | if (table[glName] == 1):
|
---|
155 | return 1
|
---|
156 | else:
|
---|
157 | return 0 #should never happen
|
---|
158 | except KeyError:
|
---|
159 | return 0
|
---|
160 |
|
---|
161 | def AllSpecials( table_file ):
|
---|
162 | table = {}
|
---|
163 | filename = table_file + "_special"
|
---|
164 | try:
|
---|
165 | table = specials[filename]
|
---|
166 | except KeyError:
|
---|
167 | table = LoadSpecials( filename )
|
---|
168 |
|
---|
169 | keys = table.keys()
|
---|
170 | keys.sort()
|
---|
171 | return keys
|
---|
172 |
|
---|
173 | def AllSpecials( table_file ):
|
---|
174 | filename = table_file + "_special"
|
---|
175 |
|
---|
176 | table = {}
|
---|
177 | try:
|
---|
178 | table = specials[filename]
|
---|
179 | except KeyError:
|
---|
180 | table = LoadSpecials(filename)
|
---|
181 |
|
---|
182 | ret = table.keys()
|
---|
183 | ret.sort()
|
---|
184 | return ret
|
---|
185 |
|
---|
186 | def NumSpecials( table_file ):
|
---|
187 | filename = table_file + "_special"
|
---|
188 |
|
---|
189 | table = {}
|
---|
190 | try:
|
---|
191 | table = specials[filename]
|
---|
192 | except KeyError:
|
---|
193 | table = LoadSpecials(filename)
|
---|
194 |
|
---|
195 | return len(table.keys())
|
---|
196 |
|
---|
197 | lengths = {}
|
---|
198 | lengths['GLbyte'] = 1
|
---|
199 | lengths['GLubyte'] = 1
|
---|
200 | lengths['GLshort'] = 2
|
---|
201 | lengths['GLushort'] = 2
|
---|
202 | lengths['GLint'] = 4
|
---|
203 | lengths['GLuint'] = 4
|
---|
204 | lengths['GLfloat'] = 4
|
---|
205 | lengths['GLclampf'] = 4
|
---|
206 | lengths['GLdouble'] = 8
|
---|
207 | lengths['GLclampd'] = 8
|
---|
208 |
|
---|
209 | lengths['GLenum'] = 4
|
---|
210 | lengths['GLboolean'] = 1
|
---|
211 | lengths['GLsizei'] = 4
|
---|
212 | lengths['GLbitfield'] = 4
|
---|
213 |
|
---|
214 | lengths['void'] = 0
|
---|
215 | lengths['int'] = 4
|
---|
216 |
|
---|
217 | align_types = 1
|
---|
218 |
|
---|
219 | def FixAlignment( pos, alignment ):
|
---|
220 | # if we want double-alignment take word-alignment instead,
|
---|
221 | # yes, this is super-lame, but we know what we are doing
|
---|
222 | if alignment > 4:
|
---|
223 | alignment = 4
|
---|
224 | if align_types and alignment and ( pos % alignment ):
|
---|
225 | pos += alignment - ( pos % alignment )
|
---|
226 | return pos
|
---|
227 |
|
---|
228 | def WordAlign( pos ):
|
---|
229 | return FixAlignment( pos, 4 )
|
---|
230 |
|
---|
231 | def PointerSize():
|
---|
232 | return 8 # Leave room for a 64 bit pointer
|
---|
233 |
|
---|
234 | def PacketLength( arg_types ):
|
---|
235 | len = 0
|
---|
236 | for arg in arg_types:
|
---|
237 | if string.find( arg, '*') != -1:
|
---|
238 | size = PointerSize()
|
---|
239 | else:
|
---|
240 | temp_arg = re.sub("const ", "", arg)
|
---|
241 | size = lengths[temp_arg]
|
---|
242 | len = FixAlignment( len, size ) + size
|
---|
243 | len = WordAlign( len )
|
---|
244 | return len
|
---|
245 |
|
---|
246 | def InternalArgumentString( arg_names, arg_types ):
|
---|
247 | """Return string of C-style function declaration arguments."""
|
---|
248 | output = ''
|
---|
249 | for index in range(0,len(arg_names)):
|
---|
250 | if len(arg_names) != 1 and arg_names[index] == '':
|
---|
251 | continue
|
---|
252 | output += arg_types[index]
|
---|
253 | if arg_types[index][-1:] != '*' and arg_names[index] != '':
|
---|
254 | output += " ";
|
---|
255 | output += arg_names[index]
|
---|
256 | if index != len(arg_names) - 1:
|
---|
257 | output += ", "
|
---|
258 | return output
|
---|
259 |
|
---|
260 | def ArgumentString( arg_names, arg_types ):
|
---|
261 | """Return InternalArgumentString inside parenthesis."""
|
---|
262 | output = '( ' + InternalArgumentString(arg_names, arg_types) + ' )'
|
---|
263 | return output
|
---|
264 |
|
---|
265 | def InternalCallString( arg_names ):
|
---|
266 | output = ''
|
---|
267 | for index in range(0,len(arg_names)):
|
---|
268 | output += arg_names[index]
|
---|
269 | if arg_names[index] != '' and index != len(arg_names) - 1:
|
---|
270 | output += ", "
|
---|
271 | return output
|
---|
272 |
|
---|
273 | def CallString( arg_names ):
|
---|
274 | output = '( '
|
---|
275 | output += InternalCallString(arg_names)
|
---|
276 | output += " )"
|
---|
277 | return output
|
---|
278 |
|
---|
279 | def IsVector ( func_name ) :
|
---|
280 | m = re.search( r"^(SecondaryColor|Color|EdgeFlag|EvalCoord|Index|Normal|TexCoord|MultiTexCoord|Vertex|RasterPos|VertexAttrib|FogCoord|WindowPos|ProgramParameter)([1234]?)N?(ub|b|us|s|ui|i|f|d|)v(ARB|EXT|NV)?$", func_name )
|
---|
281 | if m :
|
---|
282 | if m.group(2) :
|
---|
283 | return string.atoi( m.group(2) )
|
---|
284 | else:
|
---|
285 | return 1
|
---|
286 | else:
|
---|
287 | return 0
|
---|