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 "packer.h"
|
---|
8 | #include "cr_opcodes.h"
|
---|
9 | #include "cr_error.h"
|
---|
10 | #include "cr_mem.h"
|
---|
11 |
|
---|
12 | /* Note -- for these packets, the ustride and vstride are implicit,
|
---|
13 | * and are computed into the packet instead of copied.
|
---|
14 | */
|
---|
15 |
|
---|
16 | static int __gl_Map2NumComponents( GLenum target )
|
---|
17 | {
|
---|
18 | switch( target )
|
---|
19 | {
|
---|
20 | case GL_MAP2_VERTEX_3:
|
---|
21 | case GL_MAP2_NORMAL:
|
---|
22 | case GL_MAP2_TEXTURE_COORD_3:
|
---|
23 | return 3;
|
---|
24 | case GL_MAP2_VERTEX_4:
|
---|
25 | case GL_MAP2_COLOR_4:
|
---|
26 | case GL_MAP2_TEXTURE_COORD_4:
|
---|
27 | case GL_MAP1_VERTEX_ATTRIB0_4_NV:
|
---|
28 | case GL_MAP1_VERTEX_ATTRIB1_4_NV:
|
---|
29 | case GL_MAP1_VERTEX_ATTRIB2_4_NV:
|
---|
30 | case GL_MAP1_VERTEX_ATTRIB3_4_NV:
|
---|
31 | case GL_MAP1_VERTEX_ATTRIB4_4_NV:
|
---|
32 | case GL_MAP1_VERTEX_ATTRIB5_4_NV:
|
---|
33 | case GL_MAP1_VERTEX_ATTRIB6_4_NV:
|
---|
34 | case GL_MAP1_VERTEX_ATTRIB7_4_NV:
|
---|
35 | case GL_MAP1_VERTEX_ATTRIB8_4_NV:
|
---|
36 | case GL_MAP1_VERTEX_ATTRIB9_4_NV:
|
---|
37 | case GL_MAP1_VERTEX_ATTRIB10_4_NV:
|
---|
38 | case GL_MAP1_VERTEX_ATTRIB11_4_NV:
|
---|
39 | case GL_MAP1_VERTEX_ATTRIB12_4_NV:
|
---|
40 | case GL_MAP1_VERTEX_ATTRIB13_4_NV:
|
---|
41 | case GL_MAP1_VERTEX_ATTRIB14_4_NV:
|
---|
42 | case GL_MAP1_VERTEX_ATTRIB15_4_NV:
|
---|
43 | case GL_MAP2_VERTEX_ATTRIB0_4_NV:
|
---|
44 | case GL_MAP2_VERTEX_ATTRIB1_4_NV:
|
---|
45 | case GL_MAP2_VERTEX_ATTRIB2_4_NV:
|
---|
46 | case GL_MAP2_VERTEX_ATTRIB3_4_NV:
|
---|
47 | case GL_MAP2_VERTEX_ATTRIB4_4_NV:
|
---|
48 | case GL_MAP2_VERTEX_ATTRIB5_4_NV:
|
---|
49 | case GL_MAP2_VERTEX_ATTRIB6_4_NV:
|
---|
50 | case GL_MAP2_VERTEX_ATTRIB7_4_NV:
|
---|
51 | case GL_MAP2_VERTEX_ATTRIB8_4_NV:
|
---|
52 | case GL_MAP2_VERTEX_ATTRIB9_4_NV:
|
---|
53 | case GL_MAP2_VERTEX_ATTRIB10_4_NV:
|
---|
54 | case GL_MAP2_VERTEX_ATTRIB11_4_NV:
|
---|
55 | case GL_MAP2_VERTEX_ATTRIB12_4_NV:
|
---|
56 | case GL_MAP2_VERTEX_ATTRIB13_4_NV:
|
---|
57 | case GL_MAP2_VERTEX_ATTRIB14_4_NV:
|
---|
58 | case GL_MAP2_VERTEX_ATTRIB15_4_NV:
|
---|
59 | return 4;
|
---|
60 | case GL_MAP2_INDEX:
|
---|
61 | case GL_MAP2_TEXTURE_COORD_1:
|
---|
62 | return 1;
|
---|
63 | case GL_MAP2_TEXTURE_COORD_2:
|
---|
64 | return 2;
|
---|
65 | default:
|
---|
66 | return -1;
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | static int __gl_Map1NumComponents( GLenum target )
|
---|
71 | {
|
---|
72 | switch( target )
|
---|
73 | {
|
---|
74 | case GL_MAP1_VERTEX_3:
|
---|
75 | case GL_MAP1_NORMAL:
|
---|
76 | case GL_MAP1_TEXTURE_COORD_3:
|
---|
77 | return 3;
|
---|
78 | case GL_MAP1_VERTEX_4:
|
---|
79 | case GL_MAP1_COLOR_4:
|
---|
80 | case GL_MAP1_TEXTURE_COORD_4:
|
---|
81 | return 4;
|
---|
82 | case GL_MAP1_INDEX:
|
---|
83 | case GL_MAP1_TEXTURE_COORD_1:
|
---|
84 | return 1;
|
---|
85 | case GL_MAP1_TEXTURE_COORD_2:
|
---|
86 | return 2;
|
---|
87 | default:
|
---|
88 | return -1;
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | void PACK_APIENTRY crPackMap2d(GLenum target, GLdouble u1,
|
---|
93 | GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2,
|
---|
94 | GLint vstride, GLint vorder, const GLdouble *points)
|
---|
95 | {
|
---|
96 | unsigned char *data_ptr;
|
---|
97 | int u,v;
|
---|
98 | GLdouble *dest_data, *src_data;
|
---|
99 | int packet_length =
|
---|
100 | sizeof( target ) +
|
---|
101 | sizeof( u1 ) +
|
---|
102 | sizeof( u2 ) +
|
---|
103 | sizeof( uorder ) +
|
---|
104 | sizeof( ustride ) +
|
---|
105 | sizeof( v1 ) +
|
---|
106 | sizeof( v2 ) +
|
---|
107 | sizeof( vorder ) +
|
---|
108 | sizeof( vstride );
|
---|
109 |
|
---|
110 | int num_components = __gl_Map2NumComponents( target );
|
---|
111 | if (num_components < 0)
|
---|
112 | {
|
---|
113 | __PackError( __LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
114 | "crPackMap2d(bad target)" );
|
---|
115 | return;
|
---|
116 | }
|
---|
117 |
|
---|
118 | packet_length += num_components*uorder*vorder*sizeof( *points );
|
---|
119 |
|
---|
120 | data_ptr = (unsigned char *) crPackAlloc( packet_length );
|
---|
121 |
|
---|
122 | WRITE_DATA( 0, GLenum, target );
|
---|
123 | WRITE_DOUBLE( 4, u1 );
|
---|
124 | WRITE_DOUBLE( 12, u2 );
|
---|
125 | WRITE_DATA( 20, GLint, num_components );
|
---|
126 | WRITE_DATA( 24, GLint, uorder );
|
---|
127 | WRITE_DOUBLE( 28, v1 );
|
---|
128 | WRITE_DOUBLE( 36, v2 );
|
---|
129 | WRITE_DATA( 44, GLint, num_components*uorder );
|
---|
130 | WRITE_DATA( 48, GLint, vorder );
|
---|
131 |
|
---|
132 | dest_data = (GLdouble *) (data_ptr + 52);
|
---|
133 | src_data = (GLdouble *) points;
|
---|
134 | for (v = 0 ; v < vorder ; v++)
|
---|
135 | {
|
---|
136 | for (u = 0 ; u < uorder ; u++)
|
---|
137 | {
|
---|
138 | crMemcpy( dest_data, src_data, num_components * sizeof( *points ) );
|
---|
139 | dest_data += num_components;
|
---|
140 | src_data += ustride;
|
---|
141 | }
|
---|
142 | src_data += vstride - ustride*uorder;
|
---|
143 | }
|
---|
144 |
|
---|
145 | crHugePacket( CR_MAP2D_OPCODE, data_ptr );
|
---|
146 | crPackFree( data_ptr );
|
---|
147 | }
|
---|
148 |
|
---|
149 | void PACK_APIENTRY crPackMap2f(GLenum target, GLfloat u1,
|
---|
150 | GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2,
|
---|
151 | GLint vstride, GLint vorder, const GLfloat *points)
|
---|
152 | {
|
---|
153 | unsigned char *data_ptr;
|
---|
154 | int u,v;
|
---|
155 | GLfloat *dest_data, *src_data;
|
---|
156 | int packet_length =
|
---|
157 | sizeof( target ) +
|
---|
158 | sizeof( u1 ) +
|
---|
159 | sizeof( u2 ) +
|
---|
160 | sizeof( uorder ) +
|
---|
161 | sizeof( ustride ) +
|
---|
162 | sizeof( v1 ) +
|
---|
163 | sizeof( v2 ) +
|
---|
164 | sizeof( vorder ) +
|
---|
165 | sizeof( vstride );
|
---|
166 |
|
---|
167 | int num_components = __gl_Map2NumComponents( target );
|
---|
168 | if (num_components < 0)
|
---|
169 | {
|
---|
170 | __PackError( __LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
171 | "crPackMap2f(bad target)" );
|
---|
172 | return;
|
---|
173 | }
|
---|
174 |
|
---|
175 | packet_length += num_components*uorder*vorder*sizeof( *points );
|
---|
176 |
|
---|
177 | data_ptr = (unsigned char *) crPackAlloc( packet_length );
|
---|
178 |
|
---|
179 | WRITE_DATA( 0, GLenum, target );
|
---|
180 | WRITE_DATA( 4, GLfloat, u1 );
|
---|
181 | WRITE_DATA( 8, GLfloat, u2 );
|
---|
182 | WRITE_DATA( 12, GLint, num_components );
|
---|
183 | WRITE_DATA( 16, GLint, uorder );
|
---|
184 | WRITE_DATA( 20, GLfloat, v1 );
|
---|
185 | WRITE_DATA( 24, GLfloat, v2 );
|
---|
186 | WRITE_DATA( 28, GLint, num_components*uorder );
|
---|
187 | WRITE_DATA( 32, GLint, vorder );
|
---|
188 |
|
---|
189 | dest_data = (GLfloat *) (data_ptr + 36);
|
---|
190 | src_data = (GLfloat *) points;
|
---|
191 | for (v = 0 ; v < vorder ; v++)
|
---|
192 | {
|
---|
193 | for (u = 0 ; u < uorder ; u++)
|
---|
194 | {
|
---|
195 | crMemcpy( dest_data, src_data, num_components * sizeof( *points ) );
|
---|
196 | dest_data += num_components;
|
---|
197 | src_data += ustride;
|
---|
198 | }
|
---|
199 | src_data += vstride - ustride*uorder;
|
---|
200 | }
|
---|
201 |
|
---|
202 | crHugePacket( CR_MAP2F_OPCODE, data_ptr );
|
---|
203 | crPackFree( data_ptr );
|
---|
204 | }
|
---|
205 |
|
---|
206 | void PACK_APIENTRY crPackMap1d( GLenum target, GLdouble u1,
|
---|
207 | GLdouble u2, GLint stride, GLint order, const GLdouble *points )
|
---|
208 | {
|
---|
209 | unsigned char *data_ptr;
|
---|
210 | int packet_length =
|
---|
211 | sizeof( target ) +
|
---|
212 | sizeof( u1 ) +
|
---|
213 | sizeof( u2 ) +
|
---|
214 | sizeof( stride ) +
|
---|
215 | sizeof( order );
|
---|
216 |
|
---|
217 | int num_components = __gl_Map1NumComponents( target );
|
---|
218 | GLdouble *src_data, *dest_data;
|
---|
219 | int u;
|
---|
220 |
|
---|
221 | if (num_components < 0)
|
---|
222 | {
|
---|
223 | __PackError( __LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
224 | "crPackMap1d(bad target)" );
|
---|
225 | return;
|
---|
226 | }
|
---|
227 |
|
---|
228 | packet_length += num_components * order * sizeof( *points );
|
---|
229 |
|
---|
230 | data_ptr = (unsigned char *) crPackAlloc( packet_length );
|
---|
231 |
|
---|
232 | WRITE_DATA( 0, GLenum, target );
|
---|
233 | WRITE_DOUBLE( 4, u1 );
|
---|
234 | WRITE_DOUBLE( 12, u2 );
|
---|
235 | WRITE_DATA( 20, GLint, num_components );
|
---|
236 | WRITE_DATA( 24, GLint, order );
|
---|
237 |
|
---|
238 | dest_data = (GLdouble *) (data_ptr + 28);
|
---|
239 | src_data = (GLdouble *) points;
|
---|
240 | for (u = 0 ; u < order ; u++)
|
---|
241 | {
|
---|
242 | crMemcpy( dest_data, src_data, num_components * sizeof( *points ) );
|
---|
243 | dest_data += num_components;
|
---|
244 | src_data += stride;
|
---|
245 | }
|
---|
246 |
|
---|
247 | crHugePacket( CR_MAP1D_OPCODE, data_ptr );
|
---|
248 | crPackFree( data_ptr );
|
---|
249 | }
|
---|
250 |
|
---|
251 | void PACK_APIENTRY crPackMap1f( GLenum target, GLfloat u1,
|
---|
252 | GLfloat u2, GLint stride, GLint order, const GLfloat *points )
|
---|
253 | {
|
---|
254 | unsigned char *data_ptr;
|
---|
255 | int packet_length =
|
---|
256 | sizeof( target ) +
|
---|
257 | sizeof( u1 ) +
|
---|
258 | sizeof( u2 ) +
|
---|
259 | sizeof( stride ) +
|
---|
260 | sizeof( order );
|
---|
261 |
|
---|
262 | int num_components = __gl_Map1NumComponents( target );
|
---|
263 | GLfloat *src_data, *dest_data;
|
---|
264 | int u;
|
---|
265 |
|
---|
266 | if (num_components < 0)
|
---|
267 | {
|
---|
268 | __PackError( __LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
269 | "crPackMap1f(bad target)" );
|
---|
270 | return;
|
---|
271 | }
|
---|
272 |
|
---|
273 | packet_length += num_components * order * sizeof( *points );
|
---|
274 |
|
---|
275 | data_ptr = (unsigned char *) crPackAlloc( packet_length );
|
---|
276 |
|
---|
277 | WRITE_DATA( 0, GLenum, target );
|
---|
278 | WRITE_DATA( 4, GLfloat, u1 );
|
---|
279 | WRITE_DATA( 8, GLfloat, u2 );
|
---|
280 | WRITE_DATA( 12, GLint, num_components );
|
---|
281 | WRITE_DATA( 16, GLint, order );
|
---|
282 |
|
---|
283 | dest_data = (GLfloat *) (data_ptr + 20);
|
---|
284 | src_data = (GLfloat *) points;
|
---|
285 | for (u = 0 ; u < order ; u++)
|
---|
286 | {
|
---|
287 | crMemcpy( dest_data, src_data, num_components * sizeof( *points ) );
|
---|
288 | dest_data += num_components;
|
---|
289 | src_data += stride;
|
---|
290 | }
|
---|
291 |
|
---|
292 | crHugePacket( CR_MAP1F_OPCODE, data_ptr );
|
---|
293 | crPackFree( data_ptr );
|
---|
294 | }
|
---|