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 |
|
---|
13 | void 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 |
|
---|
27 | void 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 |
|
---|
41 | void 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 |
|
---|
55 | void 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 |
|
---|
70 | void 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 |
|
---|
84 | void 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 |
|
---|
98 | void 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 |
|
---|
112 | void 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 |
|
---|
126 | void 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 |
|
---|
140 | void 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 |
|
---|
154 | void PACKSPU_APIENTRY packspu_GetPointerv( GLenum pname, GLvoid **params )
|
---|
155 | {
|
---|
156 | crStateGetPointerv( pname, params );
|
---|
157 | }
|
---|
158 |
|
---|
159 | void 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 |
|
---|
183 | static GLboolean 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 |
|
---|
239 | typedef struct
|
---|
240 | {
|
---|
241 | ContextInfo *pCtx;
|
---|
242 | GLuint idBuffer;
|
---|
243 | CRClientPointer cp;
|
---|
244 | } CR_ZVA_RESTORE_CTX;
|
---|
245 |
|
---|
246 | static void 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 |
|
---|
283 | static void 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 |
|
---|
339 | void PACKSPU_APIENTRY
|
---|
340 | packspu_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 | {
|
---|
350 | GET_CONTEXT(ctx);
|
---|
351 | /*crDebug("packspu_ArrayElement index:%i", index);*/
|
---|
352 | if (ctx->clientState->extensions.ARB_vertex_buffer_object)
|
---|
353 | {
|
---|
354 | serverArrays = crStateUseServerArrays();
|
---|
355 | if (ctx->fCheckZerroVertAttr)
|
---|
356 | cZvaValues = crStateNeedDummyZeroVertexArray(thread->currentContext->clientState, &thread->packer->current, aAttrib);
|
---|
357 | }
|
---|
358 | }
|
---|
359 | #endif
|
---|
360 |
|
---|
361 | if (serverArrays
|
---|
362 | #ifdef CR_FORCE_ZVA_EXPAND
|
---|
363 | && !cZvaValues
|
---|
364 | #endif
|
---|
365 | ) {
|
---|
366 | CR_ZVA_RESTORE_CTX RestoreCtx;
|
---|
367 | GET_CONTEXT(ctx);
|
---|
368 | CRClientState *clientState = &(ctx->clientState->client);
|
---|
369 |
|
---|
370 | Assert(cZvaValues < UINT32_MAX/2);
|
---|
371 |
|
---|
372 | /* LockArraysEXT can not be executed between glBegin/glEnd pair, it also
|
---|
373 | * leads to vertexpointers being adjusted on the host side between glBegin/glEnd calls which
|
---|
374 | * produces unpredictable results. Locking is done before the glBegin call instead.
|
---|
375 | */
|
---|
376 | CRASSERT(!clientState->array.locked || clientState->array.synced);
|
---|
377 |
|
---|
378 | if (cZvaValues)
|
---|
379 | packspuZvaEnable(ctx, aAttrib, cZvaValues, &RestoreCtx);
|
---|
380 |
|
---|
381 | /* Send the DrawArrays command over the wire */
|
---|
382 | if (pack_spu.swap)
|
---|
383 | crPackArrayElementSWAP( index );
|
---|
384 | else
|
---|
385 | crPackArrayElement( index );
|
---|
386 |
|
---|
387 | if (cZvaValues)
|
---|
388 | packspuZvaDisable(&RestoreCtx);
|
---|
389 | }
|
---|
390 | else {
|
---|
391 | /* evaluate locally */
|
---|
392 | GET_CONTEXT(ctx);
|
---|
393 | CRClientState *clientState = &(ctx->clientState->client);
|
---|
394 |
|
---|
395 | #ifdef CR_FORCE_ZVA_SERVER_ARRAY
|
---|
396 | CR_ZVA_RESTORE_CTX RestoreCtx;
|
---|
397 |
|
---|
398 | if (cZvaValues && cZvaValues < UINT32_MAX/2)
|
---|
399 | packspuZvaEnable(ctx, aAttrib, cZvaValues, &RestoreCtx);
|
---|
400 | #endif
|
---|
401 |
|
---|
402 | if (pack_spu.swap)
|
---|
403 | crPackExpandArrayElementSWAP( index, clientState, cZvaValues ? aAttrib : NULL );
|
---|
404 | else
|
---|
405 | crPackExpandArrayElement( index, clientState, cZvaValues ? aAttrib : NULL );
|
---|
406 |
|
---|
407 | #ifdef CR_FORCE_ZVA_SERVER_ARRAY
|
---|
408 | if (cZvaValues && cZvaValues < UINT32_MAX/2)
|
---|
409 | packspuZvaDisable(&RestoreCtx);
|
---|
410 | #endif
|
---|
411 | }
|
---|
412 | #else
|
---|
413 | GET_CONTEXT(ctx);
|
---|
414 | CRClientState *clientState = &(ctx->clientState->client);
|
---|
415 | crPackExpandArrayElement(index, clientState, NULL);
|
---|
416 | #endif
|
---|
417 | }
|
---|
418 |
|
---|
419 | /*#define CR_USE_LOCKARRAYS*/
|
---|
420 | #ifdef CR_USE_LOCKARRAYS
|
---|
421 | # error "check Zero Vertex Attrib hack is supported properly!"
|
---|
422 | #endif
|
---|
423 |
|
---|
424 | void PACKSPU_APIENTRY
|
---|
425 | packspu_DrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices )
|
---|
426 | {
|
---|
427 | GLboolean serverArrays = GL_FALSE;
|
---|
428 | GLuint cZvaValues = 0;
|
---|
429 | GLfloat aAttrib[4];
|
---|
430 |
|
---|
431 | #if CR_ARB_vertex_buffer_object
|
---|
432 | GLboolean lockedArrays = GL_FALSE;
|
---|
433 | CRBufferObject *elementsBuffer;
|
---|
434 | {
|
---|
435 | GET_CONTEXT(ctx);
|
---|
436 | elementsBuffer = crStateGetCurrent()->bufferobject.elementsBuffer;
|
---|
437 | /*crDebug("DrawElements count=%d, indices=%p", count, indices);*/
|
---|
438 | if (ctx->clientState->extensions.ARB_vertex_buffer_object)
|
---|
439 | {
|
---|
440 | serverArrays = crStateUseServerArrays();
|
---|
441 | if (ctx->fCheckZerroVertAttr)
|
---|
442 | cZvaValues = crStateNeedDummyZeroVertexArray(thread->currentContext->clientState, &thread->packer->current, aAttrib);
|
---|
443 | }
|
---|
444 | }
|
---|
445 |
|
---|
446 | # ifdef CR_USE_LOCKARRAYS
|
---|
447 | if (!serverArrays && !ctx->clientState->client.array.locked && (count>3)
|
---|
448 | && (!elementsBuffer || !elementsBuffer->id))
|
---|
449 | {
|
---|
450 | GLuint min, max;
|
---|
451 | GLsizei i;
|
---|
452 |
|
---|
453 | switch (type)
|
---|
454 | {
|
---|
455 | case GL_UNSIGNED_BYTE:
|
---|
456 | {
|
---|
457 | GLubyte *pIdx = (GLubyte *)indices;
|
---|
458 | min = max = pIdx[0];
|
---|
459 | for (i=0; i<count; ++i)
|
---|
460 | {
|
---|
461 | if (pIdx[i]<min) min = pIdx[i];
|
---|
462 | else if (pIdx[i]>max) max = pIdx[i];
|
---|
463 | }
|
---|
464 | break;
|
---|
465 | }
|
---|
466 | case GL_UNSIGNED_SHORT:
|
---|
467 | {
|
---|
468 | GLushort *pIdx = (GLushort *)indices;
|
---|
469 | min = max = pIdx[0];
|
---|
470 | for (i=0; i<count; ++i)
|
---|
471 | {
|
---|
472 | if (pIdx[i]<min) min = pIdx[i];
|
---|
473 | else if (pIdx[i]>max) max = pIdx[i];
|
---|
474 | }
|
---|
475 | break;
|
---|
476 | }
|
---|
477 | case GL_UNSIGNED_INT:
|
---|
478 | {
|
---|
479 | GLuint *pIdx = (GLuint *)indices;
|
---|
480 | min = max = pIdx[0];
|
---|
481 | for (i=0; i<count; ++i)
|
---|
482 | {
|
---|
483 | if (pIdx[i]<min) min = pIdx[i];
|
---|
484 | else if (pIdx[i]>max) max = pIdx[i];
|
---|
485 | }
|
---|
486 | break;
|
---|
487 | }
|
---|
488 | default: crError("Unknown type 0x%x", type);
|
---|
489 | }
|
---|
490 |
|
---|
491 | if ((max-min)<(GLuint)(2*count))
|
---|
492 | {
|
---|
493 | crStateLockArraysEXT(min, max-min+1);
|
---|
494 |
|
---|
495 | serverArrays = crStateUseServerArrays();
|
---|
496 | if (serverArrays)
|
---|
497 | {
|
---|
498 | lockedArrays = GL_TRUE;
|
---|
499 | }
|
---|
500 | else
|
---|
501 | {
|
---|
502 | crStateUnlockArraysEXT();
|
---|
503 | }
|
---|
504 | }
|
---|
505 | }
|
---|
506 | # endif
|
---|
507 | #endif
|
---|
508 |
|
---|
509 | if (serverArrays
|
---|
510 | #ifdef CR_FORCE_ZVA_EXPAND
|
---|
511 | && !cZvaValues
|
---|
512 | #endif
|
---|
513 | ) {
|
---|
514 | CR_ZVA_RESTORE_CTX RestoreCtx;
|
---|
515 | GET_CONTEXT(ctx);
|
---|
516 | CRClientState *clientState = &(ctx->clientState->client);
|
---|
517 |
|
---|
518 | Assert(cZvaValues < UINT32_MAX/2);
|
---|
519 |
|
---|
520 | if (cZvaValues)
|
---|
521 | packspuZvaEnable(ctx, aAttrib, cZvaValues, &RestoreCtx);
|
---|
522 |
|
---|
523 | /*Note the comment in packspu_LockArraysEXT*/
|
---|
524 | if (clientState->array.locked && !clientState->array.synced)
|
---|
525 | {
|
---|
526 | crPackLockArraysEXT(clientState->array.lockFirst, clientState->array.lockCount);
|
---|
527 | clientState->array.synced = GL_TRUE;
|
---|
528 | }
|
---|
529 |
|
---|
530 | /* Send the DrawArrays command over the wire */
|
---|
531 | if (pack_spu.swap)
|
---|
532 | crPackDrawElementsSWAP( mode, count, type, indices );
|
---|
533 | else
|
---|
534 | crPackDrawElements( mode, count, type, indices );
|
---|
535 |
|
---|
536 | if (cZvaValues)
|
---|
537 | packspuZvaDisable(&RestoreCtx);
|
---|
538 | }
|
---|
539 | else {
|
---|
540 | /* evaluate locally */
|
---|
541 | GET_CONTEXT(ctx);
|
---|
542 | CRClientState *clientState = &(ctx->clientState->client);
|
---|
543 |
|
---|
544 | #ifdef CR_FORCE_ZVA_SERVER_ARRAY
|
---|
545 | CR_ZVA_RESTORE_CTX RestoreCtx;
|
---|
546 |
|
---|
547 | if (cZvaValues && cZvaValues < UINT32_MAX/2)
|
---|
548 | packspuZvaEnable(ctx, aAttrib, cZvaValues, &RestoreCtx);
|
---|
549 | #endif
|
---|
550 |
|
---|
551 | if (pack_spu.swap)
|
---|
552 | crPackExpandDrawElementsSWAP( mode, count, type, indices, clientState, cZvaValues ? aAttrib : NULL );
|
---|
553 | else
|
---|
554 | {
|
---|
555 | //packspu_Begin(mode);
|
---|
556 | crPackExpandDrawElements( mode, count, type, indices, clientState, cZvaValues ? aAttrib : NULL );
|
---|
557 | //packspu_End();
|
---|
558 | }
|
---|
559 |
|
---|
560 | #ifdef CR_FORCE_ZVA_SERVER_ARRAY
|
---|
561 | if (cZvaValues && cZvaValues < UINT32_MAX/2)
|
---|
562 | packspuZvaDisable(&RestoreCtx);
|
---|
563 | #endif
|
---|
564 | }
|
---|
565 |
|
---|
566 | #if CR_ARB_vertex_buffer_object
|
---|
567 | if (lockedArrays)
|
---|
568 | {
|
---|
569 | packspu_UnlockArraysEXT();
|
---|
570 | }
|
---|
571 | #endif
|
---|
572 | }
|
---|
573 |
|
---|
574 |
|
---|
575 | void PACKSPU_APIENTRY
|
---|
576 | packspu_DrawRangeElements( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices )
|
---|
577 | {
|
---|
578 | GLboolean serverArrays = GL_FALSE;
|
---|
579 | GLuint cZvaValues = 0;
|
---|
580 | GLfloat aAttrib[4];
|
---|
581 |
|
---|
582 | #if CR_ARB_vertex_buffer_object
|
---|
583 | {
|
---|
584 | GET_CONTEXT(ctx);
|
---|
585 | /*crDebug("DrawRangeElements count=%d", count);*/
|
---|
586 | if (ctx->clientState->extensions.ARB_vertex_buffer_object)
|
---|
587 | {
|
---|
588 | serverArrays = crStateUseServerArrays();
|
---|
589 | if (ctx->fCheckZerroVertAttr)
|
---|
590 | cZvaValues = crStateNeedDummyZeroVertexArray(thread->currentContext->clientState, &thread->packer->current, aAttrib);
|
---|
591 | }
|
---|
592 | }
|
---|
593 | #endif
|
---|
594 |
|
---|
595 | if (serverArrays
|
---|
596 | #ifdef CR_FORCE_ZVA_EXPAND
|
---|
597 | && !cZvaValues
|
---|
598 | #endif
|
---|
599 | ) {
|
---|
600 | CR_ZVA_RESTORE_CTX RestoreCtx;
|
---|
601 | GET_CONTEXT(ctx);
|
---|
602 | CRClientState *clientState = &(ctx->clientState->client);
|
---|
603 |
|
---|
604 | Assert(cZvaValues < UINT32_MAX/2);
|
---|
605 |
|
---|
606 | if (cZvaValues)
|
---|
607 | packspuZvaEnable(ctx, aAttrib, cZvaValues, &RestoreCtx);
|
---|
608 |
|
---|
609 | /*Note the comment in packspu_LockArraysEXT*/
|
---|
610 | if (clientState->array.locked && !clientState->array.synced)
|
---|
611 | {
|
---|
612 | crPackLockArraysEXT(clientState->array.lockFirst, clientState->array.lockCount);
|
---|
613 | clientState->array.synced = GL_TRUE;
|
---|
614 | }
|
---|
615 |
|
---|
616 | /* Send the DrawRangeElements command over the wire */
|
---|
617 | if (pack_spu.swap)
|
---|
618 | crPackDrawRangeElementsSWAP( mode, start, end, count, type, indices );
|
---|
619 | else
|
---|
620 | crPackDrawRangeElements( mode, start, end, count, type, indices );
|
---|
621 |
|
---|
622 | if (cZvaValues)
|
---|
623 | packspuZvaDisable(&RestoreCtx);
|
---|
624 | }
|
---|
625 | else {
|
---|
626 | /* evaluate locally */
|
---|
627 | GET_CONTEXT(ctx);
|
---|
628 | CRClientState *clientState = &(ctx->clientState->client);
|
---|
629 | #ifdef CR_FORCE_ZVA_SERVER_ARRAY
|
---|
630 | CR_ZVA_RESTORE_CTX RestoreCtx;
|
---|
631 |
|
---|
632 | if (cZvaValues && cZvaValues < UINT32_MAX/2)
|
---|
633 | packspuZvaEnable(ctx, aAttrib, cZvaValues, &RestoreCtx);
|
---|
634 | #endif
|
---|
635 |
|
---|
636 | if (pack_spu.swap)
|
---|
637 | crPackExpandDrawRangeElementsSWAP( mode, start, end, count, type, indices, clientState, cZvaValues ? aAttrib : NULL );
|
---|
638 | else
|
---|
639 | {
|
---|
640 | crPackExpandDrawRangeElements( mode, start, end, count, type, indices, clientState, cZvaValues ? aAttrib : NULL );
|
---|
641 | }
|
---|
642 |
|
---|
643 | #ifdef CR_FORCE_ZVA_SERVER_ARRAY
|
---|
644 | if (cZvaValues && cZvaValues < UINT32_MAX/2)
|
---|
645 | packspuZvaDisable(&RestoreCtx);
|
---|
646 | #endif
|
---|
647 | }
|
---|
648 | }
|
---|
649 |
|
---|
650 |
|
---|
651 | void PACKSPU_APIENTRY
|
---|
652 | packspu_DrawArrays( GLenum mode, GLint first, GLsizei count )
|
---|
653 | {
|
---|
654 | GLboolean serverArrays = GL_FALSE;
|
---|
655 | GLuint cZvaValues = 0;
|
---|
656 | GLfloat aAttrib[4];
|
---|
657 |
|
---|
658 | #if CR_ARB_vertex_buffer_object
|
---|
659 | GLboolean lockedArrays = GL_FALSE;
|
---|
660 | {
|
---|
661 | GET_CONTEXT(ctx);
|
---|
662 | /*crDebug("DrawArrays count=%d", count);*/
|
---|
663 | if (ctx->clientState->extensions.ARB_vertex_buffer_object)
|
---|
664 | {
|
---|
665 | serverArrays = crStateUseServerArrays();
|
---|
666 | if (ctx->fCheckZerroVertAttr)
|
---|
667 | cZvaValues = crStateNeedDummyZeroVertexArray(thread->currentContext->clientState, &thread->packer->current, aAttrib);
|
---|
668 | }
|
---|
669 | }
|
---|
670 |
|
---|
671 | # ifdef CR_USE_LOCKARRAYS
|
---|
672 | if (!serverArrays && !ctx->clientState->client.array.locked && (count>3))
|
---|
673 | {
|
---|
674 | crStateLockArraysEXT(first, count);
|
---|
675 | serverArrays = crStateUseServerArrays();
|
---|
676 | if (serverArrays)
|
---|
677 | {
|
---|
678 | lockedArrays = GL_TRUE;
|
---|
679 | }
|
---|
680 | else
|
---|
681 | {
|
---|
682 | crStateUnlockArraysEXT();
|
---|
683 | }
|
---|
684 | }
|
---|
685 | # endif
|
---|
686 | #endif
|
---|
687 |
|
---|
688 | if (serverArrays
|
---|
689 | #ifdef CR_FORCE_ZVA_EXPAND
|
---|
690 | && !cZvaValues
|
---|
691 | #endif
|
---|
692 | )
|
---|
693 | {
|
---|
694 | CR_ZVA_RESTORE_CTX RestoreCtx;
|
---|
695 | GET_CONTEXT(ctx);
|
---|
696 | CRClientState *clientState = &(ctx->clientState->client);
|
---|
697 |
|
---|
698 | Assert(cZvaValues < UINT32_MAX/2);
|
---|
699 |
|
---|
700 | if (cZvaValues)
|
---|
701 | packspuZvaEnable(ctx, aAttrib, cZvaValues, &RestoreCtx);
|
---|
702 |
|
---|
703 | /*Note the comment in packspu_LockArraysEXT*/
|
---|
704 | if (clientState->array.locked && !clientState->array.synced)
|
---|
705 | {
|
---|
706 | crPackLockArraysEXT(clientState->array.lockFirst, clientState->array.lockCount);
|
---|
707 | clientState->array.synced = GL_TRUE;
|
---|
708 | }
|
---|
709 |
|
---|
710 | /* Send the DrawArrays command over the wire */
|
---|
711 | if (pack_spu.swap)
|
---|
712 | crPackDrawArraysSWAP( mode, first, count );
|
---|
713 | else
|
---|
714 | crPackDrawArrays( mode, first, count );
|
---|
715 |
|
---|
716 | if (cZvaValues)
|
---|
717 | packspuZvaDisable(&RestoreCtx);
|
---|
718 | }
|
---|
719 | else
|
---|
720 | {
|
---|
721 | /* evaluate locally */
|
---|
722 | GET_CONTEXT(ctx);
|
---|
723 | CRClientState *clientState = &(ctx->clientState->client);
|
---|
724 | #ifdef CR_FORCE_ZVA_SERVER_ARRAY
|
---|
725 | CR_ZVA_RESTORE_CTX RestoreCtx;
|
---|
726 |
|
---|
727 | if (cZvaValues && cZvaValues < UINT32_MAX/2)
|
---|
728 | packspuZvaEnable(ctx, aAttrib, cZvaValues, &RestoreCtx);
|
---|
729 | #endif
|
---|
730 |
|
---|
731 | if (pack_spu.swap)
|
---|
732 | crPackExpandDrawArraysSWAP( mode, first, count, clientState, cZvaValues ? aAttrib : NULL );
|
---|
733 | else
|
---|
734 | crPackExpandDrawArrays( mode, first, count, clientState, cZvaValues ? aAttrib : NULL );
|
---|
735 |
|
---|
736 | #ifdef CR_FORCE_ZVA_SERVER_ARRAY
|
---|
737 | if (cZvaValues && cZvaValues < UINT32_MAX/2)
|
---|
738 | packspuZvaDisable(&RestoreCtx);
|
---|
739 | #endif
|
---|
740 |
|
---|
741 | }
|
---|
742 |
|
---|
743 | #if CR_ARB_vertex_buffer_object
|
---|
744 | if (lockedArrays)
|
---|
745 | {
|
---|
746 | packspu_UnlockArraysEXT();
|
---|
747 | }
|
---|
748 | #endif
|
---|
749 | }
|
---|
750 |
|
---|
751 |
|
---|
752 | #ifdef CR_EXT_multi_draw_arrays
|
---|
753 | void PACKSPU_APIENTRY packspu_MultiDrawArraysEXT( GLenum mode, GLint *first, GLsizei *count, GLsizei primcount )
|
---|
754 | {
|
---|
755 | GLint i;
|
---|
756 | for (i = 0; i < primcount; i++) {
|
---|
757 | if (count[i] > 0) {
|
---|
758 | packspu_DrawArrays(mode, first[i], count[i]);
|
---|
759 | }
|
---|
760 | }
|
---|
761 | }
|
---|
762 |
|
---|
763 | void PACKSPU_APIENTRY packspu_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount )
|
---|
764 | {
|
---|
765 | GLint i;
|
---|
766 | for (i = 0; i < primcount; i++) {
|
---|
767 | if (count[i] > 0) {
|
---|
768 | packspu_DrawElements(mode, count[i], type, indices[i]);
|
---|
769 | }
|
---|
770 | }
|
---|
771 | }
|
---|
772 | #endif
|
---|
773 |
|
---|
774 |
|
---|
775 | void PACKSPU_APIENTRY packspu_EnableClientState( GLenum array )
|
---|
776 | {
|
---|
777 | crStateEnableClientState(array);
|
---|
778 | crPackEnableClientState(array);
|
---|
779 | }
|
---|
780 |
|
---|
781 | void PACKSPU_APIENTRY packspu_DisableClientState( GLenum array )
|
---|
782 | {
|
---|
783 | crStateDisableClientState(array);
|
---|
784 | crPackDisableClientState(array);
|
---|
785 | }
|
---|
786 |
|
---|
787 | void PACKSPU_APIENTRY packspu_ClientActiveTextureARB( GLenum texUnit )
|
---|
788 | {
|
---|
789 | crStateClientActiveTextureARB(texUnit);
|
---|
790 | crPackClientActiveTextureARB(texUnit);
|
---|
791 | }
|
---|
792 |
|
---|
793 | void PACKSPU_APIENTRY packspu_EnableVertexAttribArrayARB(GLuint index)
|
---|
794 | {
|
---|
795 | crStateEnableVertexAttribArrayARB(index);
|
---|
796 | crPackEnableVertexAttribArrayARB(index);
|
---|
797 | }
|
---|
798 |
|
---|
799 |
|
---|
800 | void PACKSPU_APIENTRY packspu_DisableVertexAttribArrayARB(GLuint index)
|
---|
801 | {
|
---|
802 | crStateDisableVertexAttribArrayARB(index);
|
---|
803 | crPackDisableVertexAttribArrayARB(index);
|
---|
804 | }
|
---|
805 |
|
---|
806 | void PACKSPU_APIENTRY packspu_Enable( GLenum cap )
|
---|
807 | {
|
---|
808 | if (cap!=GL_LIGHT_MODEL_TWO_SIDE)
|
---|
809 | {
|
---|
810 | crStateEnable(cap);
|
---|
811 |
|
---|
812 | if (pack_spu.swap)
|
---|
813 | crPackEnableSWAP(cap);
|
---|
814 | else
|
---|
815 | crPackEnable(cap);
|
---|
816 | }
|
---|
817 | else
|
---|
818 | {
|
---|
819 | static int g_glmts1_warn=0;
|
---|
820 | if (!g_glmts1_warn)
|
---|
821 | {
|
---|
822 | crWarning("glEnable(GL_LIGHT_MODEL_TWO_SIDE) converted to valid glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1)");
|
---|
823 | g_glmts1_warn=1;
|
---|
824 | }
|
---|
825 | crStateLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
|
---|
826 | crPackLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
|
---|
827 | }
|
---|
828 | }
|
---|
829 |
|
---|
830 |
|
---|
831 | void PACKSPU_APIENTRY packspu_Disable( GLenum cap )
|
---|
832 | {
|
---|
833 | if (cap!=GL_LIGHT_MODEL_TWO_SIDE)
|
---|
834 | {
|
---|
835 | crStateDisable(cap);
|
---|
836 |
|
---|
837 | if (pack_spu.swap)
|
---|
838 | crPackDisableSWAP(cap);
|
---|
839 | else
|
---|
840 | crPackDisable(cap);
|
---|
841 | }
|
---|
842 | else
|
---|
843 | {
|
---|
844 | static int g_glmts0_warn=0;
|
---|
845 | if (!g_glmts0_warn)
|
---|
846 | {
|
---|
847 | crWarning("glDisable(GL_LIGHT_MODEL_TWO_SIDE) converted to valid glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0)");
|
---|
848 | g_glmts0_warn=1;
|
---|
849 | }
|
---|
850 | crStateLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
|
---|
851 | crPackLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
|
---|
852 | }
|
---|
853 | }
|
---|
854 |
|
---|
855 | GLboolean PACKSPU_APIENTRY packspu_IsEnabled(GLenum cap)
|
---|
856 | {
|
---|
857 | GLboolean res = crStateIsEnabled(cap);
|
---|
858 | #ifdef DEBUG
|
---|
859 | {
|
---|
860 | GET_THREAD(thread);
|
---|
861 | int writeback = 1;
|
---|
862 | GLboolean return_val = (GLboolean) 0;
|
---|
863 | crPackIsEnabled(cap, &return_val, &writeback);
|
---|
864 | packspuFlush( (void *) thread );
|
---|
865 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
866 | CRASSERT(return_val==res);
|
---|
867 | }
|
---|
868 | #endif
|
---|
869 |
|
---|
870 | return res;
|
---|
871 | }
|
---|
872 |
|
---|
873 | void PACKSPU_APIENTRY packspu_PushClientAttrib( GLbitfield mask )
|
---|
874 | {
|
---|
875 | crStatePushClientAttrib(mask);
|
---|
876 | crPackPushClientAttrib(mask);
|
---|
877 | }
|
---|
878 |
|
---|
879 | void PACKSPU_APIENTRY packspu_PopClientAttrib( void )
|
---|
880 | {
|
---|
881 | crStatePopClientAttrib();
|
---|
882 | crPackPopClientAttrib();
|
---|
883 | }
|
---|
884 |
|
---|
885 | void PACKSPU_APIENTRY packspu_LockArraysEXT(GLint first, GLint count)
|
---|
886 | {
|
---|
887 | if (first>=0 && count>0)
|
---|
888 | {
|
---|
889 | crStateLockArraysEXT(first, count);
|
---|
890 | /*Note: this is a workaround for quake3 based apps.
|
---|
891 | It's modifying vertex data between glLockArraysEXT and glDrawElements calls,
|
---|
892 | so we'd pass data to host right before the glDrawSomething or glBegin call.
|
---|
893 | */
|
---|
894 | /*crPackLockArraysEXT(first, count);*/
|
---|
895 | }
|
---|
896 | else crDebug("Ignoring packspu_LockArraysEXT: first:%i, count:%i", first, count);
|
---|
897 | }
|
---|
898 |
|
---|
899 | void PACKSPU_APIENTRY packspu_UnlockArraysEXT()
|
---|
900 | {
|
---|
901 | GET_CONTEXT(ctx);
|
---|
902 | CRClientState *clientState = &(ctx->clientState->client);
|
---|
903 |
|
---|
904 | if (clientState->array.locked && clientState->array.synced)
|
---|
905 | {
|
---|
906 | crPackUnlockArraysEXT();
|
---|
907 | }
|
---|
908 |
|
---|
909 | crStateUnlockArraysEXT();
|
---|
910 | }
|
---|