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 | if (index<7)
|
---|
167 | {
|
---|
168 | switch (index)
|
---|
169 | {
|
---|
170 | case 0:
|
---|
171 | cr_unpackDispatch.VertexPointer(size, type, stride, pointer);
|
---|
172 | break;
|
---|
173 | case 1:
|
---|
174 | cr_unpackDispatch.ColorPointer(size, type, stride, pointer);
|
---|
175 | break;
|
---|
176 | case 2:
|
---|
177 | cr_unpackDispatch.FogCoordPointerEXT(type, stride, pointer);
|
---|
178 | break;
|
---|
179 | case 3:
|
---|
180 | cr_unpackDispatch.SecondaryColorPointerEXT(size, type, stride, pointer);
|
---|
181 | break;
|
---|
182 | case 4:
|
---|
183 | cr_unpackDispatch.EdgeFlagPointer(stride, pointer);
|
---|
184 | break;
|
---|
185 | case 5:
|
---|
186 | cr_unpackDispatch.IndexPointer(type, stride, pointer);
|
---|
187 | break;
|
---|
188 | case 6:
|
---|
189 | cr_unpackDispatch.NormalPointer(type, stride, pointer);
|
---|
190 | break;
|
---|
191 | }
|
---|
192 | }
|
---|
193 | else if (index<(7+CR_MAX_TEXTURE_UNITS))
|
---|
194 | {
|
---|
195 | int curTexUnit = c->curClientTextureUnit;
|
---|
196 | if ((index-7)!=curTexUnit)
|
---|
197 | {
|
---|
198 | cr_unpackDispatch.ClientActiveTextureARB(GL_TEXTURE0_ARB+index-7);
|
---|
199 | }
|
---|
200 | cr_unpackDispatch.TexCoordPointer(size, type, stride, pointer);
|
---|
201 | if ((index-7)!=curTexUnit)
|
---|
202 | {
|
---|
203 | cr_unpackDispatch.ClientActiveTextureARB(GL_TEXTURE0_ARB+curTexUnit);
|
---|
204 | }
|
---|
205 | }
|
---|
206 | else
|
---|
207 | {
|
---|
208 | cr_unpackDispatch.VertexAttribPointerARB(index-7-CR_MAX_TEXTURE_UNITS,
|
---|
209 | size, type, normalized, stride, pointer);
|
---|
210 | }
|
---|
211 | }
|
---|
212 |
|
---|
213 | void crUnpackExtendLockArraysEXT(void)
|
---|
214 | {
|
---|
215 | GLint first = READ_DATA(sizeof(int) + 4, GLint);
|
---|
216 | GLint count = READ_DATA(sizeof(int) + 8, GLint);
|
---|
217 | int numenabled = READ_DATA(sizeof(int) + 12, int);
|
---|
218 |
|
---|
219 | CRContext *g = crStateGetCurrent();
|
---|
220 | CRClientState *c = &g->client;
|
---|
221 | CRClientPointer *cp;
|
---|
222 | int i, index, offset;
|
---|
223 | unsigned char *data;
|
---|
224 |
|
---|
225 | offset = 2*sizeof(int)+12;
|
---|
226 |
|
---|
227 | for (i=0; i<numenabled; ++i)
|
---|
228 | {
|
---|
229 | index = READ_DATA(offset, int);
|
---|
230 | offset += sizeof(int);
|
---|
231 | cp = crStateGetClientPointerByIndex(index, &c->array);
|
---|
232 | CRASSERT(cp && cp->enabled && (!cp->buffer || !cp->buffer->id));
|
---|
233 | data = crAlloc((first+count)*cp->bytesPerIndex);
|
---|
234 | crMemcpy(data+first*cp->bytesPerIndex, DATA_POINTER(offset, GLvoid), count*cp->bytesPerIndex);
|
---|
235 | offset += count*cp->bytesPerIndex;
|
---|
236 | crUnpackSetClientPointerByIndex(index, cp->size, cp->type, cp->normalized, 0, data, c);
|
---|
237 | }
|
---|
238 | cr_unpackDispatch.LockArraysEXT(first, count);
|
---|
239 | }
|
---|
240 |
|
---|
241 | void crUnpackExtendUnlockArraysEXT(void)
|
---|
242 | {
|
---|
243 | int i;
|
---|
244 | CRContext *g = crStateGetCurrent();
|
---|
245 | CRClientState *c = &g->client;
|
---|
246 | CRClientPointer *cp;
|
---|
247 |
|
---|
248 | cr_unpackDispatch.UnlockArraysEXT();
|
---|
249 |
|
---|
250 | for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i)
|
---|
251 | {
|
---|
252 | cp = crStateGetClientPointerByIndex(i, &c->array);
|
---|
253 | if (cp->enabled)
|
---|
254 | {
|
---|
255 | crUnpackSetClientPointerByIndex(i, cp->size, cp->type, cp->normalized, cp->prevStride, cp->prevPtr, c);
|
---|
256 | }
|
---|
257 | }
|
---|
258 | }
|
---|