VirtualBox

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

Last change on this file since 26121 was 26121, checked in by vboxsync, 15 years ago

crOpenGL: workaround for buggy apps using glEnable with GL_LIGHT_MODEL_TWO_SIDE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 15.2 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 /*Note the comment in packspu_LockArraysEXT*/
195 if (clientState->array.locked && !clientState->array.synced)
196 {
197 crPackLockArraysEXT(clientState->array.lockFirst, clientState->array.lockCount);
198 clientState->array.synced = GL_TRUE;
199 }
200
201 /* Send the DrawArrays command over the wire */
202 if (pack_spu.swap)
203 crPackArrayElementSWAP( index );
204 else
205 crPackArrayElement( index );
206 }
207 else {
208 /* evaluate locally */
209 GET_CONTEXT(ctx);
210 CRClientState *clientState = &(ctx->clientState->client);
211 if (pack_spu.swap)
212 crPackExpandArrayElementSWAP( index, clientState );
213 else
214 crPackExpandArrayElement( index, clientState );
215 }
216#else
217 GET_CONTEXT(ctx);
218 CRClientState *clientState = &(ctx->clientState->client);
219 crPackExpandArrayElement(index, clientState);
220#endif
221}
222
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 /*crDebug("DrawElements count=%d, indices=%p", count, indices);*/
232 if (ctx->clientState->extensions.ARB_vertex_buffer_object)
233 serverArrays = crStateUseServerArrays();
234#endif
235
236 if (serverArrays) {
237 GET_CONTEXT(ctx);
238 CRClientState *clientState = &(ctx->clientState->client);
239
240 /*Note the comment in packspu_LockArraysEXT*/
241 if (clientState->array.locked && !clientState->array.synced)
242 {
243 crPackLockArraysEXT(clientState->array.lockFirst, clientState->array.lockCount);
244 clientState->array.synced = GL_TRUE;
245 }
246
247 /* Send the DrawArrays command over the wire */
248 if (pack_spu.swap)
249 crPackDrawElementsSWAP( mode, count, type, indices );
250 else
251 crPackDrawElements( mode, count, type, indices );
252 }
253 else {
254 /* evaluate locally */
255 GET_CONTEXT(ctx);
256 CRClientState *clientState = &(ctx->clientState->client);
257 if (pack_spu.swap)
258 crPackExpandDrawElementsSWAP( mode, count, type, indices, clientState );
259 else
260 {
261 //packspu_Begin(mode);
262 crPackExpandDrawElements( mode, count, type, indices, clientState );
263 //packspu_End();
264 }
265 }
266}
267
268
269void PACKSPU_APIENTRY
270packspu_DrawRangeElements( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices )
271{
272 GLboolean serverArrays = GL_FALSE;
273
274#if CR_ARB_vertex_buffer_object
275 GET_CONTEXT(ctx);
276 /*crDebug("DrawRangeElements count=%d", count);*/
277 if (ctx->clientState->extensions.ARB_vertex_buffer_object)
278 serverArrays = crStateUseServerArrays();
279#endif
280
281 if (serverArrays) {
282 GET_CONTEXT(ctx);
283 CRClientState *clientState = &(ctx->clientState->client);
284
285 /*Note the comment in packspu_LockArraysEXT*/
286 if (clientState->array.locked && !clientState->array.synced)
287 {
288 crPackLockArraysEXT(clientState->array.lockFirst, clientState->array.lockCount);
289 clientState->array.synced = GL_TRUE;
290 }
291
292 /* Send the DrawRangeElements command over the wire */
293 if (pack_spu.swap)
294 crPackDrawRangeElementsSWAP( mode, start, end, count, type, indices );
295 else
296 crPackDrawRangeElements( mode, start, end, count, type, indices );
297 }
298 else {
299 /* evaluate locally */
300 GET_CONTEXT(ctx);
301 CRClientState *clientState = &(ctx->clientState->client);
302 if (pack_spu.swap)
303 crPackExpandDrawRangeElementsSWAP( mode, start, end, count, type, indices, clientState );
304 else
305 {
306 crPackExpandDrawRangeElements( mode, start, end, count, type, indices, clientState );
307 }
308 }
309}
310
311
312void PACKSPU_APIENTRY
313packspu_DrawArrays( GLenum mode, GLint first, GLsizei count )
314{
315 GLboolean serverArrays = GL_FALSE;
316
317#if CR_ARB_vertex_buffer_object
318 GET_CONTEXT(ctx);
319 /*crDebug("DrawArrays count=%d", count);*/
320 if (ctx->clientState->extensions.ARB_vertex_buffer_object)
321 serverArrays = crStateUseServerArrays();
322#endif
323
324 if (serverArrays) {
325 GET_CONTEXT(ctx);
326 CRClientState *clientState = &(ctx->clientState->client);
327
328 /*Note the comment in packspu_LockArraysEXT*/
329 if (clientState->array.locked && !clientState->array.synced)
330 {
331 crPackLockArraysEXT(clientState->array.lockFirst, clientState->array.lockCount);
332 clientState->array.synced = GL_TRUE;
333 }
334
335 /* Send the DrawArrays command over the wire */
336 if (pack_spu.swap)
337 crPackDrawArraysSWAP( mode, first, count );
338 else
339 crPackDrawArrays( mode, first, count );
340 }
341 else {
342 /* evaluate locally */
343 GET_CONTEXT(ctx);
344 CRClientState *clientState = &(ctx->clientState->client);
345 if (pack_spu.swap)
346 crPackExpandDrawArraysSWAP( mode, first, count, clientState );
347 else
348 crPackExpandDrawArrays( mode, first, count, clientState );
349 }
350}
351
352
353#ifdef CR_EXT_multi_draw_arrays
354void PACKSPU_APIENTRY packspu_MultiDrawArraysEXT( GLenum mode, GLint *first, GLsizei *count, GLsizei primcount )
355{
356 GLint i;
357 for (i = 0; i < primcount; i++) {
358 if (count[i] > 0) {
359 packspu_DrawArrays(mode, first[i], count[i]);
360 }
361 }
362}
363
364void PACKSPU_APIENTRY packspu_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount )
365{
366 GLint i;
367 for (i = 0; i < primcount; i++) {
368 if (count[i] > 0) {
369 packspu_DrawElements(mode, count[i], type, indices[i]);
370 }
371 }
372}
373#endif
374
375
376void PACKSPU_APIENTRY packspu_EnableClientState( GLenum array )
377{
378 crStateEnableClientState(array);
379 crPackEnableClientState(array);
380}
381
382void PACKSPU_APIENTRY packspu_DisableClientState( GLenum array )
383{
384 crStateDisableClientState(array);
385 crPackDisableClientState(array);
386}
387
388void PACKSPU_APIENTRY packspu_ClientActiveTextureARB( GLenum texUnit )
389{
390 crStateClientActiveTextureARB(texUnit);
391 crPackClientActiveTextureARB(texUnit);
392}
393
394void PACKSPU_APIENTRY packspu_EnableVertexAttribArrayARB(GLuint index)
395{
396 crStateEnableVertexAttribArrayARB(index);
397 crPackEnableVertexAttribArrayARB(index);
398}
399
400
401void PACKSPU_APIENTRY packspu_DisableVertexAttribArrayARB(GLuint index)
402{
403 crStateDisableVertexAttribArrayARB(index);
404 crPackDisableVertexAttribArrayARB(index);
405}
406
407void PACKSPU_APIENTRY packspu_Enable( GLenum cap )
408{
409 if (cap!=GL_LIGHT_MODEL_TWO_SIDE)
410 {
411 crStateEnable(cap);
412
413 if (pack_spu.swap)
414 crPackEnableSWAP(cap);
415 else
416 crPackEnable(cap);
417 }
418 else
419 {
420 static int g_glmts1_warn=0;
421 if (!g_glmts1_warn)
422 {
423 crWarning("glEnable(GL_LIGHT_MODEL_TWO_SIDE) converted to valid glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1)");
424 g_glmts1_warn=1;
425 }
426 crStateLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
427 crPackLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
428 }
429}
430
431
432void PACKSPU_APIENTRY packspu_Disable( GLenum cap )
433{
434 if (cap!=GL_LIGHT_MODEL_TWO_SIDE)
435 {
436 crStateDisable(cap);
437
438 if (pack_spu.swap)
439 crPackDisableSWAP(cap);
440 else
441 crPackDisable(cap);
442 }
443 else
444 {
445 static int g_glmts0_warn=0;
446 if (!g_glmts0_warn)
447 {
448 crWarning("glDisable(GL_LIGHT_MODEL_TWO_SIDE) converted to valid glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0)");
449 g_glmts0_warn=1;
450 }
451 crStateLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
452 crPackLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
453 }
454}
455
456GLboolean PACKSPU_APIENTRY packspu_IsEnabled(GLenum cap)
457{
458 GLboolean res = crStateIsEnabled(cap);
459#ifdef DEBUG
460 {
461 GET_THREAD(thread);
462 int writeback = 1;
463 GLboolean return_val = (GLboolean) 0;
464 crPackIsEnabled(cap, &return_val, &writeback);
465 packspuFlush( (void *) thread );
466 while (writeback)
467 crNetRecv();
468 CRASSERT(return_val==res);
469 }
470#endif
471
472 return res;
473}
474
475void PACKSPU_APIENTRY packspu_PushClientAttrib( GLbitfield mask )
476{
477 crStatePushClientAttrib(mask);
478 crPackPushClientAttrib(mask);
479}
480
481void PACKSPU_APIENTRY packspu_PopClientAttrib( void )
482{
483 crStatePopClientAttrib();
484 crPackPopClientAttrib();
485}
486
487void PACKSPU_APIENTRY packspu_LockArraysEXT(GLint first, GLint count)
488{
489 if (first>=0 && count>0)
490 {
491 crStateLockArraysEXT(first, count);
492 /*Note: this is a workaround for quake3 based apps.
493 It's modifying vertex data between glLockArraysEXT and glDrawElements calls,
494 so we'd pass data to host right before the glDrawSomething call.
495 */
496 /*crPackLockArraysEXT(first, count);*/
497 }
498 else crDebug("Ignoring packspu_LockArraysEXT: first:%i, count:%i", first, count);
499}
500
501void PACKSPU_APIENTRY packspu_UnlockArraysEXT()
502{
503 crStateUnlockArraysEXT();
504 crPackUnlockArraysEXT();
505}
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