1 /*
2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
29 */
30
31 #include "glxserver.h"
32 #include "unpack.h"
33 #include "g_disptab.h"
34
35 static GLint
__glEvalComputeK(GLenum target)36 __glEvalComputeK(GLenum target)
37 {
38 switch (target) {
39 case GL_MAP1_VERTEX_4:
40 case GL_MAP1_COLOR_4:
41 case GL_MAP1_TEXTURE_COORD_4:
42 case GL_MAP2_VERTEX_4:
43 case GL_MAP2_COLOR_4:
44 case GL_MAP2_TEXTURE_COORD_4:
45 return 4;
46 case GL_MAP1_VERTEX_3:
47 case GL_MAP1_TEXTURE_COORD_3:
48 case GL_MAP1_NORMAL:
49 case GL_MAP2_VERTEX_3:
50 case GL_MAP2_TEXTURE_COORD_3:
51 case GL_MAP2_NORMAL:
52 return 3;
53 case GL_MAP1_TEXTURE_COORD_2:
54 case GL_MAP2_TEXTURE_COORD_2:
55 return 2;
56 case GL_MAP1_TEXTURE_COORD_1:
57 case GL_MAP2_TEXTURE_COORD_1:
58 case GL_MAP1_INDEX:
59 case GL_MAP2_INDEX:
60 return 1;
61 default:
62 return 0;
63 }
64 }
65
66 void
__glXDispSwap_Map1f(GLbyte * pc)67 __glXDispSwap_Map1f(GLbyte * pc)
68 {
69 GLint order, k;
70 GLfloat *points;
71 GLenum target;
72 GLint compsize;
73
74 __GLX_DECLARE_SWAP_VARIABLES;
75 __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
76
77 __GLX_SWAP_INT(pc + 0);
78 __GLX_SWAP_INT(pc + 12);
79 __GLX_SWAP_FLOAT(pc + 4);
80 __GLX_SWAP_FLOAT(pc + 8);
81
82 target = *(GLenum *) (pc + 0);
83 order = *(GLint *) (pc + 12);
84 points = (GLfloat *) (pc + 16);
85 k = __glEvalComputeK(target);
86
87 if (order <= 0 || k < 0) {
88 /* Erroneous command. */
89 compsize = 0;
90 }
91 else {
92 compsize = order * k;
93 }
94 __GLX_SWAP_FLOAT_ARRAY(points, compsize);
95
96 }
97
98 void
__glXDispSwap_Map2f(GLbyte * pc)99 __glXDispSwap_Map2f(GLbyte * pc)
100 {
101 GLint uorder, vorder, k;
102 GLfloat *points;
103 GLenum target;
104 GLint compsize;
105
106 __GLX_DECLARE_SWAP_VARIABLES;
107 __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
108
109 __GLX_SWAP_INT(pc + 0);
110 __GLX_SWAP_INT(pc + 12);
111 __GLX_SWAP_INT(pc + 24);
112 __GLX_SWAP_FLOAT(pc + 4);
113 __GLX_SWAP_FLOAT(pc + 8);
114 __GLX_SWAP_FLOAT(pc + 16);
115 __GLX_SWAP_FLOAT(pc + 20);
116
117 target = *(GLenum *) (pc + 0);
118 uorder = *(GLint *) (pc + 12);
119 vorder = *(GLint *) (pc + 24);
120 points = (GLfloat *) (pc + 28);
121
122 k = __glEvalComputeK(target);
123
124 if (vorder <= 0 || uorder <= 0 || k < 0) {
125 /* Erroneous command. */
126 compsize = 0;
127 }
128 else {
129 compsize = uorder * vorder * k;
130 }
131 __GLX_SWAP_FLOAT_ARRAY(points, compsize);
132
133 }
134
135 void
__glXDispSwap_Map1d(GLbyte * pc)136 __glXDispSwap_Map1d(GLbyte * pc)
137 {
138 GLint order, k, compsize;
139 GLenum target;
140 GLdouble u1, u2;
141
142 __GLX_DECLARE_SWAP_VARIABLES;
143 __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
144
145 __GLX_SWAP_DOUBLE(pc + 0);
146 __GLX_SWAP_DOUBLE(pc + 8);
147 __GLX_SWAP_INT(pc + 16);
148 __GLX_SWAP_INT(pc + 20);
149
150 target = *(GLenum *) (pc + 16);
151 order = *(GLint *) (pc + 20);
152 k = __glEvalComputeK(target);
153 if (order <= 0 || k < 0) {
154 /* Erroneous command. */
155 compsize = 0;
156 }
157 else {
158 compsize = order * k;
159 }
160 __GLX_GET_DOUBLE(u1, pc);
161 __GLX_GET_DOUBLE(u2, pc + 8);
162 __GLX_SWAP_DOUBLE_ARRAY(pc + 24, compsize);
163 pc += 24;
164
165 #ifdef __GLX_ALIGN64
166 if (((unsigned long) pc) & 7) {
167 /*
168 ** Copy the doubles up 4 bytes, trashing the command but aligning
169 ** the data in the process
170 */
171 __GLX_MEM_COPY(pc - 4, pc, compsize * 8);
172 }
173 #endif
174 }
175
176 void
__glXDispSwap_Map2d(GLbyte * pc)177 __glXDispSwap_Map2d(GLbyte * pc)
178 {
179 GLdouble u1, u2, v1, v2;
180 GLint uorder, vorder, k, compsize;
181 GLenum target;
182
183 __GLX_DECLARE_SWAP_VARIABLES;
184 __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
185
186 __GLX_SWAP_DOUBLE(pc + 0);
187 __GLX_SWAP_DOUBLE(pc + 8);
188 __GLX_SWAP_DOUBLE(pc + 16);
189 __GLX_SWAP_DOUBLE(pc + 24);
190 __GLX_SWAP_INT(pc + 32);
191 __GLX_SWAP_INT(pc + 36);
192 __GLX_SWAP_INT(pc + 40);
193
194 target = *(GLenum *) (pc + 32);
195 uorder = *(GLint *) (pc + 36);
196 vorder = *(GLint *) (pc + 40);
197 k = __glEvalComputeK(target);
198 if (vorder <= 0 || uorder <= 0 || k < 0) {
199 /* Erroneous command. */
200 compsize = 0;
201 }
202 else {
203 compsize = uorder * vorder * k;
204 }
205 __GLX_GET_DOUBLE(u1, pc);
206 __GLX_GET_DOUBLE(u2, pc + 8);
207 __GLX_GET_DOUBLE(v1, pc + 16);
208 __GLX_GET_DOUBLE(v2, pc + 24);
209 __GLX_SWAP_DOUBLE_ARRAY(pc + 44, compsize);
210 pc += 44;
211
212 #ifdef __GLX_ALIGN64
213 if (((unsigned long) pc) & 7) {
214 /*
215 ** Copy the doubles up 4 bytes, trashing the command but aligning
216 ** the data in the process
217 */
218 __GLX_MEM_COPY(pc - 4, pc, compsize * 8);
219 }
220 #endif
221 }
222
223 void
__glXDispSwap_CallLists(GLbyte * pc)224 __glXDispSwap_CallLists(GLbyte * pc)
225 {
226 GLenum type;
227 GLsizei n;
228
229 __GLX_DECLARE_SWAP_VARIABLES;
230 __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
231
232 __GLX_SWAP_INT(pc + 4);
233 __GLX_SWAP_INT(pc + 0);
234 type = *(GLenum *) (pc + 4);
235 n = *(GLsizei *) (pc + 0);
236
237 switch (type) {
238 case GL_BYTE:
239 case GL_UNSIGNED_BYTE:
240 case GL_2_BYTES:
241 case GL_3_BYTES:
242 case GL_4_BYTES:
243 break;
244 case GL_SHORT:
245 case GL_UNSIGNED_SHORT:
246 __GLX_SWAP_SHORT_ARRAY(pc + 8, n);
247 break;
248 case GL_INT:
249 case GL_UNSIGNED_INT:
250 __GLX_SWAP_INT_ARRAY(pc + 8, n);
251 break;
252 case GL_FLOAT:
253 __GLX_SWAP_FLOAT_ARRAY(pc + 8, n);
254 break;
255 }
256
257 }
258
259 void
__glXDispSwap_DrawArrays(GLbyte * pc)260 __glXDispSwap_DrawArrays(GLbyte * pc)
261 {
262 __GLXdispatchDrawArraysHeader *hdr = (__GLXdispatchDrawArraysHeader *) pc;
263 __GLXdispatchDrawArraysComponentHeader *compHeader;
264 int i;
265
266 __GLX_DECLARE_SWAP_VARIABLES;
267
268 __GLX_SWAP_INT(&hdr->numVertexes);
269 __GLX_SWAP_INT(&hdr->numComponents);
270 __GLX_SWAP_INT(&hdr->primType);
271
272 pc += sizeof(__GLXdispatchDrawArraysHeader);
273 compHeader = (__GLXdispatchDrawArraysComponentHeader *) pc;
274
275 /* compute stride (same for all component arrays) */
276 for (i = 0; i < hdr->numComponents; i++) {
277 __GLX_SWAP_INT(&compHeader[i].datatype);
278 __GLX_SWAP_INT(&compHeader[i].numVals);
279 __GLX_SWAP_INT(&compHeader[i].component);
280
281 }
282
283 }
284