VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/packer/pack_client.c@ 69373

最後變更 在這個檔案從69373是 69046,由 vboxsync 提交於 7 年 前

Global: replace fall-through comments with RT_FALL_THRU().
bugref:8192: gcc warnings

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

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