VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_current.py@ 63942

Last change on this file since 63942 was 63942, checked in by vboxsync, 8 years ago

OpenGL: fixed the most annoying coding style flaws, mainly removing spaces after '(' and before ')', no semantic change

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 15.7 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
6from __future__ import print_function
7import sys
8
9from pack_currenttypes import *
10import apiutil
11
12apiutil.CopyrightC()
13
14print('''
15#include "state/cr_currentpointers.h"
16#include "state.h"
17
18#include <stdio.h>
19
20#ifdef WINDOWS
21#pragma warning( disable : 4127 )
22#endif
23
24typedef void (*convert_func) (GLfloat *, const unsigned char *);
25''')
26
27import convert
28
29for k in sorted(current_fns.keys()):
30 name = k
31 name = '%s%s' % (k[:1].lower(),k[1:])
32 ucname = k.upper()
33 num_members = len(current_fns[k]['default']) + 1
34
35 print('#define VPINCH_CONVERT_%s(op,data,dst) \\' % ucname)
36 print('{\\')
37 print('\tGLfloat vdata[%d] = {' % num_members, end=' ')
38
39## Copy dst data into vdata
40 i = 0;
41 for defaultvar in current_fns[k]['default']:
42 print('%d' % defaultvar, end=' ')
43 if i != num_members:
44 print(',', end=' ')
45 i += 1
46 print('};\\')
47
48 print('\tswitch (op) { \\')
49 for type in current_fns[k]['types']:
50 if type[0:1] == "N":
51 normalize = 1
52 type = type[1:]
53 else:
54 normalize = 0
55 for size in current_fns[k]['sizes']:
56 uctype = type.upper()
57 if ucname == 'EDGEFLAG':
58 print('\tcase CR_%s_OPCODE: \\' % ucname)
59 else:
60 print('\tcase CR_%s%d%s_OPCODE: \\' % (ucname,size,uctype))
61
62 if (ucname == 'COLOR' or ucname == 'NORMAL' or ucname == 'SECONDARYCOLOR' or normalize) and type != 'f' and type != 'd':
63 print('\t\t__convert_rescale_%s%d (vdata, (%s *) (data)); \\' % (type,size,gltypes[type]['type']))
64 else:
65 print('\t\t__convert_%s%d (vdata, (%s *) (data)); \\' % (type,size,gltypes[type]['type']))
66 print('\t\tbreak; \\')
67
68 print('\tdefault: \\')
69 print('\t\tcrSimpleError ( "Unknown opcode in VPINCH_CONVERT_%s" ); \\' % ucname)
70 print('\t}\\')
71
72 i = 0
73 for member in current_fns[k]['members']:
74 print('\t(dst).%s = vdata[%d];\\' % (member,i))
75 i += 1
76
77 print('}\n')
78
79print('''
80
81void crStateCurrentRecover( void )
82{
83 const unsigned char *v;
84 convert_func convert=NULL;
85 CRContext *g = GetCurrentContext();
86 CRCurrentState *c = &(g->current);
87 CRStateBits *sb = GetCurrentBits();
88 CRCurrentBits *cb = &(sb->current);
89 static const GLfloat color_default[4] = {0.0f, 0.0f, 0.0f, 1.0f};
90 static const GLfloat secondaryColor_default[4] = {0.0f, 0.0f, 0.0f, 0.0f};
91 static const GLfloat texCoord_default[4] = {0.0f, 0.0f, 0.0f, 1.0f};
92 static const GLfloat normal_default[4] = {0.0f, 0.0f, 0.0f, 1.0f};
93 static const GLfloat index_default = 0.0f;
94 static const GLboolean edgeFlag_default = GL_TRUE;
95 static const GLfloat vertexAttrib_default[4] = {0.0f, 0.0f, 0.0f, 1.0f};
96 static const GLfloat fogCoord_default = 0.0f;
97 GLnormal_p *normal = &(c->current->c.normal);
98 GLcolor_p *color = &(c->current->c.color);
99 GLsecondarycolor_p *secondaryColor = &(c->current->c.secondaryColor);
100 GLtexcoord_p *texCoord = &(c->current->c.texCoord);
101 GLindex_p *index = &(c->current->c.index);
102 GLedgeflag_p *edgeFlag = &(c->current->c.edgeFlag);
103 GLvertexattrib_p *vertexAttrib = &(c->current->c.vertexAttrib);
104 GLfogcoord_p *fogCoord = &(c->current->c.fogCoord);
105 unsigned int i;
106 CRbitvalue nbitID[CR_MAX_BITARRAY];
107
108 /*
109 * If the calling SPU hasn't called crStateSetCurrentPointers()
110 * we can't recover anything, so abort now. (i.e. we don't have
111 * a pincher, oh, and just emit the message once).
112 */
113 if (!c->current) {
114 static int donewarning = 0;
115 if (!donewarning)
116 crWarning("No pincher, please call crStateSetCurrentPointers() in your SPU");
117 donewarning = 1;
118 return; /* never get here */
119 }
120
121 c->attribsUsedMask = c->current->attribsUsedMask;
122
123 /* silence warnings */
124 (void) __convert_b1;
125 (void) __convert_b2;
126 (void) __convert_b3;
127 (void) __convert_b4;
128 (void) __convert_ui1;
129 (void) __convert_ui2;
130 (void) __convert_ui3;
131 (void) __convert_ui4;
132 (void) __convert_l1;
133 (void) __convert_l2;
134 (void) __convert_l3;
135 (void) __convert_l4;
136 (void) __convert_us1;
137 (void) __convert_us2;
138 (void) __convert_us3;
139 (void) __convert_us4;
140 (void) __convert_ub1;
141 (void) __convert_ub2;
142 (void) __convert_ub3;
143 (void) __convert_ub4;
144 (void) __convert_rescale_s1;
145 (void) __convert_rescale_s2;
146 (void) __convert_rescale_b1;
147 (void) __convert_rescale_b2;
148 (void) __convert_rescale_ui1;
149 (void) __convert_rescale_ui2;
150 (void) __convert_rescale_i1;
151 (void) __convert_rescale_i2;
152 (void) __convert_rescale_us1;
153 (void) __convert_rescale_us2;
154 (void) __convert_rescale_ub1;
155 (void) __convert_rescale_ub2;
156 (void) __convert_Ni1;
157 (void) __convert_Ni2;
158 (void) __convert_Ni3;
159 (void) __convert_Ni4;
160 (void) __convert_Nb1;
161 (void) __convert_Nb2;
162 (void) __convert_Nb3;
163 (void) __convert_Nb4;
164 (void) __convert_Nus1;
165 (void) __convert_Nus2;
166 (void) __convert_Nus3;
167 (void) __convert_Nus4;
168 (void) __convert_Nui1;
169 (void) __convert_Nui2;
170 (void) __convert_Nui3;
171 (void) __convert_Nui4;
172 (void) __convert_Ns1;
173 (void) __convert_Ns2;
174 (void) __convert_Ns3;
175 (void) __convert_Ns4;
176 (void) __convert_Nub1;
177 (void) __convert_Nub2;
178 (void) __convert_Nub3;
179 (void) __convert_Nub4;
180
181 DIRTY(nbitID, g->neg_bitid);
182
183 /* Save pre state */
184 for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++) {
185 COPY_4V(c->vertexAttribPre[i] , c->vertexAttrib[i]);
186 }
187 c->edgeFlagPre = c->edgeFlag;
188 c->colorIndexPre = c->colorIndex;
189
190''')
191
192for k in sorted(current_fns.keys()):
193 print('\t/* %s */' % k)
194 print('\tv = NULL;')
195 name = '%s%s' % (k[:1].lower(),k[1:])
196
197 indent = ""
198 if 'array' in current_fns[k]:
199 print('\tfor (i = 0; i < %s; i++)' % current_fns[k]['array'])
200 print('\t{')
201 indent += "\t"
202 for type in current_fns[k]['types']:
203 if type[0:1] == "N":
204 normalized = 1
205 type2 = type[1:]
206 else:
207 normalized = 0
208 type2 = type
209 for size in current_fns[k]['sizes']:
210 ptr = '%s->%s%d' % (name, type, size )
211 if 'array' in current_fns[k]:
212 ptr += "[i]"
213 print('%s\tif (v < %s)' % (indent, ptr))
214 print('%s\t{' % indent)
215 print('%s\t\tv = %s;' % (indent, ptr))
216 if (k == 'Color' or k == 'Normal' or k == 'SecondaryColor' or normalized) and type != 'f' and type != 'd' and type != 'l':
217 print('%s\t\tconvert = (convert_func) __convert_rescale_%s%d;' % (indent,type,size))
218 else:
219 print('%s\t\tconvert = (convert_func) __convert_%s%d;' % (indent,type,size))
220 print('%s\t}' % indent)
221 print('')
222 print('%s\tif (v != NULL) {' % indent)
223 if 'array' in current_fns[k]:
224 if k == 'TexCoord':
225 print('%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_TEX0 + i], %s_default);' % (indent,name))
226 else:
227 print('%s\t\tCOPY_4V(c->%s[i], %s_default);' % (indent,name,name))
228 else:
229 if k == 'Normal':
230 print('%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_NORMAL], %s_default);' % (indent,name))
231 elif k == 'FogCoord':
232 print('%s\t\tc->vertexAttrib[VERT_ATTRIB_FOG][0] = %s_default;' % (indent,name))
233 elif k == 'Color':
234 print('%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_COLOR0], %s_default);' % (indent,name))
235 elif k == 'SecondaryColor':
236 print('%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_COLOR1], %s_default);' % (indent,name))
237 elif k == 'TexCoord':
238 print('%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_TEX0], %s_default);' % (indent,name))
239 elif k == 'Index':
240 print('%s\t\tc->colorIndex = %s_default;' % (indent,name))
241 elif k == 'EdgeFlag':
242 print('%s\t\tc->edgeFlag = %s_default;' % (indent,name))
243 else:
244 print('%s\t\tc->%s = %s_default;' % (indent,name,name))
245 if k == 'EdgeFlag':
246 print('%s\t\t__convert_boolean (&c->edgeFlag, v);' % (indent))
247 dirtyVar = 'cb->edgeFlag'
248 elif k == 'Normal':
249 print('%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_NORMAL][0]), v);' % (indent))
250 dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_NORMAL]'
251 elif k == 'TexCoord':
252 print('%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_TEX0 + i][0]), v);' % (indent))
253 dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_TEX0 + i]'
254 elif k == 'Color':
255 print('%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_COLOR0][0]), v);' % (indent))
256 dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_COLOR0]'
257 elif k == 'Index':
258 print('%s\t\tconvert(&(c->colorIndex), v);' % (indent))
259 dirtyVar = 'cb->colorIndex'
260 elif k == 'SecondaryColor':
261 print('%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_COLOR1][0]), v);' % (indent))
262 dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_COLOR1]'
263 elif k == 'FogCoord':
264 print('%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_FOG][0]), v);' % (indent))
265 dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_FOG]'
266 elif k == 'VertexAttrib':
267 print('%s\t\tconvert(&(c->vertexAttrib[i][0]), v);' % (indent))
268 dirtyVar = 'cb->vertexAttrib[i]'
269 else:
270 assert 0 # should never get here
271
272 print('%s\t\tDIRTY(%s, nbitID);' % (indent, dirtyVar))
273
274# if current_fns[k].has_key( 'array' ):
275# print '%s\t\tDIRTY(cb->%s[i], nbitID);' % (indent,name)
276# else:
277# print '%s\t\tDIRTY(cb->%s, nbitID);' % (indent,name)
278
279
280
281 print('%s\t\tDIRTY(cb->dirty, nbitID);' % indent)
282 print('%s\t}' % indent)
283 if 'array' in current_fns[k]:
284 print('%s\t%s->ptr[i] = v;' % (indent, name ))
285 else:
286 print('%s\t%s->ptr = v;' % (indent, name ))
287 if 'array' in current_fns[k]:
288 print('\t}')
289print('}')
290
291print('''
292
293void crStateCurrentRecoverNew(CRContext *g, CRCurrentStatePointers *current)
294{
295 const unsigned char *v;
296 convert_func convert=NULL;
297 CRCurrentState *c = &(g->current);
298 CRStateBits *sb = GetCurrentBits();
299 CRCurrentBits *cb = &(sb->current);
300
301 static const GLfloat vertexAttrib_default[4] = {0.0f, 0.0f, 0.0f, 1.0f};
302
303 GLvertexattrib_p *vertexAttrib = &(current->c.vertexAttrib);
304
305 unsigned int i;
306 CRbitvalue nbitID[CR_MAX_BITARRAY];
307
308
309 /* silence warnings */
310 (void) __convert_b1;
311 (void) __convert_b2;
312 (void) __convert_b3;
313 (void) __convert_b4;
314 (void) __convert_ui1;
315 (void) __convert_ui2;
316 (void) __convert_ui3;
317 (void) __convert_ui4;
318 (void) __convert_l1;
319 (void) __convert_l2;
320 (void) __convert_l3;
321 (void) __convert_l4;
322 (void) __convert_us1;
323 (void) __convert_us2;
324 (void) __convert_us3;
325 (void) __convert_us4;
326 (void) __convert_ub1;
327 (void) __convert_ub2;
328 (void) __convert_ub3;
329 (void) __convert_ub4;
330 (void) __convert_rescale_s1;
331 (void) __convert_rescale_s2;
332 (void) __convert_rescale_b1;
333 (void) __convert_rescale_b2;
334 (void) __convert_rescale_ui1;
335 (void) __convert_rescale_ui2;
336 (void) __convert_rescale_i1;
337 (void) __convert_rescale_i2;
338 (void) __convert_rescale_us1;
339 (void) __convert_rescale_us2;
340 (void) __convert_rescale_ub1;
341 (void) __convert_rescale_ub2;
342 (void) __convert_Ni1;
343 (void) __convert_Ni2;
344 (void) __convert_Ni3;
345 (void) __convert_Ni4;
346 (void) __convert_Nb1;
347 (void) __convert_Nb2;
348 (void) __convert_Nb3;
349 (void) __convert_Nb4;
350 (void) __convert_Nus1;
351 (void) __convert_Nus2;
352 (void) __convert_Nus3;
353 (void) __convert_Nus4;
354 (void) __convert_Nui1;
355 (void) __convert_Nui2;
356 (void) __convert_Nui3;
357 (void) __convert_Nui4;
358 (void) __convert_Ns1;
359 (void) __convert_Ns2;
360 (void) __convert_Ns3;
361 (void) __convert_Ns4;
362 (void) __convert_Nub1;
363 (void) __convert_Nub2;
364 (void) __convert_Nub3;
365 (void) __convert_Nub4;
366
367
368''')
369
370for k in sorted(current_fns_new.keys()):
371 print('\t/* %s */' % k)
372 print('\tif (current->changed%s)' % k)
373 print('\t{')
374 print('\t\tv=NULL;')
375 name = '%s%s' % (k[:1].lower(),k[1:])
376
377 indent = ""
378 if 'array' in current_fns_new[k]:
379 print('\t\tfor (i = 0; i < %s; i++)' % current_fns_new[k]['array'])
380 print('\t\t{')
381 indent += "\t\t"
382 print('\t\tif (!(current->changed%s & (1 << i))) continue;' % k)
383 for type in current_fns_new[k]['types']:
384 if type[0:1] == "N":
385 normalized = 1
386 type2 = type[1:]
387 else:
388 normalized = 0
389 type2 = type
390 for size in current_fns_new[k]['sizes']:
391 ptr = '%s->%s%d' % (name, type, size )
392 if 'array' in current_fns_new[k]:
393 ptr += "[i]"
394 print('#ifdef DEBUG_misha')
395 print('%s\tif (%s)' % (indent, ptr))
396 print('%s\t{' % (indent))
397 print('%s\t\tuint32_t *pTst = (uint32_t*)(%s);' % (indent, ptr))
398 print('%s\t\t--pTst;' % (indent))
399 print('%s\t\tAssert((*pTst) == i);' % (indent))
400 print('%s\t}' % (indent))
401 print('#endif')
402 print('%s\tif (v < %s)' % (indent, ptr))
403 print('%s\t{' % indent)
404 print('%s\t\tv = %s;' % (indent, ptr))
405 if (k == 'Color' or k == 'Normal' or k == 'SecondaryColor' or normalized) and type != 'f' and type != 'd' and type != 'l':
406 print('%s\t\tconvert = (convert_func) __convert_rescale_%s%d;' % (indent,type,size))
407 else:
408 print('%s\t\tconvert = (convert_func) __convert_%s%d;' % (indent,type,size))
409 print('%s\t}' % indent)
410 print('')
411 print('%s\tif (v != NULL) {' % indent)
412 if 'array' in current_fns_new[k]:
413 if k == 'TexCoord':
414 print('%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_TEX0 + i], %s_default);' % (indent,name))
415 else:
416 print('%s\t\tCOPY_4V(c->%s[i], %s_default);' % (indent,name,name))
417 else:
418 if k == 'Normal':
419 print('%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_NORMAL], %s_default);' % (indent,name))
420 elif k == 'FogCoord':
421 print('%s\t\tc->vertexAttrib[VERT_ATTRIB_FOG][0] = %s_default;' % (indent,name))
422 elif k == 'Color':
423 print('%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_COLOR0], %s_default);' % (indent,name))
424 elif k == 'SecondaryColor':
425 print('%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_COLOR1], %s_default);' % (indent,name))
426 elif k == 'TexCoord':
427 print('%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_TEX0], %s_default);' % (indent,name))
428 elif k == 'Index':
429 print('%s\t\tc->colorIndex = %s_default;' % (indent,name))
430 elif k == 'EdgeFlag':
431 print('%s\t\tc->edgeFlag = %s_default;' % (indent,name))
432 else:
433 print('%s\t\tc->%s = %s_default;' % (indent,name,name))
434 if k == 'EdgeFlag':
435 print('%s\t\t__convert_boolean (&c->edgeFlag, v);' % (indent))
436 dirtyVar = 'cb->edgeFlag'
437 elif k == 'Normal':
438 print('%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_NORMAL][0]), v);' % (indent))
439 dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_NORMAL]'
440 elif k == 'TexCoord':
441 print('%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_TEX0 + i][0]), v);' % (indent))
442 dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_TEX0 + i]'
443 elif k == 'Color':
444 print('%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_COLOR0][0]), v);' % (indent))
445 dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_COLOR0]'
446 elif k == 'Index':
447 print('%s\t\tconvert(&(c->colorIndex), v);' % (indent))
448 dirtyVar = 'cb->colorIndex'
449 elif k == 'SecondaryColor':
450 print('%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_COLOR1][0]), v);' % (indent))
451 dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_COLOR1]'
452 elif k == 'FogCoord':
453 print('%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_FOG][0]), v);' % (indent))
454 dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_FOG]'
455 elif k == 'VertexAttrib':
456 print('%s\t\tconvert(&(c->vertexAttrib[i][0]), v);' % (indent))
457 dirtyVar = 'cb->vertexAttrib[i]'
458 else:
459 assert 0 # should never get here
460
461 print('%s\t\tDIRTY(%s, nbitID);' % (indent, dirtyVar))
462
463# if current_fns_new[k].has_key( 'array' ):
464# print '%s\t\tDIRTY(cb->%s[i], nbitID);' % (indent,name)
465# else:
466# print '%s\t\tDIRTY(cb->%s, nbitID);' % (indent,name)
467
468
469
470 print('%s\t\tDIRTY(cb->dirty, nbitID);' % indent)
471 print('%s\t}' % indent)
472 if 'array' in current_fns_new[k]:
473 print('%s\t%s->ptr[i] = v;' % (indent, name ))
474 else:
475 print('%s\t%s->ptr = v;' % (indent, name ))
476 if 'array' in current_fns_new[k]:
477 print('\t\t}')
478 print('\t\tcurrent->changed%s = 0;' % k)
479 print('\t}')
480print('\tcrStateResetCurrentPointers(current);')
481print('}')
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