Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / dmx / glxProxy / render2swap.c
CommitLineData
a09e091a
JB
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
35static GLint
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
66void
67__glXDispSwap_Map1f(GLbyte * pc)
68{
69 GLint order, k;
70 GLfloat u1, u2, *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 u1 = *(GLfloat *) (pc + 4);
85 u2 = *(GLfloat *) (pc + 8);
86 points = (GLfloat *) (pc + 16);
87 k = __glEvalComputeK(target);
88
89 if (order <= 0 || k < 0) {
90 /* Erroneous command. */
91 compsize = 0;
92 }
93 else {
94 compsize = order * k;
95 }
96 __GLX_SWAP_FLOAT_ARRAY(points, compsize);
97
98}
99
100void
101__glXDispSwap_Map2f(GLbyte * pc)
102{
103 GLint uorder, vorder, ustride, vstride, k;
104 GLfloat u1, u2, v1, v2, *points;
105 GLenum target;
106 GLint compsize;
107
108 __GLX_DECLARE_SWAP_VARIABLES;
109 __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
110
111 __GLX_SWAP_INT(pc + 0);
112 __GLX_SWAP_INT(pc + 12);
113 __GLX_SWAP_INT(pc + 24);
114 __GLX_SWAP_FLOAT(pc + 4);
115 __GLX_SWAP_FLOAT(pc + 8);
116 __GLX_SWAP_FLOAT(pc + 16);
117 __GLX_SWAP_FLOAT(pc + 20);
118
119 target = *(GLenum *) (pc + 0);
120 uorder = *(GLint *) (pc + 12);
121 vorder = *(GLint *) (pc + 24);
122 u1 = *(GLfloat *) (pc + 4);
123 u2 = *(GLfloat *) (pc + 8);
124 v1 = *(GLfloat *) (pc + 16);
125 v2 = *(GLfloat *) (pc + 20);
126 points = (GLfloat *) (pc + 28);
127
128 k = __glEvalComputeK(target);
129 ustride = vorder * k;
130 vstride = k;
131
132 if (vorder <= 0 || uorder <= 0 || k < 0) {
133 /* Erroneous command. */
134 compsize = 0;
135 }
136 else {
137 compsize = uorder * vorder * k;
138 }
139 __GLX_SWAP_FLOAT_ARRAY(points, compsize);
140
141}
142
143void
144__glXDispSwap_Map1d(GLbyte * pc)
145{
146 GLint order, k, compsize;
147 GLenum target;
148 GLdouble u1, u2, *points;
149
150 __GLX_DECLARE_SWAP_VARIABLES;
151 __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
152
153 __GLX_SWAP_DOUBLE(pc + 0);
154 __GLX_SWAP_DOUBLE(pc + 8);
155 __GLX_SWAP_INT(pc + 16);
156 __GLX_SWAP_INT(pc + 20);
157
158 target = *(GLenum *) (pc + 16);
159 order = *(GLint *) (pc + 20);
160 k = __glEvalComputeK(target);
161 if (order <= 0 || k < 0) {
162 /* Erroneous command. */
163 compsize = 0;
164 }
165 else {
166 compsize = order * k;
167 }
168 __GLX_GET_DOUBLE(u1, pc);
169 __GLX_GET_DOUBLE(u2, pc + 8);
170 __GLX_SWAP_DOUBLE_ARRAY(pc + 24, compsize);
171 pc += 24;
172
173#ifdef __GLX_ALIGN64
174 if (((unsigned long) pc) & 7) {
175 /*
176 ** Copy the doubles up 4 bytes, trashing the command but aligning
177 ** the data in the process
178 */
179 __GLX_MEM_COPY(pc - 4, pc, compsize * 8);
180 points = (GLdouble *) (pc - 4);
181 }
182 else {
183 points = (GLdouble *) pc;
184 }
185#else
186 points = (GLdouble *) pc;
187#endif
188}
189
190void
191__glXDispSwap_Map2d(GLbyte * pc)
192{
193 GLdouble u1, u2, v1, v2, *points;
194 GLint uorder, vorder, ustride, vstride, k, compsize;
195 GLenum target;
196
197 __GLX_DECLARE_SWAP_VARIABLES;
198 __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
199
200 __GLX_SWAP_DOUBLE(pc + 0);
201 __GLX_SWAP_DOUBLE(pc + 8);
202 __GLX_SWAP_DOUBLE(pc + 16);
203 __GLX_SWAP_DOUBLE(pc + 24);
204 __GLX_SWAP_INT(pc + 32);
205 __GLX_SWAP_INT(pc + 36);
206 __GLX_SWAP_INT(pc + 40);
207
208 target = *(GLenum *) (pc + 32);
209 uorder = *(GLint *) (pc + 36);
210 vorder = *(GLint *) (pc + 40);
211 k = __glEvalComputeK(target);
212 if (vorder <= 0 || uorder <= 0 || k < 0) {
213 /* Erroneous command. */
214 compsize = 0;
215 }
216 else {
217 compsize = uorder * vorder * k;
218 }
219 __GLX_GET_DOUBLE(u1, pc);
220 __GLX_GET_DOUBLE(u2, pc + 8);
221 __GLX_GET_DOUBLE(v1, pc + 16);
222 __GLX_GET_DOUBLE(v2, pc + 24);
223 __GLX_SWAP_DOUBLE_ARRAY(pc + 44, compsize);
224 pc += 44;
225 ustride = vorder * k;
226 vstride = k;
227
228#ifdef __GLX_ALIGN64
229 if (((unsigned long) pc) & 7) {
230 /*
231 ** Copy the doubles up 4 bytes, trashing the command but aligning
232 ** the data in the process
233 */
234 __GLX_MEM_COPY(pc - 4, pc, compsize * 8);
235 points = (GLdouble *) (pc - 4);
236 }
237 else {
238 points = (GLdouble *) pc;
239 }
240#else
241 points = (GLdouble *) pc;
242#endif
243}
244
245void
246__glXDispSwap_CallLists(GLbyte * pc)
247{
248 GLenum type;
249 GLsizei n;
250
251 __GLX_DECLARE_SWAP_VARIABLES;
252 __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
253
254 __GLX_SWAP_INT(pc + 4);
255 __GLX_SWAP_INT(pc + 0);
256 type = *(GLenum *) (pc + 4);
257 n = *(GLsizei *) (pc + 0);
258
259 switch (type) {
260 case GL_BYTE:
261 case GL_UNSIGNED_BYTE:
262 case GL_2_BYTES:
263 case GL_3_BYTES:
264 case GL_4_BYTES:
265 break;
266 case GL_SHORT:
267 case GL_UNSIGNED_SHORT:
268 __GLX_SWAP_SHORT_ARRAY(pc + 8, n);
269 break;
270 case GL_INT:
271 case GL_UNSIGNED_INT:
272 __GLX_SWAP_INT_ARRAY(pc + 8, n);
273 break;
274 case GL_FLOAT:
275 __GLX_SWAP_FLOAT_ARRAY(pc + 8, n);
276 break;
277 }
278
279}
280
281void
282__glXDispSwap_DrawArrays(GLbyte * pc)
283{
284 __GLXdispatchDrawArraysHeader *hdr = (__GLXdispatchDrawArraysHeader *) pc;
285 __GLXdispatchDrawArraysComponentHeader *compHeader;
286 int i;
287
288 __GLX_DECLARE_SWAP_VARIABLES;
289
290 __GLX_SWAP_INT(&hdr->numVertexes);
291 __GLX_SWAP_INT(&hdr->numComponents);
292 __GLX_SWAP_INT(&hdr->primType);
293
294 pc += sizeof(__GLXdispatchDrawArraysHeader);
295 compHeader = (__GLXdispatchDrawArraysComponentHeader *) pc;
296
297 /* compute stride (same for all component arrays) */
298 for (i = 0; i < hdr->numComponents; i++) {
299 __GLX_SWAP_INT(&compHeader[i].datatype);
300 __GLX_SWAP_INT(&compHeader[i].numVals);
301 __GLX_SWAP_INT(&compHeader[i].component);
302
303 }
304
305}