VirtualBox

source: vbox/trunk/src/VBox/Additions/common/crOpenGL/pack/packspu_client.c@ 55382

Last change on this file since 55382 was 51316, checked in by vboxsync, 11 years ago

build fix v2

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 26.4 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 "packspu.h"
8#include "cr_packfunctions.h"
9#include "cr_glstate.h"
10#include "packspu_proto.h"
11#include "cr_mem.h"
12
13void PACKSPU_APIENTRY packspu_FogCoordPointerEXT( GLenum type, GLsizei stride, const GLvoid *pointer )
14{
15#if CR_ARB_vertex_buffer_object
16 GET_CONTEXT(ctx);
17 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
18 if (pack_spu.swap)
19 crPackFogCoordPointerEXTSWAP( type, stride, pointer );
20 else
21 crPackFogCoordPointerEXT( type, stride, pointer );
22 }
23#endif
24 crStateFogCoordPointerEXT( type, stride, pointer );
25}
26
27void PACKSPU_APIENTRY packspu_ColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
28{
29#if CR_ARB_vertex_buffer_object
30 GET_CONTEXT(ctx);
31 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
32 if (pack_spu.swap)
33 crPackColorPointerSWAP( size, type, stride, pointer );
34 else
35 crPackColorPointer( size, type, stride, pointer );
36 }
37#endif
38 crStateColorPointer( size, type, stride, pointer );
39}
40
41void PACKSPU_APIENTRY packspu_SecondaryColorPointerEXT( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
42{
43#if CR_ARB_vertex_buffer_object
44 GET_CONTEXT(ctx);
45 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
46 if (pack_spu.swap)
47 crPackSecondaryColorPointerEXTSWAP( size, type, stride, pointer );
48 else
49 crPackSecondaryColorPointerEXT( size, type, stride, pointer );
50 }
51#endif
52 crStateSecondaryColorPointerEXT( size, type, stride, pointer );
53}
54
55void PACKSPU_APIENTRY packspu_VertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
56{
57#if CR_ARB_vertex_buffer_object
58 GET_CONTEXT(ctx);
59 CRASSERT(ctx->clientState->extensions.ARB_vertex_buffer_object);
60 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
61 if (pack_spu.swap)
62 crPackVertexPointerSWAP( size, type, stride, pointer );
63 else
64 crPackVertexPointer( size, type, stride, pointer );
65 }
66#endif
67 crStateVertexPointer( size, type, stride, pointer );
68}
69
70void PACKSPU_APIENTRY packspu_TexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
71{
72#if CR_ARB_vertex_buffer_object
73 GET_CONTEXT(ctx);
74 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
75 if (pack_spu.swap)
76 crPackTexCoordPointerSWAP( size, type, stride, pointer );
77 else
78 crPackTexCoordPointer( size, type, stride, pointer );
79 }
80#endif
81 crStateTexCoordPointer( size, type, stride, pointer );
82}
83
84void PACKSPU_APIENTRY packspu_NormalPointer( GLenum type, GLsizei stride, const GLvoid *pointer )
85{
86#if CR_ARB_vertex_buffer_object
87 GET_CONTEXT(ctx);
88 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
89 if (pack_spu.swap)
90 crPackNormalPointerSWAP( type, stride, pointer );
91 else
92 crPackNormalPointer( type, stride, pointer );
93 }
94#endif
95 crStateNormalPointer( type, stride, pointer );
96}
97
98void PACKSPU_APIENTRY packspu_EdgeFlagPointer( GLsizei stride, const GLvoid *pointer )
99{
100#if CR_ARB_vertex_buffer_object
101 GET_CONTEXT(ctx);
102 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
103 if (pack_spu.swap)
104 crPackEdgeFlagPointerSWAP( stride, pointer );
105 else
106 crPackEdgeFlagPointer( stride, pointer );
107 }
108#endif
109 crStateEdgeFlagPointer( stride, pointer );
110}
111
112void PACKSPU_APIENTRY packspu_VertexAttribPointerARB( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer )
113{
114#if CR_ARB_vertex_buffer_object
115 GET_CONTEXT(ctx);
116 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
117 if (pack_spu.swap)
118 crPackVertexAttribPointerARBSWAP( index, size, type, normalized, stride, pointer );
119 else
120 crPackVertexAttribPointerARB( index, size, type, normalized, stride, pointer );
121 }
122#endif
123 crStateVertexAttribPointerARB( index, size, type, normalized, stride, pointer );
124}
125
126void PACKSPU_APIENTRY packspu_VertexAttribPointerNV( GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
127{
128#if CR_ARB_vertex_buffer_object
129 GET_CONTEXT(ctx);
130 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
131 if (pack_spu.swap)
132 crPackVertexAttribPointerNVSWAP( index, size, type, stride, pointer );
133 else
134 crPackVertexAttribPointerNV( index, size, type, stride, pointer );
135 }
136#endif
137 crStateVertexAttribPointerNV( index, size, type, stride, pointer );
138}
139
140void PACKSPU_APIENTRY packspu_IndexPointer( GLenum type, GLsizei stride, const GLvoid *pointer )
141{
142#if CR_ARB_vertex_buffer_object
143 GET_CONTEXT(ctx);
144 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
145 if (pack_spu.swap)
146 crPackIndexPointerSWAP( type, stride, pointer );
147 else
148 crPackIndexPointer( type, stride, pointer );
149 }
150#endif
151 crStateIndexPointer(type, stride, pointer);
152}
153
154void PACKSPU_APIENTRY packspu_GetPointerv( GLenum pname, GLvoid **params )
155{
156 crStateGetPointerv( pname, params );
157}
158
159void PACKSPU_APIENTRY packspu_InterleavedArrays( GLenum format, GLsizei stride, const GLvoid *pointer )
160{
161#if CR_ARB_vertex_buffer_object
162 GET_CONTEXT(ctx);
163 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
164 if (pack_spu.swap)
165 crPackInterleavedArraysSWAP( format, stride, pointer );
166 else
167 crPackInterleavedArrays( format, stride, pointer );
168 }
169#endif
170
171 /*crDebug("packspu_InterleavedArrays");*/
172
173 crStateInterleavedArrays( format, stride, pointer );
174}
175
176#ifdef DEBUG_misha
177/* debugging */
178//# define CR_FORCE_ZVA_SERVER_ARRAY
179#endif
180# define CR_FORCE_ZVA_EXPAND
181
182
183GLboolean packspuZvaCreate(ContextInfo *pCtx, const GLfloat *pValue, GLuint cValues)
184{
185 ZvaBufferInfo *pInfo = &pCtx->zvaBufferInfo;
186 GLuint cbValue = 4 * sizeof (*pValue);
187 GLuint cbValues = cValues * cbValue;
188 GLfloat *pBuffer;
189 uint8_t *pu8Buf;
190 GLuint i;
191
192 /* quickly sort out if we can use the current value */
193 if (pInfo->idBuffer
194 && pInfo->cValues >= cValues
195 && !crMemcmp(pValue, &pInfo->Value, cbValue))
196 return GL_FALSE;
197
198 pBuffer = (GLfloat*)crAlloc(cbValues);
199 if (!pBuffer)
200 {
201 WARN(("crAlloc for pBuffer failed"));
202 return GL_FALSE;
203 }
204
205 pu8Buf = (uint8_t *)pBuffer;
206 for (i = 0; i < cValues; ++i)
207 {
208 crMemcpy(pu8Buf, pValue, cbValue);
209 pu8Buf += cbValue;
210 }
211
212 /* */
213 if (!pInfo->idBuffer)
214 {
215 pack_spu.self.GenBuffersARB(1, &pInfo->idBuffer);
216 Assert(pInfo->idBuffer);
217 }
218
219 pack_spu.self.BindBufferARB(GL_ARRAY_BUFFER_ARB, pInfo->idBuffer);
220
221 if (pInfo->cbBuffer < cbValues)
222 {
223 pack_spu.self.BufferDataARB(GL_ARRAY_BUFFER_ARB, cbValues, pBuffer, GL_DYNAMIC_DRAW_ARB);
224 pInfo->cbBuffer = cbValues;
225 }
226 else
227 {
228 pack_spu.self.BufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, cbValues, pBuffer);
229 }
230
231 pInfo->cValues = cValues;
232 crMemcpy(&pInfo->Value, pValue, cbValue);
233
234 crFree(pBuffer);
235
236 return GL_TRUE;
237}
238
239typedef struct
240{
241 ContextInfo *pCtx;
242 GLuint idBuffer;
243 CRClientPointer cp;
244} CR_ZVA_RESTORE_CTX;
245
246void packspuZvaEnable(ContextInfo *pCtx, const GLfloat *pValue, GLuint cValues, CR_ZVA_RESTORE_CTX *pRestoreCtx)
247{
248 CRContext *g = pCtx->clientState;
249
250 Assert(0);
251
252#ifdef DEBUG
253 {
254 CRContext *pCurState = crStateGetCurrent();
255
256 Assert(g == pCurState);
257 }
258#endif
259
260 pRestoreCtx->pCtx = pCtx;
261 pRestoreCtx->idBuffer = g->bufferobject.arrayBuffer ? g->bufferobject.arrayBuffer->id : 0;
262 pRestoreCtx->cp = g->client.array.a[0];
263
264 Assert(!pRestoreCtx->cp.enabled);
265
266 /* buffer ref count mechanism does not work actually atm,
267 * still ensure the buffer does not get destroyed if we fix it in the future */
268 if (pRestoreCtx->cp.buffer)
269 pRestoreCtx->cp.buffer->refCount++;
270
271 packspuZvaCreate(pCtx, pValue, cValues);
272
273 pack_spu.self.BindBufferARB(GL_ARRAY_BUFFER_ARB, pCtx->zvaBufferInfo.idBuffer);
274
275 pack_spu.self.VertexAttribPointerARB(0, 4, GL_FLOAT,
276 GL_FALSE, /*normalized*/
277 0, /*stride*/
278 NULL /*addr*/);
279
280 pack_spu.self.EnableVertexAttribArrayARB(0);
281}
282
283void packspuZvaDisable(CR_ZVA_RESTORE_CTX *pRestoreCtx)
284{
285 if (pRestoreCtx->cp.buffer)
286 pack_spu.self.BindBufferARB(GL_ARRAY_BUFFER_ARB, pRestoreCtx->cp.buffer->id);
287 else
288 pack_spu.self.BindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
289
290 pack_spu.self.VertexAttribPointerARB(0, pRestoreCtx->cp.size, pRestoreCtx->cp.type,
291 pRestoreCtx->cp.normalized, /*normalized*/
292 pRestoreCtx->cp.stride, /*stride*/
293 pRestoreCtx->cp.p);
294
295 if (pRestoreCtx->cp.enabled)
296 pack_spu.self.EnableVertexAttribArrayARB(0);
297 else
298 pack_spu.self.DisableVertexAttribArrayARB(0);
299
300 if (pRestoreCtx->cp.buffer)
301 {
302 if (pRestoreCtx->cp.buffer->id != pRestoreCtx->idBuffer)
303 pack_spu.self.BindBufferARB(GL_ARRAY_BUFFER_ARB, pRestoreCtx->idBuffer);
304
305 /* we have increased the refcount above, decrease it back */
306 pRestoreCtx->cp.buffer->refCount--;
307 }
308 else
309 {
310 if (pRestoreCtx->idBuffer)
311 pack_spu.self.BindBufferARB(GL_ARRAY_BUFFER_ARB, pRestoreCtx->idBuffer);
312 }
313
314#ifdef DEBUG
315 {
316 CRContext *g = pRestoreCtx->pCtx->clientState;
317 CRContext *pCurState = crStateGetCurrent();
318
319 Assert(g == pCurState);
320
321 Assert(pRestoreCtx->cp.p == g->client.array.a[0].p);
322 Assert(pRestoreCtx->cp.size == g->client.array.a[0].size);
323 Assert(pRestoreCtx->cp.type == g->client.array.a[0].type);
324 Assert(pRestoreCtx->cp.stride == g->client.array.a[0].stride);
325 Assert(pRestoreCtx->cp.enabled == g->client.array.a[0].enabled);
326 Assert(pRestoreCtx->cp.normalized == g->client.array.a[0].normalized);
327 Assert(pRestoreCtx->cp.bytesPerIndex == g->client.array.a[0].bytesPerIndex);
328# ifdef CR_ARB_vertex_buffer_object
329 Assert(pRestoreCtx->cp.buffer == g->client.array.a[0].buffer);
330# endif
331# ifdef CR_EXT_compiled_vertex_array
332 Assert(pRestoreCtx->cp.locked == g->client.array.a[0].locked);
333# endif
334 Assert(pRestoreCtx->idBuffer == (g->bufferobject.arrayBuffer ? g->bufferobject.arrayBuffer->id : 0));
335 }
336#endif
337}
338
339void PACKSPU_APIENTRY
340packspu_ArrayElement( GLint index )
341{
342/*@todo cash guest/host pointers calculation and use appropriate path here without crStateUseServerArrays call*/
343#if 1
344 GLboolean serverArrays = GL_FALSE;
345 GLuint cZvaValues = 0;
346 GLfloat aAttrib[4];
347
348#if CR_ARB_vertex_buffer_object
349 GET_CONTEXT(ctx);
350 /*crDebug("packspu_ArrayElement index:%i", index);*/
351 if (ctx->clientState->extensions.ARB_vertex_buffer_object)
352 {
353 serverArrays = crStateUseServerArrays();
354 if (ctx->fCheckZerroVertAttr)
355 cZvaValues = crStateNeedDummyZeroVertexArray(thread->currentContext->clientState, &thread->packer->current, aAttrib);
356 }
357#endif
358
359 if (serverArrays
360#ifdef CR_FORCE_ZVA_EXPAND
361 && !cZvaValues
362#endif
363 ) {
364 CR_ZVA_RESTORE_CTX RestoreCtx;
365 GET_CONTEXT(ctx);
366 CRClientState *clientState = &(ctx->clientState->client);
367
368 Assert(cZvaValues < UINT32_MAX/2);
369
370 /* LockArraysEXT can not be executed between glBegin/glEnd pair, it also
371 * leads to vertexpointers being adjusted on the host side between glBegin/glEnd calls which
372 * produces unpredictable results. Locking is done before the glBegin call instead.
373 */
374 CRASSERT(!clientState->array.locked || clientState->array.synced);
375
376 if (cZvaValues)
377 packspuZvaEnable(ctx, aAttrib, cZvaValues, &RestoreCtx);
378
379 /* Send the DrawArrays command over the wire */
380 if (pack_spu.swap)
381 crPackArrayElementSWAP( index );
382 else
383 crPackArrayElement( index );
384
385 if (cZvaValues)
386 packspuZvaDisable(&RestoreCtx);
387 }
388 else {
389 /* evaluate locally */
390 GET_CONTEXT(ctx);
391 CRClientState *clientState = &(ctx->clientState->client);
392
393#ifdef CR_FORCE_ZVA_SERVER_ARRAY
394 CR_ZVA_RESTORE_CTX RestoreCtx;
395
396 if (cZvaValues && cZvaValues < UINT32_MAX/2)
397 packspuZvaEnable(ctx, aAttrib, cZvaValues, &RestoreCtx);
398#endif
399
400 if (pack_spu.swap)
401 crPackExpandArrayElementSWAP( index, clientState, cZvaValues ? aAttrib : NULL );
402 else
403 crPackExpandArrayElement( index, clientState, cZvaValues ? aAttrib : NULL );
404
405#ifdef CR_FORCE_ZVA_SERVER_ARRAY
406 if (cZvaValues && cZvaValues < UINT32_MAX/2)
407 packspuZvaDisable(&RestoreCtx);
408#endif
409 }
410#else
411 GET_CONTEXT(ctx);
412 CRClientState *clientState = &(ctx->clientState->client);
413 crPackExpandArrayElement(index, clientState, NULL);
414#endif
415}
416
417/*#define CR_USE_LOCKARRAYS*/
418#ifdef CR_USE_LOCKARRAYS
419# error "check Zero Vertex Attrib hack is supported properly!"
420#endif
421
422void PACKSPU_APIENTRY
423packspu_DrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices )
424{
425 GLboolean serverArrays = GL_FALSE;
426 GLuint cZvaValues = 0;
427 GLfloat aAttrib[4];
428
429#if CR_ARB_vertex_buffer_object
430 GET_CONTEXT(ctx);
431 GLboolean lockedArrays = GL_FALSE;
432 CRBufferObject *elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer;
433 /*crDebug("DrawElements count=%d, indices=%p", count, indices);*/
434 if (ctx->clientState->extensions.ARB_vertex_buffer_object)
435 {
436 serverArrays = crStateUseServerArrays();
437 if (ctx->fCheckZerroVertAttr)
438 cZvaValues = crStateNeedDummyZeroVertexArray(thread->currentContext->clientState, &thread->packer->current, aAttrib);
439 }
440
441# ifdef CR_USE_LOCKARRAYS
442 if (!serverArrays && !ctx->clientState->client.array.locked && (count>3)
443 && (!elementsBuffer || !elementsBuffer->id))
444 {
445 GLuint min, max;
446 GLsizei i;
447
448 switch (type)
449 {
450 case GL_UNSIGNED_BYTE:
451 {
452 GLubyte *pIdx = (GLubyte *)indices;
453 min = max = pIdx[0];
454 for (i=0; i<count; ++i)
455 {
456 if (pIdx[i]<min) min = pIdx[i];
457 else if (pIdx[i]>max) max = pIdx[i];
458 }
459 break;
460 }
461 case GL_UNSIGNED_SHORT:
462 {
463 GLushort *pIdx = (GLushort *)indices;
464 min = max = pIdx[0];
465 for (i=0; i<count; ++i)
466 {
467 if (pIdx[i]<min) min = pIdx[i];
468 else if (pIdx[i]>max) max = pIdx[i];
469 }
470 break;
471 }
472 case GL_UNSIGNED_INT:
473 {
474 GLuint *pIdx = (GLuint *)indices;
475 min = max = pIdx[0];
476 for (i=0; i<count; ++i)
477 {
478 if (pIdx[i]<min) min = pIdx[i];
479 else if (pIdx[i]>max) max = pIdx[i];
480 }
481 break;
482 }
483 default: crError("Unknown type 0x%x", type);
484 }
485
486 if ((max-min)<(GLuint)(2*count))
487 {
488 crStateLockArraysEXT(min, max-min+1);
489
490 serverArrays = crStateUseServerArrays();
491 if (serverArrays)
492 {
493 lockedArrays = GL_TRUE;
494 }
495 else
496 {
497 crStateUnlockArraysEXT();
498 }
499 }
500 }
501# endif
502#endif
503
504 if (serverArrays
505#ifdef CR_FORCE_ZVA_EXPAND
506 && !cZvaValues
507#endif
508 ) {
509 CR_ZVA_RESTORE_CTX RestoreCtx;
510 GET_CONTEXT(ctx);
511 CRClientState *clientState = &(ctx->clientState->client);
512
513 Assert(cZvaValues < UINT32_MAX/2);
514
515 if (cZvaValues)
516 packspuZvaEnable(ctx, aAttrib, cZvaValues, &RestoreCtx);
517
518 /*Note the comment in packspu_LockArraysEXT*/
519 if (clientState->array.locked && !clientState->array.synced)
520 {
521 crPackLockArraysEXT(clientState->array.lockFirst, clientState->array.lockCount);
522 clientState->array.synced = GL_TRUE;
523 }
524
525 /* Send the DrawArrays command over the wire */
526 if (pack_spu.swap)
527 crPackDrawElementsSWAP( mode, count, type, indices );
528 else
529 crPackDrawElements( mode, count, type, indices );
530
531 if (cZvaValues)
532 packspuZvaDisable(&RestoreCtx);
533 }
534 else {
535 /* evaluate locally */
536 GET_CONTEXT(ctx);
537 CRClientState *clientState = &(ctx->clientState->client);
538
539#ifdef CR_FORCE_ZVA_SERVER_ARRAY
540 CR_ZVA_RESTORE_CTX RestoreCtx;
541
542 if (cZvaValues && cZvaValues < UINT32_MAX/2)
543 packspuZvaEnable(ctx, aAttrib, cZvaValues, &RestoreCtx);
544#endif
545
546 if (pack_spu.swap)
547 crPackExpandDrawElementsSWAP( mode, count, type, indices, clientState, cZvaValues ? aAttrib : NULL );
548 else
549 {
550 //packspu_Begin(mode);
551 crPackExpandDrawElements( mode, count, type, indices, clientState, cZvaValues ? aAttrib : NULL );
552 //packspu_End();
553 }
554
555#ifdef CR_FORCE_ZVA_SERVER_ARRAY
556 if (cZvaValues && cZvaValues < UINT32_MAX/2)
557 packspuZvaDisable(&RestoreCtx);
558#endif
559 }
560
561#if CR_ARB_vertex_buffer_object
562 if (lockedArrays)
563 {
564 packspu_UnlockArraysEXT();
565 }
566#endif
567}
568
569
570void PACKSPU_APIENTRY
571packspu_DrawRangeElements( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices )
572{
573 GLboolean serverArrays = GL_FALSE;
574 GLuint cZvaValues = 0;
575 GLfloat aAttrib[4];
576
577#if CR_ARB_vertex_buffer_object
578 GET_CONTEXT(ctx);
579 /*crDebug("DrawRangeElements count=%d", count);*/
580 if (ctx->clientState->extensions.ARB_vertex_buffer_object)
581 {
582 serverArrays = crStateUseServerArrays();
583 if (ctx->fCheckZerroVertAttr)
584 cZvaValues = crStateNeedDummyZeroVertexArray(thread->currentContext->clientState, &thread->packer->current, aAttrib);
585 }
586#endif
587
588 if (serverArrays
589#ifdef CR_FORCE_ZVA_EXPAND
590 && !cZvaValues
591#endif
592 ) {
593 CR_ZVA_RESTORE_CTX RestoreCtx;
594 GET_CONTEXT(ctx);
595 CRClientState *clientState = &(ctx->clientState->client);
596
597 Assert(cZvaValues < UINT32_MAX/2);
598
599 if (cZvaValues)
600 packspuZvaEnable(ctx, aAttrib, cZvaValues, &RestoreCtx);
601
602 /*Note the comment in packspu_LockArraysEXT*/
603 if (clientState->array.locked && !clientState->array.synced)
604 {
605 crPackLockArraysEXT(clientState->array.lockFirst, clientState->array.lockCount);
606 clientState->array.synced = GL_TRUE;
607 }
608
609 /* Send the DrawRangeElements command over the wire */
610 if (pack_spu.swap)
611 crPackDrawRangeElementsSWAP( mode, start, end, count, type, indices );
612 else
613 crPackDrawRangeElements( mode, start, end, count, type, indices );
614
615 if (cZvaValues)
616 packspuZvaDisable(&RestoreCtx);
617 }
618 else {
619 /* evaluate locally */
620 GET_CONTEXT(ctx);
621 CRClientState *clientState = &(ctx->clientState->client);
622#ifdef CR_FORCE_ZVA_SERVER_ARRAY
623 CR_ZVA_RESTORE_CTX RestoreCtx;
624
625 if (cZvaValues && cZvaValues < UINT32_MAX/2)
626 packspuZvaEnable(ctx, aAttrib, cZvaValues, &RestoreCtx);
627#endif
628
629 if (pack_spu.swap)
630 crPackExpandDrawRangeElementsSWAP( mode, start, end, count, type, indices, clientState, cZvaValues ? aAttrib : NULL );
631 else
632 {
633 crPackExpandDrawRangeElements( mode, start, end, count, type, indices, clientState, cZvaValues ? aAttrib : NULL );
634 }
635
636#ifdef CR_FORCE_ZVA_SERVER_ARRAY
637 if (cZvaValues && cZvaValues < UINT32_MAX/2)
638 packspuZvaDisable(&RestoreCtx);
639#endif
640 }
641}
642
643
644void PACKSPU_APIENTRY
645packspu_DrawArrays( GLenum mode, GLint first, GLsizei count )
646{
647 GLboolean serverArrays = GL_FALSE;
648 GLuint cZvaValues = 0;
649 GLfloat aAttrib[4];
650
651#if CR_ARB_vertex_buffer_object
652 GET_CONTEXT(ctx);
653 GLboolean lockedArrays = GL_FALSE;
654 /*crDebug("DrawArrays count=%d", count);*/
655 if (ctx->clientState->extensions.ARB_vertex_buffer_object)
656 {
657 serverArrays = crStateUseServerArrays();
658 if (ctx->fCheckZerroVertAttr)
659 cZvaValues = crStateNeedDummyZeroVertexArray(thread->currentContext->clientState, &thread->packer->current, aAttrib);
660 }
661
662# ifdef CR_USE_LOCKARRAYS
663 if (!serverArrays && !ctx->clientState->client.array.locked && (count>3))
664 {
665 crStateLockArraysEXT(first, count);
666 serverArrays = crStateUseServerArrays();
667 if (serverArrays)
668 {
669 lockedArrays = GL_TRUE;
670 }
671 else
672 {
673 crStateUnlockArraysEXT();
674 }
675 }
676# endif
677#endif
678
679 if (serverArrays
680#ifdef CR_FORCE_ZVA_EXPAND
681 && !cZvaValues
682#endif
683 )
684 {
685 CR_ZVA_RESTORE_CTX RestoreCtx;
686 GET_CONTEXT(ctx);
687 CRClientState *clientState = &(ctx->clientState->client);
688
689 Assert(cZvaValues < UINT32_MAX/2);
690
691 if (cZvaValues)
692 packspuZvaEnable(ctx, aAttrib, cZvaValues, &RestoreCtx);
693
694 /*Note the comment in packspu_LockArraysEXT*/
695 if (clientState->array.locked && !clientState->array.synced)
696 {
697 crPackLockArraysEXT(clientState->array.lockFirst, clientState->array.lockCount);
698 clientState->array.synced = GL_TRUE;
699 }
700
701 /* Send the DrawArrays command over the wire */
702 if (pack_spu.swap)
703 crPackDrawArraysSWAP( mode, first, count );
704 else
705 crPackDrawArrays( mode, first, count );
706
707 if (cZvaValues)
708 packspuZvaDisable(&RestoreCtx);
709 }
710 else
711 {
712 /* evaluate locally */
713 GET_CONTEXT(ctx);
714 CRClientState *clientState = &(ctx->clientState->client);
715#ifdef CR_FORCE_ZVA_SERVER_ARRAY
716 CR_ZVA_RESTORE_CTX RestoreCtx;
717
718 if (cZvaValues && cZvaValues < UINT32_MAX/2)
719 packspuZvaEnable(ctx, aAttrib, cZvaValues, &RestoreCtx);
720#endif
721
722 if (pack_spu.swap)
723 crPackExpandDrawArraysSWAP( mode, first, count, clientState, cZvaValues ? aAttrib : NULL );
724 else
725 crPackExpandDrawArrays( mode, first, count, clientState, cZvaValues ? aAttrib : NULL );
726
727#ifdef CR_FORCE_ZVA_SERVER_ARRAY
728 if (cZvaValues && cZvaValues < UINT32_MAX/2)
729 packspuZvaDisable(&RestoreCtx);
730#endif
731
732 }
733
734#if CR_ARB_vertex_buffer_object
735 if (lockedArrays)
736 {
737 packspu_UnlockArraysEXT();
738 }
739#endif
740}
741
742
743#ifdef CR_EXT_multi_draw_arrays
744void PACKSPU_APIENTRY packspu_MultiDrawArraysEXT( GLenum mode, GLint *first, GLsizei *count, GLsizei primcount )
745{
746 GLint i;
747 for (i = 0; i < primcount; i++) {
748 if (count[i] > 0) {
749 packspu_DrawArrays(mode, first[i], count[i]);
750 }
751 }
752}
753
754void PACKSPU_APIENTRY packspu_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount )
755{
756 GLint i;
757 for (i = 0; i < primcount; i++) {
758 if (count[i] > 0) {
759 packspu_DrawElements(mode, count[i], type, indices[i]);
760 }
761 }
762}
763#endif
764
765
766void PACKSPU_APIENTRY packspu_EnableClientState( GLenum array )
767{
768 crStateEnableClientState(array);
769 crPackEnableClientState(array);
770}
771
772void PACKSPU_APIENTRY packspu_DisableClientState( GLenum array )
773{
774 crStateDisableClientState(array);
775 crPackDisableClientState(array);
776}
777
778void PACKSPU_APIENTRY packspu_ClientActiveTextureARB( GLenum texUnit )
779{
780 crStateClientActiveTextureARB(texUnit);
781 crPackClientActiveTextureARB(texUnit);
782}
783
784void PACKSPU_APIENTRY packspu_EnableVertexAttribArrayARB(GLuint index)
785{
786 crStateEnableVertexAttribArrayARB(index);
787 crPackEnableVertexAttribArrayARB(index);
788}
789
790
791void PACKSPU_APIENTRY packspu_DisableVertexAttribArrayARB(GLuint index)
792{
793 crStateDisableVertexAttribArrayARB(index);
794 crPackDisableVertexAttribArrayARB(index);
795}
796
797void PACKSPU_APIENTRY packspu_Enable( GLenum cap )
798{
799 if (cap!=GL_LIGHT_MODEL_TWO_SIDE)
800 {
801 crStateEnable(cap);
802
803 if (pack_spu.swap)
804 crPackEnableSWAP(cap);
805 else
806 crPackEnable(cap);
807 }
808 else
809 {
810 static int g_glmts1_warn=0;
811 if (!g_glmts1_warn)
812 {
813 crWarning("glEnable(GL_LIGHT_MODEL_TWO_SIDE) converted to valid glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1)");
814 g_glmts1_warn=1;
815 }
816 crStateLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
817 crPackLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
818 }
819}
820
821
822void PACKSPU_APIENTRY packspu_Disable( GLenum cap )
823{
824 if (cap!=GL_LIGHT_MODEL_TWO_SIDE)
825 {
826 crStateDisable(cap);
827
828 if (pack_spu.swap)
829 crPackDisableSWAP(cap);
830 else
831 crPackDisable(cap);
832 }
833 else
834 {
835 static int g_glmts0_warn=0;
836 if (!g_glmts0_warn)
837 {
838 crWarning("glDisable(GL_LIGHT_MODEL_TWO_SIDE) converted to valid glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0)");
839 g_glmts0_warn=1;
840 }
841 crStateLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
842 crPackLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
843 }
844}
845
846GLboolean PACKSPU_APIENTRY packspu_IsEnabled(GLenum cap)
847{
848 GLboolean res = crStateIsEnabled(cap);
849#ifdef DEBUG
850 {
851 GET_THREAD(thread);
852 int writeback = 1;
853 GLboolean return_val = (GLboolean) 0;
854 crPackIsEnabled(cap, &return_val, &writeback);
855 packspuFlush( (void *) thread );
856 CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
857 CRASSERT(return_val==res);
858 }
859#endif
860
861 return res;
862}
863
864void PACKSPU_APIENTRY packspu_PushClientAttrib( GLbitfield mask )
865{
866 crStatePushClientAttrib(mask);
867 crPackPushClientAttrib(mask);
868}
869
870void PACKSPU_APIENTRY packspu_PopClientAttrib( void )
871{
872 crStatePopClientAttrib();
873 crPackPopClientAttrib();
874}
875
876void PACKSPU_APIENTRY packspu_LockArraysEXT(GLint first, GLint count)
877{
878 if (first>=0 && count>0)
879 {
880 crStateLockArraysEXT(first, count);
881 /*Note: this is a workaround for quake3 based apps.
882 It's modifying vertex data between glLockArraysEXT and glDrawElements calls,
883 so we'd pass data to host right before the glDrawSomething or glBegin call.
884 */
885 /*crPackLockArraysEXT(first, count);*/
886 }
887 else crDebug("Ignoring packspu_LockArraysEXT: first:%i, count:%i", first, count);
888}
889
890void PACKSPU_APIENTRY packspu_UnlockArraysEXT()
891{
892 GET_CONTEXT(ctx);
893 CRClientState *clientState = &(ctx->clientState->client);
894
895 if (clientState->array.locked && clientState->array.synced)
896 {
897 crPackUnlockArraysEXT();
898 }
899
900 crStateUnlockArraysEXT();
901}
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