VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/unpacker/unpack_arrays.cpp@ 78264

Last change on this file since 78264 was 78191, checked in by vboxsync, 6 years ago

Some build fixes

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