VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/packer/pack_swap_map.c@ 57541

Last change on this file since 57541 was 33457, checked in by vboxsync, 14 years ago

crOpenGL: tabs to spaces

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