VirtualBox

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

最後變更 在這個檔案從49891是 40431,由 vboxsync 提交於 13 年 前

crOpenGL: more TLS data handling fixes

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 33.2 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 <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 overridden 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 //crDebug("arrayspu_DrawElements mode:0x%x, count:%d, type:0x%x", mode, count, type);
481
482
483 array_spu.self.Begin(mode);
484 switch (type)
485 {
486 case GL_UNSIGNED_BYTE:
487 for (i=0; i<count; i++)
488 {
489 array_spu.self.ArrayElement((GLint) *p++);
490 }
491 break;
492 case GL_UNSIGNED_SHORT:
493 for (i=0; i<count; i++)
494 {
495 array_spu.self.ArrayElement((GLint) * (GLushort *) p);
496 p+=sizeof (GLushort);
497 }
498 break;
499 case GL_UNSIGNED_INT:
500 for (i=0; i<count; i++)
501 {
502 array_spu.self.ArrayElement((GLint) * (GLuint *) p);
503 p+=sizeof (GLuint);
504 }
505 break;
506 default:
507 crError( "this can't happen: array_spu.self.DrawElements" );
508 break;
509 }
510 array_spu.self.End();
511}
512
513static void ARRAYSPU_APIENTRY arrayspu_DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices)
514{
515 if (start>end)
516 {
517 crError("array_spu.self.arrayspu_DrawRangeElements start>end (%d>%d)", start, end);
518 }
519
520 arrayspu_DrawElements(mode, count, type, indices);
521}
522
523static void ARRAYSPU_APIENTRY arrayspu_ColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
524{
525 crStateColorPointer(size, type, stride, pointer);
526 array_spu.child.ColorPointer(size, type, stride, pointer);
527}
528
529static void ARRAYSPU_APIENTRY arrayspu_SecondaryColorPointerEXT( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
530{
531 crStateSecondaryColorPointerEXT(size, type, stride, pointer);
532 array_spu.child.SecondaryColorPointerEXT(size, type, stride, pointer);
533}
534
535static void ARRAYSPU_APIENTRY arrayspu_VertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
536{
537 crStateVertexPointer(size, type, stride, pointer);
538 array_spu.child.VertexPointer(size, type, stride, pointer);
539}
540
541static void ARRAYSPU_APIENTRY arrayspu_TexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
542{
543 crStateTexCoordPointer(size, type, stride, pointer);
544 array_spu.child.TexCoordPointer(size, type, stride, pointer);
545}
546
547static void ARRAYSPU_APIENTRY arrayspu_NormalPointer( GLenum type, GLsizei stride, const GLvoid *pointer )
548{
549 crStateNormalPointer(type, stride, pointer);
550 array_spu.child.NormalPointer(type, stride, pointer);
551}
552
553static void ARRAYSPU_APIENTRY arrayspu_IndexPointer( GLenum type, GLsizei stride, const GLvoid *pointer )
554{
555 crStateIndexPointer(type, stride, pointer);
556 array_spu.child.IndexPointer(type, stride, pointer);
557}
558
559static void ARRAYSPU_APIENTRY arrayspu_EdgeFlagPointer( GLsizei stride, const GLvoid *pointer )
560{
561 crStateEdgeFlagPointer(stride, pointer);
562 array_spu.child.EdgeFlagPointer(stride, pointer);
563}
564
565static void ARRAYSPU_APIENTRY arrayspu_VertexAttribPointerNV( GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid * pointer )
566{
567 crStateVertexAttribPointerNV(index, size, type, stride, pointer);
568 array_spu.child.VertexAttribPointerNV(index, size, type, stride, pointer);
569}
570
571static void ARRAYSPU_APIENTRY arrayspu_FogCoordPointerEXT( GLenum type, GLsizei stride, const GLvoid *pointer )
572{
573 crStateFogCoordPointerEXT(type, stride, pointer);
574 array_spu.child.FogCoordPointerEXT(type, stride, pointer);
575}
576
577static void ARRAYSPU_APIENTRY arrayspu_GetPointerv( GLenum pname, GLvoid **params )
578{
579 crStateGetPointerv(pname, params);
580}
581
582static void ARRAYSPU_APIENTRY arrayspu_EnableClientState( GLenum array )
583{
584 crStateEnableClientState(array);
585 array_spu.child.EnableClientState(array);
586}
587
588static void ARRAYSPU_APIENTRY arrayspu_DisableClientState( GLenum array )
589{
590 crStateDisableClientState(array);
591 array_spu.child.DisableClientState(array);
592}
593
594static void ARRAYSPU_APIENTRY arrayspu_ClientActiveTextureARB( GLenum texture )
595{
596 crStateClientActiveTextureARB(texture);
597 array_spu.child.ClientActiveTextureARB(texture);
598}
599
600static void ARRAYSPU_APIENTRY arrayspu_MultiDrawArraysEXT(GLenum mode, GLint *first, GLsizei *count, GLsizei primcount)
601{
602 int i;
603
604 if (primcount < 0)
605 {
606 crError("array_spu.self.MultiDrawArraysEXT passed negative count: %d", primcount);
607 }
608
609 if (mode > GL_POLYGON)
610 {
611 crError("array_spu.self.MultiDrawArraysEXT called with invalid mode: %d", mode);
612 }
613
614 for (i = 0; i < primcount; i++)
615 {
616 array_spu.self.DrawArrays(mode, first[i], count[i]);
617 }
618}
619
620static void ARRAYSPU_APIENTRY arrayspu_MultiDrawElementsEXT(GLenum mode, GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount)
621{
622 int i;
623
624 if (primcount < 0)
625 {
626 crError("array_spu.self.MultiDrawElementsEXT passed negative count: %d", primcount);
627 }
628
629 if (mode > GL_POLYGON)
630 {
631 crError("array_spu.self.MultiDrawElementsEXT called with invalid mode: %d", mode);
632 }
633
634 if (type != GL_UNSIGNED_BYTE && type != GL_UNSIGNED_SHORT && type != GL_UNSIGNED_INT)
635 {
636 crError("array_spu.self.MultiDrawElementsEXT called with invalid type: %d", type);
637 }
638
639 for (i = 0; i < primcount; i++)
640 {
641 array_spu.self.DrawElements(mode, count[i], type, indices[i]);
642 }
643}
644
645/*
646 * We need to know when vertex program mode is enabled/disabled
647 * in order to handle vertex attribute arrays correctly.
648 */
649static void ARRAYSPU_APIENTRY arrayspu_Enable(GLenum cap)
650{
651 if (cap == GL_VERTEX_PROGRAM_NV) {
652 crStateGetCurrent()->program.vpEnabled = GL_TRUE;
653 }
654 array_spu.child.Enable(cap);
655}
656
657
658static void ARRAYSPU_APIENTRY arrayspu_Disable(GLenum cap)
659{
660 if (cap == GL_VERTEX_PROGRAM_NV) {
661 crStateGetCurrent()->program.vpEnabled = GL_FALSE;
662 }
663 array_spu.child.Disable(cap);
664}
665
666/*@todo: it's a hack, as GLSL shouldn't blindly reuse this bit from nv_vertex_program*/
667static void ARRAYSPU_APIENTRY arrayspu_UseProgram(GLuint program)
668{
669 crStateGetCurrent()->program.vpEnabled = program>0;
670 array_spu.child.UseProgram(program);
671}
672
673static void ARRAYSPU_APIENTRY
674arrayspu_VertexAttribPointerARB(GLuint index, GLint size, GLenum type,
675 GLboolean normalized, GLsizei stride,
676 const GLvoid *pointer)
677{
678 crStateVertexAttribPointerARB(index, size, type, normalized, stride, pointer);
679 array_spu.child.VertexAttribPointerARB(index, size, type, normalized, stride, pointer);
680}
681
682
683static void ARRAYSPU_APIENTRY
684arrayspu_EnableVertexAttribArrayARB(GLuint index)
685{
686 crStateEnableVertexAttribArrayARB(index);
687}
688
689
690static void ARRAYSPU_APIENTRY
691arrayspu_DisableVertexAttribArrayARB(GLuint index)
692{
693 crStateDisableVertexAttribArrayARB(index);
694}
695
696
697/* We need to implement Push/PopClientAttrib here so that _our_ state
698 * tracker gets used. Also, pass the call onto the next SPU (in case
699 * it's the GL_CLIENT_PIXEL_STORE_BIT, etc).
700 */
701static void ARRAYSPU_APIENTRY
702arrayspu_PushClientAttrib( GLbitfield mask )
703{
704 crStatePushClientAttrib(mask);
705 array_spu.child.PushClientAttrib(mask);
706}
707
708
709static void ARRAYSPU_APIENTRY
710arrayspu_PopClientAttrib( void )
711{
712 crStatePopClientAttrib();
713 array_spu.child.PopClientAttrib();
714}
715
716
717static void ARRAYSPU_APIENTRY
718arrayspu_GenBuffersARB( GLsizei n, GLuint * buffers )
719{
720 array_spu.child.GenBuffersARB(n, buffers);
721}
722
723static void ARRAYSPU_APIENTRY
724arrayspu_DeleteBuffersARB( GLsizei n, const GLuint *buffers )
725{
726 crStateDeleteBuffersARB(n, buffers);
727 array_spu.child.DeleteBuffersARB(n, buffers);
728}
729
730static void ARRAYSPU_APIENTRY
731arrayspu_BindBufferARB( GLenum target, GLuint buffer )
732{
733 crStateBindBufferARB(target, buffer);
734 array_spu.child.BindBufferARB(target, buffer);
735}
736
737static GLboolean ARRAYSPU_APIENTRY
738arrayspu_IsBufferARB (GLuint buffer)
739{
740 return array_spu.child.IsBufferARB(buffer);
741}
742
743static void ARRAYSPU_APIENTRY
744arrayspu_BufferDataARB( GLenum target, GLsizeiptrARB size, const GLvoid * data, GLenum usage )
745{
746 crStateBufferDataARB(target, size, data, usage);
747 array_spu.child.BufferDataARB(target, size, data, usage);
748}
749
750static void ARRAYSPU_APIENTRY
751arrayspu_BufferSubDataARB( GLenum target, GLintptrARB offset,
752 GLsizeiptrARB size, const GLvoid * data )
753{
754 crStateBufferSubDataARB(target, offset, size, data);
755 array_spu.child.BufferSubDataARB(target, offset, size, data);
756}
757
758static void ARRAYSPU_APIENTRY
759arrayspu_GetBufferSubDataARB(GLenum target, GLintptrARB offset, GLsizeiptrARB size, void * data)
760{
761 crStateGetBufferSubDataARB(target, offset, size, data);
762}
763
764static void * ARRAYSPU_APIENTRY
765arrayspu_MapBufferARB(GLenum target, GLenum access)
766{
767 return crStateMapBufferARB(target, access);
768}
769
770static GLboolean ARRAYSPU_APIENTRY
771arrayspu_UnmapBufferARB(GLenum target)
772{
773 crStateUnmapBufferARB(target);
774 return array_spu.child.UnmapBufferARB(target);
775}
776
777static void ARRAYSPU_APIENTRY
778arrayspu_GetBufferParameterivARB(GLenum target, GLenum pname, GLint *params)
779{
780 crStateGetBufferParameterivARB(target, pname, params);
781}
782
783static void ARRAYSPU_APIENTRY
784arrayspu_GetBufferPointervARB(GLenum target, GLenum pname, GLvoid **params)
785{
786 crStateGetBufferPointervARB(target, pname, params);
787}
788
789static void ARRAYSPU_APIENTRY
790arrayspu_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *p)
791{
792 crStateInterleavedArrays(format, stride, p);
793}
794
795static GLint ARRAYSPU_APIENTRY
796arrayspu_CreateContext( const char *dpyName, GLint visual, GLint shareCtx )
797{
798 GLint ctx, slot;
799
800#ifdef CHROMIUM_THREADSAFE
801 crLockMutex(&_ArrayMutex);
802#endif
803
804 ctx = array_spu.child.CreateContext(dpyName, visual, shareCtx);
805
806 /* find an empty context slot */
807 for (slot = 0; slot < array_spu.numContexts; slot++) {
808 if (!array_spu.context[slot].clientState) {
809 /* found empty slot */
810 break;
811 }
812 }
813 if (slot == array_spu.numContexts) {
814 array_spu.numContexts++;
815 }
816
817 array_spu.context[slot].clientState = crStateCreateContext(NULL, visual, NULL);
818 array_spu.context[slot].clientCtx = ctx;
819#ifdef CR_ARB_vertex_buffer_object
820 array_spu.context[slot].clientState->bufferobject.retainBufferData = GL_TRUE;
821#endif
822
823#ifdef CHROMIUM_THREADSAFE
824 crUnlockMutex(&_ArrayMutex);
825#endif
826
827 return ctx;
828}
829
830static void ARRAYSPU_APIENTRY
831arrayspu_MakeCurrent( GLint window, GLint nativeWindow, GLint ctx )
832{
833#ifdef CHROMIUM_THREADSAFE
834 crLockMutex(&_ArrayMutex);
835#endif
836 array_spu.child.MakeCurrent(window, nativeWindow, ctx);
837
838 if (ctx) {
839 int slot;
840
841 for (slot=0; slot<array_spu.numContexts; ++slot)
842 if (array_spu.context[slot].clientCtx == ctx) break;
843 CRASSERT(slot < array_spu.numContexts);
844
845 crStateMakeCurrent(array_spu.context[slot].clientState);
846 }
847 else
848 {
849 crStateMakeCurrent(NULL);
850 }
851
852#ifdef CHROMIUM_THREADSAFE
853 crUnlockMutex(&_ArrayMutex);
854#endif
855}
856
857static void ARRAYSPU_APIENTRY
858arrayspu_DestroyContext( GLint ctx )
859{
860#ifdef CHROMIUM_THREADSAFE
861 crLockMutex(&_ArrayMutex);
862#endif
863 array_spu.child.DestroyContext(ctx);
864
865 if (ctx) {
866 int slot;
867
868 for (slot=0; slot<array_spu.numContexts; ++slot)
869 if (array_spu.context[slot].clientCtx == ctx) break;
870 CRASSERT(slot < array_spu.numContexts);
871
872 crStateDestroyContext(array_spu.context[slot].clientState);
873
874 array_spu.context[slot].clientState = NULL;
875 array_spu.context[slot].clientCtx = 0;
876 }
877
878#ifdef CHROMIUM_THREADSAFE
879 crUnlockMutex(&_ArrayMutex);
880#endif
881}
882
883static void ARRAYSPU_APIENTRY
884arrayspu_VBoxAttachThread()
885{
886 crStateVBoxAttachThread();
887 array_spu.child.VBoxAttachThread();
888}
889
890static void ARRAYSPU_APIENTRY
891arrayspu_VBoxDetachThread()
892{
893 crStateVBoxDetachThread();
894 array_spu.child.VBoxDetachThread();
895}
896
897
898SPUNamedFunctionTable _cr_array_table[] = {
899 { "ArrayElement", (SPUGenericFunction) arrayspu_ArrayElement },
900 { "DrawArrays", (SPUGenericFunction) arrayspu_DrawArrays},
901 { "DrawElements", (SPUGenericFunction) arrayspu_DrawElements},
902 { "DrawRangeElements", (SPUGenericFunction) arrayspu_DrawRangeElements},
903 { "ColorPointer", (SPUGenericFunction) arrayspu_ColorPointer},
904 { "SecondaryColorPointerEXT", (SPUGenericFunction) arrayspu_SecondaryColorPointerEXT},
905 { "VertexPointer", (SPUGenericFunction) arrayspu_VertexPointer},
906 { "TexCoordPointer", (SPUGenericFunction) arrayspu_TexCoordPointer},
907 { "NormalPointer", (SPUGenericFunction) arrayspu_NormalPointer},
908 { "IndexPointer", (SPUGenericFunction) arrayspu_IndexPointer},
909 { "EdgeFlagPointer", (SPUGenericFunction) arrayspu_EdgeFlagPointer},
910 { "VertexAttribPointerNV", (SPUGenericFunction) arrayspu_VertexAttribPointerNV},
911 { "FogCoordPointerEXT", (SPUGenericFunction) arrayspu_FogCoordPointerEXT},
912 { "GetPointerv", (SPUGenericFunction) arrayspu_GetPointerv},
913 { "EnableClientState", (SPUGenericFunction) arrayspu_EnableClientState},
914 { "DisableClientState", (SPUGenericFunction) arrayspu_DisableClientState},
915 { "ClientActiveTextureARB", (SPUGenericFunction) arrayspu_ClientActiveTextureARB },
916 { "MultiDrawArraysEXT", (SPUGenericFunction) arrayspu_MultiDrawArraysEXT },
917 { "MultiDrawElementsEXT", (SPUGenericFunction) arrayspu_MultiDrawElementsEXT },
918 { "Enable", (SPUGenericFunction) arrayspu_Enable },
919 { "Disable", (SPUGenericFunction) arrayspu_Disable },
920 { "PushClientAttrib", (SPUGenericFunction) arrayspu_PushClientAttrib },
921 { "PopClientAttrib", (SPUGenericFunction) arrayspu_PopClientAttrib },
922 { "VertexAttribPointerARB", (SPUGenericFunction) arrayspu_VertexAttribPointerARB },
923 { "EnableVertexAttribArrayARB", (SPUGenericFunction) arrayspu_EnableVertexAttribArrayARB },
924 { "DisableVertexAttribArrayARB", (SPUGenericFunction) arrayspu_DisableVertexAttribArrayARB },
925 { "GenBuffersARB", (SPUGenericFunction) arrayspu_GenBuffersARB },
926 { "DeleteBuffersARB", (SPUGenericFunction) arrayspu_DeleteBuffersARB },
927 { "BindBufferARB", (SPUGenericFunction) arrayspu_BindBufferARB },
928 { "IsBufferARB", (SPUGenericFunction) arrayspu_IsBufferARB },
929 { "BufferDataARB", (SPUGenericFunction) arrayspu_BufferDataARB },
930 { "BufferSubDataARB", (SPUGenericFunction) arrayspu_BufferSubDataARB },
931 { "GetBufferSubDataARB", (SPUGenericFunction) arrayspu_GetBufferSubDataARB },
932 { "MapBufferARB", (SPUGenericFunction) arrayspu_MapBufferARB },
933 { "UnmapBufferARB", (SPUGenericFunction) arrayspu_UnmapBufferARB },
934 { "GetBufferParameterivARB", (SPUGenericFunction) arrayspu_GetBufferParameterivARB},
935 { "GetBufferPointervARB", (SPUGenericFunction) arrayspu_GetBufferPointervARB},
936 { "InterleavedArrays", (SPUGenericFunction) arrayspu_InterleavedArrays},
937 { "CreateContext", (SPUGenericFunction) arrayspu_CreateContext},
938 { "MakeCurrent", (SPUGenericFunction) arrayspu_MakeCurrent},
939 { "DestroyContext", (SPUGenericFunction) arrayspu_DestroyContext},
940 { "UseProgram", (SPUGenericFunction) arrayspu_UseProgram},
941 { "VBoxAttachThread", (SPUGenericFunction) arrayspu_VBoxAttachThread},
942 { "VBoxDetachThread", (SPUGenericFunction) arrayspu_VBoxDetachThread},
943 { NULL, NULL }
944};
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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