VirtualBox

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

Last change on this file since 71930 was 69392, checked in by vboxsync, 7 years ago

GuestHost/OpenGL: scm updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 15.8 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 /* Invalid parameters, do nothing */
309 if (!g || !current)
310 return;
311
312 /* silence warnings */
313 (void) __convert_b1;
314 (void) __convert_b2;
315 (void) __convert_b3;
316 (void) __convert_b4;
317 (void) __convert_ui1;
318 (void) __convert_ui2;
319 (void) __convert_ui3;
320 (void) __convert_ui4;
321 (void) __convert_l1;
322 (void) __convert_l2;
323 (void) __convert_l3;
324 (void) __convert_l4;
325 (void) __convert_us1;
326 (void) __convert_us2;
327 (void) __convert_us3;
328 (void) __convert_us4;
329 (void) __convert_ub1;
330 (void) __convert_ub2;
331 (void) __convert_ub3;
332 (void) __convert_ub4;
333 (void) __convert_rescale_s1;
334 (void) __convert_rescale_s2;
335 (void) __convert_rescale_b1;
336 (void) __convert_rescale_b2;
337 (void) __convert_rescale_ui1;
338 (void) __convert_rescale_ui2;
339 (void) __convert_rescale_i1;
340 (void) __convert_rescale_i2;
341 (void) __convert_rescale_us1;
342 (void) __convert_rescale_us2;
343 (void) __convert_rescale_ub1;
344 (void) __convert_rescale_ub2;
345 (void) __convert_Ni1;
346 (void) __convert_Ni2;
347 (void) __convert_Ni3;
348 (void) __convert_Ni4;
349 (void) __convert_Nb1;
350 (void) __convert_Nb2;
351 (void) __convert_Nb3;
352 (void) __convert_Nb4;
353 (void) __convert_Nus1;
354 (void) __convert_Nus2;
355 (void) __convert_Nus3;
356 (void) __convert_Nus4;
357 (void) __convert_Nui1;
358 (void) __convert_Nui2;
359 (void) __convert_Nui3;
360 (void) __convert_Nui4;
361 (void) __convert_Ns1;
362 (void) __convert_Ns2;
363 (void) __convert_Ns3;
364 (void) __convert_Ns4;
365 (void) __convert_Nub1;
366 (void) __convert_Nub2;
367 (void) __convert_Nub3;
368 (void) __convert_Nub4;
369
370 DIRTY(nbitID, g->neg_bitid);
371
372''')
373
374for k in sorted(current_fns_new.keys()):
375 print('\t/* %s */' % k)
376 print('\tif (current->changed%s)' % k)
377 print('\t{')
378 print('\t\tv=NULL;')
379 name = '%s%s' % (k[:1].lower(),k[1:])
380
381 indent = ""
382 if 'array' in current_fns_new[k]:
383 print('\t\tfor (i = 0; i < %s; i++)' % current_fns_new[k]['array'])
384 print('\t\t{')
385 indent += "\t\t"
386 print('\t\tif (!(current->changed%s & (1 << i))) continue;' % k)
387 for type in current_fns_new[k]['types']:
388 if type[0:1] == "N":
389 normalized = 1
390 type2 = type[1:]
391 else:
392 normalized = 0
393 type2 = type
394 for size in current_fns_new[k]['sizes']:
395 ptr = '%s->%s%d' % (name, type, size )
396 if 'array' in current_fns_new[k]:
397 ptr += "[i]"
398 print('#ifdef DEBUG_misha')
399 print('%s\tif (%s)' % (indent, ptr))
400 print('%s\t{' % (indent))
401 print('%s\t\tuint32_t *pTst = (uint32_t*)(%s);' % (indent, ptr))
402 print('%s\t\t--pTst;' % (indent))
403 print('%s\t\tAssert((*pTst) == i);' % (indent))
404 print('%s\t}' % (indent))
405 print('#endif')
406 print('%s\tif (v < %s)' % (indent, ptr))
407 print('%s\t{' % indent)
408 print('%s\t\tv = %s;' % (indent, ptr))
409 if (k == 'Color' or k == 'Normal' or k == 'SecondaryColor' or normalized) and type != 'f' and type != 'd' and type != 'l':
410 print('%s\t\tconvert = (convert_func) __convert_rescale_%s%d;' % (indent,type,size))
411 else:
412 print('%s\t\tconvert = (convert_func) __convert_%s%d;' % (indent,type,size))
413 print('%s\t}' % indent)
414 print('')
415 print('%s\tif (v != NULL) {' % indent)
416 if 'array' in current_fns_new[k]:
417 if k == 'TexCoord':
418 print('%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_TEX0 + i], %s_default);' % (indent,name))
419 else:
420 print('%s\t\tCOPY_4V(c->%s[i], %s_default);' % (indent,name,name))
421 else:
422 if k == 'Normal':
423 print('%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_NORMAL], %s_default);' % (indent,name))
424 elif k == 'FogCoord':
425 print('%s\t\tc->vertexAttrib[VERT_ATTRIB_FOG][0] = %s_default;' % (indent,name))
426 elif k == 'Color':
427 print('%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_COLOR0], %s_default);' % (indent,name))
428 elif k == 'SecondaryColor':
429 print('%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_COLOR1], %s_default);' % (indent,name))
430 elif k == 'TexCoord':
431 print('%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_TEX0], %s_default);' % (indent,name))
432 elif k == 'Index':
433 print('%s\t\tc->colorIndex = %s_default;' % (indent,name))
434 elif k == 'EdgeFlag':
435 print('%s\t\tc->edgeFlag = %s_default;' % (indent,name))
436 else:
437 print('%s\t\tc->%s = %s_default;' % (indent,name,name))
438 if k == 'EdgeFlag':
439 print('%s\t\t__convert_boolean (&c->edgeFlag, v);' % (indent))
440 dirtyVar = 'cb->edgeFlag'
441 elif k == 'Normal':
442 print('%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_NORMAL][0]), v);' % (indent))
443 dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_NORMAL]'
444 elif k == 'TexCoord':
445 print('%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_TEX0 + i][0]), v);' % (indent))
446 dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_TEX0 + i]'
447 elif k == 'Color':
448 print('%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_COLOR0][0]), v);' % (indent))
449 dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_COLOR0]'
450 elif k == 'Index':
451 print('%s\t\tconvert(&(c->colorIndex), v);' % (indent))
452 dirtyVar = 'cb->colorIndex'
453 elif k == 'SecondaryColor':
454 print('%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_COLOR1][0]), v);' % (indent))
455 dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_COLOR1]'
456 elif k == 'FogCoord':
457 print('%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_FOG][0]), v);' % (indent))
458 dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_FOG]'
459 elif k == 'VertexAttrib':
460 print('%s\t\tconvert(&(c->vertexAttrib[i][0]), v);' % (indent))
461 dirtyVar = 'cb->vertexAttrib[i]'
462 else:
463 assert 0 # should never get here
464
465 print('%s\t\tDIRTY(%s, nbitID);' % (indent, dirtyVar))
466
467# if current_fns_new[k].has_key( 'array' ):
468# print '%s\t\tDIRTY(cb->%s[i], nbitID);' % (indent,name)
469# else:
470# print '%s\t\tDIRTY(cb->%s, nbitID);' % (indent,name)
471
472
473
474 print('%s\t\tDIRTY(cb->dirty, nbitID);' % indent)
475 print('%s\t}' % indent)
476 if 'array' in current_fns_new[k]:
477 print('%s\t%s->ptr[i] = v;' % (indent, name ))
478 else:
479 print('%s\t%s->ptr = v;' % (indent, name ))
480 if 'array' in current_fns_new[k]:
481 print('\t\t}')
482 print('\t\tcurrent->changed%s = 0;' % k)
483 print('\t}')
484print('\tcrStateResetCurrentPointers(current);')
485print('}')
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