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 |
|
---|
8 | from pack_currenttypes import *
|
---|
9 | import apiutil
|
---|
10 |
|
---|
11 | apiutil.CopyrightC()
|
---|
12 |
|
---|
13 | print '''
|
---|
14 | #include "state/cr_currentpointers.h"
|
---|
15 | #include "state.h"
|
---|
16 |
|
---|
17 | #include <stdio.h>
|
---|
18 |
|
---|
19 | #ifdef WINDOWS
|
---|
20 | #pragma warning( disable : 4127 )
|
---|
21 | #endif
|
---|
22 |
|
---|
23 | typedef void (*convert_func) (GLfloat *, const unsigned char *);
|
---|
24 | '''
|
---|
25 |
|
---|
26 | import convert
|
---|
27 |
|
---|
28 | for k in current_fns.keys():
|
---|
29 | name = k
|
---|
30 | name = '%s%s' % (k[:1].lower(),k[1:])
|
---|
31 | ucname = k.upper()
|
---|
32 | num_members = len(current_fns[k]['default']) + 1
|
---|
33 |
|
---|
34 | print '#define VPINCH_CONVERT_%s(op,data,dst) \\' % ucname
|
---|
35 | print '{\\'
|
---|
36 | print '\tGLfloat vdata[%d] = {' % num_members,
|
---|
37 |
|
---|
38 | ## Copy dst data into vdata
|
---|
39 | i = 0;
|
---|
40 | for defaultvar in current_fns[k]['default']:
|
---|
41 | print '%d' % defaultvar,
|
---|
42 | if i != num_members:
|
---|
43 | print ',',
|
---|
44 | i += 1
|
---|
45 | print '};\\'
|
---|
46 |
|
---|
47 | print '\tswitch (op) { \\'
|
---|
48 | for type in current_fns[k]['types']:
|
---|
49 | if type[0:1] == "N":
|
---|
50 | normalize = 1
|
---|
51 | type = type[1:]
|
---|
52 | else:
|
---|
53 | normalize = 0
|
---|
54 | for size in current_fns[k]['sizes']:
|
---|
55 | uctype = type.upper()
|
---|
56 | if ucname == 'EDGEFLAG':
|
---|
57 | print '\tcase CR_%s_OPCODE: \\' % ucname
|
---|
58 | else:
|
---|
59 | print '\tcase CR_%s%d%s_OPCODE: \\' % (ucname,size,uctype)
|
---|
60 |
|
---|
61 | if (ucname == 'COLOR' or ucname == 'NORMAL' or ucname == 'SECONDARYCOLOR' or normalize) and type != 'f' and type != 'd':
|
---|
62 | print '\t\t__convert_rescale_%s%d (vdata, (%s *) (data)); \\' % (type,size,gltypes[type]['type'])
|
---|
63 | else:
|
---|
64 | print '\t\t__convert_%s%d (vdata, (%s *) (data)); \\' % (type,size,gltypes[type]['type'])
|
---|
65 | print '\t\tbreak; \\'
|
---|
66 |
|
---|
67 | print '\tdefault: \\'
|
---|
68 | print '\t\tcrSimpleError ( "Unknown opcode in VPINCH_CONVERT_%s" ); \\' % ucname
|
---|
69 | print '\t}\\'
|
---|
70 |
|
---|
71 | i = 0
|
---|
72 | for member in current_fns[k]['members']:
|
---|
73 | print '\t(dst).%s = vdata[%d];\\' % (member,i)
|
---|
74 | i += 1
|
---|
75 |
|
---|
76 | print '}\n'
|
---|
77 |
|
---|
78 | print '''
|
---|
79 |
|
---|
80 | void crStateCurrentRecover( void )
|
---|
81 | {
|
---|
82 | const unsigned char *v;
|
---|
83 | convert_func convert=NULL;
|
---|
84 | CRContext *g = GetCurrentContext();
|
---|
85 | CRCurrentState *c = &(g->current);
|
---|
86 | CRStateBits *sb = GetCurrentBits();
|
---|
87 | CRCurrentBits *cb = &(sb->current);
|
---|
88 | static const GLfloat color_default[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
---|
89 | static const GLfloat secondaryColor_default[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
---|
90 | static const GLfloat texCoord_default[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
---|
91 | static const GLfloat normal_default[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
---|
92 | static const GLfloat index_default = 0.0f;
|
---|
93 | static const GLboolean edgeFlag_default = GL_TRUE;
|
---|
94 | static const GLfloat vertexAttrib_default[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
---|
95 | static const GLfloat fogCoord_default = 0.0f;
|
---|
96 | GLnormal_p *normal = &(c->current->c.normal);
|
---|
97 | GLcolor_p *color = &(c->current->c.color);
|
---|
98 | GLsecondarycolor_p *secondaryColor = &(c->current->c.secondaryColor);
|
---|
99 | GLtexcoord_p *texCoord = &(c->current->c.texCoord);
|
---|
100 | GLindex_p *index = &(c->current->c.index);
|
---|
101 | GLedgeflag_p *edgeFlag = &(c->current->c.edgeFlag);
|
---|
102 | GLvertexattrib_p *vertexAttrib = &(c->current->c.vertexAttrib);
|
---|
103 | GLfogcoord_p *fogCoord = &(c->current->c.fogCoord);
|
---|
104 | unsigned int i;
|
---|
105 | CRbitvalue nbitID[CR_MAX_BITARRAY];
|
---|
106 |
|
---|
107 | /*
|
---|
108 | * If the calling SPU hasn't called crStateSetCurrentPointers()
|
---|
109 | * we can't recover anything, so abort now. (i.e. we don't have
|
---|
110 | * a pincher, oh, and just emit the message once).
|
---|
111 | */
|
---|
112 | if (!c->current) {
|
---|
113 | static int donewarning = 0;
|
---|
114 | if (!donewarning)
|
---|
115 | crWarning("No pincher, please call crStateSetCurrentPointers() in your SPU");
|
---|
116 | donewarning = 1;
|
---|
117 | return; /* never get here */
|
---|
118 | }
|
---|
119 |
|
---|
120 | c->attribsUsedMask = c->current->attribsUsedMask;
|
---|
121 |
|
---|
122 | /* silence warnings */
|
---|
123 | (void) __convert_b1;
|
---|
124 | (void) __convert_b2;
|
---|
125 | (void) __convert_b3;
|
---|
126 | (void) __convert_b4;
|
---|
127 | (void) __convert_ui1;
|
---|
128 | (void) __convert_ui2;
|
---|
129 | (void) __convert_ui3;
|
---|
130 | (void) __convert_ui4;
|
---|
131 | (void) __convert_l1;
|
---|
132 | (void) __convert_l2;
|
---|
133 | (void) __convert_l3;
|
---|
134 | (void) __convert_l4;
|
---|
135 | (void) __convert_us1;
|
---|
136 | (void) __convert_us2;
|
---|
137 | (void) __convert_us3;
|
---|
138 | (void) __convert_us4;
|
---|
139 | (void) __convert_ub1;
|
---|
140 | (void) __convert_ub2;
|
---|
141 | (void) __convert_ub3;
|
---|
142 | (void) __convert_ub4;
|
---|
143 | (void) __convert_rescale_s1;
|
---|
144 | (void) __convert_rescale_s2;
|
---|
145 | (void) __convert_rescale_b1;
|
---|
146 | (void) __convert_rescale_b2;
|
---|
147 | (void) __convert_rescale_ui1;
|
---|
148 | (void) __convert_rescale_ui2;
|
---|
149 | (void) __convert_rescale_i1;
|
---|
150 | (void) __convert_rescale_i2;
|
---|
151 | (void) __convert_rescale_us1;
|
---|
152 | (void) __convert_rescale_us2;
|
---|
153 | (void) __convert_rescale_ub1;
|
---|
154 | (void) __convert_rescale_ub2;
|
---|
155 | (void) __convert_Ni1;
|
---|
156 | (void) __convert_Ni2;
|
---|
157 | (void) __convert_Ni3;
|
---|
158 | (void) __convert_Ni4;
|
---|
159 | (void) __convert_Nb1;
|
---|
160 | (void) __convert_Nb2;
|
---|
161 | (void) __convert_Nb3;
|
---|
162 | (void) __convert_Nb4;
|
---|
163 | (void) __convert_Nus1;
|
---|
164 | (void) __convert_Nus2;
|
---|
165 | (void) __convert_Nus3;
|
---|
166 | (void) __convert_Nus4;
|
---|
167 | (void) __convert_Nui1;
|
---|
168 | (void) __convert_Nui2;
|
---|
169 | (void) __convert_Nui3;
|
---|
170 | (void) __convert_Nui4;
|
---|
171 | (void) __convert_Ns1;
|
---|
172 | (void) __convert_Ns2;
|
---|
173 | (void) __convert_Ns3;
|
---|
174 | (void) __convert_Ns4;
|
---|
175 | (void) __convert_Nub1;
|
---|
176 | (void) __convert_Nub2;
|
---|
177 | (void) __convert_Nub3;
|
---|
178 | (void) __convert_Nub4;
|
---|
179 |
|
---|
180 | DIRTY(nbitID, g->neg_bitid);
|
---|
181 |
|
---|
182 | /* Save pre state */
|
---|
183 | for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++) {
|
---|
184 | COPY_4V(c->vertexAttribPre[i] , c->vertexAttrib[i]);
|
---|
185 | }
|
---|
186 | c->edgeFlagPre = c->edgeFlag;
|
---|
187 | c->colorIndexPre = c->colorIndex;
|
---|
188 |
|
---|
189 | '''
|
---|
190 |
|
---|
191 | for k in current_fns.keys():
|
---|
192 | print '\t/* %s */' % k
|
---|
193 | print '\tv=NULL;'
|
---|
194 | name = '%s%s' % (k[:1].lower(),k[1:])
|
---|
195 |
|
---|
196 | indent = ""
|
---|
197 | if current_fns[k].has_key( 'array' ):
|
---|
198 | print '\tfor (i = 0 ; i < %s ; i++)' % current_fns[k]['array']
|
---|
199 | print '\t{'
|
---|
200 | indent += "\t"
|
---|
201 | for type in current_fns[k]['types']:
|
---|
202 | if type[0:1] == "N":
|
---|
203 | normalized = 1
|
---|
204 | type2 = type[1:]
|
---|
205 | else:
|
---|
206 | normalized = 0
|
---|
207 | type2 = type
|
---|
208 | for size in current_fns[k]['sizes']:
|
---|
209 | ptr = '%s->%s%d' % (name, type, size )
|
---|
210 | if current_fns[k].has_key( 'array' ):
|
---|
211 | ptr += "[i]"
|
---|
212 | print '%s\tif (v < %s)' % (indent, ptr)
|
---|
213 | print '%s\t{' % indent
|
---|
214 | print '%s\t\tv = %s;' % (indent, ptr)
|
---|
215 | if (k == 'Color' or k == 'Normal' or k == 'SecondaryColor' or normalized) and type != 'f' and type != 'd' and type != 'l':
|
---|
216 | print '%s\t\tconvert = (convert_func) __convert_rescale_%s%d;' % (indent,type,size)
|
---|
217 | else:
|
---|
218 | print '%s\t\tconvert = (convert_func) __convert_%s%d;' % (indent,type,size)
|
---|
219 | print '%s\t}' % indent
|
---|
220 | print ''
|
---|
221 | print '%s\tif (v != NULL) {' % indent
|
---|
222 | if current_fns[k].has_key( 'array' ):
|
---|
223 | if k == 'TexCoord':
|
---|
224 | print '%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_TEX0 + i], %s_default);' % (indent,name)
|
---|
225 | else:
|
---|
226 | print '%s\t\tCOPY_4V(c->%s[i], %s_default);' % (indent,name,name)
|
---|
227 | else:
|
---|
228 | if k == 'Normal':
|
---|
229 | print '%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_NORMAL], %s_default);' % (indent,name)
|
---|
230 | elif k == 'FogCoord':
|
---|
231 | print '%s\t\tc->vertexAttrib[VERT_ATTRIB_FOG][0] = %s_default;' % (indent,name)
|
---|
232 | elif k == 'Color':
|
---|
233 | print '%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_COLOR0], %s_default);' % (indent,name)
|
---|
234 | elif k == 'SecondaryColor':
|
---|
235 | print '%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_COLOR1], %s_default);' % (indent,name)
|
---|
236 | elif k == 'TexCoord':
|
---|
237 | print '%s\t\tCOPY_4V(c->vertexAttrib[VERT_ATTRIB_TEX0], %s_default);' % (indent,name)
|
---|
238 | elif k == 'Index':
|
---|
239 | print '%s\t\tc->colorIndex = %s_default;' % (indent,name)
|
---|
240 | elif k == 'EdgeFlag':
|
---|
241 | print '%s\t\tc->edgeFlag = %s_default;' % (indent,name)
|
---|
242 | else:
|
---|
243 | print '%s\t\tc->%s = %s_default;' % (indent,name,name)
|
---|
244 | if k == 'EdgeFlag':
|
---|
245 | print '%s\t\t__convert_boolean (&c->edgeFlag, v);' % (indent)
|
---|
246 | dirtyVar = 'cb->edgeFlag'
|
---|
247 | elif k == 'Normal':
|
---|
248 | print '%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_NORMAL][0]), v);' % (indent)
|
---|
249 | dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_NORMAL]'
|
---|
250 | elif k == 'TexCoord':
|
---|
251 | print '%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_TEX0 + i][0]), v);' % (indent)
|
---|
252 | dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_TEX0 + i]'
|
---|
253 | elif k == 'Color':
|
---|
254 | print '%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_COLOR0][0]), v);' % (indent)
|
---|
255 | dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_COLOR0]'
|
---|
256 | elif k == 'Index':
|
---|
257 | print '%s\t\tconvert(&(c->colorIndex), v);' % (indent)
|
---|
258 | dirtyVar = 'cb->colorIndex'
|
---|
259 | elif k == 'SecondaryColor':
|
---|
260 | print '%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_COLOR1][0]), v);' % (indent)
|
---|
261 | dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_COLOR1]'
|
---|
262 | elif k == 'FogCoord':
|
---|
263 | print '%s\t\tconvert(&(c->vertexAttrib[VERT_ATTRIB_FOG][0]), v);' % (indent)
|
---|
264 | dirtyVar = 'cb->vertexAttrib[VERT_ATTRIB_FOG]'
|
---|
265 | elif k == 'VertexAttrib':
|
---|
266 | print '%s\t\tconvert(&(c->vertexAttrib[i][0]), v);' % (indent)
|
---|
267 | dirtyVar = 'cb->vertexAttrib[i]'
|
---|
268 | else:
|
---|
269 | assert 0 # should never get here
|
---|
270 |
|
---|
271 | print '%s\t\tDIRTY(%s, nbitID);' % (indent, dirtyVar)
|
---|
272 |
|
---|
273 | # if current_fns[k].has_key( 'array' ):
|
---|
274 | # print '%s\t\tDIRTY(cb->%s[i], nbitID);' % (indent,name)
|
---|
275 | # else:
|
---|
276 | # print '%s\t\tDIRTY(cb->%s, nbitID);' % (indent,name)
|
---|
277 |
|
---|
278 |
|
---|
279 |
|
---|
280 | print '%s\t\tDIRTY(cb->dirty, nbitID);' % indent
|
---|
281 | print '%s\t}' % indent
|
---|
282 | if current_fns[k].has_key( 'array' ):
|
---|
283 | print '%s\t%s->ptr[i] = v;' % (indent, name )
|
---|
284 | else:
|
---|
285 | print '%s\t%s->ptr = v;' % (indent, name )
|
---|
286 | if current_fns[k].has_key( 'array' ):
|
---|
287 | print '\t}'
|
---|
288 | print '}'
|
---|