VirtualBox

source: vbox/trunk/src/VBox/Additions/common/crOpenGL/array/arrayspu.c@ 20476

Last change on this file since 20476 was 20476, checked in by vboxsync, 16 years ago

crOpenGL: fix vertex arrays and glsl interaction

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 31.3 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 */
6
7#include <stdio.h>
8#include "cr_spu.h"
9#include "cr_error.h"
10#include "state/cr_limits.h"
11#include "arrayspu.h"
12
13ArraySPU array_spu;
14
15#ifdef CHROMIUM_THREADSAFE
16CRmutex _ArrayMutex;
17#endif
18
19static void ARRAYSPU_APIENTRY arrayspu_ArrayElement( GLint index )
20{
21 const CRClientState *c = &(crStateGetCurrent()->client);
22 const CRVertexArrays *array = &(c->array);
23 const GLboolean vpEnabled = crStateGetCurrent()->program.vpEnabled;
24 unsigned char *p;
25 unsigned int unit, attr;
26
27 if (array->e.enabled)
28 {
29 p = array->e.p + index * array->e.stride;
30
31#ifdef CR_ARB_vertex_buffer_object
32 if (array->e.buffer && array->e.buffer->data)
33 {
34 p = (unsigned char *)(array->e.buffer->data) + (unsigned long)p;
35 }
36#endif
37
38 array_spu.self.EdgeFlagv(p);
39 }
40
41 /*
42 * Vertex attribute arrays (GL_NV_vertex_program) have priority over
43 * the conventional vertex arrays.
44 */
45 if (vpEnabled)
46 {
47 for (attr = 1; attr < VERT_ATTRIB_MAX; attr++)
48 {
49 if (array->a[attr].enabled)
50 {
51 GLint *iPtr;
52 p = array->a[attr].p + index * array->a[attr].stride;
53
54#ifdef CR_ARB_vertex_buffer_object
55 if (array->a[attr].buffer && array->a[attr].buffer->data)
56 {
57 p = (unsigned char *)(array->a[attr].buffer->data) + (unsigned long)p;
58 }
59#endif
60
61 switch (array->a[attr].type)
62 {
63 case GL_SHORT:
64 switch (array->a[attr].size)
65 {
66 case 1: array_spu.self.VertexAttrib1svARB(attr, (GLshort *)p); break;
67 case 2: array_spu.self.VertexAttrib2svARB(attr, (GLshort *)p); break;
68 case 3: array_spu.self.VertexAttrib3svARB(attr, (GLshort *)p); break;
69 case 4: array_spu.self.VertexAttrib4svARB(attr, (GLshort *)p); break;
70 }
71 break;
72 case GL_INT:
73 iPtr = (GLint *) p;
74 switch (array->a[attr].size)
75 {
76 case 1: array_spu.self.VertexAttrib1fARB(attr, p[0]); break;
77 case 2: array_spu.self.VertexAttrib2fARB(attr, p[0], p[1]); break;
78 case 3: array_spu.self.VertexAttrib3fARB(attr, p[0], p[1], p[2]); break;
79 case 4: array_spu.self.VertexAttrib4fARB(attr, p[0], p[1], p[2], p[3]); break;
80 }
81 break;
82 case GL_FLOAT:
83 switch (array->a[attr].size)
84 {
85 case 1: array_spu.self.VertexAttrib1fvARB(attr, (GLfloat *)p); break;
86 case 2: array_spu.self.VertexAttrib2fvARB(attr, (GLfloat *)p); break;
87 case 3: array_spu.self.VertexAttrib3fvARB(attr, (GLfloat *)p); break;
88 case 4: array_spu.self.VertexAttrib4fvARB(attr, (GLfloat *)p); break;
89 }
90 break;
91 case GL_DOUBLE:
92 switch (array->a[attr].size)
93 {
94 case 1: array_spu.self.VertexAttrib1dvARB(attr, (GLdouble *)p); break;
95 case 2: array_spu.self.VertexAttrib2dvARB(attr, (GLdouble *)p); break;
96 case 3: array_spu.self.VertexAttrib3dvARB(attr, (GLdouble *)p); break;
97 case 4: array_spu.self.VertexAttrib4dvARB(attr, (GLdouble *)p); break;
98 }
99 break;
100 default:
101 crWarning("Bad datatype for vertex attribute [%d] array: 0x%x\n",
102 attr, array->a[attr].type);
103 }
104 }
105 }
106 }
107
108 /* Now do conventional arrays, unless overriden by generic arrays above */
109 for (unit = 0 ; unit < crStateGetCurrent()->limits.maxTextureUnits ; unit++)
110 {
111 if (array->t[unit].enabled && !(vpEnabled && array->a[VERT_ATTRIB_TEX0+unit].enabled))
112 {
113 p = array->t[unit].p + index * array->t[unit].stride;
114
115#ifdef CR_ARB_vertex_buffer_object
116 if (array->t[unit].buffer && array->t[unit].buffer->data)
117 {
118 p = (unsigned char *)(array->t[unit].buffer->data) + (unsigned long)p;
119 }
120#endif
121
122 switch (array->t[unit].type)
123 {
124 case GL_SHORT:
125 switch (array->t[unit].size)
126 {
127 case 1: array_spu.self.MultiTexCoord1svARB(GL_TEXTURE0_ARB + unit, (GLshort *)p); break;
128 case 2: array_spu.self.MultiTexCoord2svARB(GL_TEXTURE0_ARB + unit, (GLshort *)p); break;
129 case 3: array_spu.self.MultiTexCoord3svARB(GL_TEXTURE0_ARB + unit, (GLshort *)p); break;
130 case 4: array_spu.self.MultiTexCoord4svARB(GL_TEXTURE0_ARB + unit, (GLshort *)p); break;
131 }
132 break;
133 case GL_INT:
134 switch (array->t[unit].size)
135 {
136 case 1: array_spu.self.MultiTexCoord1ivARB(GL_TEXTURE0_ARB + unit, (GLint *)p); break;
137 case 2: array_spu.self.MultiTexCoord2ivARB(GL_TEXTURE0_ARB + unit, (GLint *)p); break;
138 case 3: array_spu.self.MultiTexCoord3ivARB(GL_TEXTURE0_ARB + unit, (GLint *)p); break;
139 case 4: array_spu.self.MultiTexCoord4ivARB(GL_TEXTURE0_ARB + unit, (GLint *)p); break;
140 }
141 break;
142 case GL_FLOAT:
143 switch (array->t[unit].size)
144 {
145 case 1: array_spu.self.MultiTexCoord1fvARB(GL_TEXTURE0_ARB + unit, (GLfloat *)p); break;
146 case 2: array_spu.self.MultiTexCoord2fvARB(GL_TEXTURE0_ARB + unit, (GLfloat *)p); break;
147 case 3: array_spu.self.MultiTexCoord3fvARB(GL_TEXTURE0_ARB + unit, (GLfloat *)p); break;
148 case 4: array_spu.self.MultiTexCoord4fvARB(GL_TEXTURE0_ARB + unit, (GLfloat *)p); break;
149 }
150 break;
151 case GL_DOUBLE:
152 switch (array->t[unit].size)
153 {
154 case 1: array_spu.self.MultiTexCoord1dvARB(GL_TEXTURE0_ARB + unit, (GLdouble *)p); break;
155 case 2: array_spu.self.MultiTexCoord2dvARB(GL_TEXTURE0_ARB + unit, (GLdouble *)p); break;
156 case 3: array_spu.self.MultiTexCoord3dvARB(GL_TEXTURE0_ARB + unit, (GLdouble *)p); break;
157 case 4: array_spu.self.MultiTexCoord4dvARB(GL_TEXTURE0_ARB + unit, (GLdouble *)p); break;
158 }
159 break;
160 }
161 }
162 }
163 if (array->i.enabled)
164 {
165 p = array->i.p + index * array->i.stride;
166
167#ifdef CR_ARB_vertex_buffer_object
168 if (array->i.buffer && array->i.buffer->data)
169 {
170 p = (unsigned char *)(array->i.buffer->data) + (unsigned long)p;
171 }
172#endif
173
174 switch (array->i.type)
175 {
176 case GL_SHORT: array_spu.self.Indexsv((GLshort *)p); break;
177 case GL_INT: array_spu.self.Indexiv((GLint *)p); break;
178 case GL_FLOAT: array_spu.self.Indexfv((GLfloat *)p); break;
179 case GL_DOUBLE: array_spu.self.Indexdv((GLdouble *)p); break;
180 }
181 }
182 if (array->c.enabled && !(vpEnabled && array->a[VERT_ATTRIB_COLOR0].enabled))
183 {
184 p = array->c.p + index * array->c.stride;
185
186#ifdef CR_ARB_vertex_buffer_object
187 if (array->c.buffer && array->c.buffer->data)
188 {
189 p = (unsigned char *)(array->c.buffer->data) + (unsigned long)p;
190 }
191#endif
192
193 switch (array->c.type)
194 {
195 case GL_BYTE:
196 switch (array->c.size)
197 {
198 case 3: array_spu.self.Color3bv((GLbyte *)p); break;
199 case 4: array_spu.self.Color4bv((GLbyte *)p); break;
200 }
201 break;
202 case GL_UNSIGNED_BYTE:
203 switch (array->c.size)
204 {
205 case 3: array_spu.self.Color3ubv((GLubyte *)p); break;
206 case 4: array_spu.self.Color4ubv((GLubyte *)p); break;
207 }
208 break;
209 case GL_SHORT:
210 switch (array->c.size)
211 {
212 case 3: array_spu.self.Color3sv((GLshort *)p); break;
213 case 4: array_spu.self.Color4sv((GLshort *)p); break;
214 }
215 break;
216 case GL_UNSIGNED_SHORT:
217 switch (array->c.size)
218 {
219 case 3: array_spu.self.Color3usv((GLushort *)p); break;
220 case 4: array_spu.self.Color4usv((GLushort *)p); break;
221 }
222 break;
223 case GL_INT:
224 switch (array->c.size)
225 {
226 case 3: array_spu.self.Color3iv((GLint *)p); break;
227 case 4: array_spu.self.Color4iv((GLint *)p); break;
228 }
229 break;
230 case GL_UNSIGNED_INT:
231 switch (array->c.size)
232 {
233 case 3: array_spu.self.Color3uiv((GLuint *)p); break;
234 case 4: array_spu.self.Color4uiv((GLuint *)p); break;
235 }
236 break;
237 case GL_FLOAT:
238 switch (array->c.size)
239 {
240 case 3: array_spu.self.Color3fv((GLfloat *)p); break;
241 case 4: array_spu.self.Color4fv((GLfloat *)p); break;
242 }
243 break;
244 case GL_DOUBLE:
245 switch (array->c.size)
246 {
247 case 3: array_spu.self.Color3dv((GLdouble *)p); break;
248 case 4: array_spu.self.Color4dv((GLdouble *)p); break;
249 }
250 break;
251 }
252 }
253 if (array->n.enabled && !(vpEnabled && array->a[VERT_ATTRIB_NORMAL].enabled))
254 {
255 p = array->n.p + index * array->n.stride;
256
257#ifdef CR_ARB_vertex_buffer_object
258 if (array->n.buffer && array->n.buffer->data)
259 {
260 p = (unsigned char *)(array->n.buffer->data) + (unsigned long)p;
261 }
262#endif
263
264 switch (array->n.type)
265 {
266 case GL_BYTE: array_spu.self.Normal3bv((GLbyte *)p); break;
267 case GL_SHORT: array_spu.self.Normal3sv((GLshort *)p); break;
268 case GL_INT: array_spu.self.Normal3iv((GLint *)p); break;
269 case GL_FLOAT: array_spu.self.Normal3fv((GLfloat *)p); break;
270 case GL_DOUBLE: array_spu.self.Normal3dv((GLdouble *)p); break;
271 }
272 }
273#ifdef CR_EXT_secondary_color
274 if (array->s.enabled && !(vpEnabled && array->a[VERT_ATTRIB_COLOR1].enabled))
275 {
276 p = array->s.p + index * array->s.stride;
277
278#ifdef CR_ARB_vertex_buffer_object
279 if (array->s.buffer && array->s.buffer->data)
280 {
281 p = (unsigned char *)(array->s.buffer->data) + (unsigned long)p;
282 }
283#endif
284
285 switch (array->s.type)
286 {
287 case GL_BYTE:
288 array_spu.self.SecondaryColor3bvEXT((GLbyte *)p); break;
289 case GL_UNSIGNED_BYTE:
290 array_spu.self.SecondaryColor3ubvEXT((GLubyte *)p); break;
291 case GL_SHORT:
292 array_spu.self.SecondaryColor3svEXT((GLshort *)p); break;
293 case GL_UNSIGNED_SHORT:
294 array_spu.self.SecondaryColor3usvEXT((GLushort *)p); break;
295 case GL_INT:
296 array_spu.self.SecondaryColor3ivEXT((GLint *)p); break;
297 case GL_UNSIGNED_INT:
298 array_spu.self.SecondaryColor3uivEXT((GLuint *)p); break;
299 case GL_FLOAT:
300 array_spu.self.SecondaryColor3fvEXT((GLfloat *)p); break;
301 case GL_DOUBLE:
302 array_spu.self.SecondaryColor3dvEXT((GLdouble *)p); break;
303 }
304 }
305#endif // CR_EXT_secondary_color
306#ifdef CR_EXT_fog_coord
307 if (array->f.enabled && !(vpEnabled && array->a[VERT_ATTRIB_FOG].enabled))
308 {
309 p = array->f.p + index * array->f.stride;
310
311#ifdef CR_ARB_vertex_buffer_object
312 if (array->f.buffer && array->f.buffer->data)
313 {
314 p = (unsigned char *)(array->f.buffer->data) + (unsigned long)p;
315 }
316#endif
317
318 array_spu.self.FogCoordfEXT( *((GLfloat *) p) );
319 }
320#endif // CR_EXT_fog_coord
321
322 /* Need to do attrib[0] / vertex position last */
323 if (array->a[VERT_ATTRIB_POS].enabled) {
324 GLint *iPtr;
325 p = array->a[VERT_ATTRIB_POS].p + index * array->a[VERT_ATTRIB_POS].stride;
326
327#ifdef CR_ARB_vertex_buffer_object
328 if (array->a[VERT_ATTRIB_POS].buffer && array->a[VERT_ATTRIB_POS].buffer->data)
329 {
330 p = (unsigned char *)(array->a[VERT_ATTRIB_POS].buffer->data) + (unsigned long)p;
331 }
332#endif
333
334 switch (array->a[VERT_ATTRIB_POS].type)
335 {
336 case GL_SHORT:
337 switch (array->a[VERT_ATTRIB_POS].size)
338 {
339 case 1: array_spu.self.VertexAttrib1svARB(0, (GLshort *)p); break;
340 case 2: array_spu.self.VertexAttrib2svARB(0, (GLshort *)p); break;
341 case 3: array_spu.self.VertexAttrib3svARB(0, (GLshort *)p); break;
342 case 4: array_spu.self.VertexAttrib4svARB(0, (GLshort *)p); break;
343 }
344 break;
345 case GL_INT:
346 iPtr = (GLint *) p;
347 switch (array->a[VERT_ATTRIB_POS].size)
348 {
349 case 1: array_spu.self.VertexAttrib1fARB(0, p[0]); break;
350 case 2: array_spu.self.VertexAttrib2fARB(0, p[0], p[1]); break;
351 case 3: array_spu.self.VertexAttrib3fARB(0, p[0], p[1], p[2]); break;
352 case 4: array_spu.self.VertexAttrib4fARB(0, p[0], p[1], p[2], p[3]); break;
353 }
354 break;
355 case GL_FLOAT:
356 switch (array->a[VERT_ATTRIB_POS].size)
357 {
358 case 1: array_spu.self.VertexAttrib1fvARB(0, (GLfloat *)p); break;
359 case 2: array_spu.self.VertexAttrib2fvARB(0, (GLfloat *)p); break;
360 case 3: array_spu.self.VertexAttrib3fvARB(0, (GLfloat *)p); break;
361 case 4: array_spu.self.VertexAttrib4fvARB(0, (GLfloat *)p); break;
362 }
363 break;
364 case GL_DOUBLE:
365 switch (array->a[VERT_ATTRIB_POS].size)
366 {
367 case 1: array_spu.self.VertexAttrib1dvARB(0, (GLdouble *)p); break;
368 case 2: array_spu.self.VertexAttrib2dvARB(0, (GLdouble *)p); break;
369 case 3: array_spu.self.VertexAttrib3dvARB(0, (GLdouble *)p); break;
370 case 4: array_spu.self.VertexAttrib4dvARB(0, (GLdouble *)p); break;
371 }
372 break;
373 default:
374 crWarning("Bad datatype for vertex attribute [0] array: 0x%x\n", array->a[0].type);
375 }
376 }
377 else if (array->v.enabled)
378 {
379 p = array->v.p + index * array->v.stride;
380
381#ifdef CR_ARB_vertex_buffer_object
382 if (array->v.buffer && array->v.buffer->data)
383 {
384 p = (unsigned char *)(array->v.buffer->data) + (unsigned long)p;
385 }
386#endif
387
388 switch (array->v.type)
389 {
390 case GL_SHORT:
391 switch (array->v.size)
392 {
393 case 2: array_spu.self.Vertex2sv((GLshort *)p); break;
394 case 3: array_spu.self.Vertex3sv((GLshort *)p); break;
395 case 4: array_spu.self.Vertex4sv((GLshort *)p); break;
396 }
397 break;
398 case GL_INT:
399 switch (array->v.size)
400 {
401 case 2: array_spu.self.Vertex2iv((GLint *)p); break;
402 case 3: array_spu.self.Vertex3iv((GLint *)p); break;
403 case 4: array_spu.self.Vertex4iv((GLint *)p); break;
404 }
405 break;
406 case GL_FLOAT:
407 switch (array->v.size)
408 {
409 case 2: array_spu.self.Vertex2fv((GLfloat *)p); break;
410 case 3: array_spu.self.Vertex3fv((GLfloat *)p); break;
411 case 4: array_spu.self.Vertex4fv((GLfloat *)p); break;
412 }
413 break;
414 case GL_DOUBLE:
415 switch (array->v.size)
416 {
417 case 2: array_spu.self.Vertex2dv((GLdouble *)p); break;
418 case 3: array_spu.self.Vertex3dv((GLdouble *)p); break;
419 case 4: array_spu.self.Vertex4dv((GLdouble *)p); break;
420 }
421 break;
422 default:
423 crWarning("Bad datatype for vertex array: 0x%x\n", array->v.type);
424 }
425 }
426}
427
428static void ARRAYSPU_APIENTRY arrayspu_DrawArrays(GLenum mode, GLint first, GLsizei count)
429{
430 int i;
431
432 if (count < 0)
433 {
434 crError("array_spu.self.DrawArrays passed negative count: %d", count);
435 }
436
437 if (mode > GL_POLYGON)
438 {
439 crError("array_spu.self.DrawArrays called with invalid mode: %d", mode);
440 }
441
442 array_spu.self.Begin(mode);
443 for (i=0; i<count; i++)
444 {
445 array_spu.self.ArrayElement(first++);
446 }
447 array_spu.self.End();
448}
449
450static void ARRAYSPU_APIENTRY arrayspu_DrawElements(GLenum mode, GLsizei count,
451 GLenum type, const GLvoid *indices)
452{
453 int i;
454 GLubyte *p = (GLubyte *)indices;
455#ifdef CR_ARB_vertex_buffer_object
456 CRBufferObject *elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer;
457#endif
458
459 if (count < 0)
460 {
461 crError("array_spu.self.DrawElements passed negative count: %d", count);
462 }
463
464 if (mode > GL_POLYGON)
465 {
466 crError("array_spu.self.DrawElements called with invalid mode: %d", mode);
467 }
468
469 if (type != GL_UNSIGNED_BYTE && type != GL_UNSIGNED_SHORT && type != GL_UNSIGNED_INT)
470 {
471 crError("array_spu.self.DrawElements called with invalid type: %d", type);
472 }
473
474#ifdef CR_ARB_vertex_buffer_object
475 if (elementsBuffer && elementsBuffer->data)
476 {
477 p = (unsigned char *)(elementsBuffer->data) + (unsigned long)p;
478 }
479#endif
480
481 array_spu.self.Begin(mode);
482 switch (type)
483 {
484 case GL_UNSIGNED_BYTE:
485 for (i=0; i<count; i++)
486 {
487 array_spu.self.ArrayElement((GLint) *p++);
488 }
489 break;
490 case GL_UNSIGNED_SHORT:
491 for (i=0; i<count; i++)
492 {
493 array_spu.self.ArrayElement((GLint) * (GLushort *) p);
494 p+=sizeof (GLushort);
495 }
496 break;
497 case GL_UNSIGNED_INT:
498 for (i=0; i<count; i++)
499 {
500 array_spu.self.ArrayElement((GLint) * (GLuint *) p);
501 p+=sizeof (GLuint);
502 }
503 break;
504 default:
505 crError( "this can't happen: array_spu.self.DrawElements" );
506 break;
507 }
508 array_spu.self.End();
509}
510
511static void ARRAYSPU_APIENTRY arrayspu_ColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
512{
513 crStateColorPointer( size, type, stride, pointer );
514}
515
516static void ARRAYSPU_APIENTRY arrayspu_SecondaryColorPointerEXT( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
517{
518 crStateSecondaryColorPointerEXT( size, type, stride, pointer );
519}
520
521static void ARRAYSPU_APIENTRY arrayspu_VertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
522{
523 crStateVertexPointer( size, type, stride, pointer );
524}
525
526static void ARRAYSPU_APIENTRY arrayspu_TexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
527{
528 crStateTexCoordPointer( size, type, stride, pointer );
529}
530
531static void ARRAYSPU_APIENTRY arrayspu_NormalPointer( GLenum type, GLsizei stride, const GLvoid *pointer )
532{
533 crStateNormalPointer( type, stride, pointer );
534}
535
536static void ARRAYSPU_APIENTRY arrayspu_IndexPointer( GLenum type, GLsizei stride, const GLvoid *pointer )
537{
538 crStateIndexPointer( type, stride, pointer );
539}
540
541static void ARRAYSPU_APIENTRY arrayspu_EdgeFlagPointer( GLsizei stride, const GLvoid *pointer )
542{
543 crStateEdgeFlagPointer( stride, pointer );
544}
545
546static void ARRAYSPU_APIENTRY arrayspu_VertexAttribPointerNV( GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid * pointer )
547{
548 crStateVertexAttribPointerNV( index, size, type, stride, pointer );
549}
550
551static void ARRAYSPU_APIENTRY arrayspu_FogCoordPointerEXT( GLenum type, GLsizei stride, const GLvoid *pointer )
552{
553 crStateFogCoordPointerEXT( type, stride, pointer );
554}
555
556static void ARRAYSPU_APIENTRY arrayspu_GetPointerv( GLenum pname, GLvoid **params )
557{
558 crStateGetPointerv( pname, params );
559}
560
561static void ARRAYSPU_APIENTRY arrayspu_EnableClientState( GLenum array )
562{
563 crStateEnableClientState( array );
564}
565
566static void ARRAYSPU_APIENTRY arrayspu_DisableClientState( GLenum array )
567{
568 crStateDisableClientState( array );
569}
570
571static void ARRAYSPU_APIENTRY arrayspu_ClientActiveTextureARB( GLenum texture )
572{
573 crStateClientActiveTextureARB( texture );
574}
575
576static void ARRAYSPU_APIENTRY arrayspu_MultiDrawArraysEXT(GLenum mode, GLint *first, GLsizei *count, GLsizei primcount)
577{
578 int i;
579
580 if (primcount < 0)
581 {
582 crError("array_spu.self.MultiDrawArraysEXT passed negative count: %d", primcount);
583 }
584
585 if (mode > GL_POLYGON)
586 {
587 crError("array_spu.self.MultiDrawArraysEXT called with invalid mode: %d", mode);
588 }
589
590 for (i = 0; i < primcount; i++)
591 {
592 array_spu.self.DrawArrays(mode, first[i], count[i]);
593 }
594}
595
596static void ARRAYSPU_APIENTRY arrayspu_MultiDrawElementsEXT(GLenum mode, GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount)
597{
598 int i;
599
600 if (primcount < 0)
601 {
602 crError("array_spu.self.MultiDrawElementsEXT passed negative count: %d", primcount);
603 }
604
605 if (mode > GL_POLYGON)
606 {
607 crError("array_spu.self.MultiDrawElementsEXT called with invalid mode: %d", mode);
608 }
609
610 if (type != GL_UNSIGNED_BYTE && type != GL_UNSIGNED_SHORT && type != GL_UNSIGNED_INT)
611 {
612 crError("array_spu.self.MultiDrawElementsEXT called with invalid type: %d", type);
613 }
614
615 for (i = 0; i < primcount; i++)
616 {
617 array_spu.self.DrawElements(mode, count[i], type, indices[i]);
618 }
619}
620
621/*
622 * We need to know when vertex program mode is enabled/disabled
623 * in order to handle vertex attribute arrays correctly.
624 */
625static void ARRAYSPU_APIENTRY arrayspu_Enable(GLenum cap)
626{
627 if (cap == GL_VERTEX_PROGRAM_NV) {
628 crStateGetCurrent()->program.vpEnabled = GL_TRUE;
629 }
630 array_spu.child.Enable(cap);
631}
632
633
634static void ARRAYSPU_APIENTRY arrayspu_Disable(GLenum cap)
635{
636 if (cap == GL_VERTEX_PROGRAM_NV) {
637 crStateGetCurrent()->program.vpEnabled = GL_FALSE;
638 }
639 array_spu.child.Disable(cap);
640}
641
642/*@todo: it's a hack, as GLSL shouldn't blindly reuse this bit from nv_vertex_program*/
643static void ARRAYSPU_APIENTRY arrayspu_UseProgram(GLuint program)
644{
645 crStateGetCurrent()->program.vpEnabled = program>0;
646 array_spu.child.UseProgram(program);
647}
648
649static void ARRAYSPU_APIENTRY
650arrayspu_VertexAttribPointerARB(GLuint index, GLint size, GLenum type,
651 GLboolean normalized, GLsizei stride,
652 const GLvoid *pointer)
653{
654 crStateVertexAttribPointerARB( index, size, type, normalized, stride, pointer );
655}
656
657
658static void ARRAYSPU_APIENTRY
659arrayspu_EnableVertexAttribArrayARB(GLuint index)
660{
661 crStateEnableVertexAttribArrayARB(index);
662}
663
664
665static void ARRAYSPU_APIENTRY
666arrayspu_DisableVertexAttribArrayARB(GLuint index)
667{
668 crStateDisableVertexAttribArrayARB(index);
669}
670
671
672/* We need to implement Push/PopClientAttrib here so that _our_ state
673 * tracker gets used. Also, pass the call onto the next SPU (in case
674 * it's the GL_CLIENT_PIXEL_STORE_BIT, etc).
675 */
676static void ARRAYSPU_APIENTRY
677arrayspu_PushClientAttrib( GLbitfield mask )
678{
679 crStatePushClientAttrib(mask);
680 array_spu.child.PushClientAttrib(mask);
681}
682
683
684static void ARRAYSPU_APIENTRY
685arrayspu_PopClientAttrib( void )
686{
687 crStatePopClientAttrib();
688 array_spu.child.PopClientAttrib();
689}
690
691
692static void ARRAYSPU_APIENTRY
693arrayspu_GenBuffersARB( GLsizei n, GLuint * buffers )
694{
695 crStateGenBuffersARB(n, buffers);
696}
697
698static void ARRAYSPU_APIENTRY
699arrayspu_DeleteBuffersARB( GLsizei n, const GLuint *buffers )
700{
701 crStateDeleteBuffersARB(n, buffers);
702}
703
704static void ARRAYSPU_APIENTRY
705arrayspu_BindBufferARB( GLenum target, GLuint buffer )
706{
707 crStateBindBufferARB(target, buffer);
708}
709
710static GLboolean ARRAYSPU_APIENTRY
711arrayspu_IsBufferARB (GLuint buffer)
712{
713 return crStateIsBufferARB(buffer);
714}
715
716static void ARRAYSPU_APIENTRY
717arrayspu_BufferDataARB( GLenum target, GLsizeiptrARB size, const GLvoid * data, GLenum usage )
718{
719 crStateBufferDataARB(target, size, data, usage);
720}
721
722static void ARRAYSPU_APIENTRY
723arrayspu_BufferSubDataARB( GLenum target, GLintptrARB offset,
724 GLsizeiptrARB size, const GLvoid * data )
725{
726 crStateBufferSubDataARB(target, offset, size, data);
727}
728
729static void ARRAYSPU_APIENTRY
730arrayspu_GetBufferSubDataARB(GLenum target, GLintptrARB offset, GLsizeiptrARB size, void * data)
731{
732 crStateGetBufferSubDataARB(target, offset, size, data);
733}
734
735static void * ARRAYSPU_APIENTRY
736arrayspu_MapBufferARB(GLenum target, GLenum access)
737{
738 return crStateMapBufferARB(target, access);
739}
740
741static GLboolean ARRAYSPU_APIENTRY
742arrayspu_UnmapBufferARB(GLenum target)
743{
744 return crStateUnmapBufferARB(target);
745}
746
747static void ARRAYSPU_APIENTRY
748arrayspu_GetBufferParameterivARB(GLenum target, GLenum pname, GLint *params)
749{
750 crStateGetBufferParameterivARB(target, pname, params);
751}
752
753static void ARRAYSPU_APIENTRY
754arrayspu_GetBufferPointervARB(GLenum target, GLenum pname, GLvoid **params)
755{
756 crStateGetBufferPointervARB(target, pname, params);
757}
758
759static void ARRAYSPU_APIENTRY
760arrayspu_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *p)
761{
762 crStateInterleavedArrays(format, stride, p);
763}
764
765static GLint ARRAYSPU_APIENTRY
766arrayspu_CreateContext( const char *dpyName, GLint visual, GLint shareCtx )
767{
768 GLint ctx, slot;
769
770#ifdef CHROMIUM_THREADSAFE
771 crLockMutex(&_ArrayMutex);
772#endif
773
774 ctx = array_spu.child.CreateContext(dpyName, visual, shareCtx);
775
776 /* find an empty context slot */
777 for (slot = 0; slot < array_spu.numContexts; slot++) {
778 if (!array_spu.context[slot].clientState) {
779 /* found empty slot */
780 break;
781 }
782 }
783 if (slot == array_spu.numContexts) {
784 array_spu.numContexts++;
785 }
786
787 array_spu.context[slot].clientState = crStateCreateContext(NULL, visual, NULL);
788 array_spu.context[slot].clientCtx = ctx;
789#ifdef CR_ARB_vertex_buffer_object
790 array_spu.context[slot].clientState->bufferobject.retainBufferData = GL_TRUE;
791#endif
792
793#ifdef CHROMIUM_THREADSAFE
794 crUnlockMutex(&_ArrayMutex);
795#endif
796
797 return ctx;
798}
799
800static void ARRAYSPU_APIENTRY
801arrayspu_MakeCurrent( GLint window, GLint nativeWindow, GLint ctx )
802{
803#ifdef CHROMIUM_THREADSAFE
804 crLockMutex(&_ArrayMutex);
805#endif
806 array_spu.child.MakeCurrent(window, nativeWindow, ctx);
807
808 if (ctx) {
809 int slot;
810
811 for (slot=0; slot<array_spu.numContexts; ++slot)
812 if (array_spu.context[slot].clientCtx == ctx) break;
813 CRASSERT(slot < array_spu.numContexts);
814
815 crStateMakeCurrent(array_spu.context[slot].clientState);
816 }
817 else
818 {
819 crStateMakeCurrent(NULL);
820 }
821
822#ifdef CHROMIUM_THREADSAFE
823 crUnlockMutex(&_ArrayMutex);
824#endif
825}
826
827static void ARRAYSPU_APIENTRY
828arrayspu_DestroyContext( GLint ctx )
829{
830#ifdef CHROMIUM_THREADSAFE
831 crLockMutex(&_ArrayMutex);
832#endif
833 array_spu.child.DestroyContext(ctx);
834
835 if (ctx) {
836 int slot;
837
838 for (slot=0; slot<array_spu.numContexts; ++slot)
839 if (array_spu.context[slot].clientCtx == ctx) break;
840 CRASSERT(slot < array_spu.numContexts);
841
842 crStateDestroyContext(array_spu.context[slot].clientState);
843
844 array_spu.context[slot].clientState = NULL;
845 array_spu.context[slot].clientCtx = 0;
846 }
847
848#ifdef CHROMIUM_THREADSAFE
849 crUnlockMutex(&_ArrayMutex);
850#endif
851}
852
853SPUNamedFunctionTable _cr_array_table[] = {
854 { "ArrayElement", (SPUGenericFunction) arrayspu_ArrayElement },
855 { "DrawArrays", (SPUGenericFunction) arrayspu_DrawArrays},
856 { "DrawElements", (SPUGenericFunction) arrayspu_DrawElements},
857 { "ColorPointer", (SPUGenericFunction) arrayspu_ColorPointer},
858 { "SecondaryColorPointerEXT", (SPUGenericFunction) arrayspu_SecondaryColorPointerEXT},
859 { "VertexPointer", (SPUGenericFunction) arrayspu_VertexPointer},
860 { "TexCoordPointer", (SPUGenericFunction) arrayspu_TexCoordPointer},
861 { "NormalPointer", (SPUGenericFunction) arrayspu_NormalPointer},
862 { "IndexPointer", (SPUGenericFunction) arrayspu_IndexPointer},
863 { "EdgeFlagPointer", (SPUGenericFunction) arrayspu_EdgeFlagPointer},
864 { "VertexAttribPointerNV", (SPUGenericFunction) arrayspu_VertexAttribPointerNV},
865 { "FogCoordPointerEXT", (SPUGenericFunction) arrayspu_FogCoordPointerEXT},
866 { "GetPointerv", (SPUGenericFunction) arrayspu_GetPointerv},
867 { "EnableClientState", (SPUGenericFunction) arrayspu_EnableClientState},
868 { "DisableClientState", (SPUGenericFunction) arrayspu_DisableClientState},
869 { "ClientActiveTextureARB", (SPUGenericFunction) arrayspu_ClientActiveTextureARB },
870 { "MultiDrawArraysEXT", (SPUGenericFunction) arrayspu_MultiDrawArraysEXT },
871 { "MultiDrawElementsEXT", (SPUGenericFunction) arrayspu_MultiDrawElementsEXT },
872 { "Enable", (SPUGenericFunction) arrayspu_Enable },
873 { "Disable", (SPUGenericFunction) arrayspu_Disable },
874 { "PushClientAttrib", (SPUGenericFunction) arrayspu_PushClientAttrib },
875 { "PopClientAttrib", (SPUGenericFunction) arrayspu_PopClientAttrib },
876 { "VertexAttribPointerARB", (SPUGenericFunction) arrayspu_VertexAttribPointerARB },
877 { "EnableVertexAttribArrayARB", (SPUGenericFunction) arrayspu_EnableVertexAttribArrayARB },
878 { "DisableVertexAttribArrayARB", (SPUGenericFunction) arrayspu_DisableVertexAttribArrayARB },
879 { "GenBuffersARB", (SPUGenericFunction) arrayspu_GenBuffersARB },
880 { "DeleteBuffersARB", (SPUGenericFunction) arrayspu_DeleteBuffersARB },
881 { "BindBufferARB", (SPUGenericFunction) arrayspu_BindBufferARB },
882 { "IsBufferARB", (SPUGenericFunction) arrayspu_IsBufferARB },
883 { "BufferDataARB", (SPUGenericFunction) arrayspu_BufferDataARB },
884 { "BufferSubDataARB", (SPUGenericFunction) arrayspu_BufferSubDataARB },
885 { "GetBufferSubDataARB", (SPUGenericFunction) arrayspu_GetBufferSubDataARB },
886 { "MapBufferARB", (SPUGenericFunction) arrayspu_MapBufferARB },
887 { "UnmapBufferARB", (SPUGenericFunction) arrayspu_UnmapBufferARB },
888 { "GetBufferParameterivARB", (SPUGenericFunction) arrayspu_GetBufferParameterivARB},
889 { "GetBufferPointervARB", (SPUGenericFunction) arrayspu_GetBufferPointervARB},
890 { "InterleavedArrays", (SPUGenericFunction) arrayspu_InterleavedArrays},
891 { "CreateContext", (SPUGenericFunction) arrayspu_CreateContext},
892 { "MakeCurrent", (SPUGenericFunction) arrayspu_MakeCurrent},
893 { "DestroyContext", (SPUGenericFunction) arrayspu_DestroyContext},
894 { "UseProgram", (SPUGenericFunction) arrayspu_UseProgram},
895 { NULL, NULL }
896};
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