Make the transition to script-genereated GLX code easier.
[mesa.git] / src / glx / x11 / singlepix.c
1 /* $XFree86: xc/lib/GL/glx/singlepix.c,v 1.3 2001/03/21 16:04:39 dawes 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 "packsingle.h"
38
39 void __indirect_glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
40 GLenum format, GLenum type, GLvoid *pixels)
41 {
42 __GLX_SINGLE_DECLARE_VARIABLES();
43 const __GLXattribute * state;
44 xGLXReadPixelsReply reply;
45 GLubyte *buf;
46
47 if (!dpy) return;
48 __GLX_SINGLE_LOAD_VARIABLES();
49 state = gc->client_state_private;
50
51 /* Send request */
52 __GLX_SINGLE_BEGIN(X_GLsop_ReadPixels,__GLX_PAD(26));
53 __GLX_SINGLE_PUT_LONG(0,x);
54 __GLX_SINGLE_PUT_LONG(4,y);
55 __GLX_SINGLE_PUT_LONG(8,width);
56 __GLX_SINGLE_PUT_LONG(12,height);
57 __GLX_SINGLE_PUT_LONG(16,format);
58 __GLX_SINGLE_PUT_LONG(20,type);
59 __GLX_SINGLE_PUT_CHAR(24,state->storePack.swapEndian);
60 __GLX_SINGLE_PUT_CHAR(25,GL_FALSE);
61 __GLX_SINGLE_READ_XREPLY();
62 compsize = reply.length << 2;
63
64 if (compsize != 0) {
65 /* Allocate a holding buffer to transform the data from */
66 buf = (GLubyte*) Xmalloc(compsize);
67 if (!buf) {
68 /* Throw data away */
69 _XEatData(dpy, compsize);
70 __glXSetError(gc, GL_OUT_OF_MEMORY);
71 } else {
72 /*
73 ** Fetch data into holding buffer. Apply pixel store pack modes
74 ** to put data back into client memory
75 */
76 __GLX_SINGLE_GET_CHAR_ARRAY(buf,compsize);
77 __glEmptyImage(gc, 2, width, height, 1, format, type, buf, pixels);
78 Xfree((char*) buf);
79 }
80 } else {
81 /*
82 ** GL error occurred; don't modify user's buffer.
83 */
84 }
85 __GLX_SINGLE_END();
86 }
87
88 void __indirect_glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type,
89 GLvoid *texels)
90 {
91 __GLX_SINGLE_DECLARE_VARIABLES();
92 const __GLXattribute * state;
93 xGLXGetTexImageReply reply;
94 GLubyte *buf;
95
96 if (!dpy) return;
97 __GLX_SINGLE_LOAD_VARIABLES();
98 state = gc->client_state_private;
99
100 /* Send request */
101 __GLX_SINGLE_BEGIN(X_GLsop_GetTexImage,__GLX_PAD(17));
102 __GLX_SINGLE_PUT_LONG(0,target);
103 __GLX_SINGLE_PUT_LONG(4,level);
104 __GLX_SINGLE_PUT_LONG(8,format);
105 __GLX_SINGLE_PUT_LONG(12,type);
106 __GLX_SINGLE_PUT_CHAR(16,state->storePack.swapEndian);
107 __GLX_SINGLE_READ_XREPLY();
108 compsize = reply.length << 2;
109
110 if (compsize != 0) {
111 /* Allocate a holding buffer to transform the data from */
112 buf = (GLubyte*) Xmalloc(compsize);
113 if (!buf) {
114 /* Throw data away */
115 _XEatData(dpy, compsize);
116 __glXSetError(gc, GL_OUT_OF_MEMORY);
117 } else {
118 GLint width, height, depth;
119
120 /*
121 ** Fetch data into holding buffer. Apply pixel store pack modes
122 ** to put data back into client memory
123 */
124 width = reply.width;
125 height = reply.height;
126 depth = reply.depth;
127 __GLX_SINGLE_GET_CHAR_ARRAY(buf,compsize);
128 __glEmptyImage(gc, 2, width, height, depth, format, type, buf,
129 texels);
130 Xfree((char*) buf);
131 }
132 } else {
133 /*
134 ** GL error occured, don't modify user's buffer.
135 */
136 }
137 __GLX_SINGLE_END();
138 }
139
140 void __indirect_glGetPolygonStipple(GLubyte *mask)
141 {
142 __GLX_SINGLE_DECLARE_VARIABLES();
143 xGLXSingleReply reply;
144 GLubyte buf[128];
145
146 if (!dpy) return;
147
148 __GLX_SINGLE_LOAD_VARIABLES();
149 __GLX_SINGLE_BEGIN(X_GLsop_GetPolygonStipple,__GLX_PAD(1));
150 __GLX_SINGLE_PUT_CHAR(0,GL_FALSE);
151 __GLX_SINGLE_READ_XREPLY();
152 if (reply.length == 32) {
153 __GLX_SINGLE_GET_CHAR_ARRAY(buf,128);
154 __glEmptyImage(gc, 2, 32, 32, 1, GL_COLOR_INDEX, GL_BITMAP, buf, mask);
155 }
156 __GLX_SINGLE_END();
157 }
158
159 void __indirect_glGetColorTable(GLenum target, GLenum format, GLenum type, GLvoid *table)
160 {
161 __GLX_SINGLE_DECLARE_VARIABLES();
162 const __GLXattribute * state;
163 xGLXGetColorTableReply reply;
164 GLubyte *buf;
165
166 if (!dpy) return;
167 __GLX_SINGLE_LOAD_VARIABLES();
168 state = gc->client_state_private;
169
170 /* Send request */
171 __GLX_SINGLE_BEGIN(X_GLsop_GetColorTable,__GLX_PAD(13));
172 __GLX_SINGLE_PUT_LONG(0,(long)target);
173 __GLX_SINGLE_PUT_LONG(4,(long)format);
174 __GLX_SINGLE_PUT_LONG(8,(long)type);
175 __GLX_SINGLE_PUT_CHAR(12,state->storePack.swapEndian);
176 __GLX_SINGLE_READ_XREPLY();
177 compsize = (long)reply.length << 2;
178
179 if (compsize != 0) {
180 /* Allocate a holding buffer to transform the data from */
181 buf = (GLubyte*)Xmalloc(compsize);
182 if (!buf) {
183 /* Throw data away */
184 _XEatData(dpy, compsize);
185 __glXSetError(gc, GL_OUT_OF_MEMORY);
186 } else {
187 GLint width;
188
189 /*
190 ** Fetch data into holding buffer. Apply pixel store pack modes
191 ** to put data back into client memory
192 */
193 width = (int)reply.width;
194 __GLX_SINGLE_GET_CHAR_ARRAY(((char*)buf),(long)compsize);
195 __glEmptyImage(gc, 1, width, 1, 1, format, type, buf, table);
196 Xfree((char*) buf);
197 }
198 } else {
199 /*
200 ** GL error occured, don't modify user's buffer.
201 */
202 }
203 __GLX_SINGLE_END();
204 }
205
206 void __indirect_glGetConvolutionFilter(GLenum target, GLenum format, GLenum type,
207 GLvoid *image)
208 {
209 __GLX_SINGLE_DECLARE_VARIABLES();
210 const __GLXattribute * state;
211 xGLXGetConvolutionFilterReply reply;
212 GLubyte *buf;
213
214 if (!dpy) return;
215 __GLX_SINGLE_LOAD_VARIABLES();
216 state = gc->client_state_private;
217
218 /* Send request */
219 __GLX_SINGLE_BEGIN(X_GLsop_GetConvolutionFilter, __GLX_PAD(13));
220 __GLX_SINGLE_PUT_LONG(0,target);
221 __GLX_SINGLE_PUT_LONG(4,format);
222 __GLX_SINGLE_PUT_LONG(8,type);
223 __GLX_SINGLE_PUT_CHAR(12,state->storePack.swapEndian);
224 __GLX_SINGLE_READ_XREPLY();
225 compsize = reply.length << 2;
226
227 if (compsize != 0) {
228 /* Allocate a holding buffer to transform the data from */
229 buf = (GLubyte*) Xmalloc(compsize);
230 if (!buf) {
231 /* Throw data away */
232 _XEatData(dpy, compsize);
233 __glXSetError(gc, GL_OUT_OF_MEMORY);
234 } else {
235 GLint width, height;
236
237 /*
238 ** Fetch data into holding buffer. Apply pixel store pack modes
239 ** to put data back into client memory
240 */
241 width = reply.width;
242 height = reply.height;
243 __GLX_SINGLE_GET_CHAR_ARRAY(((char*)buf),compsize);
244 __glEmptyImage(gc, 2, width, height, 1, format, type, buf, image);
245 Xfree((char*) buf);
246 }
247 } else {
248 /*
249 ** GL error occured, don't modify user's buffer.
250 */
251 }
252 __GLX_SINGLE_END();
253 }
254
255 void __indirect_glGetSeparableFilter(GLenum target, GLenum format, GLenum type,
256 GLvoid *row, GLvoid *column, GLvoid *span)
257 {
258 __GLX_SINGLE_DECLARE_VARIABLES();
259 const __GLXattribute * state;
260 xGLXGetSeparableFilterReply reply;
261 GLubyte *rowBuf, *colBuf;
262
263 if (!dpy) return;
264 __GLX_SINGLE_LOAD_VARIABLES();
265 state = gc->client_state_private;
266
267 /* Send request */
268 __GLX_SINGLE_BEGIN(X_GLsop_GetSeparableFilter, __GLX_PAD(13));
269 __GLX_SINGLE_PUT_LONG(0,target);
270 __GLX_SINGLE_PUT_LONG(4,format);
271 __GLX_SINGLE_PUT_LONG(8,type);
272 __GLX_SINGLE_PUT_CHAR(12,state->storePack.swapEndian);
273 __GLX_SINGLE_READ_XREPLY();
274 compsize = reply.length << 2;
275
276 if (compsize != 0) {
277 GLint width, height;
278 GLint widthsize, heightsize;
279
280 width = reply.width;
281 height = reply.height;
282
283 widthsize = __glImageSize(width,1,1,format, type);
284 heightsize = __glImageSize(height,1,1,format, type);
285
286 /* Allocate a holding buffer to transform the data from */
287 rowBuf = (GLubyte*) Xmalloc(widthsize);
288 if (!rowBuf) {
289 /* Throw data away */
290 _XEatData(dpy, compsize);
291 __glXSetError(gc, GL_OUT_OF_MEMORY);
292 UnlockDisplay(dpy);
293 SyncHandle();
294 return;
295 } else {
296 __GLX_SINGLE_GET_CHAR_ARRAY(((char*)rowBuf),widthsize);
297 __glEmptyImage(gc, 1, width, 1, 1, format, type, rowBuf, row);
298 Xfree((char*) rowBuf);
299 }
300 colBuf = (GLubyte*) Xmalloc(heightsize);
301 if (!colBuf) {
302 /* Throw data away */
303 _XEatData(dpy, compsize - __GLX_PAD(widthsize));
304 __glXSetError(gc, GL_OUT_OF_MEMORY);
305 UnlockDisplay(dpy);
306 SyncHandle();
307 return;
308 } else {
309 __GLX_SINGLE_GET_CHAR_ARRAY(((char*)colBuf),heightsize);
310 __glEmptyImage(gc, 1, height, 1, 1, format, type, colBuf, column);
311 Xfree((char*) colBuf);
312 }
313 } else {
314 /*
315 ** don't modify user's buffer.
316 */
317 }
318 __GLX_SINGLE_END();
319
320 }
321
322 void __indirect_glGetHistogram(GLenum target, GLboolean reset, GLenum format,
323 GLenum type, GLvoid *values)
324 {
325 __GLX_SINGLE_DECLARE_VARIABLES();
326 const __GLXattribute * state;
327 xGLXGetHistogramReply reply;
328 GLubyte *buf;
329
330 if (!dpy) return;
331 __GLX_SINGLE_LOAD_VARIABLES();
332 state = gc->client_state_private;
333
334 /* Send request */
335 __GLX_SINGLE_BEGIN(X_GLsop_GetHistogram,__GLX_PAD(14));
336 __GLX_SINGLE_PUT_LONG(0,(long)target);
337 __GLX_SINGLE_PUT_LONG(4,(long)format);
338 __GLX_SINGLE_PUT_LONG(8,(long)type);
339 __GLX_SINGLE_PUT_CHAR(12,state->storePack.swapEndian);
340 __GLX_SINGLE_PUT_CHAR(13,reset);
341 __GLX_SINGLE_READ_XREPLY();
342 compsize = (long)reply.length << 2;
343
344 if (compsize != 0) {
345 /* Allocate a holding buffer to transform the data from */
346 buf = (GLubyte*)Xmalloc(compsize);
347 if (!buf) {
348 /* Throw data away */
349 _XEatData(dpy, compsize);
350 __glXSetError(gc, GL_OUT_OF_MEMORY);
351 } else {
352 GLint width;
353
354 /*
355 ** Fetch data into holding buffer. Apply pixel store pack modes
356 ** to put data back into client memory
357 */
358 width = (int)reply.width;
359 __GLX_SINGLE_GET_CHAR_ARRAY(((char*)buf),(long)compsize);
360 __glEmptyImage(gc, 1, width, 1, 1, format, type, buf, values);
361 Xfree((char*) buf);
362 }
363 } else {
364 /*
365 ** GL error occured, don't modify user's buffer.
366 */
367 }
368 __GLX_SINGLE_END();
369 }
370
371 void __indirect_glGetMinmax(GLenum target, GLboolean reset, GLenum format, GLenum type,
372 GLvoid *values)
373 {
374 __GLX_SINGLE_DECLARE_VARIABLES();
375 const __GLXattribute * state;
376 xGLXGetMinmaxReply reply;
377 GLubyte *buf;
378
379 if (!dpy) return;
380 __GLX_SINGLE_LOAD_VARIABLES();
381 state = gc->client_state_private;
382
383 /* Send request */
384 __GLX_SINGLE_BEGIN(X_GLsop_GetMinmax,__GLX_PAD(14));
385 __GLX_SINGLE_PUT_LONG(0,(long)target);
386 __GLX_SINGLE_PUT_LONG(4,(long)format);
387 __GLX_SINGLE_PUT_LONG(8,(long)type);
388 __GLX_SINGLE_PUT_CHAR(12,state->storePack.swapEndian);
389 __GLX_SINGLE_PUT_CHAR(13,reset);
390 __GLX_SINGLE_READ_XREPLY();
391 compsize = (long)reply.length << 2;
392
393 if (compsize != 0) {
394 /* Allocate a holding buffer to transform the data from */
395 buf = (GLubyte*)Xmalloc(compsize);
396 if (!buf) {
397 /* Throw data away */
398 _XEatData(dpy, compsize);
399 __glXSetError(gc, GL_OUT_OF_MEMORY);
400 } else {
401 /*
402 ** Fetch data into holding buffer. Apply pixel store pack modes
403 ** to put data back into client memory
404 */
405 __GLX_SINGLE_GET_CHAR_ARRAY(((char*)buf),(long)compsize);
406 __glEmptyImage(gc, 1, 2, 1, 1, format, type, buf, values);
407 Xfree((char*) buf);
408 }
409 } else {
410 /*
411 ** GL error occured, don't modify user's buffer.
412 */
413 }
414 __GLX_SINGLE_END();
415 }