VirtualBox

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

Last change on this file since 41971 was 35912, checked in by vboxsync, 14 years ago

crOpenGL: fix sometimes missing textures and geometry

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 17.9 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
12void PACKSPU_APIENTRY packspu_FogCoordPointerEXT( GLenum type, GLsizei stride, const GLvoid *pointer )
13{
14#if CR_ARB_vertex_buffer_object
15 GET_CONTEXT(ctx);
16 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
17 if (pack_spu.swap)
18 crPackFogCoordPointerEXTSWAP( type, stride, pointer );
19 else
20 crPackFogCoordPointerEXT( type, stride, pointer );
21 }
22#endif
23 crStateFogCoordPointerEXT( type, stride, pointer );
24}
25
26void PACKSPU_APIENTRY packspu_ColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
27{
28#if CR_ARB_vertex_buffer_object
29 GET_CONTEXT(ctx);
30 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
31 if (pack_spu.swap)
32 crPackColorPointerSWAP( size, type, stride, pointer );
33 else
34 crPackColorPointer( size, type, stride, pointer );
35 }
36#endif
37 crStateColorPointer( size, type, stride, pointer );
38}
39
40void PACKSPU_APIENTRY packspu_SecondaryColorPointerEXT( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
41{
42#if CR_ARB_vertex_buffer_object
43 GET_CONTEXT(ctx);
44 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
45 if (pack_spu.swap)
46 crPackSecondaryColorPointerEXTSWAP( size, type, stride, pointer );
47 else
48 crPackSecondaryColorPointerEXT( size, type, stride, pointer );
49 }
50#endif
51 crStateSecondaryColorPointerEXT( size, type, stride, pointer );
52}
53
54void PACKSPU_APIENTRY packspu_VertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
55{
56#if CR_ARB_vertex_buffer_object
57 GET_CONTEXT(ctx);
58 CRASSERT(ctx->clientState->extensions.ARB_vertex_buffer_object);
59 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
60 if (pack_spu.swap)
61 crPackVertexPointerSWAP( size, type, stride, pointer );
62 else
63 crPackVertexPointer( size, type, stride, pointer );
64 }
65#endif
66 crStateVertexPointer( size, type, stride, pointer );
67}
68
69void PACKSPU_APIENTRY packspu_TexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
70{
71#if CR_ARB_vertex_buffer_object
72 GET_CONTEXT(ctx);
73 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
74 if (pack_spu.swap)
75 crPackTexCoordPointerSWAP( size, type, stride, pointer );
76 else
77 crPackTexCoordPointer( size, type, stride, pointer );
78 }
79#endif
80 crStateTexCoordPointer( size, type, stride, pointer );
81}
82
83void PACKSPU_APIENTRY packspu_NormalPointer( GLenum type, GLsizei stride, const GLvoid *pointer )
84{
85#if CR_ARB_vertex_buffer_object
86 GET_CONTEXT(ctx);
87 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
88 if (pack_spu.swap)
89 crPackNormalPointerSWAP( type, stride, pointer );
90 else
91 crPackNormalPointer( type, stride, pointer );
92 }
93#endif
94 crStateNormalPointer( type, stride, pointer );
95}
96
97void PACKSPU_APIENTRY packspu_EdgeFlagPointer( GLsizei stride, const GLvoid *pointer )
98{
99#if CR_ARB_vertex_buffer_object
100 GET_CONTEXT(ctx);
101 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
102 if (pack_spu.swap)
103 crPackEdgeFlagPointerSWAP( stride, pointer );
104 else
105 crPackEdgeFlagPointer( stride, pointer );
106 }
107#endif
108 crStateEdgeFlagPointer( stride, pointer );
109}
110
111void PACKSPU_APIENTRY packspu_VertexAttribPointerARB( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer )
112{
113#if CR_ARB_vertex_buffer_object
114 GET_CONTEXT(ctx);
115 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
116 if (pack_spu.swap)
117 crPackVertexAttribPointerARBSWAP( index, size, type, normalized, stride, pointer );
118 else
119 crPackVertexAttribPointerARB( index, size, type, normalized, stride, pointer );
120 }
121#endif
122 crStateVertexAttribPointerARB( index, size, type, normalized, stride, pointer );
123}
124
125void PACKSPU_APIENTRY packspu_VertexAttribPointerNV( GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer )
126{
127#if CR_ARB_vertex_buffer_object
128 GET_CONTEXT(ctx);
129 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
130 if (pack_spu.swap)
131 crPackVertexAttribPointerNVSWAP( index, size, type, stride, pointer );
132 else
133 crPackVertexAttribPointerNV( index, size, type, stride, pointer );
134 }
135#endif
136 crStateVertexAttribPointerNV( index, size, type, stride, pointer );
137}
138
139void PACKSPU_APIENTRY packspu_IndexPointer( GLenum type, GLsizei stride, const GLvoid *pointer )
140{
141#if CR_ARB_vertex_buffer_object
142 GET_CONTEXT(ctx);
143 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
144 if (pack_spu.swap)
145 crPackIndexPointerSWAP( type, stride, pointer );
146 else
147 crPackIndexPointer( type, stride, pointer );
148 }
149#endif
150 crStateIndexPointer(type, stride, pointer);
151}
152
153void PACKSPU_APIENTRY packspu_GetPointerv( GLenum pname, GLvoid **params )
154{
155 crStateGetPointerv( pname, params );
156}
157
158void PACKSPU_APIENTRY packspu_InterleavedArrays( GLenum format, GLsizei stride, const GLvoid *pointer )
159{
160#if CR_ARB_vertex_buffer_object
161 GET_CONTEXT(ctx);
162 if (ctx->clientState->extensions.ARB_vertex_buffer_object) {
163 if (pack_spu.swap)
164 crPackInterleavedArraysSWAP( format, stride, pointer );
165 else
166 crPackInterleavedArrays( format, stride, pointer );
167 }
168#endif
169
170 /*crDebug("packspu_InterleavedArrays");*/
171
172 crStateInterleavedArrays( format, stride, pointer );
173}
174
175
176void PACKSPU_APIENTRY
177packspu_ArrayElement( GLint index )
178{
179/*@todo cash guest/host pointers calculation and use appropriate path here without crStateUseServerArrays call*/
180#if 1
181 GLboolean serverArrays = GL_FALSE;
182
183#if CR_ARB_vertex_buffer_object
184 GET_CONTEXT(ctx);
185 /*crDebug("packspu_ArrayElement index:%i", index);*/
186 if (ctx->clientState->extensions.ARB_vertex_buffer_object)
187 serverArrays = crStateUseServerArrays();
188#endif
189
190 if (serverArrays) {
191 GET_CONTEXT(ctx);
192 CRClientState *clientState = &(ctx->clientState->client);
193
194 /* LockArraysEXT can not be executed between glBegin/glEnd pair, it also
195 * leads to vertexpointers being adjusted on the host side between glBegin/glEnd calls which
196 * produces unpredictable results. Locking is done before the glBegin call instead.
197 */
198 CRASSERT(!clientState->array.locked || clientState->array.synced);
199
200 /* Send the DrawArrays command over the wire */
201 if (pack_spu.swap)
202 crPackArrayElementSWAP( index );
203 else
204 crPackArrayElement( index );
205 }
206 else {
207 /* evaluate locally */
208 GET_CONTEXT(ctx);
209 CRClientState *clientState = &(ctx->clientState->client);
210 if (pack_spu.swap)
211 crPackExpandArrayElementSWAP( index, clientState );
212 else
213 crPackExpandArrayElement( index, clientState );
214 }
215#else
216 GET_CONTEXT(ctx);
217 CRClientState *clientState = &(ctx->clientState->client);
218 crPackExpandArrayElement(index, clientState);
219#endif
220}
221
222/*#define CR_USE_LOCKARRAYS*/
223
224void PACKSPU_APIENTRY
225packspu_DrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices )
226{
227 GLboolean serverArrays = GL_FALSE;
228
229#if CR_ARB_vertex_buffer_object
230 GET_CONTEXT(ctx);
231 GLboolean lockedArrays = GL_FALSE;
232 CRBufferObject *elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer;
233 /*crDebug("DrawElements count=%d, indices=%p", count, indices);*/
234 if (ctx->clientState->extensions.ARB_vertex_buffer_object)
235 serverArrays = crStateUseServerArrays();
236
237# ifdef CR_USE_LOCKARRAYS
238 if (!serverArrays && !ctx->clientState->client.array.locked && (count>3)
239 && (!elementsBuffer || !elementsBuffer->id))
240 {
241 GLuint min, max;
242 GLsizei i;
243
244 switch (type)
245 {
246 case GL_UNSIGNED_BYTE:
247 {
248 GLubyte *pIdx = (GLubyte *)indices;
249 min = max = pIdx[0];
250 for (i=0; i<count; ++i)
251 {
252 if (pIdx[i]<min) min = pIdx[i];
253 else if (pIdx[i]>max) max = pIdx[i];
254 }
255 break;
256 }
257 case GL_UNSIGNED_SHORT:
258 {
259 GLushort *pIdx = (GLushort *)indices;
260 min = max = pIdx[0];
261 for (i=0; i<count; ++i)
262 {
263 if (pIdx[i]<min) min = pIdx[i];
264 else if (pIdx[i]>max) max = pIdx[i];
265 }
266 break;
267 }
268 case GL_UNSIGNED_INT:
269 {
270 GLuint *pIdx = (GLuint *)indices;
271 min = max = pIdx[0];
272 for (i=0; i<count; ++i)
273 {
274 if (pIdx[i]<min) min = pIdx[i];
275 else if (pIdx[i]>max) max = pIdx[i];
276 }
277 break;
278 }
279 default: crError("Unknown type 0x%x", type);
280 }
281
282 if ((max-min)<(GLuint)(2*count))
283 {
284 crStateLockArraysEXT(min, max-min+1);
285
286 serverArrays = crStateUseServerArrays();
287 if (serverArrays)
288 {
289 lockedArrays = GL_TRUE;
290 }
291 else
292 {
293 crStateUnlockArraysEXT();
294 }
295 }
296 }
297# endif
298#endif
299
300 if (serverArrays) {
301 GET_CONTEXT(ctx);
302 CRClientState *clientState = &(ctx->clientState->client);
303
304 /*Note the comment in packspu_LockArraysEXT*/
305 if (clientState->array.locked && !clientState->array.synced)
306 {
307 crPackLockArraysEXT(clientState->array.lockFirst, clientState->array.lockCount);
308 clientState->array.synced = GL_TRUE;
309 }
310 /* Send the DrawArrays command over the wire */
311 if (pack_spu.swap)
312 crPackDrawElementsSWAP( mode, count, type, indices );
313 else
314 crPackDrawElements( mode, count, type, indices );
315 }
316 else {
317 /* evaluate locally */
318 GET_CONTEXT(ctx);
319 CRClientState *clientState = &(ctx->clientState->client);
320 if (pack_spu.swap)
321 crPackExpandDrawElementsSWAP( mode, count, type, indices, clientState );
322 else
323 {
324 //packspu_Begin(mode);
325 crPackExpandDrawElements( mode, count, type, indices, clientState );
326 //packspu_End();
327 }
328 }
329
330#if CR_ARB_vertex_buffer_object
331 if (lockedArrays)
332 {
333 packspu_UnlockArraysEXT();
334 }
335#endif
336}
337
338
339void PACKSPU_APIENTRY
340packspu_DrawRangeElements( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices )
341{
342 GLboolean serverArrays = GL_FALSE;
343
344#if CR_ARB_vertex_buffer_object
345 GET_CONTEXT(ctx);
346 /*crDebug("DrawRangeElements count=%d", count);*/
347 if (ctx->clientState->extensions.ARB_vertex_buffer_object)
348 serverArrays = crStateUseServerArrays();
349#endif
350
351 if (serverArrays) {
352 GET_CONTEXT(ctx);
353 CRClientState *clientState = &(ctx->clientState->client);
354
355 /*Note the comment in packspu_LockArraysEXT*/
356 if (clientState->array.locked && !clientState->array.synced)
357 {
358 crPackLockArraysEXT(clientState->array.lockFirst, clientState->array.lockCount);
359 clientState->array.synced = GL_TRUE;
360 }
361
362 /* Send the DrawRangeElements command over the wire */
363 if (pack_spu.swap)
364 crPackDrawRangeElementsSWAP( mode, start, end, count, type, indices );
365 else
366 crPackDrawRangeElements( mode, start, end, count, type, indices );
367 }
368 else {
369 /* evaluate locally */
370 GET_CONTEXT(ctx);
371 CRClientState *clientState = &(ctx->clientState->client);
372 if (pack_spu.swap)
373 crPackExpandDrawRangeElementsSWAP( mode, start, end, count, type, indices, clientState );
374 else
375 {
376 crPackExpandDrawRangeElements( mode, start, end, count, type, indices, clientState );
377 }
378 }
379}
380
381
382void PACKSPU_APIENTRY
383packspu_DrawArrays( GLenum mode, GLint first, GLsizei count )
384{
385 GLboolean serverArrays = GL_FALSE;
386
387#if CR_ARB_vertex_buffer_object
388 GET_CONTEXT(ctx);
389 GLboolean lockedArrays = GL_FALSE;
390 /*crDebug("DrawArrays count=%d", count);*/
391 if (ctx->clientState->extensions.ARB_vertex_buffer_object)
392 serverArrays = crStateUseServerArrays();
393
394# ifdef CR_USE_LOCKARRAYS
395 if (!serverArrays && !ctx->clientState->client.array.locked && (count>3))
396 {
397 crStateLockArraysEXT(first, count);
398 serverArrays = crStateUseServerArrays();
399 if (serverArrays)
400 {
401 lockedArrays = GL_TRUE;
402 }
403 else
404 {
405 crStateUnlockArraysEXT();
406 }
407 }
408# endif
409#endif
410
411 if (serverArrays)
412 {
413 GET_CONTEXT(ctx);
414 CRClientState *clientState = &(ctx->clientState->client);
415
416 /*Note the comment in packspu_LockArraysEXT*/
417 if (clientState->array.locked && !clientState->array.synced)
418 {
419 crPackLockArraysEXT(clientState->array.lockFirst, clientState->array.lockCount);
420 clientState->array.synced = GL_TRUE;
421 }
422
423 /* Send the DrawArrays command over the wire */
424 if (pack_spu.swap)
425 crPackDrawArraysSWAP( mode, first, count );
426 else
427 crPackDrawArrays( mode, first, count );
428 }
429 else
430 {
431 /* evaluate locally */
432 GET_CONTEXT(ctx);
433 CRClientState *clientState = &(ctx->clientState->client);
434 if (pack_spu.swap)
435 crPackExpandDrawArraysSWAP( mode, first, count, clientState );
436 else
437 crPackExpandDrawArrays( mode, first, count, clientState );
438 }
439
440#if CR_ARB_vertex_buffer_object
441 if (lockedArrays)
442 {
443 packspu_UnlockArraysEXT();
444 }
445#endif
446}
447
448
449#ifdef CR_EXT_multi_draw_arrays
450void PACKSPU_APIENTRY packspu_MultiDrawArraysEXT( GLenum mode, GLint *first, GLsizei *count, GLsizei primcount )
451{
452 GLint i;
453 for (i = 0; i < primcount; i++) {
454 if (count[i] > 0) {
455 packspu_DrawArrays(mode, first[i], count[i]);
456 }
457 }
458}
459
460void PACKSPU_APIENTRY packspu_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount )
461{
462 GLint i;
463 for (i = 0; i < primcount; i++) {
464 if (count[i] > 0) {
465 packspu_DrawElements(mode, count[i], type, indices[i]);
466 }
467 }
468}
469#endif
470
471
472void PACKSPU_APIENTRY packspu_EnableClientState( GLenum array )
473{
474 crStateEnableClientState(array);
475 crPackEnableClientState(array);
476}
477
478void PACKSPU_APIENTRY packspu_DisableClientState( GLenum array )
479{
480 crStateDisableClientState(array);
481 crPackDisableClientState(array);
482}
483
484void PACKSPU_APIENTRY packspu_ClientActiveTextureARB( GLenum texUnit )
485{
486 crStateClientActiveTextureARB(texUnit);
487 crPackClientActiveTextureARB(texUnit);
488}
489
490void PACKSPU_APIENTRY packspu_EnableVertexAttribArrayARB(GLuint index)
491{
492 crStateEnableVertexAttribArrayARB(index);
493 crPackEnableVertexAttribArrayARB(index);
494}
495
496
497void PACKSPU_APIENTRY packspu_DisableVertexAttribArrayARB(GLuint index)
498{
499 crStateDisableVertexAttribArrayARB(index);
500 crPackDisableVertexAttribArrayARB(index);
501}
502
503void PACKSPU_APIENTRY packspu_Enable( GLenum cap )
504{
505 if (cap!=GL_LIGHT_MODEL_TWO_SIDE)
506 {
507 crStateEnable(cap);
508
509 if (pack_spu.swap)
510 crPackEnableSWAP(cap);
511 else
512 crPackEnable(cap);
513 }
514 else
515 {
516 static int g_glmts1_warn=0;
517 if (!g_glmts1_warn)
518 {
519 crWarning("glEnable(GL_LIGHT_MODEL_TWO_SIDE) converted to valid glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1)");
520 g_glmts1_warn=1;
521 }
522 crStateLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
523 crPackLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
524 }
525}
526
527
528void PACKSPU_APIENTRY packspu_Disable( GLenum cap )
529{
530 if (cap!=GL_LIGHT_MODEL_TWO_SIDE)
531 {
532 crStateDisable(cap);
533
534 if (pack_spu.swap)
535 crPackDisableSWAP(cap);
536 else
537 crPackDisable(cap);
538 }
539 else
540 {
541 static int g_glmts0_warn=0;
542 if (!g_glmts0_warn)
543 {
544 crWarning("glDisable(GL_LIGHT_MODEL_TWO_SIDE) converted to valid glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0)");
545 g_glmts0_warn=1;
546 }
547 crStateLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
548 crPackLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
549 }
550}
551
552GLboolean PACKSPU_APIENTRY packspu_IsEnabled(GLenum cap)
553{
554 GLboolean res = crStateIsEnabled(cap);
555#ifdef DEBUG
556 {
557 GET_THREAD(thread);
558 int writeback = 1;
559 GLboolean return_val = (GLboolean) 0;
560 crPackIsEnabled(cap, &return_val, &writeback);
561 packspuFlush( (void *) thread );
562 while (writeback)
563 crNetRecv();
564 CRASSERT(return_val==res);
565 }
566#endif
567
568 return res;
569}
570
571void PACKSPU_APIENTRY packspu_PushClientAttrib( GLbitfield mask )
572{
573 crStatePushClientAttrib(mask);
574 crPackPushClientAttrib(mask);
575}
576
577void PACKSPU_APIENTRY packspu_PopClientAttrib( void )
578{
579 crStatePopClientAttrib();
580 crPackPopClientAttrib();
581}
582
583void PACKSPU_APIENTRY packspu_LockArraysEXT(GLint first, GLint count)
584{
585 if (first>=0 && count>0)
586 {
587 crStateLockArraysEXT(first, count);
588 /*Note: this is a workaround for quake3 based apps.
589 It's modifying vertex data between glLockArraysEXT and glDrawElements calls,
590 so we'd pass data to host right before the glDrawSomething or glBegin call.
591 */
592 /*crPackLockArraysEXT(first, count);*/
593 }
594 else crDebug("Ignoring packspu_LockArraysEXT: first:%i, count:%i", first, count);
595}
596
597void PACKSPU_APIENTRY packspu_UnlockArraysEXT()
598{
599 GET_CONTEXT(ctx);
600 CRClientState *clientState = &(ctx->clientState->client);
601
602 if (clientState->array.locked && clientState->array.synced)
603 {
604 crPackUnlockArraysEXT();
605 }
606
607 crStateUnlockArraysEXT();
608}
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