Fix builds with compilers other than gcc 3.0 & newer
[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 "glheader.h"
38 #include "glxclient.h"
39 #include "indirect.h"
40
41 /**
42 * Send glPixelStore command to the server
43 *
44 * \param gc Current GLX context
45 * \param sop Either \c X_GLsop_PixelStoref or \c X_GLsop_PixelStorei
46 * \param pname Selector of which pixel parameter is to be set.
47 * \param param Value that \c pname is set to.
48 *
49 * \sa __indirect_glPixelStorei, __indirect_glPixelStoref
50 */
51 static void
52 send_PixelStore( __GLXcontext * gc, unsigned sop, GLenum pname,
53 const void * param )
54 {
55 Display * const dpy = gc->currentDpy;
56 const GLuint cmdlen = 8;
57 if (__builtin_expect(dpy != NULL, 1)) {
58 GLubyte const * pc = __glXSetupSingleRequest(gc, sop, cmdlen);
59 (void) memcpy((void *)(pc + 0), (void *)(&pname), 4);
60 (void) memcpy((void *)(pc + 4), param, 4);
61 UnlockDisplay(dpy); SyncHandle();
62 }
63 return;
64 }
65
66 /*
67 ** Specify parameters that control the storage format of pixel arrays.
68 */
69 void __indirect_glPixelStoref(GLenum pname, GLfloat param)
70 {
71 __GLXcontext *gc = __glXGetCurrentContext();
72 __GLXattribute * state = gc->client_state_private;
73 Display *dpy = gc->currentDpy;
74 GLuint a;
75
76 if (!dpy) return;
77
78 switch (pname) {
79 case GL_PACK_ROW_LENGTH:
80 a = (GLuint) (param + 0.5);
81 if (((GLint) a) < 0) {
82 __glXSetError(gc, GL_INVALID_VALUE);
83 return;
84 }
85 state->storePack.rowLength = a;
86 break;
87 case GL_PACK_IMAGE_HEIGHT:
88 a = (GLuint) (param + 0.5);
89 if (((GLint) a) < 0) {
90 __glXSetError(gc, GL_INVALID_VALUE);
91 return;
92 }
93 state->storePack.imageHeight = a;
94 break;
95 case GL_PACK_SKIP_ROWS:
96 a = (GLuint) (param + 0.5);
97 if (((GLint) a) < 0) {
98 __glXSetError(gc, GL_INVALID_VALUE);
99 return;
100 }
101 state->storePack.skipRows = a;
102 break;
103 case GL_PACK_SKIP_PIXELS:
104 a = (GLuint) (param + 0.5);
105 if (((GLint) a) < 0) {
106 __glXSetError(gc, GL_INVALID_VALUE);
107 return;
108 }
109 state->storePack.skipPixels = a;
110 break;
111 case GL_PACK_SKIP_IMAGES:
112 a = (GLuint) (param + 0.5);
113 if (((GLint) a) < 0) {
114 __glXSetError(gc, GL_INVALID_VALUE);
115 return;
116 }
117 state->storePack.skipImages = a;
118 break;
119 case GL_PACK_ALIGNMENT:
120 a = (GLint) (param + 0.5);
121 switch (a) {
122 case 1: case 2: case 4: case 8:
123 state->storePack.alignment = a;
124 break;
125 default:
126 __glXSetError(gc, GL_INVALID_VALUE);
127 return;
128 }
129 break;
130 case GL_PACK_SWAP_BYTES:
131 state->storePack.swapEndian = (param != 0);
132 break;
133 case GL_PACK_LSB_FIRST:
134 state->storePack.lsbFirst = (param != 0);
135 break;
136
137 case GL_UNPACK_ROW_LENGTH:
138 a = (GLuint) (param + 0.5);
139 if (((GLint) a) < 0) {
140 __glXSetError(gc, GL_INVALID_VALUE);
141 return;
142 }
143 state->storeUnpack.rowLength = a;
144 break;
145 case GL_UNPACK_IMAGE_HEIGHT:
146 a = (GLuint) (param + 0.5);
147 if (((GLint) a) < 0) {
148 __glXSetError(gc, GL_INVALID_VALUE);
149 return;
150 }
151 state->storeUnpack.imageHeight = a;
152 break;
153 case GL_UNPACK_SKIP_ROWS:
154 a = (GLuint) (param + 0.5);
155 if (((GLint) a) < 0) {
156 __glXSetError(gc, GL_INVALID_VALUE);
157 return;
158 }
159 state->storeUnpack.skipRows = a;
160 break;
161 case GL_UNPACK_SKIP_PIXELS:
162 a = (GLuint) (param + 0.5);
163 if (((GLint) a) < 0) {
164 __glXSetError(gc, GL_INVALID_VALUE);
165 return;
166 }
167 state->storeUnpack.skipPixels = a;
168 break;
169 case GL_UNPACK_SKIP_IMAGES:
170 a = (GLuint) (param + 0.5);
171 if (((GLint) a) < 0) {
172 __glXSetError(gc, GL_INVALID_VALUE);
173 return;
174 }
175 state->storeUnpack.skipImages = a;
176 break;
177 case GL_UNPACK_ALIGNMENT:
178 a = (GLint) (param + 0.5);
179 switch (a) {
180 case 1: case 2: case 4: case 8:
181 state->storeUnpack.alignment = a;
182 break;
183 default:
184 __glXSetError(gc, GL_INVALID_VALUE);
185 return;
186 }
187 break;
188 case GL_UNPACK_SWAP_BYTES:
189 state->storeUnpack.swapEndian = (param != 0);
190 break;
191 case GL_UNPACK_LSB_FIRST:
192 state->storeUnpack.lsbFirst = (param != 0);
193 break;
194
195 /* Group all of the pixel store modes that need to be sent to the
196 * server here. Care must be used to only send modes to the server that
197 * won't affect the size of the data sent to or received from the
198 * server. GL_PACK_INVERT_MESA is safe in this respect, but other,
199 * future modes may not be.
200 */
201 case GL_PACK_INVERT_MESA:
202 send_PixelStore( gc, X_GLsop_PixelStoref, pname, & param );
203 break;
204
205 default:
206 __glXSetError(gc, GL_INVALID_ENUM);
207 break;
208 }
209 }
210
211 void __indirect_glPixelStorei(GLenum pname, GLint param)
212 {
213 __GLXcontext *gc = __glXGetCurrentContext();
214 __GLXattribute * state = gc->client_state_private;
215 Display *dpy = gc->currentDpy;
216
217 if (!dpy) return;
218
219 switch (pname) {
220 case GL_PACK_ROW_LENGTH:
221 if (param < 0) {
222 __glXSetError(gc, GL_INVALID_VALUE);
223 return;
224 }
225 state->storePack.rowLength = param;
226 break;
227 case GL_PACK_IMAGE_HEIGHT:
228 if (param < 0) {
229 __glXSetError(gc, GL_INVALID_VALUE);
230 return;
231 }
232 state->storePack.imageHeight = param;
233 break;
234 case GL_PACK_SKIP_ROWS:
235 if (param < 0) {
236 __glXSetError(gc, GL_INVALID_VALUE);
237 return;
238 }
239 state->storePack.skipRows = param;
240 break;
241 case GL_PACK_SKIP_PIXELS:
242 if (param < 0) {
243 __glXSetError(gc, GL_INVALID_VALUE);
244 return;
245 }
246 state->storePack.skipPixels = param;
247 break;
248 case GL_PACK_SKIP_IMAGES:
249 if (param < 0) {
250 __glXSetError(gc, GL_INVALID_VALUE);
251 return;
252 }
253 state->storePack.skipImages = param;
254 break;
255 case GL_PACK_ALIGNMENT:
256 switch (param) {
257 case 1: case 2: case 4: case 8:
258 state->storePack.alignment = param;
259 break;
260 default:
261 __glXSetError(gc, GL_INVALID_VALUE);
262 return;
263 }
264 break;
265 case GL_PACK_SWAP_BYTES:
266 state->storePack.swapEndian = (param != 0);
267 break;
268 case GL_PACK_LSB_FIRST:
269 state->storePack.lsbFirst = (param != 0);
270 break;
271
272 case GL_UNPACK_ROW_LENGTH:
273 if (param < 0) {
274 __glXSetError(gc, GL_INVALID_VALUE);
275 return;
276 }
277 state->storeUnpack.rowLength = param;
278 break;
279 case GL_UNPACK_IMAGE_HEIGHT:
280 if (param < 0) {
281 __glXSetError(gc, GL_INVALID_VALUE);
282 return;
283 }
284 state->storeUnpack.imageHeight = param;
285 break;
286 case GL_UNPACK_SKIP_ROWS:
287 if (param < 0) {
288 __glXSetError(gc, GL_INVALID_VALUE);
289 return;
290 }
291 state->storeUnpack.skipRows = param;
292 break;
293 case GL_UNPACK_SKIP_PIXELS:
294 if (param < 0) {
295 __glXSetError(gc, GL_INVALID_VALUE);
296 return;
297 }
298 state->storeUnpack.skipPixels = param;
299 break;
300 case GL_UNPACK_SKIP_IMAGES:
301 if (param < 0) {
302 __glXSetError(gc, GL_INVALID_VALUE);
303 return;
304 }
305 state->storeUnpack.skipImages = param;
306 break;
307 case GL_UNPACK_ALIGNMENT:
308 switch (param) {
309 case 1: case 2: case 4: case 8:
310 state->storeUnpack.alignment = param;
311 break;
312 default:
313 __glXSetError(gc, GL_INVALID_VALUE);
314 return;
315 }
316 break;
317 case GL_UNPACK_SWAP_BYTES:
318 state->storeUnpack.swapEndian = (param != 0);
319 break;
320 case GL_UNPACK_LSB_FIRST:
321 state->storeUnpack.lsbFirst = (param != 0);
322 break;
323
324 /* Group all of the pixel store modes that need to be sent to the
325 * server here. Care must be used to only send modes to the server that
326 * won't affect the size of the data sent to or received from the
327 * server. GL_PACK_INVERT_MESA is safe in this respect, but other,
328 * future modes may not be.
329 */
330 case GL_PACK_INVERT_MESA:
331 send_PixelStore( gc, X_GLsop_PixelStorei, pname, & param );
332 break;
333
334 default:
335 __glXSetError(gc, GL_INVALID_ENUM);
336 break;
337 }
338 }