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 |
|
---|
7 | #include "packer.h"
|
---|
8 | #include "cr_opcodes.h"
|
---|
9 | #include "cr_version.h"
|
---|
10 | #include "state/cr_limits.h"
|
---|
11 | #include "cr_glstate.h"
|
---|
12 |
|
---|
13 | /*Convert from GLint to GLfloat in [-1.f,1.f]*/
|
---|
14 | #define CRP_I2F_NORM(i) ((2.f*((GLint)(i))+1.f) * (1.f/4294967294.f))
|
---|
15 | /*Convert from GLshort to GLfloat in [-1.f,1.f]*/
|
---|
16 | #define CRP_S2F_NORM(s) ((2.f*((GLshort)(s))+1.f) * (1.f/65535.f))
|
---|
17 | /*Convert from GLbyte to GLfloat in [-1.f,1.f]*/
|
---|
18 | #define CRP_B2F_NORM(b) ((2.f*((GLbyte)(b))+1.f) * (1.f/255.f))
|
---|
19 | /*Convert from GLuint to GLfloat in [0.f,1.f]*/
|
---|
20 | #define CRP_UI2F_NORM(i) ((GLfloat)(i) * (1.f/4294967295.f))
|
---|
21 | /*Convert from GLushort to GLfloat in [0.f,1.f]*/
|
---|
22 | #define CRP_US2F_NORM(s) ((GLfloat)(s) * (1.f/65535.f))
|
---|
23 | /*Convert from GLubyte to GLfloat in [0.f,1.f]*/
|
---|
24 | #define CRP_UB2F_NORM(b) ((GLfloat)(b) * (1.f/255.f))
|
---|
25 |
|
---|
26 | static void crPackVertexAttrib(const CRVertexArrays *array, unsigned int attr, GLint index)
|
---|
27 | {
|
---|
28 | unsigned char *p = array->a[attr].p + index * array->a[attr].stride;
|
---|
29 |
|
---|
30 | #ifdef CR_ARB_vertex_buffer_object
|
---|
31 | if (array->a[attr].buffer && array->a[attr].buffer->data)
|
---|
32 | {
|
---|
33 | p = (unsigned char *)(array->a[attr].buffer->data) + (unsigned long)p;
|
---|
34 | }
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | if (!p)
|
---|
38 | {
|
---|
39 | crWarning("crPackVertexAttrib: NULL ptr!");
|
---|
40 | return;
|
---|
41 | }
|
---|
42 |
|
---|
43 | switch (array->a[attr].type)
|
---|
44 | {
|
---|
45 | case GL_SHORT:
|
---|
46 | {
|
---|
47 | GLshort *sPtr = (GLshort*) p;
|
---|
48 | switch (array->a[attr].size)
|
---|
49 | {
|
---|
50 | case 1:
|
---|
51 | if (array->a[attr].normalized)
|
---|
52 | crPackVertexAttrib1fARB(attr, CRP_S2F_NORM(sPtr[0]));
|
---|
53 | else
|
---|
54 | crPackVertexAttrib1svARB(attr, sPtr);
|
---|
55 | break;
|
---|
56 | case 2:
|
---|
57 | if (array->a[attr].normalized)
|
---|
58 | crPackVertexAttrib2fARB(attr, CRP_S2F_NORM(sPtr[0]), CRP_S2F_NORM(sPtr[1]));
|
---|
59 | else
|
---|
60 | crPackVertexAttrib2svARB(attr, sPtr);
|
---|
61 | break;
|
---|
62 | case 3:
|
---|
63 | if (array->a[attr].normalized)
|
---|
64 | crPackVertexAttrib3fARB(attr, CRP_S2F_NORM(sPtr[0]), CRP_S2F_NORM(sPtr[1]), CRP_S2F_NORM(sPtr[2]));
|
---|
65 | else
|
---|
66 | crPackVertexAttrib3svARB(attr, sPtr);
|
---|
67 | break;
|
---|
68 | case 4:
|
---|
69 | if (array->a[attr].normalized)
|
---|
70 | crPackVertexAttrib4NsvARB(attr, sPtr);
|
---|
71 | else
|
---|
72 | crPackVertexAttrib4svARB(attr, sPtr);
|
---|
73 | break;
|
---|
74 | }
|
---|
75 | break;
|
---|
76 | }
|
---|
77 | case GL_UNSIGNED_SHORT:
|
---|
78 | {
|
---|
79 | GLushort *usPtr = (GLushort*) p;
|
---|
80 | if (array->a[attr].normalized)
|
---|
81 | {
|
---|
82 | switch (array->a[attr].size)
|
---|
83 | {
|
---|
84 | case 1:
|
---|
85 | crPackVertexAttrib1fARB(attr, CRP_US2F_NORM(usPtr[0]));
|
---|
86 | break;
|
---|
87 | case 2:
|
---|
88 | crPackVertexAttrib2fARB(attr, CRP_US2F_NORM(usPtr[0]), CRP_US2F_NORM(usPtr[1]));
|
---|
89 | break;
|
---|
90 | case 3:
|
---|
91 | crPackVertexAttrib3fARB(attr, CRP_US2F_NORM(usPtr[0]), CRP_US2F_NORM(usPtr[1]), CRP_US2F_NORM(usPtr[2]));
|
---|
92 | break;
|
---|
93 | case 4:
|
---|
94 | crPackVertexAttrib4NusvARB(attr, usPtr);
|
---|
95 | break;
|
---|
96 | }
|
---|
97 | }
|
---|
98 | else
|
---|
99 | {
|
---|
100 | GLushort usv[4];
|
---|
101 | switch (array->a[attr].size)
|
---|
102 | {
|
---|
103 | case 4:
|
---|
104 | crPackVertexAttrib4usvARB(attr, usPtr);
|
---|
105 | break;
|
---|
106 | case 3: usv[2] = usPtr[2];
|
---|
107 | case 2: usv[1] = usPtr[1];
|
---|
108 | case 1:
|
---|
109 | usv[0] = usPtr[0];
|
---|
110 | crPackVertexAttrib4usvARB(attr, usv);
|
---|
111 | break;
|
---|
112 | }
|
---|
113 | }
|
---|
114 | break;
|
---|
115 | }
|
---|
116 | case GL_INT:
|
---|
117 | {
|
---|
118 | GLint *iPtr = (GLint*) p;
|
---|
119 | if (array->a[attr].normalized)
|
---|
120 | {
|
---|
121 | switch (array->a[attr].size)
|
---|
122 | {
|
---|
123 | case 1:
|
---|
124 | crPackVertexAttrib1fARB(attr, CRP_I2F_NORM(iPtr[0]));
|
---|
125 | break;
|
---|
126 | case 2:
|
---|
127 | crPackVertexAttrib2fARB(attr, CRP_I2F_NORM(iPtr[0]), CRP_I2F_NORM(iPtr[1]));
|
---|
128 | break;
|
---|
129 | case 3:
|
---|
130 | crPackVertexAttrib3fARB(attr, CRP_I2F_NORM(iPtr[0]), CRP_I2F_NORM(iPtr[1]), CRP_I2F_NORM(iPtr[2]));
|
---|
131 | break;
|
---|
132 | case 4:
|
---|
133 | crPackVertexAttrib4NivARB(attr, iPtr);
|
---|
134 | break;
|
---|
135 | }
|
---|
136 | }
|
---|
137 | else
|
---|
138 | {
|
---|
139 | GLint iv[4];
|
---|
140 | switch (array->a[attr].size)
|
---|
141 | {
|
---|
142 | case 4:
|
---|
143 | crPackVertexAttrib4ivARB(attr, iPtr);
|
---|
144 | break;
|
---|
145 | case 3: iv[2] = iPtr[2];
|
---|
146 | case 2: iv[1] = iPtr[1];
|
---|
147 | case 1:
|
---|
148 | iv[0] = iPtr[0];
|
---|
149 | crPackVertexAttrib4ivARB(attr, iv);
|
---|
150 | break;
|
---|
151 | }
|
---|
152 | }
|
---|
153 | break;
|
---|
154 | }
|
---|
155 | case GL_UNSIGNED_INT:
|
---|
156 | {
|
---|
157 | GLuint *uiPtr = (GLuint*) p;
|
---|
158 | if (array->a[attr].normalized)
|
---|
159 | {
|
---|
160 | switch (array->a[attr].size)
|
---|
161 | {
|
---|
162 | case 1:
|
---|
163 | crPackVertexAttrib1fARB(attr, CRP_UI2F_NORM(uiPtr[0]));
|
---|
164 | break;
|
---|
165 | case 2:
|
---|
166 | crPackVertexAttrib2fARB(attr, CRP_UI2F_NORM(uiPtr[0]), CRP_UI2F_NORM(uiPtr[1]));
|
---|
167 | break;
|
---|
168 | case 3:
|
---|
169 | crPackVertexAttrib3fARB(attr, CRP_UI2F_NORM(uiPtr[0]), CRP_UI2F_NORM(uiPtr[1]), CRP_UI2F_NORM(uiPtr[2]));
|
---|
170 | break;
|
---|
171 | case 4:
|
---|
172 | crPackVertexAttrib4NivARB(attr, uiPtr);
|
---|
173 | break;
|
---|
174 | }
|
---|
175 | }
|
---|
176 | else
|
---|
177 | {
|
---|
178 | GLuint uiv[4];
|
---|
179 | switch (array->a[attr].size)
|
---|
180 | {
|
---|
181 | case 4:
|
---|
182 | crPackVertexAttrib4uivARB(attr, uiPtr);
|
---|
183 | break;
|
---|
184 | case 3: uiv[2] = uiPtr[2];
|
---|
185 | case 2: uiv[1] = uiPtr[1];
|
---|
186 | case 1:
|
---|
187 | uiv[0] = uiPtr[0];
|
---|
188 | crPackVertexAttrib4uivARB(attr, uiv);
|
---|
189 | break;
|
---|
190 | }
|
---|
191 | }
|
---|
192 | break;
|
---|
193 | }
|
---|
194 | case GL_FLOAT:
|
---|
195 | switch (array->a[attr].size)
|
---|
196 | {
|
---|
197 | case 1: crPackVertexAttrib1fvARB(attr, (GLfloat *)p); break;
|
---|
198 | case 2: crPackVertexAttrib2fvARB(attr, (GLfloat *)p); break;
|
---|
199 | case 3: crPackVertexAttrib3fvARB(attr, (GLfloat *)p); break;
|
---|
200 | case 4: crPackVertexAttrib4fvARB(attr, (GLfloat *)p); break;
|
---|
201 | }
|
---|
202 | break;
|
---|
203 | case GL_DOUBLE:
|
---|
204 | switch (array->a[attr].size)
|
---|
205 | {
|
---|
206 | case 1: crPackVertexAttrib1dvARB(attr, (GLdouble *)p); break;
|
---|
207 | case 2: crPackVertexAttrib2dvARB(attr, (GLdouble *)p); break;
|
---|
208 | case 3: crPackVertexAttrib3dvARB(attr, (GLdouble *)p); break;
|
---|
209 | case 4: crPackVertexAttrib4dvARB(attr, (GLdouble *)p); break;
|
---|
210 | }
|
---|
211 | break;
|
---|
212 | case GL_BYTE:
|
---|
213 | {
|
---|
214 | GLbyte *bPtr = (GLbyte*) p;
|
---|
215 | if (array->a[attr].normalized)
|
---|
216 | {
|
---|
217 | switch (array->a[attr].size)
|
---|
218 | {
|
---|
219 | case 1:
|
---|
220 | crPackVertexAttrib1fARB(attr, CRP_B2F_NORM(bPtr[0]));
|
---|
221 | break;
|
---|
222 | case 2:
|
---|
223 | crPackVertexAttrib2fARB(attr, CRP_B2F_NORM(bPtr[0]), CRP_B2F_NORM(bPtr[1]));
|
---|
224 | break;
|
---|
225 | case 3:
|
---|
226 | crPackVertexAttrib3fARB(attr, CRP_B2F_NORM(bPtr[0]), CRP_B2F_NORM(bPtr[1]), CRP_B2F_NORM(bPtr[2]));
|
---|
227 | break;
|
---|
228 | case 4:
|
---|
229 | crPackVertexAttrib4NbvARB(attr, bPtr);
|
---|
230 | break;
|
---|
231 | }
|
---|
232 | }
|
---|
233 | else
|
---|
234 | {
|
---|
235 | GLbyte bv[4];
|
---|
236 | switch (array->a[attr].size)
|
---|
237 | {
|
---|
238 | case 4:
|
---|
239 | crPackVertexAttrib4bvARB(attr, bPtr);
|
---|
240 | break;
|
---|
241 | case 3: bv[2] = bPtr[2];
|
---|
242 | case 2: bv[1] = bPtr[1];
|
---|
243 | case 1:
|
---|
244 | bv[0] = bPtr[0];
|
---|
245 | crPackVertexAttrib4bvARB(attr, bv);
|
---|
246 | break;
|
---|
247 | }
|
---|
248 | }
|
---|
249 | break;
|
---|
250 | }
|
---|
251 | case GL_UNSIGNED_BYTE:
|
---|
252 | {
|
---|
253 | GLubyte *ubPtr = (GLubyte*) p;
|
---|
254 | if (array->a[attr].normalized)
|
---|
255 | {
|
---|
256 | switch (array->a[attr].size)
|
---|
257 | {
|
---|
258 | case 1:
|
---|
259 | crPackVertexAttrib1fARB(attr, CRP_UB2F_NORM(ubPtr[0]));
|
---|
260 | break;
|
---|
261 | case 2:
|
---|
262 | crPackVertexAttrib2fARB(attr, CRP_UB2F_NORM(ubPtr[0]), CRP_UB2F_NORM(ubPtr[1]));
|
---|
263 | break;
|
---|
264 | case 3:
|
---|
265 | crPackVertexAttrib3fARB(attr, CRP_UB2F_NORM(ubPtr[0]), CRP_UB2F_NORM(ubPtr[1]), CRP_UB2F_NORM(ubPtr[2]));
|
---|
266 | break;
|
---|
267 | case 4:
|
---|
268 | crPackVertexAttrib4NubvARB(attr, ubPtr);
|
---|
269 | break;
|
---|
270 | }
|
---|
271 | }
|
---|
272 | else
|
---|
273 | {
|
---|
274 | GLubyte ubv[4];
|
---|
275 | switch (array->a[attr].size)
|
---|
276 | {
|
---|
277 | case 4:
|
---|
278 | crPackVertexAttrib4ubvARB(attr, ubPtr);
|
---|
279 | break;
|
---|
280 | case 3: ubv[2] = ubPtr[2];
|
---|
281 | case 2: ubv[1] = ubPtr[1];
|
---|
282 | case 1:
|
---|
283 | ubv[0] = ubPtr[0];
|
---|
284 | crPackVertexAttrib4ubvARB(attr, ubv);
|
---|
285 | break;
|
---|
286 | }
|
---|
287 | }
|
---|
288 | break;
|
---|
289 | }
|
---|
290 | default:
|
---|
291 | crWarning("Bad datatype for vertex attribute [%d] array: 0x%x\n",
|
---|
292 | attr, array->a[attr].type);
|
---|
293 | }
|
---|
294 | }
|
---|
295 |
|
---|
296 | /*
|
---|
297 | * Expand glArrayElement into crPackVertex/Color/Normal/etc.
|
---|
298 | */
|
---|
299 | void
|
---|
300 | crPackExpandArrayElement(GLint index, CRClientState *c)
|
---|
301 | {
|
---|
302 | unsigned char *p;
|
---|
303 | unsigned int unit, attr;
|
---|
304 | const CRVertexArrays *array = &(c->array);
|
---|
305 | const GLboolean vpEnabled = crStateGetCurrent()->program.vpEnabled;
|
---|
306 |
|
---|
307 | /*crDebug("crPackExpandArrayElement(%i)", index);*/
|
---|
308 |
|
---|
309 | if (array->n.enabled && !(vpEnabled && array->a[VERT_ATTRIB_NORMAL].enabled))
|
---|
310 | {
|
---|
311 | p = array->n.p + index * array->n.stride;
|
---|
312 |
|
---|
313 | #ifdef CR_ARB_vertex_buffer_object
|
---|
314 | if (array->n.buffer && array->n.buffer->data)
|
---|
315 | {
|
---|
316 | p = (unsigned char *)(array->n.buffer->data) + (unsigned long)p;
|
---|
317 | }
|
---|
318 | #endif
|
---|
319 |
|
---|
320 | switch (array->n.type)
|
---|
321 | {
|
---|
322 | case GL_BYTE: crPackNormal3bv((GLbyte *)p); break;
|
---|
323 | case GL_SHORT: crPackNormal3sv((GLshort *)p); break;
|
---|
324 | case GL_INT: crPackNormal3iv((GLint *)p); break;
|
---|
325 | case GL_FLOAT: crPackNormal3fv((GLfloat *)p); break;
|
---|
326 | case GL_DOUBLE: crPackNormal3dv((GLdouble *)p); break;
|
---|
327 | default:
|
---|
328 | crWarning("Unhandled: crPackExpandArrayElement, array->n.type 0x%x", array->n.type);
|
---|
329 | }
|
---|
330 | }
|
---|
331 |
|
---|
332 | if (array->c.enabled && !(vpEnabled && array->a[VERT_ATTRIB_COLOR0].enabled))
|
---|
333 | {
|
---|
334 | p = array->c.p + index * array->c.stride;
|
---|
335 |
|
---|
336 | #ifdef CR_ARB_vertex_buffer_object
|
---|
337 | if (array->c.buffer && array->c.buffer->data)
|
---|
338 | {
|
---|
339 | p = (unsigned char *)(array->c.buffer->data) + (unsigned long)p;
|
---|
340 | }
|
---|
341 | #endif
|
---|
342 |
|
---|
343 | switch (array->c.type)
|
---|
344 | {
|
---|
345 | case GL_BYTE:
|
---|
346 | switch (c->array.c.size)
|
---|
347 | {
|
---|
348 | case 3: crPackColor3bv((GLbyte *)p); break;
|
---|
349 | case 4: crPackColor4bv((GLbyte *)p); break;
|
---|
350 | }
|
---|
351 | break;
|
---|
352 | case GL_UNSIGNED_BYTE:
|
---|
353 | switch (c->array.c.size)
|
---|
354 | {
|
---|
355 | case 3: crPackColor3ubv((GLubyte *)p); break;
|
---|
356 | case 4: crPackColor4ubv((GLubyte *)p); break;
|
---|
357 | }
|
---|
358 | break;
|
---|
359 | case GL_SHORT:
|
---|
360 | switch (c->array.c.size)
|
---|
361 | {
|
---|
362 | case 3: crPackColor3sv((GLshort *)p); break;
|
---|
363 | case 4: crPackColor4sv((GLshort *)p); break;
|
---|
364 | }
|
---|
365 | break;
|
---|
366 | case GL_UNSIGNED_SHORT:
|
---|
367 | switch (c->array.c.size)
|
---|
368 | {
|
---|
369 | case 3: crPackColor3usv((GLushort *)p); break;
|
---|
370 | case 4: crPackColor4usv((GLushort *)p); break;
|
---|
371 | }
|
---|
372 | break;
|
---|
373 | case GL_INT:
|
---|
374 | switch (c->array.c.size)
|
---|
375 | {
|
---|
376 | case 3: crPackColor3iv((GLint *)p); break;
|
---|
377 | case 4: crPackColor4iv((GLint *)p); break;
|
---|
378 | }
|
---|
379 | break;
|
---|
380 | case GL_UNSIGNED_INT:
|
---|
381 | switch (c->array.c.size)
|
---|
382 | {
|
---|
383 | case 3: crPackColor3uiv((GLuint *)p); break;
|
---|
384 | case 4: crPackColor4uiv((GLuint *)p); break;
|
---|
385 | }
|
---|
386 | break;
|
---|
387 | case GL_FLOAT:
|
---|
388 | switch (c->array.c.size)
|
---|
389 | {
|
---|
390 | case 3: crPackColor3fv((GLfloat *)p); break;
|
---|
391 | case 4: crPackColor4fv((GLfloat *)p); break;
|
---|
392 | }
|
---|
393 | break;
|
---|
394 | case GL_DOUBLE:
|
---|
395 | switch (c->array.c.size)
|
---|
396 | {
|
---|
397 | case 3: crPackColor3dv((GLdouble *)p); break;
|
---|
398 | case 4: crPackColor4dv((GLdouble *)p); break;
|
---|
399 | }
|
---|
400 | break;
|
---|
401 | default:
|
---|
402 | crWarning("Unhandled: crPackExpandArrayElement, array->c.type 0x%x", array->c.type);
|
---|
403 | }
|
---|
404 | }
|
---|
405 |
|
---|
406 | #ifdef CR_EXT_secondary_color
|
---|
407 | if (array->s.enabled && !(vpEnabled && array->a[VERT_ATTRIB_COLOR1].enabled))
|
---|
408 | {
|
---|
409 | p = array->s.p + index * array->s.stride;
|
---|
410 |
|
---|
411 | #ifdef CR_ARB_vertex_buffer_object
|
---|
412 | if (array->s.buffer && array->s.buffer->data)
|
---|
413 | {
|
---|
414 | p = (unsigned char *)(array->s.buffer->data) + (unsigned long)p;
|
---|
415 | }
|
---|
416 | #endif
|
---|
417 |
|
---|
418 | switch (array->s.type)
|
---|
419 | {
|
---|
420 | case GL_BYTE:
|
---|
421 | crPackSecondaryColor3bvEXT((GLbyte *)p); break;
|
---|
422 | case GL_UNSIGNED_BYTE:
|
---|
423 | crPackSecondaryColor3ubvEXT((GLubyte *)p); break;
|
---|
424 | case GL_SHORT:
|
---|
425 | crPackSecondaryColor3svEXT((GLshort *)p); break;
|
---|
426 | case GL_UNSIGNED_SHORT:
|
---|
427 | crPackSecondaryColor3usvEXT((GLushort *)p); break;
|
---|
428 | case GL_INT:
|
---|
429 | crPackSecondaryColor3ivEXT((GLint *)p); break;
|
---|
430 | case GL_UNSIGNED_INT:
|
---|
431 | crPackSecondaryColor3uivEXT((GLuint *)p); break;
|
---|
432 | case GL_FLOAT:
|
---|
433 | crPackSecondaryColor3fvEXT((GLfloat *)p); break;
|
---|
434 | case GL_DOUBLE:
|
---|
435 | crPackSecondaryColor3dvEXT((GLdouble *)p); break;
|
---|
436 | default:
|
---|
437 | crWarning("Unhandled: crPackExpandArrayElement, array->s.type 0x%x", array->s.type);
|
---|
438 | }
|
---|
439 | }
|
---|
440 | #endif // CR_EXT_secondary_color
|
---|
441 |
|
---|
442 |
|
---|
443 | #ifdef CR_EXT_fog_coord
|
---|
444 | if (array->f.enabled && !(vpEnabled && array->a[VERT_ATTRIB_FOG].enabled))
|
---|
445 | {
|
---|
446 | p = array->f.p + index * array->f.stride;
|
---|
447 |
|
---|
448 | #ifdef CR_ARB_vertex_buffer_object
|
---|
449 | if (array->f.buffer && array->f.buffer->data)
|
---|
450 | {
|
---|
451 | p = (unsigned char *)(array->f.buffer->data) + (unsigned long)p;
|
---|
452 | }
|
---|
453 | #endif
|
---|
454 | crPackFogCoordfEXT( *((GLfloat *) p) );
|
---|
455 | }
|
---|
456 | #endif // CR_EXT_fog_coord
|
---|
457 |
|
---|
458 | for (unit = 0 ; unit < CR_MAX_TEXTURE_UNITS ; unit++)
|
---|
459 | {
|
---|
460 | if (array->t[unit].enabled && !(vpEnabled && array->a[VERT_ATTRIB_TEX0+unit].enabled))
|
---|
461 | {
|
---|
462 | p = array->t[unit].p + index * array->t[unit].stride;
|
---|
463 |
|
---|
464 | #ifdef CR_ARB_vertex_buffer_object
|
---|
465 | if (array->t[unit].buffer && array->t[unit].buffer->data)
|
---|
466 | {
|
---|
467 | p = (unsigned char *)(array->t[unit].buffer->data) + (unsigned long)p;
|
---|
468 | }
|
---|
469 | #endif
|
---|
470 |
|
---|
471 | switch (array->t[unit].type)
|
---|
472 | {
|
---|
473 | case GL_SHORT:
|
---|
474 | switch (array->t[unit].size)
|
---|
475 | {
|
---|
476 | case 1: crPackMultiTexCoord1svARB(GL_TEXTURE0_ARB + unit, (GLshort *)p); break;
|
---|
477 | case 2: crPackMultiTexCoord2svARB(GL_TEXTURE0_ARB + unit, (GLshort *)p); break;
|
---|
478 | case 3: crPackMultiTexCoord3svARB(GL_TEXTURE0_ARB + unit, (GLshort *)p); break;
|
---|
479 | case 4: crPackMultiTexCoord4svARB(GL_TEXTURE0_ARB + unit, (GLshort *)p); break;
|
---|
480 | }
|
---|
481 | break;
|
---|
482 | case GL_INT:
|
---|
483 | switch (array->t[unit].size)
|
---|
484 | {
|
---|
485 | case 1: crPackMultiTexCoord1ivARB(GL_TEXTURE0_ARB + unit, (GLint *)p); break;
|
---|
486 | case 2: crPackMultiTexCoord2ivARB(GL_TEXTURE0_ARB + unit, (GLint *)p); break;
|
---|
487 | case 3: crPackMultiTexCoord3ivARB(GL_TEXTURE0_ARB + unit, (GLint *)p); break;
|
---|
488 | case 4: crPackMultiTexCoord4ivARB(GL_TEXTURE0_ARB + unit, (GLint *)p); break;
|
---|
489 | }
|
---|
490 | break;
|
---|
491 | case GL_FLOAT:
|
---|
492 | switch (array->t[unit].size)
|
---|
493 | {
|
---|
494 | case 1: crPackMultiTexCoord1fvARB(GL_TEXTURE0_ARB + unit, (GLfloat *)p); break;
|
---|
495 | case 2: crPackMultiTexCoord2fvARB(GL_TEXTURE0_ARB + unit, (GLfloat *)p); break;
|
---|
496 | case 3: crPackMultiTexCoord3fvARB(GL_TEXTURE0_ARB + unit, (GLfloat *)p); break;
|
---|
497 | case 4: crPackMultiTexCoord4fvARB(GL_TEXTURE0_ARB + unit, (GLfloat *)p); break;
|
---|
498 | }
|
---|
499 | break;
|
---|
500 | case GL_DOUBLE:
|
---|
501 | switch (array->t[unit].size)
|
---|
502 | {
|
---|
503 | case 1: crPackMultiTexCoord1dvARB(GL_TEXTURE0_ARB + unit, (GLdouble *)p); break;
|
---|
504 | case 2: crPackMultiTexCoord2dvARB(GL_TEXTURE0_ARB + unit, (GLdouble *)p); break;
|
---|
505 | case 3: crPackMultiTexCoord3dvARB(GL_TEXTURE0_ARB + unit, (GLdouble *)p); break;
|
---|
506 | case 4: crPackMultiTexCoord4dvARB(GL_TEXTURE0_ARB + unit, (GLdouble *)p); break;
|
---|
507 | }
|
---|
508 | break;
|
---|
509 | default:
|
---|
510 | crWarning("Unhandled: crPackExpandArrayElement, array->t[%i].type 0x%x", unit, array->t[unit].type);
|
---|
511 | }
|
---|
512 | }
|
---|
513 | }
|
---|
514 |
|
---|
515 | if (array->i.enabled)
|
---|
516 | {
|
---|
517 | p = array->i.p + index * array->i.stride;
|
---|
518 |
|
---|
519 | #ifdef CR_ARB_vertex_buffer_object
|
---|
520 | if (array->i.buffer && array->i.buffer->data)
|
---|
521 | {
|
---|
522 | p = (unsigned char *)(array->i.buffer->data) + (unsigned long)p;
|
---|
523 | }
|
---|
524 | #endif
|
---|
525 |
|
---|
526 | switch (array->i.type)
|
---|
527 | {
|
---|
528 | case GL_SHORT: crPackIndexsv((GLshort *)p); break;
|
---|
529 | case GL_INT: crPackIndexiv((GLint *)p); break;
|
---|
530 | case GL_FLOAT: crPackIndexfv((GLfloat *)p); break;
|
---|
531 | case GL_DOUBLE: crPackIndexdv((GLdouble *)p); break;
|
---|
532 | default:
|
---|
533 | crWarning("Unhandled: crPackExpandArrayElement, array->i.type 0x%x", array->i.type);
|
---|
534 | }
|
---|
535 | }
|
---|
536 |
|
---|
537 | if (array->e.enabled)
|
---|
538 | {
|
---|
539 | p = array->e.p + index * array->e.stride;
|
---|
540 |
|
---|
541 | #ifdef CR_ARB_vertex_buffer_object
|
---|
542 | if (array->e.buffer && array->e.buffer->data)
|
---|
543 | {
|
---|
544 | p = (unsigned char *)(array->e.buffer->data) + (unsigned long)p;
|
---|
545 | }
|
---|
546 | #endif
|
---|
547 |
|
---|
548 | crPackEdgeFlagv(p);
|
---|
549 | }
|
---|
550 |
|
---|
551 | for (attr = 1; attr < VERT_ATTRIB_MAX; attr++)
|
---|
552 | {
|
---|
553 | if (array->a[attr].enabled)
|
---|
554 | {
|
---|
555 | crPackVertexAttrib(array, attr, index);
|
---|
556 | }
|
---|
557 | }
|
---|
558 |
|
---|
559 | if (array->a[VERT_ATTRIB_POS].enabled)
|
---|
560 | {
|
---|
561 | crPackVertexAttrib(array, 0, index);
|
---|
562 | }
|
---|
563 | else if (array->v.enabled)
|
---|
564 | {
|
---|
565 | p = array->v.p + index * array->v.stride;
|
---|
566 |
|
---|
567 | #ifdef CR_ARB_vertex_buffer_object
|
---|
568 | if (array->v.buffer && array->v.buffer->data)
|
---|
569 | {
|
---|
570 | p = (unsigned char *)(array->v.buffer->data) + (unsigned long)p;
|
---|
571 | }
|
---|
572 | #endif
|
---|
573 | switch (array->v.type)
|
---|
574 | {
|
---|
575 | case GL_SHORT:
|
---|
576 | switch (c->array.v.size)
|
---|
577 | {
|
---|
578 | case 2: crPackVertex2sv((GLshort *)p); break;
|
---|
579 | case 3: crPackVertex3sv((GLshort *)p); break;
|
---|
580 | case 4: crPackVertex4sv((GLshort *)p); break;
|
---|
581 | }
|
---|
582 | break;
|
---|
583 | case GL_INT:
|
---|
584 | switch (c->array.v.size)
|
---|
585 | {
|
---|
586 | case 2: crPackVertex2iv((GLint *)p); break;
|
---|
587 | case 3: crPackVertex3iv((GLint *)p); break;
|
---|
588 | case 4: crPackVertex4iv((GLint *)p); break;
|
---|
589 | }
|
---|
590 | break;
|
---|
591 | case GL_FLOAT:
|
---|
592 | switch (c->array.v.size)
|
---|
593 | {
|
---|
594 | case 2: crPackVertex2fv((GLfloat *)p); break;
|
---|
595 | case 3: crPackVertex3fv((GLfloat *)p); break;
|
---|
596 | case 4: crPackVertex4fv((GLfloat *)p); break;
|
---|
597 | }
|
---|
598 | break;
|
---|
599 | case GL_DOUBLE:
|
---|
600 | switch (c->array.v.size)
|
---|
601 | {
|
---|
602 | case 2: crPackVertex2dv((GLdouble *)p); break;
|
---|
603 | case 3: crPackVertex3dv((GLdouble *)p); break;
|
---|
604 | case 4: crPackVertex4dv((GLdouble *)p); break;
|
---|
605 | }
|
---|
606 | break;
|
---|
607 | default:
|
---|
608 | crWarning("Unhandled: crPackExpandArrayElement, array->v.type 0x%x", array->v.type);
|
---|
609 | }
|
---|
610 | }
|
---|
611 | }
|
---|
612 |
|
---|
613 |
|
---|
614 | void
|
---|
615 | crPackExpandDrawArrays(GLenum mode, GLint first, GLsizei count, CRClientState *c)
|
---|
616 | {
|
---|
617 | int i;
|
---|
618 |
|
---|
619 | if (count < 0)
|
---|
620 | {
|
---|
621 | __PackError(__LINE__, __FILE__, GL_INVALID_VALUE, "crPackDrawArrays(negative count)");
|
---|
622 | return;
|
---|
623 | }
|
---|
624 |
|
---|
625 | if (mode > GL_POLYGON)
|
---|
626 | {
|
---|
627 | __PackError(__LINE__, __FILE__, GL_INVALID_ENUM, "crPackDrawArrays(bad mode)");
|
---|
628 | return;
|
---|
629 | }
|
---|
630 |
|
---|
631 | crPackBegin(mode);
|
---|
632 | for (i=0; i<count; i++)
|
---|
633 | {
|
---|
634 | crPackExpandArrayElement(first + i, c);
|
---|
635 | }
|
---|
636 | crPackEnd();
|
---|
637 | }
|
---|
638 |
|
---|
639 | static GLsizei crPackElementsIndexSize(GLenum type)
|
---|
640 | {
|
---|
641 | switch (type)
|
---|
642 | {
|
---|
643 | case GL_UNSIGNED_BYTE:
|
---|
644 | return sizeof(GLubyte);
|
---|
645 | case GL_UNSIGNED_SHORT:
|
---|
646 | return sizeof(GLushort);
|
---|
647 | case GL_UNSIGNED_INT:
|
---|
648 | return sizeof(GLuint);
|
---|
649 | default:
|
---|
650 | crError("Unknown type 0x%x in crPackElementsIndexSize", type);
|
---|
651 | return 0;
|
---|
652 | }
|
---|
653 | }
|
---|
654 |
|
---|
655 | void PACK_APIENTRY
|
---|
656 | crPackDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
|
---|
657 | {
|
---|
658 | unsigned char *data_ptr, *start_ptr;
|
---|
659 | int packet_length = sizeof(int) + sizeof(mode) + sizeof(count) + sizeof(type) + sizeof(GLuint);
|
---|
660 | GLsizei indexsize;
|
---|
661 | #ifdef CR_ARB_vertex_buffer_object
|
---|
662 | CRBufferObject *elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer;
|
---|
663 | packet_length += sizeof(GLint);
|
---|
664 | if (elementsBuffer && elementsBuffer->name)
|
---|
665 | {
|
---|
666 | /*@todo not sure it's possible, and not sure what to do*/
|
---|
667 | if (!elementsBuffer->data)
|
---|
668 | {
|
---|
669 | crWarning("crPackDrawElements: trying to use bound but empty elements buffer, ignoring.");
|
---|
670 | return;
|
---|
671 | }
|
---|
672 | indexsize = 0;
|
---|
673 | }
|
---|
674 | else
|
---|
675 | #endif
|
---|
676 | {
|
---|
677 | indexsize = crPackElementsIndexSize(type);
|
---|
678 | }
|
---|
679 |
|
---|
680 | packet_length += count * indexsize;
|
---|
681 |
|
---|
682 | start_ptr = data_ptr = (unsigned char *) crPackAlloc(packet_length);
|
---|
683 | WRITE_DATA_AI(GLenum, CR_DRAWELEMENTS_EXTEND_OPCODE );
|
---|
684 | WRITE_DATA_AI(GLenum, mode );
|
---|
685 | WRITE_DATA_AI(GLsizei, count);
|
---|
686 | WRITE_DATA_AI(GLenum, type);
|
---|
687 | WRITE_DATA_AI(GLuint, (GLuint) indices );
|
---|
688 | #ifdef CR_ARB_vertex_buffer_object
|
---|
689 | WRITE_DATA_AI(GLint, (GLint)(indexsize>0));
|
---|
690 | #endif
|
---|
691 | if (indexsize>0)
|
---|
692 | {
|
---|
693 | crMemcpy(data_ptr, indices, count * indexsize);
|
---|
694 | }
|
---|
695 | crHugePacket(CR_EXTEND_OPCODE, start_ptr);
|
---|
696 | crPackFree(start_ptr);
|
---|
697 | }
|
---|
698 |
|
---|
699 | void PACK_APIENTRY
|
---|
700 | crPackDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count,
|
---|
701 | GLenum type, const GLvoid *indices)
|
---|
702 | {
|
---|
703 | unsigned char *data_ptr, *start_ptr;
|
---|
704 | int packet_length = sizeof(int) + sizeof(mode) + sizeof(start)
|
---|
705 | + sizeof(end) + sizeof(count) + sizeof(type) + sizeof(GLuint);
|
---|
706 | GLsizei indexsize;
|
---|
707 |
|
---|
708 | #ifdef CR_ARB_vertex_buffer_object
|
---|
709 | CRBufferObject *elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer;
|
---|
710 | packet_length += sizeof(GLint);
|
---|
711 | if (elementsBuffer && elementsBuffer->name)
|
---|
712 | {
|
---|
713 | /*@todo not sure it's possible, and not sure what to do*/
|
---|
714 | if (!elementsBuffer->data)
|
---|
715 | {
|
---|
716 | crWarning("crPackDrawElements: trying to use bound but empty elements buffer, ignoring.");
|
---|
717 | return;
|
---|
718 | }
|
---|
719 | indexsize = 0;
|
---|
720 | }
|
---|
721 | else
|
---|
722 | #endif
|
---|
723 | {
|
---|
724 | indexsize = crPackElementsIndexSize(type);
|
---|
725 | }
|
---|
726 |
|
---|
727 | packet_length += count * indexsize;
|
---|
728 |
|
---|
729 | start_ptr = data_ptr = (unsigned char *) crPackAlloc(packet_length);
|
---|
730 | WRITE_DATA_AI(GLenum, CR_DRAWRANGEELEMENTS_EXTEND_OPCODE);
|
---|
731 | WRITE_DATA_AI(GLenum, mode);
|
---|
732 | WRITE_DATA_AI(GLuint, start);
|
---|
733 | WRITE_DATA_AI(GLuint, end);
|
---|
734 | WRITE_DATA_AI(GLsizei, count);
|
---|
735 | WRITE_DATA_AI(GLenum, type);
|
---|
736 | WRITE_DATA_AI(GLuint, (GLuint) indices);
|
---|
737 | #ifdef CR_ARB_vertex_buffer_object
|
---|
738 | WRITE_DATA_AI(GLint, (GLint) (indexsize>0));
|
---|
739 | #endif
|
---|
740 | if (indexsize>0)
|
---|
741 | {
|
---|
742 | crMemcpy(data_ptr, indices, count * indexsize);
|
---|
743 | }
|
---|
744 | crHugePacket(CR_EXTEND_OPCODE, start_ptr);
|
---|
745 | crPackFree(start_ptr);
|
---|
746 | }
|
---|
747 |
|
---|
748 |
|
---|
749 | /**
|
---|
750 | * Expand glDrawElements into crPackBegin/Vertex/End, etc commands.
|
---|
751 | * Note: if mode==999, don't call glBegin/glEnd.
|
---|
752 | */
|
---|
753 | void
|
---|
754 | crPackExpandDrawElements(GLenum mode, GLsizei count, GLenum type,
|
---|
755 | const GLvoid *indices, CRClientState *c)
|
---|
756 | {
|
---|
757 | int i;
|
---|
758 | GLubyte *p = (GLubyte *)indices;
|
---|
759 | #ifdef CR_ARB_vertex_buffer_object
|
---|
760 | CRBufferObject *elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer;
|
---|
761 | #endif
|
---|
762 |
|
---|
763 | if (count < 0)
|
---|
764 | {
|
---|
765 | __PackError(__LINE__, __FILE__, GL_INVALID_VALUE,
|
---|
766 | "crPackDrawElements(negative count)");
|
---|
767 | return;
|
---|
768 | }
|
---|
769 |
|
---|
770 | if (mode > GL_POLYGON && mode != 999)
|
---|
771 | {
|
---|
772 | __PackError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
773 | "crPackDrawElements(bad mode)");
|
---|
774 | return;
|
---|
775 | }
|
---|
776 |
|
---|
777 | if (type != GL_UNSIGNED_BYTE &&
|
---|
778 | type != GL_UNSIGNED_SHORT &&
|
---|
779 | type != GL_UNSIGNED_INT)
|
---|
780 | {
|
---|
781 | __PackError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
782 | "crPackDrawElements(bad type)");
|
---|
783 | return;
|
---|
784 | }
|
---|
785 |
|
---|
786 | #ifdef CR_ARB_vertex_buffer_object
|
---|
787 | if (elementsBuffer && elementsBuffer->data)
|
---|
788 | {
|
---|
789 | p = (unsigned char *)(elementsBuffer->data) + (unsigned long)p;
|
---|
790 | }
|
---|
791 | #endif
|
---|
792 |
|
---|
793 | if (mode != 999)
|
---|
794 | crPackBegin(mode);
|
---|
795 |
|
---|
796 | //crDebug("crPackExpandDrawElements mode:0x%x, count:%d, type:0x%x", mode, count, type);
|
---|
797 |
|
---|
798 | switch (type)
|
---|
799 | {
|
---|
800 | case GL_UNSIGNED_BYTE:
|
---|
801 | for (i=0; i<count; i++)
|
---|
802 | {
|
---|
803 | crPackExpandArrayElement((GLint) *p++, c);
|
---|
804 | }
|
---|
805 | break;
|
---|
806 | case GL_UNSIGNED_SHORT:
|
---|
807 | for (i=0; i<count; i++)
|
---|
808 | {
|
---|
809 | crPackExpandArrayElement((GLint) * (GLushort *) p, c);
|
---|
810 | p+=sizeof (GLushort);
|
---|
811 | }
|
---|
812 | break;
|
---|
813 | case GL_UNSIGNED_INT:
|
---|
814 | for (i=0; i<count; i++)
|
---|
815 | {
|
---|
816 | crPackExpandArrayElement((GLint) * (GLuint *) p, c);
|
---|
817 | p+=sizeof (GLuint);
|
---|
818 | }
|
---|
819 | break;
|
---|
820 | default:
|
---|
821 | crError( "this can't happen: array_spu.self.DrawElements" );
|
---|
822 | break;
|
---|
823 | }
|
---|
824 |
|
---|
825 | if (mode != 999)
|
---|
826 | crPackEnd();
|
---|
827 | }
|
---|
828 |
|
---|
829 |
|
---|
830 | /**
|
---|
831 | * Convert a glDrawElements command into a sequence of ArrayElement() calls.
|
---|
832 | * NOTE: Caller must issue the glBegin/glEnd.
|
---|
833 | */
|
---|
834 | void
|
---|
835 | crPackUnrollDrawElements(GLsizei count, GLenum type,
|
---|
836 | const GLvoid *indices)
|
---|
837 | {
|
---|
838 | int i;
|
---|
839 |
|
---|
840 | switch (type) {
|
---|
841 | case GL_UNSIGNED_BYTE:
|
---|
842 | {
|
---|
843 | const GLubyte *p = (const GLubyte *) indices;
|
---|
844 | for (i = 0; i < count; i++)
|
---|
845 | crPackArrayElement(p[i]);
|
---|
846 | }
|
---|
847 | break;
|
---|
848 | case GL_UNSIGNED_SHORT:
|
---|
849 | {
|
---|
850 | const GLushort *p = (const GLushort *) indices;
|
---|
851 | for (i = 0; i < count; i++)
|
---|
852 | crPackArrayElement(p[i]);
|
---|
853 | }
|
---|
854 | break;
|
---|
855 | case GL_UNSIGNED_INT:
|
---|
856 | {
|
---|
857 | const GLuint *p = (const GLuint *) indices;
|
---|
858 | for (i = 0; i < count; i++)
|
---|
859 | crPackArrayElement(p[i]);
|
---|
860 | }
|
---|
861 | break;
|
---|
862 | default:
|
---|
863 | __PackError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
864 | "crPackUnrollDrawElements(bad type)");
|
---|
865 | }
|
---|
866 | }
|
---|
867 |
|
---|
868 |
|
---|
869 |
|
---|
870 | /*
|
---|
871 | * glDrawRangeElements, expanded into crPackBegin/Vertex/End/etc.
|
---|
872 | */
|
---|
873 | void
|
---|
874 | crPackExpandDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, CRClientState *c)
|
---|
875 | {
|
---|
876 | if (start>end)
|
---|
877 | {
|
---|
878 | crWarning("crPackExpandDrawRangeElements start>end (%d>%d)", start, end);
|
---|
879 | return;
|
---|
880 | }
|
---|
881 |
|
---|
882 | crPackExpandDrawElements(mode, count, type, indices, c);
|
---|
883 | }
|
---|
884 |
|
---|
885 |
|
---|
886 | #ifdef CR_EXT_multi_draw_arrays
|
---|
887 | /*
|
---|
888 | * Pack real DrawArrays commands.
|
---|
889 | */
|
---|
890 | void PACK_APIENTRY
|
---|
891 | crPackMultiDrawArraysEXT( GLenum mode, GLint *first, GLsizei *count,
|
---|
892 | GLsizei primcount )
|
---|
893 | {
|
---|
894 | GLint i;
|
---|
895 | for (i = 0; i < primcount; i++) {
|
---|
896 | if (count[i] > 0) {
|
---|
897 | crPackDrawArrays(mode, first[i], count[i]);
|
---|
898 | }
|
---|
899 | }
|
---|
900 | }
|
---|
901 |
|
---|
902 |
|
---|
903 | /*
|
---|
904 | * Pack with crPackBegin/Vertex/End/etc.
|
---|
905 | */
|
---|
906 | void
|
---|
907 | crPackExpandMultiDrawArraysEXT( GLenum mode, GLint *first, GLsizei *count,
|
---|
908 | GLsizei primcount, CRClientState *c )
|
---|
909 | {
|
---|
910 | GLint i;
|
---|
911 | for (i = 0; i < primcount; i++) {
|
---|
912 | if (count[i] > 0) {
|
---|
913 | crPackExpandDrawArrays(mode, first[i], count[i], c);
|
---|
914 | }
|
---|
915 | }
|
---|
916 | }
|
---|
917 |
|
---|
918 |
|
---|
919 | /*
|
---|
920 | * Pack real DrawElements commands.
|
---|
921 | */
|
---|
922 | void PACK_APIENTRY
|
---|
923 | crPackMultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type,
|
---|
924 | const GLvoid **indices, GLsizei primcount )
|
---|
925 | {
|
---|
926 | GLint i;
|
---|
927 | for (i = 0; i < primcount; i++) {
|
---|
928 | if (count[i] > 0) {
|
---|
929 | crPackDrawElements(mode, count[i], type, indices[i]);
|
---|
930 | }
|
---|
931 | }
|
---|
932 | }
|
---|
933 |
|
---|
934 |
|
---|
935 | /*
|
---|
936 | * Pack with crPackBegin/Vertex/End/etc.
|
---|
937 | */
|
---|
938 | void
|
---|
939 | crPackExpandMultiDrawElementsEXT( GLenum mode, const GLsizei *count,
|
---|
940 | GLenum type, const GLvoid **indices,
|
---|
941 | GLsizei primcount, CRClientState *c )
|
---|
942 | {
|
---|
943 | GLint i;
|
---|
944 | for (i = 0; i < primcount; i++) {
|
---|
945 | if (count[i] > 0) {
|
---|
946 | crPackExpandDrawElements(mode, count[i], type, indices[i], c);
|
---|
947 | }
|
---|
948 | }
|
---|
949 | }
|
---|
950 | #endif /* CR_EXT_multi_draw_arrays */
|
---|
951 |
|
---|
952 | static int crPack_GetNumEnabledArrays(CRClientState *c, int *size)
|
---|
953 | {
|
---|
954 | int i, count=0;
|
---|
955 |
|
---|
956 | *size = 0;
|
---|
957 |
|
---|
958 | if (c->array.v.enabled)
|
---|
959 | {
|
---|
960 | count++;
|
---|
961 | *size += c->array.v.bytesPerIndex;
|
---|
962 | }
|
---|
963 |
|
---|
964 | if (c->array.c.enabled)
|
---|
965 | {
|
---|
966 | count++;
|
---|
967 | *size += c->array.c.bytesPerIndex;
|
---|
968 | }
|
---|
969 |
|
---|
970 | if (c->array.f.enabled)
|
---|
971 | {
|
---|
972 | count++;
|
---|
973 | *size += c->array.f.bytesPerIndex;
|
---|
974 | }
|
---|
975 |
|
---|
976 | if (c->array.s.enabled)
|
---|
977 | {
|
---|
978 | count++;
|
---|
979 | *size += c->array.s.bytesPerIndex;
|
---|
980 | }
|
---|
981 |
|
---|
982 | if (c->array.e.enabled)
|
---|
983 | {
|
---|
984 | count++;
|
---|
985 | *size += c->array.e.bytesPerIndex;
|
---|
986 | }
|
---|
987 |
|
---|
988 | if (c->array.i.enabled)
|
---|
989 | {
|
---|
990 | count++;
|
---|
991 | *size += c->array.i.bytesPerIndex;
|
---|
992 | }
|
---|
993 |
|
---|
994 | if (c->array.n.enabled)
|
---|
995 | {
|
---|
996 | count++;
|
---|
997 | *size += c->array.n.bytesPerIndex;
|
---|
998 | }
|
---|
999 |
|
---|
1000 | for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
|
---|
1001 | {
|
---|
1002 | if (c->array.t[i].enabled)
|
---|
1003 | {
|
---|
1004 | count++;
|
---|
1005 | *size += c->array.t[i].bytesPerIndex;
|
---|
1006 | }
|
---|
1007 | }
|
---|
1008 |
|
---|
1009 | for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++)
|
---|
1010 | {
|
---|
1011 | if (c->array.a[i].enabled)
|
---|
1012 | {
|
---|
1013 | count++;
|
---|
1014 | *size += c->array.a[i].bytesPerIndex;
|
---|
1015 | }
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | return count;
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | static void crPackLockClientPointer(GLint first, GLint count, unsigned char **ppData, int index, CRClientState *c)
|
---|
1022 | {
|
---|
1023 | CRClientPointer *cp;
|
---|
1024 | unsigned char *data_ptr = *ppData, *cptr;
|
---|
1025 | GLint i;
|
---|
1026 |
|
---|
1027 | cp = crStateGetClientPointerByIndex(index, &c->array);
|
---|
1028 |
|
---|
1029 | if (cp->enabled)
|
---|
1030 | {
|
---|
1031 | if (cp->buffer && cp->buffer->name)
|
---|
1032 | {
|
---|
1033 | crWarning("crPackLockClientPointer called when there's VBO enabled!");
|
---|
1034 | }
|
---|
1035 |
|
---|
1036 | WRITE_DATA_AI(int, index);
|
---|
1037 | cptr = cp->p + first*cp->bytesPerIndex;
|
---|
1038 | if (cp->bytesPerIndex==cp->stride)
|
---|
1039 | {
|
---|
1040 | crMemcpy(data_ptr, cptr, count*cp->bytesPerIndex);
|
---|
1041 | data_ptr += count*cp->bytesPerIndex;
|
---|
1042 | }
|
---|
1043 | else
|
---|
1044 | {
|
---|
1045 | for (i=0; i<count; ++i)
|
---|
1046 | {
|
---|
1047 | crMemcpy(data_ptr, cptr, cp->bytesPerIndex);
|
---|
1048 | data_ptr += cp->bytesPerIndex;
|
---|
1049 | cptr += cp->stride;
|
---|
1050 | }
|
---|
1051 | }
|
---|
1052 | *ppData = data_ptr;
|
---|
1053 | }
|
---|
1054 | }
|
---|
1055 |
|
---|
1056 | void PACK_APIENTRY crPackLockArraysEXT(GLint first, GLint count)
|
---|
1057 | {
|
---|
1058 | CRContext *g = crStateGetCurrent();
|
---|
1059 | CRClientState *c = &g->client;
|
---|
1060 | unsigned char *data_ptr, *start_ptr;
|
---|
1061 | int packet_length = sizeof(int); /*extopcode*/
|
---|
1062 | int vertex_size, i, numenabled;
|
---|
1063 |
|
---|
1064 | packet_length += sizeof(first) + sizeof(count); /*params*/
|
---|
1065 | numenabled = crPack_GetNumEnabledArrays(c, &vertex_size);
|
---|
1066 | packet_length += sizeof(int) + numenabled*sizeof(int); /*numenabled + indices*/
|
---|
1067 | packet_length += vertex_size * count; /*vertices data*/
|
---|
1068 |
|
---|
1069 | start_ptr = data_ptr = (unsigned char *) crPackAlloc(packet_length);
|
---|
1070 | WRITE_DATA_AI(GLenum, CR_LOCKARRAYSEXT_EXTEND_OPCODE );
|
---|
1071 | WRITE_DATA_AI(GLint, first);
|
---|
1072 | WRITE_DATA_AI(GLint, count);
|
---|
1073 | WRITE_DATA_AI(int, numenabled);
|
---|
1074 | for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i)
|
---|
1075 | {
|
---|
1076 | crPackLockClientPointer(first, count, &data_ptr, i, c);
|
---|
1077 | }
|
---|
1078 | crHugePacket(CR_EXTEND_OPCODE, start_ptr);
|
---|
1079 | crPackFree(start_ptr);
|
---|
1080 | }
|
---|