Make the transition to script-genereated GLX code easier.
[mesa.git] / src / glx / x11 / pixelstore.c
1 /* $XFree86: xc/lib/GL/glx/pixelstore.c,v 1.4 2004/01/28 18:11:43 alanh Exp $ */
2 /*
3 ** License Applicability. Except to the extent portions of this file are
4 ** made subject to an alternative license as permitted in the SGI Free
5 ** Software License B, Version 1.1 (the "License"), the contents of this
6 ** file are subject only to the provisions of the License. You may not use
7 ** this file except in compliance with the License. You may obtain a copy
8 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 **
11 ** http://oss.sgi.com/projects/FreeB
12 **
13 ** Note that, as provided in the License, the Software is distributed on an
14 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 **
19 ** Original Code. The Original Code is: OpenGL Sample Implementation,
20 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22 ** Copyright in any portions created by third parties is as indicated
23 ** elsewhere herein. All Rights Reserved.
24 **
25 ** Additional Notice Provisions: The application programming interfaces
26 ** established by SGI in conjunction with the Original Code are The
27 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30 ** Window System(R) (Version 1.3), released October 19, 1998. This software
31 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32 ** published by SGI, but has not been independently verified as being
33 ** compliant with the OpenGL(R) version 1.2.1 Specification.
34 **
35 */
36
37 #include "glxclient.h"
38
39 /*
40 ** Specify parameters that control the storage format of pixel arrays.
41 */
42 void __indirect_glPixelStoref(GLenum pname, GLfloat param)
43 {
44 __GLXcontext *gc = __glXGetCurrentContext();
45 __GLXattribute * state = gc->client_state_private;
46 Display *dpy = gc->currentDpy;
47 GLuint a;
48
49 if (!dpy) return;
50
51 switch (pname) {
52 case GL_PACK_ROW_LENGTH:
53 a = (GLuint) (param + 0.5);
54 if (((GLint) a) < 0) {
55 __glXSetError(gc, GL_INVALID_VALUE);
56 return;
57 }
58 state->storePack.rowLength = a;
59 break;
60 case GL_PACK_IMAGE_HEIGHT:
61 a = (GLuint) (param + 0.5);
62 if (((GLint) a) < 0) {
63 __glXSetError(gc, GL_INVALID_VALUE);
64 return;
65 }
66 state->storePack.imageHeight = a;
67 break;
68 case GL_PACK_SKIP_ROWS:
69 a = (GLuint) (param + 0.5);
70 if (((GLint) a) < 0) {
71 __glXSetError(gc, GL_INVALID_VALUE);
72 return;
73 }
74 state->storePack.skipRows = a;
75 break;
76 case GL_PACK_SKIP_PIXELS:
77 a = (GLuint) (param + 0.5);
78 if (((GLint) a) < 0) {
79 __glXSetError(gc, GL_INVALID_VALUE);
80 return;
81 }
82 state->storePack.skipPixels = a;
83 break;
84 case GL_PACK_SKIP_IMAGES:
85 a = (GLuint) (param + 0.5);
86 if (((GLint) a) < 0) {
87 __glXSetError(gc, GL_INVALID_VALUE);
88 return;
89 }
90 state->storePack.skipImages = a;
91 break;
92 case GL_PACK_ALIGNMENT:
93 a = (GLint) (param + 0.5);
94 switch (a) {
95 case 1: case 2: case 4: case 8:
96 state->storePack.alignment = a;
97 break;
98 default:
99 __glXSetError(gc, GL_INVALID_VALUE);
100 return;
101 }
102 break;
103 case GL_PACK_SWAP_BYTES:
104 state->storePack.swapEndian = (param != 0);
105 break;
106 case GL_PACK_LSB_FIRST:
107 state->storePack.lsbFirst = (param != 0);
108 break;
109
110 case GL_UNPACK_ROW_LENGTH:
111 a = (GLuint) (param + 0.5);
112 if (((GLint) a) < 0) {
113 __glXSetError(gc, GL_INVALID_VALUE);
114 return;
115 }
116 state->storeUnpack.rowLength = a;
117 break;
118 case GL_UNPACK_IMAGE_HEIGHT:
119 a = (GLuint) (param + 0.5);
120 if (((GLint) a) < 0) {
121 __glXSetError(gc, GL_INVALID_VALUE);
122 return;
123 }
124 state->storeUnpack.imageHeight = a;
125 break;
126 case GL_UNPACK_SKIP_ROWS:
127 a = (GLuint) (param + 0.5);
128 if (((GLint) a) < 0) {
129 __glXSetError(gc, GL_INVALID_VALUE);
130 return;
131 }
132 state->storeUnpack.skipRows = a;
133 break;
134 case GL_UNPACK_SKIP_PIXELS:
135 a = (GLuint) (param + 0.5);
136 if (((GLint) a) < 0) {
137 __glXSetError(gc, GL_INVALID_VALUE);
138 return;
139 }
140 state->storeUnpack.skipPixels = a;
141 break;
142 case GL_UNPACK_SKIP_IMAGES:
143 a = (GLuint) (param + 0.5);
144 if (((GLint) a) < 0) {
145 __glXSetError(gc, GL_INVALID_VALUE);
146 return;
147 }
148 state->storeUnpack.skipImages = a;
149 break;
150 case GL_UNPACK_ALIGNMENT:
151 a = (GLint) (param + 0.5);
152 switch (a) {
153 case 1: case 2: case 4: case 8:
154 state->storeUnpack.alignment = a;
155 break;
156 default:
157 __glXSetError(gc, GL_INVALID_VALUE);
158 return;
159 }
160 break;
161 case GL_UNPACK_SWAP_BYTES:
162 state->storeUnpack.swapEndian = (param != 0);
163 break;
164 case GL_UNPACK_LSB_FIRST:
165 state->storeUnpack.lsbFirst = (param != 0);
166 break;
167 default:
168 /*
169 ** NOTE: there are currently no pixel storage commands that need to
170 ** be sent to the server. This may change in future versions
171 ** of the API, however.
172 */
173 __glXSetError(gc, GL_INVALID_ENUM);
174 break;
175 }
176 }
177
178 void __indirect_glPixelStorei(GLenum pname, GLint param)
179 {
180 __GLXcontext *gc = __glXGetCurrentContext();
181 __GLXattribute * state = gc->client_state_private;
182 Display *dpy = gc->currentDpy;
183
184 if (!dpy) return;
185
186 switch (pname) {
187 case GL_PACK_ROW_LENGTH:
188 if (param < 0) {
189 __glXSetError(gc, GL_INVALID_VALUE);
190 return;
191 }
192 state->storePack.rowLength = param;
193 break;
194 case GL_PACK_IMAGE_HEIGHT:
195 if (param < 0) {
196 __glXSetError(gc, GL_INVALID_VALUE);
197 return;
198 }
199 state->storePack.imageHeight = param;
200 break;
201 case GL_PACK_SKIP_ROWS:
202 if (param < 0) {
203 __glXSetError(gc, GL_INVALID_VALUE);
204 return;
205 }
206 state->storePack.skipRows = param;
207 break;
208 case GL_PACK_SKIP_PIXELS:
209 if (param < 0) {
210 __glXSetError(gc, GL_INVALID_VALUE);
211 return;
212 }
213 state->storePack.skipPixels = param;
214 break;
215 case GL_PACK_SKIP_IMAGES:
216 if (param < 0) {
217 __glXSetError(gc, GL_INVALID_VALUE);
218 return;
219 }
220 state->storePack.skipImages = param;
221 break;
222 case GL_PACK_ALIGNMENT:
223 switch (param) {
224 case 1: case 2: case 4: case 8:
225 state->storePack.alignment = param;
226 break;
227 default:
228 __glXSetError(gc, GL_INVALID_VALUE);
229 return;
230 }
231 break;
232 case GL_PACK_SWAP_BYTES:
233 state->storePack.swapEndian = (param != 0);
234 break;
235 case GL_PACK_LSB_FIRST:
236 state->storePack.lsbFirst = (param != 0);
237 break;
238
239 case GL_UNPACK_ROW_LENGTH:
240 if (param < 0) {
241 __glXSetError(gc, GL_INVALID_VALUE);
242 return;
243 }
244 state->storeUnpack.rowLength = param;
245 break;
246 case GL_UNPACK_IMAGE_HEIGHT:
247 if (param < 0) {
248 __glXSetError(gc, GL_INVALID_VALUE);
249 return;
250 }
251 state->storeUnpack.imageHeight = param;
252 break;
253 case GL_UNPACK_SKIP_ROWS:
254 if (param < 0) {
255 __glXSetError(gc, GL_INVALID_VALUE);
256 return;
257 }
258 state->storeUnpack.skipRows = param;
259 break;
260 case GL_UNPACK_SKIP_PIXELS:
261 if (param < 0) {
262 __glXSetError(gc, GL_INVALID_VALUE);
263 return;
264 }
265 state->storeUnpack.skipPixels = param;
266 break;
267 case GL_UNPACK_SKIP_IMAGES:
268 if (param < 0) {
269 __glXSetError(gc, GL_INVALID_VALUE);
270 return;
271 }
272 state->storeUnpack.skipImages = param;
273 break;
274 case GL_UNPACK_ALIGNMENT:
275 switch (param) {
276 case 1: case 2: case 4: case 8:
277 state->storeUnpack.alignment = param;
278 break;
279 default:
280 __glXSetError(gc, GL_INVALID_VALUE);
281 return;
282 }
283 break;
284 case GL_UNPACK_SWAP_BYTES:
285 state->storeUnpack.swapEndian = (param != 0);
286 break;
287 case GL_UNPACK_LSB_FIRST:
288 state->storeUnpack.lsbFirst = (param != 0);
289 break;
290 default:
291 /*
292 ** NOTE: there are currently no pixel storage commands that need to
293 ** be sent to the server. This may change in future versions
294 ** of the API, however.
295 */
296 __glXSetError(gc, GL_INVALID_ENUM);
297 break;
298 }
299 }