VirtualBox

source: vbox/trunk/src/VBox/Additions/common/crOpenGL/stub_common.py@ 65902

最後變更 在這個檔案從65902是 63939,由 vboxsync 提交於 8 年 前

Build/scripts (bugref:6627): Python build scripts updated to generate the same code when used with Python 2 and 3.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette