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 | * \mainpage Unpacker
|
---|
13 | *
|
---|
14 | * \section UnpackerIntroduction Introduction
|
---|
15 | *
|
---|
16 | * Chromium consists of all the top-level files in the cr
|
---|
17 | * directory. The unpacker module basically takes care of API dispatch,
|
---|
18 | * and OpenGL state management.
|
---|
19 | *
|
---|
20 | */
|
---|
21 |
|
---|
22 | void crUnpackExtendVertexPointer(void)
|
---|
23 | {
|
---|
24 | GLint size = READ_DATA( 8, GLint );
|
---|
25 | GLenum type = READ_DATA( 12, GLenum );
|
---|
26 | GLsizei stride = READ_DATA( 16, GLsizei );
|
---|
27 | GLintptrARB pointer = (GLintptrARB) READ_DATA( 20, GLuint );
|
---|
28 | cr_unpackDispatch.VertexPointer( size, type, stride, (void *) pointer );
|
---|
29 | }
|
---|
30 |
|
---|
31 | void crUnpackExtendTexCoordPointer(void)
|
---|
32 | {
|
---|
33 | GLint size = READ_DATA( 8, GLint );
|
---|
34 | GLenum type = READ_DATA( 12, GLenum );
|
---|
35 | GLsizei stride = READ_DATA( 16, GLsizei );
|
---|
36 | GLintptrARB pointer = READ_DATA( 20, GLuint );
|
---|
37 | cr_unpackDispatch.TexCoordPointer( size, type, stride, (void *) pointer );
|
---|
38 | }
|
---|
39 |
|
---|
40 | void crUnpackExtendNormalPointer(void)
|
---|
41 | {
|
---|
42 | GLenum type = READ_DATA( 8, GLenum );
|
---|
43 | GLsizei stride = READ_DATA( 12, GLsizei );
|
---|
44 | GLintptrARB pointer = READ_DATA( 16, GLuint );
|
---|
45 | cr_unpackDispatch.NormalPointer( type, stride, (void *) pointer );
|
---|
46 | }
|
---|
47 |
|
---|
48 | void crUnpackExtendIndexPointer(void)
|
---|
49 | {
|
---|
50 | GLenum type = READ_DATA( 8, GLenum );
|
---|
51 | GLsizei stride = READ_DATA( 12, GLsizei );
|
---|
52 | GLintptrARB pointer = READ_DATA( 16, GLuint );
|
---|
53 | cr_unpackDispatch.IndexPointer( type, stride, (void *) pointer );
|
---|
54 | }
|
---|
55 |
|
---|
56 | void crUnpackExtendEdgeFlagPointer(void)
|
---|
57 | {
|
---|
58 | GLsizei stride = READ_DATA( 8, GLsizei );
|
---|
59 | GLintptrARB pointer = READ_DATA( 12, GLuint );
|
---|
60 | cr_unpackDispatch.EdgeFlagPointer( stride, (void *) pointer );
|
---|
61 | }
|
---|
62 |
|
---|
63 | void crUnpackExtendColorPointer(void)
|
---|
64 | {
|
---|
65 | GLint size = READ_DATA( 8, GLint );
|
---|
66 | GLenum type = READ_DATA( 12, GLenum );
|
---|
67 | GLsizei stride = READ_DATA( 16, GLsizei );
|
---|
68 | GLintptrARB pointer = READ_DATA( 20, GLuint );
|
---|
69 | cr_unpackDispatch.ColorPointer( size, type, stride, (void *) pointer );
|
---|
70 | }
|
---|
71 |
|
---|
72 | void crUnpackExtendFogCoordPointerEXT(void)
|
---|
73 | {
|
---|
74 | GLenum type = READ_DATA( 8, GLenum );
|
---|
75 | GLsizei stride = READ_DATA( 12, GLsizei );
|
---|
76 | GLintptrARB pointer = READ_DATA( 16, GLuint );
|
---|
77 | cr_unpackDispatch.FogCoordPointerEXT( type, stride, (void *) pointer );
|
---|
78 | }
|
---|
79 |
|
---|
80 | void crUnpackExtendSecondaryColorPointerEXT(void)
|
---|
81 | {
|
---|
82 | GLint size = READ_DATA( 8, GLint );
|
---|
83 | GLenum type = READ_DATA( 12, GLenum );
|
---|
84 | GLsizei stride = READ_DATA( 16, GLsizei );
|
---|
85 | GLintptrARB pointer = READ_DATA( 20, GLuint );
|
---|
86 | cr_unpackDispatch.SecondaryColorPointerEXT( size, type, stride, (void *) pointer );
|
---|
87 | }
|
---|
88 |
|
---|
89 | void crUnpackExtendVertexAttribPointerARB(void)
|
---|
90 | {
|
---|
91 | GLuint index = READ_DATA( 8, GLuint);
|
---|
92 | GLint size = READ_DATA( 12, GLint );
|
---|
93 | GLenum type = READ_DATA( 16, GLenum );
|
---|
94 | GLboolean normalized = READ_DATA( 20, GLboolean );
|
---|
95 | GLsizei stride = READ_DATA( 24, GLsizei );
|
---|
96 | GLintptrARB pointer = READ_DATA( 28, GLuint );
|
---|
97 | cr_unpackDispatch.VertexAttribPointerARB( index, size, type, normalized, stride, (void *) pointer );
|
---|
98 | }
|
---|
99 |
|
---|
100 | void crUnpackExtendVertexAttribPointerNV(void)
|
---|
101 | {
|
---|
102 | GLuint index = READ_DATA( 8, GLuint);
|
---|
103 | GLint size = READ_DATA( 12, GLint );
|
---|
104 | GLenum type = READ_DATA( 16, GLenum );
|
---|
105 | GLsizei stride = READ_DATA( 20, GLsizei );
|
---|
106 | GLintptrARB pointer = READ_DATA( 24, GLuint );
|
---|
107 | cr_unpackDispatch.VertexAttribPointerNV( index, size, type, stride, (void *) pointer );
|
---|
108 | }
|
---|
109 |
|
---|
110 | void crUnpackExtendInterleavedArrays(void)
|
---|
111 | {
|
---|
112 | GLenum format = READ_DATA( 8, GLenum );
|
---|
113 | GLsizei stride = READ_DATA( 12, GLsizei );
|
---|
114 | GLintptrARB pointer = READ_DATA( 16, GLuint );
|
---|
115 | cr_unpackDispatch.InterleavedArrays( format, stride, (void *) pointer );
|
---|
116 | }
|
---|
117 |
|
---|
118 | void crUnpackExtendDrawElements(void)
|
---|
119 | {
|
---|
120 | GLenum mode = READ_DATA( 8, GLenum );
|
---|
121 | GLsizei count = READ_DATA( 12, GLsizei );
|
---|
122 | GLenum type = READ_DATA( 16, GLenum );
|
---|
123 | GLintptrARB indices = READ_DATA( 20, GLuint );
|
---|
124 | void * indexptr;
|
---|
125 | #ifdef CR_ARB_vertex_buffer_object
|
---|
126 | GLboolean hasidxdata = READ_DATA(24, GLint);
|
---|
127 | indexptr = hasidxdata ? DATA_POINTER(28, void) : (void*)indices;
|
---|
128 | #else
|
---|
129 | indexptr = DATA_POINTER(24, void);
|
---|
130 | #endif
|
---|
131 | cr_unpackDispatch.DrawElements(mode, count, type, indexptr);
|
---|
132 | }
|
---|
133 |
|
---|
134 | void crUnpackExtendDrawRangeElements(void)
|
---|
135 | {
|
---|
136 | GLenum mode = READ_DATA( 8, GLenum );
|
---|
137 | GLuint start = READ_DATA( 12, GLuint );
|
---|
138 | GLuint end = READ_DATA( 16, GLuint );
|
---|
139 | GLsizei count = READ_DATA( 20, GLsizei );
|
---|
140 | GLenum type = READ_DATA( 24, GLenum );
|
---|
141 | GLintptrARB indices = READ_DATA( 28, GLuint );
|
---|
142 | void * indexptr;
|
---|
143 | #ifdef CR_ARB_vertex_buffer_object
|
---|
144 | GLboolean hasidxdata = READ_DATA(32, GLint);
|
---|
145 | indexptr = hasidxdata ? DATA_POINTER(36, void) : (void*)indices;
|
---|
146 | #else
|
---|
147 | indexptr = DATA_POINTER(32, void);
|
---|
148 | #endif
|
---|
149 | cr_unpackDispatch.DrawRangeElements(mode, start, end, count, type, indexptr);
|
---|
150 | }
|
---|
151 |
|
---|
152 | void crUnpackMultiDrawArraysEXT(void)
|
---|
153 | {
|
---|
154 | crError( "Can't decode MultiDrawArraysEXT" );
|
---|
155 | }
|
---|
156 |
|
---|
157 | void crUnpackMultiDrawElementsEXT(void)
|
---|
158 | {
|
---|
159 | crError( "Can't decode MultiDrawElementsEXT" );
|
---|
160 | }
|
---|
161 |
|
---|
162 | static void crUnpackSetClientPointerByIndex(int index, GLint size,
|
---|
163 | GLenum type, GLboolean normalized,
|
---|
164 | GLsizei stride, const GLvoid *pointer, CRClientState *c)
|
---|
165 | {
|
---|
166 | /*crDebug("crUnpackSetClientPointerByIndex: %i(s=%i, t=0x%x, n=%i, str=%i) -> %p", index, size, type, normalized, stride, pointer);*/
|
---|
167 |
|
---|
168 | if (index<7)
|
---|
169 | {
|
---|
170 | switch (index)
|
---|
171 | {
|
---|
172 | case 0:
|
---|
173 | cr_unpackDispatch.VertexPointer(size, type, stride, pointer);
|
---|
174 | break;
|
---|
175 | case 1:
|
---|
176 | cr_unpackDispatch.ColorPointer(size, type, stride, pointer);
|
---|
177 | break;
|
---|
178 | case 2:
|
---|
179 | cr_unpackDispatch.FogCoordPointerEXT(type, stride, pointer);
|
---|
180 | break;
|
---|
181 | case 3:
|
---|
182 | cr_unpackDispatch.SecondaryColorPointerEXT(size, type, stride, pointer);
|
---|
183 | break;
|
---|
184 | case 4:
|
---|
185 | cr_unpackDispatch.EdgeFlagPointer(stride, pointer);
|
---|
186 | break;
|
---|
187 | case 5:
|
---|
188 | cr_unpackDispatch.IndexPointer(type, stride, pointer);
|
---|
189 | break;
|
---|
190 | case 6:
|
---|
191 | cr_unpackDispatch.NormalPointer(type, stride, pointer);
|
---|
192 | break;
|
---|
193 | }
|
---|
194 | }
|
---|
195 | else if (index<(7+CR_MAX_TEXTURE_UNITS))
|
---|
196 | {
|
---|
197 | int curTexUnit = c->curClientTextureUnit;
|
---|
198 | if ((index-7)!=curTexUnit)
|
---|
199 | {
|
---|
200 | cr_unpackDispatch.ClientActiveTextureARB(GL_TEXTURE0_ARB+index-7);
|
---|
201 | }
|
---|
202 | cr_unpackDispatch.TexCoordPointer(size, type, stride, pointer);
|
---|
203 | if ((index-7)!=curTexUnit)
|
---|
204 | {
|
---|
205 | cr_unpackDispatch.ClientActiveTextureARB(GL_TEXTURE0_ARB+curTexUnit);
|
---|
206 | }
|
---|
207 | }
|
---|
208 | else
|
---|
209 | {
|
---|
210 | cr_unpackDispatch.VertexAttribPointerARB(index-7-CR_MAX_TEXTURE_UNITS,
|
---|
211 | size, type, normalized, stride, pointer);
|
---|
212 | }
|
---|
213 | }
|
---|
214 |
|
---|
215 | void crUnpackExtendLockArraysEXT(void)
|
---|
216 | {
|
---|
217 | GLint first = READ_DATA(sizeof(int) + 4, GLint);
|
---|
218 | GLint count = READ_DATA(sizeof(int) + 8, GLint);
|
---|
219 | int numenabled = READ_DATA(sizeof(int) + 12, int);
|
---|
220 |
|
---|
221 | CRContext *g = crStateGetCurrent();
|
---|
222 | CRClientState *c = &g->client;
|
---|
223 | CRClientPointer *cp;
|
---|
224 | int i, index, offset;
|
---|
225 | unsigned char *data;
|
---|
226 |
|
---|
227 | if (first < 0 || count <= 0 || first >= INT32_MAX - count)
|
---|
228 | {
|
---|
229 | crError("crUnpackExtendLockArraysEXT: first(%i) count(%i), parameters out of range", first, count);
|
---|
230 | return;
|
---|
231 | }
|
---|
232 |
|
---|
233 | if (numenabled <= 0 || numenabled >= CRSTATECLIENT_MAX_VERTEXARRAYS)
|
---|
234 | {
|
---|
235 | crError("crUnpackExtendLockArraysEXT: numenabled(%i), parameter out of range", numenabled);
|
---|
236 | return;
|
---|
237 | }
|
---|
238 |
|
---|
239 | offset = 2 * sizeof(int) + 12;
|
---|
240 |
|
---|
241 | /*crDebug("crUnpackExtendLockArraysEXT(%i, %i) ne=%i", first, count, numenabled);*/
|
---|
242 |
|
---|
243 | for (i = 0; i < numenabled; ++i)
|
---|
244 | {
|
---|
245 | index = READ_DATA(offset, int);
|
---|
246 | offset += sizeof(int);
|
---|
247 |
|
---|
248 | cp = crStateGetClientPointerByIndex(index, &c->array);
|
---|
249 |
|
---|
250 | CRASSERT(cp && cp->enabled && (!cp->buffer || !cp->buffer->id));
|
---|
251 |
|
---|
252 | if (cp && cp->bytesPerIndex > 0)
|
---|
253 | {
|
---|
254 | if (first + count >= INT32_MAX / cp->bytesPerIndex)
|
---|
255 | {
|
---|
256 | crError("crUnpackExtendLockArraysEXT: first(%i) count(%i) bpi(%i), parameters out of range", first, count, cp->bytesPerIndex);
|
---|
257 | return;
|
---|
258 | }
|
---|
259 |
|
---|
260 | data = crAlloc((first + count) * cp->bytesPerIndex);
|
---|
261 |
|
---|
262 | if (data)
|
---|
263 | {
|
---|
264 | crMemcpy(data + first * cp->bytesPerIndex, DATA_POINTER(offset, GLvoid), count * cp->bytesPerIndex);
|
---|
265 | /*crDebug("crUnpackExtendLockArraysEXT: old cp(%i): en/l=%i(%i) p=%p size=%i type=0x%x n=%i str=%i pp=%p pstr=%i",
|
---|
266 | index, cp->enabled, cp->locked, cp->p, cp->size, cp->type, cp->normalized, cp->stride, cp->prevPtr, cp->prevStride);*/
|
---|
267 | crUnpackSetClientPointerByIndex(index, cp->size, cp->type, cp->normalized, 0, data, c);
|
---|
268 | /*crDebug("crUnpackExtendLockArraysEXT: new cp(%i): en/l=%i(%i) p=%p size=%i type=0x%x n=%i str=%i pp=%p pstr=%i",
|
---|
269 | index, cp->enabled, cp->locked, cp->p, cp->size, cp->type, cp->normalized, cp->stride, cp->prevPtr, cp->prevStride);*/
|
---|
270 | }
|
---|
271 | else
|
---|
272 | {
|
---|
273 | crError("crUnpackExtendLockArraysEXT: crAlloc failed");
|
---|
274 | return;
|
---|
275 | }
|
---|
276 | }
|
---|
277 | else
|
---|
278 | {
|
---|
279 | crError("crUnpackExtendLockArraysEXT: wrong CRClientState %i", index);
|
---|
280 | return;
|
---|
281 | }
|
---|
282 |
|
---|
283 | offset += count * cp->bytesPerIndex;
|
---|
284 | }
|
---|
285 |
|
---|
286 | cr_unpackDispatch.LockArraysEXT(first, count);
|
---|
287 | }
|
---|
288 |
|
---|
289 | void crUnpackExtendUnlockArraysEXT(void)
|
---|
290 | {
|
---|
291 | int i;
|
---|
292 | CRContext *g = crStateGetCurrent();
|
---|
293 | CRClientState *c = &g->client;
|
---|
294 | CRClientPointer *cp;
|
---|
295 |
|
---|
296 | /*crDebug("crUnpackExtendUnlockArraysEXT");*/
|
---|
297 |
|
---|
298 | cr_unpackDispatch.UnlockArraysEXT();
|
---|
299 |
|
---|
300 | for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i)
|
---|
301 | {
|
---|
302 | cp = crStateGetClientPointerByIndex(i, &c->array);
|
---|
303 | if (cp->enabled)
|
---|
304 | {
|
---|
305 | /*crDebug("crUnpackExtendUnlockArraysEXT: old cp(%i): en/l=%i(%i) p=%p size=%i type=0x%x n=%i str=%i pp=%p pstr=%i",
|
---|
306 | i, cp->enabled, cp->locked, cp->p, cp->size, cp->type, cp->normalized, cp->stride, cp->prevPtr, cp->prevStride);*/
|
---|
307 | crUnpackSetClientPointerByIndex(i, cp->size, cp->type, cp->normalized, cp->prevStride, cp->prevPtr, c);
|
---|
308 | /*crDebug("crUnpackExtendUnlockArraysEXT: new cp(%i): en/l=%i(%i) p=%p size=%i type=0x%x n=%i str=%i pp=%p pstr=%i",
|
---|
309 | i, cp->enabled, cp->locked, cp->p, cp->size, cp->type, cp->normalized, cp->stride, cp->prevPtr, cp->prevStride);*/
|
---|
310 | }
|
---|
311 | }
|
---|
312 | }
|
---|