First import
[xorg_rtime.git] / xorg-server-1.4 / hw / dmx / glxProxy / render2swap.c
blobe7cbff21fc330278bf33d5bd088d455b815f8710
1 /*
2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
9 **
10 ** http://oss.sgi.com/projects/FreeB
11 **
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
17 **
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
23 **
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
36 /* #define NEED_REPLIES */
37 #include "glxserver.h"
38 #include "unpack.h"
39 #include "g_disptab.h"
41 GLint __glEvalComputeK(GLenum target)
43 switch (target) {
44 case GL_MAP1_VERTEX_4:
45 case GL_MAP1_COLOR_4:
46 case GL_MAP1_TEXTURE_COORD_4:
47 case GL_MAP2_VERTEX_4:
48 case GL_MAP2_COLOR_4:
49 case GL_MAP2_TEXTURE_COORD_4:
50 return 4;
51 case GL_MAP1_VERTEX_3:
52 case GL_MAP1_TEXTURE_COORD_3:
53 case GL_MAP1_NORMAL:
54 case GL_MAP2_VERTEX_3:
55 case GL_MAP2_TEXTURE_COORD_3:
56 case GL_MAP2_NORMAL:
57 return 3;
58 case GL_MAP1_TEXTURE_COORD_2:
59 case GL_MAP2_TEXTURE_COORD_2:
60 return 2;
61 case GL_MAP1_TEXTURE_COORD_1:
62 case GL_MAP2_TEXTURE_COORD_1:
63 case GL_MAP1_INDEX:
64 case GL_MAP2_INDEX:
65 return 1;
66 default:
67 return 0;
71 void __glXDispSwap_Map1f(GLbyte *pc)
73 GLint order, k;
74 GLfloat u1, u2, *points;
75 GLenum target;
76 GLint compsize;
77 __GLX_DECLARE_SWAP_VARIABLES;
79 __GLX_SWAP_INT(pc + 0);
80 __GLX_SWAP_INT(pc + 12);
81 __GLX_SWAP_FLOAT(pc + 4);
82 __GLX_SWAP_FLOAT(pc + 8);
84 target = *(GLenum *)(pc + 0);
85 order = *(GLint *)(pc + 12);
86 u1 = *(GLfloat *)(pc + 4);
87 u2 = *(GLfloat *)(pc + 8);
88 points = (GLfloat *)(pc + 16);
89 k = __glEvalComputeK(target);
91 if (order <= 0 || k < 0) {
92 /* Erroneous command. */
93 compsize = 0;
94 } else {
95 compsize = order * k;
97 __GLX_SWAP_FLOAT_ARRAY(points, compsize);
101 void __glXDispSwap_Map2f(GLbyte *pc)
103 GLint uorder, vorder, ustride, vstride, k;
104 GLfloat u1, u2, v1, v2, *points;
105 GLenum target;
106 GLint compsize;
107 __GLX_DECLARE_SWAP_VARIABLES;
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);
117 target = *(GLenum *)(pc + 0);
118 uorder = *(GLint *)(pc + 12);
119 vorder = *(GLint *)(pc + 24);
120 u1 = *(GLfloat *)(pc + 4);
121 u2 = *(GLfloat *)(pc + 8);
122 v1 = *(GLfloat *)(pc + 16);
123 v2 = *(GLfloat *)(pc + 20);
124 points = (GLfloat *)(pc + 28);
126 k = __glEvalComputeK(target);
127 ustride = vorder * k;
128 vstride = k;
130 if (vorder <= 0 || uorder <= 0 || k < 0) {
131 /* Erroneous command. */
132 compsize = 0;
133 } else {
134 compsize = uorder * vorder * k;
136 __GLX_SWAP_FLOAT_ARRAY(points, compsize);
140 void __glXDispSwap_Map1d(GLbyte *pc)
142 GLint order, k, compsize;
143 GLenum target;
144 GLdouble u1, u2, *points;
145 __GLX_DECLARE_SWAP_VARIABLES;
147 __GLX_SWAP_DOUBLE(pc + 0);
148 __GLX_SWAP_DOUBLE(pc + 8);
149 __GLX_SWAP_INT(pc + 16);
150 __GLX_SWAP_INT(pc + 20);
152 target = *(GLenum*) (pc + 16);
153 order = *(GLint*) (pc + 20);
154 k = __glEvalComputeK(target);
155 if (order <= 0 || k < 0) {
156 /* Erroneous command. */
157 compsize = 0;
158 } else {
159 compsize = order * k;
161 __GLX_GET_DOUBLE(u1,pc);
162 __GLX_GET_DOUBLE(u2,pc+8);
163 __GLX_SWAP_DOUBLE_ARRAY(pc+24, compsize);
164 pc += 24;
166 #ifdef __GLX_ALIGN64
167 if (((unsigned long)pc) & 7) {
169 ** Copy the doubles up 4 bytes, trashing the command but aligning
170 ** the data in the process
172 __GLX_MEM_COPY(pc-4, pc, compsize*8);
173 points = (GLdouble*) (pc - 4);
174 } else {
175 points = (GLdouble*) pc;
177 #else
178 points = (GLdouble*) pc;
179 #endif
182 void __glXDispSwap_Map2d(GLbyte *pc)
184 GLdouble u1, u2, v1, v2, *points;
185 GLint uorder, vorder, ustride, vstride, k, compsize;
186 GLenum target;
187 __GLX_DECLARE_SWAP_VARIABLES;
189 __GLX_SWAP_DOUBLE(pc + 0);
190 __GLX_SWAP_DOUBLE(pc + 8);
191 __GLX_SWAP_DOUBLE(pc + 16);
192 __GLX_SWAP_DOUBLE(pc + 24);
193 __GLX_SWAP_INT(pc + 32);
194 __GLX_SWAP_INT(pc + 36);
195 __GLX_SWAP_INT(pc + 40);
197 target = *(GLenum *)(pc + 32);
198 uorder = *(GLint *)(pc + 36);
199 vorder = *(GLint *)(pc + 40);
200 k = __glEvalComputeK(target);
201 if (vorder <= 0 || uorder <= 0 || k < 0) {
202 /* Erroneous command. */
203 compsize = 0;
204 } else {
205 compsize = uorder * vorder * k;
207 __GLX_GET_DOUBLE(u1,pc);
208 __GLX_GET_DOUBLE(u2,pc+8);
209 __GLX_GET_DOUBLE(v1,pc+16);
210 __GLX_GET_DOUBLE(v2,pc+24);
211 __GLX_SWAP_DOUBLE_ARRAY(pc+44, compsize);
212 pc += 44;
213 ustride = vorder * k;
214 vstride = k;
216 #ifdef __GLX_ALIGN64
217 if (((unsigned long)pc) & 7) {
219 ** Copy the doubles up 4 bytes, trashing the command but aligning
220 ** the data in the process
222 __GLX_MEM_COPY(pc-4, pc, compsize*8);
223 points = (GLdouble*) (pc - 4);
224 } else {
225 points = (GLdouble*) pc;
227 #else
228 points = (GLdouble*) pc;
229 #endif
232 void __glXDispSwap_CallLists(GLbyte *pc)
234 GLenum type;
235 GLsizei n;
236 __GLX_DECLARE_SWAP_VARIABLES;
238 __GLX_SWAP_INT(pc + 4);
239 __GLX_SWAP_INT(pc + 0);
240 type = *(GLenum *)(pc + 4);
241 n = *(GLsizei *)(pc + 0);
243 switch (type) {
244 case GL_BYTE:
245 case GL_UNSIGNED_BYTE:
246 case GL_2_BYTES:
247 case GL_3_BYTES:
248 case GL_4_BYTES:
249 break;
250 case GL_SHORT:
251 case GL_UNSIGNED_SHORT:
252 __GLX_SWAP_SHORT_ARRAY(pc+8, n);
253 break;
254 case GL_INT:
255 case GL_UNSIGNED_INT:
256 __GLX_SWAP_INT_ARRAY(pc+8, n);
257 break;
258 case GL_FLOAT:
259 __GLX_SWAP_FLOAT_ARRAY(pc+8, n);
260 break;
265 static void swapArray(GLint numVals, GLenum datatype,
266 GLint stride, GLint numVertexes, GLbyte *pc)
268 int i,j;
269 __GLX_DECLARE_SWAP_VARIABLES;
271 switch (datatype) {
272 case GL_BYTE:
273 case GL_UNSIGNED_BYTE:
274 /* don't need to swap */
275 return;
276 case GL_SHORT:
277 case GL_UNSIGNED_SHORT:
278 for (i=0; i<numVertexes; i++) {
279 GLshort *pVal = (GLshort *) pc;
280 for (j=0; j<numVals; j++) {
281 __GLX_SWAP_SHORT(&pVal[j]);
283 pc += stride;
285 break;
286 case GL_INT:
287 case GL_UNSIGNED_INT:
288 for (i=0; i<numVertexes; i++) {
289 GLint *pVal = (GLint *) pc;
290 for (j=0; j<numVals; j++) {
291 __GLX_SWAP_INT(&pVal[j]);
293 pc += stride;
295 break;
296 case GL_FLOAT:
297 for (i=0; i<numVertexes; i++) {
298 GLfloat *pVal = (GLfloat *) pc;
299 for (j=0; j<numVals; j++) {
300 __GLX_SWAP_FLOAT(&pVal[j]);
302 pc += stride;
304 break;
305 case GL_DOUBLE:
306 for (i=0; i<numVertexes; i++) {
307 GLdouble *pVal = (GLdouble *) pc;
308 for (j=0; j<numVals; j++) {
309 __GLX_SWAP_DOUBLE(&pVal[j]);
311 pc += stride;
313 break;
314 default:
315 return;
319 void __glXDispSwap_DrawArrays(GLbyte *pc)
321 __GLXdispatchDrawArraysHeader *hdr = (__GLXdispatchDrawArraysHeader *)pc;
322 __GLXdispatchDrawArraysComponentHeader *compHeader;
323 int i;
324 __GLX_DECLARE_SWAP_VARIABLES;
326 __GLX_SWAP_INT(&hdr->numVertexes);
327 __GLX_SWAP_INT(&hdr->numComponents);
328 __GLX_SWAP_INT(&hdr->primType);
330 pc += sizeof(__GLXdispatchDrawArraysHeader);
331 compHeader = (__GLXdispatchDrawArraysComponentHeader *) pc;
333 /* compute stride (same for all component arrays) */
334 for (i=0; i<hdr->numComponents; i++) {
335 __GLX_SWAP_INT(&compHeader[i].datatype);
336 __GLX_SWAP_INT(&compHeader[i].numVals);
337 __GLX_SWAP_INT(&compHeader[i].component);
343 void __glXDispSwap_DrawArraysEXT(GLbyte *pc)
345 #ifdef XXX_STUB
346 #endif /*XXX_STUB*/