1 /* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */
2 #ifndef __GLX_packsingle_h__
3 #define __GLX_packsingle_h__
6 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
7 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice including the dates of first publication and
17 * either this permission notice or a reference to
18 * http://oss.sgi.com/projects/FreeB/
19 * shall be included in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
26 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 * Except as contained in this notice, the name of Silicon Graphics, Inc.
30 * shall not be used in advertising or otherwise to promote the sale, use or
31 * other dealings in this Software without prior written authorization from
32 * Silicon Graphics, Inc.
35 #include "packrender.h"
38 ** The macros in this header convert wire protocol data types to the client
39 ** machine's native data types. The header is part of the porting layer of
40 ** the client library, and it is intended that hardware vendors will rewrite
41 ** this header to suit their own machines.
45 ** Dummy define to make the GetReqExtra macro happy. The value is not
46 ** used, but instead the code in __GLX_SINGLE_BEGIN issues its own store
47 ** to req->reqType with the proper code (our extension code).
51 /* Declare common variables used during a single command */
52 #define __GLX_SINGLE_DECLARE_VARIABLES() \
53 __GLXcontext *gc = __glXGetCurrentContext(); \
54 GLubyte *pc, *pixelHeaderPC; \
55 GLuint compsize, cmdlen; \
56 Display *dpy = gc->currentDpy; \
59 #define __GLX_SINGLE_LOAD_VARIABLES() \
61 /* Muffle compilers */ \
62 pixelHeaderPC = 0; (void)pixelHeaderPC; \
63 compsize = 0; (void)compsize; \
64 cmdlen = 0; (void)cmdlen
66 /* Start a single command */
67 #define __GLX_SINGLE_BEGIN(opcode,bytes) \
69 (void) __glXFlushRenderBuffer(gc, pc); \
71 GetReqExtra(GLXSingle,bytes,req); \
72 req->reqType = gc->majorOpcode; \
73 req->glxCode = opcode; \
74 req->contextTag = gc->currentContextTag; \
75 pc = ((GLubyte *)(req) + sz_xGLXSingleReq)
77 /* End a single command */
78 #define __GLX_SINGLE_END() \
83 /* Store data to sending for a single command */
84 #define __GLX_SINGLE_PUT_CHAR(offset,a) \
85 *((INT8 *) (pc + offset)) = a
88 #define __GLX_SINGLE_PUT_SHORT(offset,a) \
89 *((INT16 *) (pc + offset)) = a
91 #define __GLX_SINGLE_PUT_LONG(offset,a) \
92 *((INT32 *) (pc + offset)) = a
94 #define __GLX_SINGLE_PUT_FLOAT(offset,a) \
95 *((FLOAT32 *) (pc + offset)) = a
98 #define __GLX_SINGLE_PUT_SHORT(offset,a) \
99 { GLubyte *cp = (pc+offset); \
100 int shift = (64-16) - ((int)(cp) >> (64-6)); \
101 *(int *)cp = (*(int *)cp & ~(0xffff << shift)) | ((a & 0xffff) << shift); }
103 #define __GLX_SINGLE_PUT_LONG(offset,a) \
104 { GLubyte *cp = (pc+offset); \
105 int shift = (64-32) - ((int)(cp) >> (64-6)); \
106 *(int *)cp = (*(int *)cp & ~(0xffffffff << shift)) | ((a & 0xffffffff) << shift); }
108 #define __GLX_SINGLE_PUT_FLOAT(offset,a) \
109 gl_put_float(pc + offset, a)
112 /* Read support macros */
113 #define __GLX_SINGLE_READ_XREPLY() \
114 (void) _XReply(dpy, (xReply*) &reply, 0, False)
116 #define __GLX_SINGLE_GET_RETVAL(a,cast) \
117 a = (cast) reply.retval
119 #define __GLX_SINGLE_GET_SIZE(a) \
120 a = (GLint) reply.size
123 #define __GLX_SINGLE_GET_CHAR(p) \
124 *p = *(GLbyte *)&reply.pad3;
126 #define __GLX_SINGLE_GET_SHORT(p) \
127 *p = *(GLshort *)&reply.pad3;
129 #define __GLX_SINGLE_GET_LONG(p) \
130 *p = *(GLint *)&reply.pad3;
132 #define __GLX_SINGLE_GET_FLOAT(p) \
133 *p = *(GLfloat *)&reply.pad3;
136 #define __GLX_SINGLE_GET_CHAR(p) \
137 *p = reply.pad3 >> 24;
139 #define __GLX_SINGLE_GET_SHORT(p) \
140 {int t = reply.pad3 >> 16; \
141 *p = (t & 0x8000) ? (t | ~0xffff) : (t & 0xffff);}
143 #define __GLX_SINGLE_GET_LONG(p) \
144 {int t = reply.pad3; \
145 *p = (t & 0x80000000) ? (t | ~0xffffffff) : (t & 0xffffffff);}
147 #define PAD3OFFSET 16
148 #define __GLX_SINGLE_GET_FLOAT(p) \
149 *p = gl_ntoh_float((GLubyte *)&reply + PAD3OFFSET);
151 #define __GLX_SINGLE_GET_DOUBLE(p) \
152 *p = gl_ntoh_double((GLubyte *)&reply + PAD3OFFSET);
154 extern float gl_ntoh_float(GLubyte
*);
155 extern float gl_ntoh_double(GLubyte
*);
161 #define __GLX_SINGLE_GET_DOUBLE(p) \
162 __GLX_MEM_COPY(p, &reply.pad3, 8)
164 #define __GLX_SINGLE_GET_DOUBLE(p) \
165 *p = *(GLdouble *)&reply.pad3
170 /* Get an array of typed data */
171 #define __GLX_SINGLE_GET_VOID_ARRAY(a,alen) \
173 GLint slop = alen*__GLX_SIZE_INT8 & 3; \
174 _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT8); \
175 if (slop) _XEatData(dpy,4-slop); \
178 #define __GLX_SINGLE_GET_CHAR_ARRAY(a,alen) \
180 GLint slop = alen*__GLX_SIZE_INT8 & 3; \
181 _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT8); \
182 if (slop) _XEatData(dpy,4-slop); \
186 #define __GLX_SINGLE_GET_SHORT_ARRAY(a,alen) \
188 GLint slop = (alen*__GLX_SIZE_INT16) & 3; \
189 _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT16); \
190 if (slop) _XEatData(dpy,4-slop); \
193 #define __GLX_SINGLE_GET_LONG_ARRAY(a,alen) \
194 _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT32);
197 #define __GLX_SINGLE_GET_FLOAT_ARRAY(a,alen) \
198 _XRead(dpy,(char *)a,alen*__GLX_SIZE_FLOAT32);
200 #define __GLX_SINGLE_GET_DOUBLE_ARRAY(a,alen) \
201 _XRead(dpy,(char *)a,alen*__GLX_SIZE_FLOAT64);
204 #define __GLX_SINGLE_GET_FLOAT_ARRAY(a,alen) \
205 gl_get_float_array(dpy,a,alen);
207 #define __GLX_SINGLE_GET_DOUBLE_ARRAY(a,alen) \
208 gl_get_double_array(dpy, a, alen);
210 extern void gl_get_float_array(Display
* dpy
, float *a
, int alen
);
211 extern void gl_get_double_array(Display
* dpy
, double *a
, int alen
);
214 #endif /* !__GLX_packsingle_h__ */