VirtualBox

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

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

crOpenGL: fixed host crashes when using GL_EXT_compiled_vertex_array and array element calls (#6165)

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

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