VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/packer/packer_bbox.py@ 19223

Last change on this file since 19223 was 15532, checked in by vboxsync, 16 years ago

crOpenGL: export to OSE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.3 KB
Line 
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# This script generates the packer_bbox.c file from gl_header.parsed
7
8import sys
9import cPickle
10import string
11
12import apiutil
13
14
15apiutil.CopyrightC()
16
17print """
18/* DO NOT EDIT - THIS FILE GENERATED BY THE packer_bbox.py SCRIPT */
19
20/* These functions pack glVertex functions and also update the bounding box
21 * if the cr_packer_globals.updateBBOX variable is non-zero.
22 */
23
24#include "packer.h"
25#include "cr_opcodes.h"
26#include "pack_bbox.h"
27
28#include <float.h>
29
30/**
31 * Reset packer bounding box to empty state.
32 */
33void crPackResetBoundingBox( CRPackContext *pc )
34{
35 pc->bounds_min.x = FLT_MAX;
36 pc->bounds_min.y = FLT_MAX;
37 pc->bounds_min.z = FLT_MAX;
38 pc->bounds_max.x = -FLT_MAX;
39 pc->bounds_max.y = -FLT_MAX;
40 pc->bounds_max.z = -FLT_MAX;
41 pc->updateBBOX = 1;
42}
43
44/**
45 * Query current bounding box.
46 * \return GL_TRUE if non-empty box, GL_FALSE if empty box.
47 */
48GLboolean crPackGetBoundingBox( CRPackContext *pc,
49 GLfloat *xmin, GLfloat *ymin, GLfloat *zmin,
50 GLfloat *xmax, GLfloat *ymax, GLfloat *zmax)
51{
52 if (pc->bounds_min.x != FLT_MAX) {
53 *xmin = pc->bounds_min.x;
54 *ymin = pc->bounds_min.y;
55 *zmin = pc->bounds_min.z;
56 *xmax = pc->bounds_max.x;
57 *ymax = pc->bounds_max.y;
58 *zmax = pc->bounds_max.z;
59 return GL_TRUE;
60 }
61 else {
62 return GL_FALSE;
63 }
64}
65
66"""
67
68def WriteData( offset, arg_type, arg_name, is_swapped ):
69 if string.find( arg_type, '*' ) != -1:
70 retval = "\tWRITE_NETWORK_POINTER( %d, (void *) %s );" % (offset, arg_name )
71 else:
72 if is_swapped:
73 if arg_type == "GLfloat" or arg_type == "GLclampf":
74 retval = "\tWRITE_DATA( %d, GLuint, SWAPFLOAT(%s) );" % (offset, arg_name)
75 elif arg_type == "GLdouble" or arg_type == "GLclampd":
76 retval = "\tWRITE_SWAPPED_DOUBLE( %d, %s );" % (offset, arg_name)
77 elif apiutil.sizeof(arg_type) == 1:
78 retval = "\tWRITE_DATA( %d, %s, %s );" % (offset, arg_type, arg_name)
79 elif apiutil.sizeof(arg_type) == 2:
80 retval = "\tWRITE_DATA( %d, %s, SWAP16(%s) );" % (offset, arg_type, arg_name)
81 elif apiutil.sizeof(arg_type) == 4:
82 retval = "\tWRITE_DATA( %d, %s, SWAP32(%s) );" % (offset, arg_type, arg_name)
83 else:
84 if arg_type == "GLdouble" or arg_type == "GLclampd":
85 retval = "\tWRITE_DOUBLE( %d, %s );" % (offset, arg_name)
86 else:
87 retval = "\tWRITE_DATA( %d, %s, %s );" % (offset, arg_type, arg_name)
88 return retval
89
90
91def PrintFunction( func_name, extSuffix, num_coords, argtype,
92 do_swapped, do_count, do_vector ):
93 """
94 Generate all the functions named crPackVertex[234][dfis][v]BBOX() and
95 crPackVertex[234][dfis][v]BBOX_COUNT().
96 We also handle glVertexAttrib*ARB.
97 Note: func_name should not have an ARB suffix.
98 """
99
100 if do_count:
101 countSuffix = "_COUNT"
102 else:
103 countSuffix = ""
104
105 if do_swapped:
106 swapSuffix = "SWAP"
107 else:
108 swapSuffix = ""
109
110 if func_name[0:12] == "VertexAttrib":
111 isVertexAttrib = 1
112 else:
113 isVertexAttrib = 0
114
115 if argtype[0] == "N":
116 normalized = 1
117 else:
118 normalized = 0;
119
120 if argtype == "b" or argtype == "Nb":
121 vector_type = "GLbyte"
122 elif argtype == "ub" or argtype == "Nub":
123 vector_type = "GLubyte"
124 elif argtype == "s" or argtype == "Ns":
125 vector_type = "GLshort"
126 elif argtype == "us" or argtype == "Nus":
127 vector_type = "GLushort"
128 elif argtype == "i" or argtype == "Ni":
129 vector_type = "GLint"
130 elif argtype == "ui" or argtype == "Nui":
131 vector_type = "GLuint"
132 elif argtype == "f":
133 vector_type = "GLfloat"
134 elif argtype == "d":
135 vector_type = "GLdouble"
136 else:
137 print "type is %s" % argtype
138 abort()
139
140 if do_vector:
141 if isVertexAttrib:
142 func_name = 'VertexAttrib%d%sv' % (num_coords, argtype)
143 else:
144 func_name = 'Vertex%d%sv' % (num_coords,argtype)
145
146 params = apiutil.Parameters(func_name + extSuffix)
147
148 print 'void PACK_APIENTRY crPack%sBBOX%s%s( %s )' % (func_name + extSuffix, countSuffix,
149 swapSuffix, apiutil.MakeDeclarationString(params))
150 print '{'
151
152 if do_vector:
153 # vector version
154 packet_length = num_coords * apiutil.sizeof(vector_type)
155 if isVertexAttrib:
156 packet_length += 4 # for index
157 if packet_length % 4 != 0:
158 packet_length += 2
159
160 else:
161 # non-vector
162 packet_length = apiutil.PacketLength( params )
163 if isVertexAttrib:
164 packet_length += 0 # for index
165 if packet_length % 4 != 0:
166 packet_length += 2
167
168
169 print "\tGET_PACKER_CONTEXT(pc);"
170 print "\tunsigned char *data_ptr;"
171
172 if normalized:
173 if argtype == "Nb":
174 t = "B"
175 elif argtype == "Ni":
176 t = "I"
177 elif argtype == "Nui":
178 t = "UI"
179 elif argtype == "Nub":
180 t = "UB"
181 elif argtype == "Ns":
182 t = "S"
183 elif argtype == "Nus":
184 t = "US"
185 else:
186 abort()
187 if do_vector:
188 print "\tCREATE_%dD_VFLOATS_%s_NORMALIZED();" % (num_coords, t)
189 else:
190 print "\tCREATE_%dD_FLOATS_%s_NORMALIZED();" % (num_coords, t)
191 else:
192 if do_vector:
193 print "\tCREATE_%dD_VFLOATS();" % num_coords
194 else:
195 print "\tCREATE_%dD_FLOATS();" % num_coords
196
197 print "\tGET_BUFFERED%s_POINTER( pc, %d );" % (countSuffix, packet_length)
198
199 # Bounding box code
200 if isVertexAttrib:
201 print "\tif (pc->updateBBOX && index == 0)"
202 else:
203 print "\tif (pc->updateBBOX)"
204 print "\t{"
205 if num_coords < 4:
206 print "\t\tUPDATE_%dD_BBOX();" % num_coords
207 else:
208 print "\t\tUPDATE_3D_BBOX();"
209 print "\t}"
210
211 if isVertexAttrib:
212 print "\tif (index > 0) {"
213 t = argtype
214 print "\t\tpc->current.c.vertexAttrib.%s%d[index] = data_ptr + 4;" % (t, num_coords)
215 print "\t\tpc->current.attribsUsedMask |= (1 << index);"
216 if do_count:
217 print "\t\tpc->current.vtx_count--;"
218
219 print "\t}"
220
221 fname = func_name + extSuffix
222 if do_vector:
223 # use non-vector opcode
224 opcode = apiutil.OpcodeName( func_name[:-1] + extSuffix )
225 else:
226 opcode = apiutil.OpcodeName( func_name + extSuffix )
227 counter = 0
228
229 if do_vector:
230 if isVertexAttrib:
231 if do_swapped:
232 print "\tWRITE_DATA( 0, GLuint, SWAP32(index) );"
233 else:
234 print "\tWRITE_DATA( 0, GLuint, index );"
235 counter += 4
236 argname = params[1][0] # skip 'index' parameter
237 else:
238 argname = params[0][0]
239
240 for index in range(num_coords):
241 print WriteData( counter, vector_type, "%s[%d]" % (argname, index), do_swapped )
242 counter += apiutil.sizeof(vector_type)
243
244 if isVertexAttrib:
245 if do_vector == 2:
246 # this is a bit of a hack
247 print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName( func_name + "ARB" )
248 else:
249 print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName( func_name[:-1] + "ARB" )
250 else:
251 print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName( func_name[:-1] )
252 else:
253 for index in range(0,len(params)):
254 (name, type, vecSize) = params[index]
255 print WriteData( counter, type, name, do_swapped )
256 counter += apiutil.sizeof(type)
257
258 if isVertexAttrib:
259 print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName( func_name + "ARB" )
260 else:
261 print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName( func_name )
262
263 print '}\n'
264
265#end PrintFunction()
266
267
268for num_coords in [2,3,4]:
269 for argtype in ['d', 'f', 'i', 's']:
270 func_name = 'Vertex%d%s' % (num_coords, argtype)
271 for swap in range(0, 2):
272 for count in range(0, 2):
273 for vec in range(0, 2):
274 PrintFunction( func_name, "", num_coords, argtype, swap,
275 count, vec )
276
277for num_coords in [1,2,3,4]:
278 for argtype in ['d', 'f', 's']:
279 func_name = 'VertexAttrib%d%s' % (num_coords, argtype)
280 for swap in range(0, 2):
281 for count in range(0, 2):
282 for vec in range(0, 2):
283 PrintFunction( func_name, "ARB", num_coords, argtype, swap,
284 count, vec )
285
286# Special vector functions
287moreFuncs = [ [ "VertexAttrib4ubv", "ub" ],
288 [ "VertexAttrib4usv", "us" ],
289 [ "VertexAttrib4uiv", "ui" ],
290 [ "VertexAttrib4bv", "b" ],
291 [ "VertexAttrib4iv", "i" ],
292 [ "VertexAttrib4Nbv", "Nb" ],
293 [ "VertexAttrib4Nsv", "Ns" ],
294 [ "VertexAttrib4Niv", "Ni" ],
295 [ "VertexAttrib4Nubv", "Nub" ],
296 [ "VertexAttrib4Nusv", "Nus" ],
297 [ "VertexAttrib4Nuiv", "Nui" ]
298 ]
299for (func_name, argtype) in moreFuncs:
300 vec = 2 # special, hacked value
301 num_coords = 4
302 for swap in range(0, 2):
303 for count in range(0, 2):
304 PrintFunction( func_name, "ARB", num_coords, argtype, swap, count, vec )
305
306# Special non-vector functions
307moreFuncs = [ [ "VertexAttrib4Nub", "Nub" ] ]
308for (func_name, argtype) in moreFuncs:
309 vec = 0
310 num_coords = 4
311 for swap in range(0, 2):
312 for count in range(0, 2):
313 PrintFunction( func_name, "ARB", num_coords, argtype, swap, count, vec )
Note: See TracBrowser for help on using the repository browser.

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