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 "cr_error.h"
|
---|
8 | #include "unpack_extend.h"
|
---|
9 | #include "unpacker.h"
|
---|
10 |
|
---|
11 |
|
---|
12 | void crUnpackExtendVertexPointer(PCrUnpackerState pState)
|
---|
13 | {
|
---|
14 | CHECK_BUFFER_SIZE_STATIC(pState, 20 + sizeof(GLuint) );
|
---|
15 |
|
---|
16 | GLint size = READ_DATA(pState, 8, GLint );
|
---|
17 | GLenum type = READ_DATA(pState, 12, GLenum );
|
---|
18 | GLsizei stride = READ_DATA(pState, 16, GLsizei );
|
---|
19 | GLintptrARB pointer = (GLintptrARB) READ_DATA(pState, 20, GLuint );
|
---|
20 | pState->pDispatchTbl->VertexPointer( size, type, stride, (void *) pointer, false /*fRealPtr*/ );
|
---|
21 | }
|
---|
22 |
|
---|
23 | void crUnpackExtendTexCoordPointer(PCrUnpackerState pState)
|
---|
24 | {
|
---|
25 | CHECK_BUFFER_SIZE_STATIC(pState, 20 + sizeof(GLuint) );
|
---|
26 |
|
---|
27 | GLint size = READ_DATA(pState, 8, GLint );
|
---|
28 | GLenum type = READ_DATA(pState, 12, GLenum );
|
---|
29 | GLsizei stride = READ_DATA(pState, 16, GLsizei );
|
---|
30 | GLintptrARB pointer = READ_DATA(pState, 20, GLuint );
|
---|
31 | pState->pDispatchTbl->TexCoordPointer( size, type, stride, (void *) pointer, false /*fRealPtr*/ );
|
---|
32 | }
|
---|
33 |
|
---|
34 | void crUnpackExtendNormalPointer(PCrUnpackerState pState)
|
---|
35 | {
|
---|
36 | CHECK_BUFFER_SIZE_STATIC(pState, 16 + sizeof(GLuint) );
|
---|
37 |
|
---|
38 | GLenum type = READ_DATA(pState, 8, GLenum );
|
---|
39 | GLsizei stride = READ_DATA(pState, 12, GLsizei );
|
---|
40 | GLintptrARB pointer = READ_DATA(pState, 16, GLuint );
|
---|
41 | pState->pDispatchTbl->NormalPointer( type, stride, (void *) pointer, false /*fRealPtr*/ );
|
---|
42 | }
|
---|
43 |
|
---|
44 | void crUnpackExtendIndexPointer(PCrUnpackerState pState)
|
---|
45 | {
|
---|
46 | CHECK_BUFFER_SIZE_STATIC(pState, 16 + sizeof(GLuint) );
|
---|
47 |
|
---|
48 | GLenum type = READ_DATA(pState, 8, GLenum );
|
---|
49 | GLsizei stride = READ_DATA(pState, 12, GLsizei );
|
---|
50 | GLintptrARB pointer = READ_DATA(pState, 16, GLuint );
|
---|
51 | pState->pDispatchTbl->IndexPointer( type, stride, (void *) pointer, false /*fRealPtr*/ );
|
---|
52 | }
|
---|
53 |
|
---|
54 | void crUnpackExtendEdgeFlagPointer(PCrUnpackerState pState)
|
---|
55 | {
|
---|
56 | CHECK_BUFFER_SIZE_STATIC(pState, 12 + sizeof(GLuint) );
|
---|
57 |
|
---|
58 | GLsizei stride = READ_DATA(pState, 8, GLsizei );
|
---|
59 | GLintptrARB pointer = READ_DATA(pState, 12, GLuint );
|
---|
60 | pState->pDispatchTbl->EdgeFlagPointer( stride, (void *) pointer, false /*fRealPtr*/ );
|
---|
61 | }
|
---|
62 |
|
---|
63 | void crUnpackExtendColorPointer(PCrUnpackerState pState)
|
---|
64 | {
|
---|
65 | CHECK_BUFFER_SIZE_STATIC(pState, 20 + sizeof(GLuint) );
|
---|
66 |
|
---|
67 | GLint size = READ_DATA(pState, 8, GLint );
|
---|
68 | GLenum type = READ_DATA(pState, 12, GLenum );
|
---|
69 | GLsizei stride = READ_DATA(pState, 16, GLsizei );
|
---|
70 | GLintptrARB pointer = READ_DATA(pState, 20, GLuint );
|
---|
71 | pState->pDispatchTbl->ColorPointer( size, type, stride, (void *) pointer, false /*fRealPtr*/ );
|
---|
72 | }
|
---|
73 |
|
---|
74 | void crUnpackExtendFogCoordPointerEXT(PCrUnpackerState pState)
|
---|
75 | {
|
---|
76 | CHECK_BUFFER_SIZE_STATIC(pState, 16 + sizeof(GLuint) );
|
---|
77 |
|
---|
78 | GLenum type = READ_DATA(pState, 8, GLenum );
|
---|
79 | GLsizei stride = READ_DATA(pState, 12, GLsizei );
|
---|
80 | GLintptrARB pointer = READ_DATA(pState, 16, GLuint );
|
---|
81 | pState->pDispatchTbl->FogCoordPointerEXT( type, stride, (void *) pointer, false /*fRealPtr*/ );
|
---|
82 | }
|
---|
83 |
|
---|
84 | void crUnpackExtendSecondaryColorPointerEXT(PCrUnpackerState pState)
|
---|
85 | {
|
---|
86 | CHECK_BUFFER_SIZE_STATIC(pState, 20 + sizeof(GLuint) );
|
---|
87 |
|
---|
88 | GLint size = READ_DATA(pState, 8, GLint );
|
---|
89 | GLenum type = READ_DATA(pState, 12, GLenum );
|
---|
90 | GLsizei stride = READ_DATA(pState, 16, GLsizei );
|
---|
91 | GLintptrARB pointer = READ_DATA(pState, 20, GLuint );
|
---|
92 | pState->pDispatchTbl->SecondaryColorPointerEXT( size, type, stride, (void *) pointer, false /*fRealPtr*/ );
|
---|
93 | }
|
---|
94 |
|
---|
95 | void crUnpackExtendVertexAttribPointerARB(PCrUnpackerState pState)
|
---|
96 | {
|
---|
97 | CHECK_BUFFER_SIZE_STATIC(pState, 28 + sizeof(GLuint) );
|
---|
98 |
|
---|
99 | GLuint index = READ_DATA(pState, 8, GLuint);
|
---|
100 | GLint size = READ_DATA(pState, 12, GLint );
|
---|
101 | GLenum type = READ_DATA(pState, 16, GLenum );
|
---|
102 | GLboolean normalized = READ_DATA(pState, 20, GLboolean );
|
---|
103 | GLsizei stride = READ_DATA(pState, 24, GLsizei );
|
---|
104 | GLintptrARB pointer = READ_DATA(pState, 28, GLuint );
|
---|
105 | pState->pDispatchTbl->VertexAttribPointerARB( index, size, type, normalized, stride, (void *) pointer, false /*fRealPtr*/ );
|
---|
106 | }
|
---|
107 |
|
---|
108 | void crUnpackExtendVertexAttribPointerNV(PCrUnpackerState pState)
|
---|
109 | {
|
---|
110 | CHECK_BUFFER_SIZE_STATIC(pState, 24 + sizeof(GLuint) );
|
---|
111 |
|
---|
112 | GLuint index = READ_DATA(pState, 8, GLuint);
|
---|
113 | GLint size = READ_DATA(pState, 12, GLint );
|
---|
114 | GLenum type = READ_DATA(pState, 16, GLenum );
|
---|
115 | GLsizei stride = READ_DATA(pState, 20, GLsizei );
|
---|
116 | GLintptrARB pointer = READ_DATA(pState, 24, GLuint );
|
---|
117 | pState->pDispatchTbl->VertexAttribPointerNV( index, size, type, stride, (void *) pointer, false /*fRealPtr*/ );
|
---|
118 | }
|
---|
119 |
|
---|
120 | void crUnpackExtendInterleavedArrays(PCrUnpackerState pState)
|
---|
121 | {
|
---|
122 | CHECK_BUFFER_SIZE_STATIC(pState, 16 + sizeof(GLuint) );
|
---|
123 |
|
---|
124 | GLenum format = READ_DATA(pState, 8, GLenum );
|
---|
125 | GLsizei stride = READ_DATA(pState, 12, GLsizei );
|
---|
126 | GLintptrARB pointer = READ_DATA(pState, 16, GLuint );
|
---|
127 | pState->pDispatchTbl->InterleavedArrays( format, stride, (void *) pointer, false /*fRealPtr*/ );
|
---|
128 | }
|
---|
129 |
|
---|
130 | void crUnpackExtendDrawElements(PCrUnpackerState pState)
|
---|
131 | {
|
---|
132 | #ifdef CR_ARB_vertex_buffer_object
|
---|
133 | CHECK_BUFFER_SIZE_STATIC(pState, 28);
|
---|
134 | #else
|
---|
135 | CHECK_BUFFER_SIZE_STATIC(pState, 24);
|
---|
136 | #endif
|
---|
137 |
|
---|
138 | GLenum mode = READ_DATA(pState, 8, GLenum );
|
---|
139 | GLsizei count = READ_DATA(pState, 12, GLsizei );
|
---|
140 | GLenum type = READ_DATA(pState, 16, GLenum );
|
---|
141 | GLintptrARB indices = READ_DATA(pState, 20, GLuint );
|
---|
142 | void * indexptr;
|
---|
143 |
|
---|
144 | size_t cbElem = 0;
|
---|
145 | switch (type)
|
---|
146 | {
|
---|
147 | case GL_UNSIGNED_BYTE:
|
---|
148 | cbElem = sizeof(GLubyte);
|
---|
149 | break;
|
---|
150 | case GL_UNSIGNED_SHORT:
|
---|
151 | cbElem = sizeof(GLubyte);
|
---|
152 | break;
|
---|
153 | case GL_UNSIGNED_INT:
|
---|
154 | cbElem = sizeof(GLubyte);
|
---|
155 | break;
|
---|
156 | default:
|
---|
157 | crError("crUnpackExtendDrawElements: Invalid type (%#x) passed!\n", type);
|
---|
158 | pState->rcUnpack = VERR_INVALID_PARAMETER;
|
---|
159 | return;
|
---|
160 | }
|
---|
161 |
|
---|
162 | #ifdef CR_ARB_vertex_buffer_object
|
---|
163 | GLboolean hasidxdata = READ_DATA(pState, 24, GLint);
|
---|
164 | indexptr = hasidxdata ? DATA_POINTER(pState, 28, void) : (void*)indices;
|
---|
165 | if (hasidxdata)
|
---|
166 | CHECK_ARRAY_SIZE_FROM_PTR_UPDATE_SZ_LAST(pState, indexptr, count, cbElem);
|
---|
167 | #else
|
---|
168 | indexptr = DATA_POINTER(pState, 24, void);
|
---|
169 | CHECK_ARRAY_SIZE_FROM_PTR_UPDATE_SZ_LAST(pState, indexptr, count, cbElem);
|
---|
170 | #endif
|
---|
171 | pState->pDispatchTbl->DrawElements(mode, count, type, indexptr);
|
---|
172 | }
|
---|
173 |
|
---|
174 | void crUnpackExtendDrawRangeElements(PCrUnpackerState pState)
|
---|
175 | {
|
---|
176 | #ifdef CR_ARB_vertex_buffer_object
|
---|
177 | CHECK_BUFFER_SIZE_STATIC(pState, 36);
|
---|
178 | #else
|
---|
179 | CHECK_BUFFER_SIZE_STATIC(pState, 32);
|
---|
180 | #endif
|
---|
181 |
|
---|
182 | GLenum mode = READ_DATA(pState, 8, GLenum );
|
---|
183 | GLuint start = READ_DATA(pState, 12, GLuint );
|
---|
184 | GLuint end = READ_DATA(pState, 16, GLuint );
|
---|
185 | GLsizei count = READ_DATA(pState, 20, GLsizei );
|
---|
186 | GLenum type = READ_DATA(pState, 24, GLenum );
|
---|
187 | GLintptrARB indices = READ_DATA(pState, 28, GLuint );
|
---|
188 | void * indexptr;
|
---|
189 |
|
---|
190 | size_t cbElem = 0;
|
---|
191 | switch (type)
|
---|
192 | {
|
---|
193 | case GL_UNSIGNED_BYTE:
|
---|
194 | cbElem = sizeof(GLubyte);
|
---|
195 | break;
|
---|
196 | case GL_UNSIGNED_SHORT:
|
---|
197 | cbElem = sizeof(GLubyte);
|
---|
198 | break;
|
---|
199 | case GL_UNSIGNED_INT:
|
---|
200 | cbElem = sizeof(GLubyte);
|
---|
201 | break;
|
---|
202 | default:
|
---|
203 | crError("crUnpackExtendDrawElements: Invalid type (%#x) passed!\n", type);
|
---|
204 | pState->rcUnpack = VERR_INVALID_PARAMETER;
|
---|
205 | return;
|
---|
206 | }
|
---|
207 | #ifdef CR_ARB_vertex_buffer_object
|
---|
208 | GLboolean hasidxdata = READ_DATA(pState, 32, GLint);
|
---|
209 | indexptr = hasidxdata ? DATA_POINTER(pState, 36, void) : (void*)indices;
|
---|
210 | if (hasidxdata)
|
---|
211 | CHECK_ARRAY_SIZE_FROM_PTR_UPDATE_SZ_LAST(pState, indexptr, count, cbElem);
|
---|
212 | #else
|
---|
213 | indexptr = DATA_POINTER(pState, 32, void);
|
---|
214 | CHECK_ARRAY_SIZE_FROM_PTR_UPDATE_SZ_LAST(pState, indexptr, count, cbElem);
|
---|
215 | #endif
|
---|
216 |
|
---|
217 | pState->pDispatchTbl->DrawRangeElements(mode, start, end, count, type, indexptr);
|
---|
218 | }
|
---|
219 |
|
---|
220 | void crUnpackMultiDrawArraysEXT(PCrUnpackerState pState)
|
---|
221 | {
|
---|
222 | RT_NOREF(pState);
|
---|
223 | crError( "Can't decode MultiDrawArraysEXT" );
|
---|
224 | }
|
---|
225 |
|
---|
226 | void crUnpackMultiDrawElementsEXT(PCrUnpackerState pState)
|
---|
227 | {
|
---|
228 | RT_NOREF(pState);
|
---|
229 | crError( "Can't decode MultiDrawElementsEXT" );
|
---|
230 | }
|
---|
231 |
|
---|
232 | static void crUnpackSetClientPointerByIndex(PCrUnpackerState pState, int index, GLint size,
|
---|
233 | GLenum type, GLboolean normalized,
|
---|
234 | GLsizei stride, const GLvoid *pointer, CRClientState *c, int fRealPtr)
|
---|
235 | {
|
---|
236 | /*crDebug("crUnpackSetClientPointerByIndex: %i(s=%i, t=0x%x, n=%i, str=%i) -> %p", index, size, type, normalized, stride, pointer);*/
|
---|
237 |
|
---|
238 | if (index<7)
|
---|
239 | {
|
---|
240 | switch (index)
|
---|
241 | {
|
---|
242 | case 0:
|
---|
243 | pState->pDispatchTbl->VertexPointer(size, type, stride, pointer, fRealPtr);
|
---|
244 | break;
|
---|
245 | case 1:
|
---|
246 | pState->pDispatchTbl->ColorPointer(size, type, stride, pointer, fRealPtr);
|
---|
247 | break;
|
---|
248 | case 2:
|
---|
249 | pState->pDispatchTbl->FogCoordPointerEXT(type, stride, pointer, fRealPtr);
|
---|
250 | break;
|
---|
251 | case 3:
|
---|
252 | pState->pDispatchTbl->SecondaryColorPointerEXT(size, type, stride, pointer, fRealPtr);
|
---|
253 | break;
|
---|
254 | case 4:
|
---|
255 | pState->pDispatchTbl->EdgeFlagPointer(stride, pointer, fRealPtr);
|
---|
256 | break;
|
---|
257 | case 5:
|
---|
258 | pState->pDispatchTbl->IndexPointer(type, stride, pointer, fRealPtr);
|
---|
259 | break;
|
---|
260 | case 6:
|
---|
261 | pState->pDispatchTbl->NormalPointer(type, stride, pointer, fRealPtr);
|
---|
262 | break;
|
---|
263 | }
|
---|
264 | }
|
---|
265 | else if (index<(7+CR_MAX_TEXTURE_UNITS))
|
---|
266 | {
|
---|
267 | int curTexUnit = c->curClientTextureUnit;
|
---|
268 | if ((index-7)!=curTexUnit)
|
---|
269 | {
|
---|
270 | pState->pDispatchTbl->ClientActiveTextureARB(GL_TEXTURE0_ARB+index-7);
|
---|
271 | }
|
---|
272 | pState->pDispatchTbl->TexCoordPointer(size, type, stride, pointer, fRealPtr);
|
---|
273 | if ((index-7)!=curTexUnit)
|
---|
274 | {
|
---|
275 | pState->pDispatchTbl->ClientActiveTextureARB(GL_TEXTURE0_ARB+curTexUnit);
|
---|
276 | }
|
---|
277 | }
|
---|
278 | else
|
---|
279 | {
|
---|
280 | pState->pDispatchTbl->VertexAttribPointerARB(index-7-CR_MAX_TEXTURE_UNITS,
|
---|
281 | size, type, normalized, stride, pointer, fRealPtr);
|
---|
282 | }
|
---|
283 | }
|
---|
284 |
|
---|
285 | void crUnpackExtendLockArraysEXT(PCrUnpackerState pState)
|
---|
286 | {
|
---|
287 | CHECK_BUFFER_SIZE_STATIC(pState, sizeof(int) + 12 + sizeof(int));
|
---|
288 |
|
---|
289 | GLint first = READ_DATA(pState, sizeof(int) + 4, GLint);
|
---|
290 | GLint count = READ_DATA(pState, sizeof(int) + 8, GLint);
|
---|
291 | int numenabled = READ_DATA(pState, sizeof(int) + 12, int);
|
---|
292 |
|
---|
293 | CRContext *g = crStateGetCurrent(pState->pStateTracker);
|
---|
294 | CRClientState *c = &g->client;
|
---|
295 | CRClientPointer *cp;
|
---|
296 | int i, index, offset;
|
---|
297 | uint8_t *data;
|
---|
298 |
|
---|
299 | if (first < 0 || count <= 0 || first >= INT32_MAX - count)
|
---|
300 | {
|
---|
301 | crError("crUnpackExtendLockArraysEXT: first(%i) count(%i), parameters out of range", first, count);
|
---|
302 | return;
|
---|
303 | }
|
---|
304 |
|
---|
305 | if (numenabled <= 0 || numenabled >= CRSTATECLIENT_MAX_VERTEXARRAYS)
|
---|
306 | {
|
---|
307 | crError("crUnpackExtendLockArraysEXT: numenabled(%i), parameter out of range", numenabled);
|
---|
308 | return;
|
---|
309 | }
|
---|
310 |
|
---|
311 | offset = 2 * sizeof(int) + 12;
|
---|
312 |
|
---|
313 | /*crDebug("crUnpackExtendLockArraysEXT(%i, %i) ne=%i", first, count, numenabled);*/
|
---|
314 |
|
---|
315 | for (i = 0; i < numenabled; ++i)
|
---|
316 | {
|
---|
317 | CHECK_BUFFER_SIZE_STATIC_LAST(pState, offset, int);
|
---|
318 | index = READ_DATA(pState, offset, int);
|
---|
319 | offset += sizeof(int);
|
---|
320 |
|
---|
321 | cp = crStateGetClientPointerByIndex(index, &c->array);
|
---|
322 |
|
---|
323 | CRASSERT(cp && cp->enabled && (!cp->buffer || !cp->buffer->id));
|
---|
324 |
|
---|
325 | if (cp && cp->bytesPerIndex > 0)
|
---|
326 | {
|
---|
327 | if (first + count >= INT32_MAX / cp->bytesPerIndex)
|
---|
328 | {
|
---|
329 | crError("crUnpackExtendLockArraysEXT: first(%i) count(%i) bpi(%i), parameters out of range", first, count, cp->bytesPerIndex);
|
---|
330 | return;
|
---|
331 | }
|
---|
332 |
|
---|
333 | data = (uint8_t *)crAlloc((first + count) * cp->bytesPerIndex);
|
---|
334 |
|
---|
335 | if (data)
|
---|
336 | {
|
---|
337 | crMemcpy(data + first * cp->bytesPerIndex, DATA_POINTER(pState, offset, GLvoid), count * cp->bytesPerIndex);
|
---|
338 | /*crDebug("crUnpackExtendLockArraysEXT: old cp(%i): en/l=%i(%i) p=%p size=%i type=0x%x n=%i str=%i pp=%p pstr=%i",
|
---|
339 | index, cp->enabled, cp->locked, cp->p, cp->size, cp->type, cp->normalized, cp->stride, cp->prevPtr, cp->prevStride);*/
|
---|
340 | crUnpackSetClientPointerByIndex(pState, index, cp->size, cp->type, cp->normalized, 0, data, c, 1);
|
---|
341 | /*crDebug("crUnpackExtendLockArraysEXT: new cp(%i): en/l=%i(%i) p=%p size=%i type=0x%x n=%i str=%i pp=%p pstr=%i",
|
---|
342 | index, cp->enabled, cp->locked, cp->p, cp->size, cp->type, cp->normalized, cp->stride, cp->prevPtr, cp->prevStride);*/
|
---|
343 | }
|
---|
344 | else
|
---|
345 | {
|
---|
346 | crError("crUnpackExtendLockArraysEXT: crAlloc failed");
|
---|
347 | return;
|
---|
348 | }
|
---|
349 | }
|
---|
350 | else
|
---|
351 | {
|
---|
352 | crError("crUnpackExtendLockArraysEXT: wrong CRClientState %i", index);
|
---|
353 | return;
|
---|
354 | }
|
---|
355 |
|
---|
356 | offset += count * cp->bytesPerIndex;
|
---|
357 | }
|
---|
358 |
|
---|
359 | pState->pDispatchTbl->LockArraysEXT(first, count);
|
---|
360 | }
|
---|
361 |
|
---|
362 | void crUnpackExtendUnlockArraysEXT(PCrUnpackerState pState)
|
---|
363 | {
|
---|
364 | int i;
|
---|
365 | CRContext *g = crStateGetCurrent(pState->pStateTracker);
|
---|
366 | CRClientState *c = &g->client;
|
---|
367 | CRClientPointer *cp;
|
---|
368 |
|
---|
369 | /*crDebug("crUnpackExtendUnlockArraysEXT");*/
|
---|
370 |
|
---|
371 | pState->pDispatchTbl->UnlockArraysEXT();
|
---|
372 |
|
---|
373 | for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i)
|
---|
374 | {
|
---|
375 | cp = crStateGetClientPointerByIndex(i, &c->array);
|
---|
376 | if (cp->enabled)
|
---|
377 | {
|
---|
378 | /*crDebug("crUnpackExtendUnlockArraysEXT: old cp(%i): en/l=%i(%i) p=%p size=%i type=0x%x n=%i str=%i pp=%p pstr=%i",
|
---|
379 | i, cp->enabled, cp->locked, cp->p, cp->size, cp->type, cp->normalized, cp->stride, cp->prevPtr, cp->prevStride);*/
|
---|
380 | unsigned char *prevPtr = cp->prevPtr;
|
---|
381 | int fPrevRealPtr = cp->fPrevRealPtr;
|
---|
382 | cp->prevPtr = NULL;
|
---|
383 | cp->fPrevRealPtr = 0;
|
---|
384 |
|
---|
385 | crUnpackSetClientPointerByIndex(pState, i, cp->size, cp->type, cp->normalized, cp->prevStride, prevPtr, c, fPrevRealPtr);
|
---|
386 | /*crDebug("crUnpackExtendUnlockArraysEXT: new cp(%i): en/l=%i(%i) p=%p size=%i type=0x%x n=%i str=%i pp=%p pstr=%i",
|
---|
387 | i, cp->enabled, cp->locked, cp->p, cp->size, cp->type, cp->normalized, cp->stride, cp->prevPtr, cp->prevStride);*/
|
---|
388 | }
|
---|
389 | }
|
---|
390 | }
|
---|