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