glx: added "glapi/" prefix to include
[mesa.git] / src / glx / x11 / packsingle.h
1 /* $XFree86: xc/lib/GL/glx/packsingle.h,v 1.5tsi Exp $ */
2 #ifndef __GLX_packsingle_h__
3 #define __GLX_packsingle_h__
4
5 /*
6 ** License Applicability. Except to the extent portions of this file are
7 ** made subject to an alternative license as permitted in the SGI Free
8 ** Software License B, Version 1.1 (the "License"), the contents of this
9 ** file are subject only to the provisions of the License. You may not use
10 ** this file except in compliance with the License. You may obtain a copy
11 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
12 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
13 **
14 ** http://oss.sgi.com/projects/FreeB
15 **
16 ** Note that, as provided in the License, the Software is distributed on an
17 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
18 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
19 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
20 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
21 **
22 ** Original Code. The Original Code is: OpenGL Sample Implementation,
23 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
24 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
25 ** Copyright in any portions created by third parties is as indicated
26 ** elsewhere herein. All Rights Reserved.
27 **
28 ** Additional Notice Provisions: The application programming interfaces
29 ** established by SGI in conjunction with the Original Code are The
30 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
31 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
32 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
33 ** Window System(R) (Version 1.3), released October 19, 1998. This software
34 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
35 ** published by SGI, but has not been independently verified as being
36 ** compliant with the OpenGL(R) version 1.2.1 Specification.
37 **
38 */
39
40 #include "packrender.h"
41
42 /*
43 ** The macros in this header convert wire protocol data types to the client
44 ** machine's native data types. The header is part of the porting layer of
45 ** the client library, and it is intended that hardware vendors will rewrite
46 ** this header to suit their own machines.
47 */
48
49 /*
50 ** Dummy define to make the GetReqExtra macro happy. The value is not
51 ** used, but instead the code in __GLX_SINGLE_BEGIN issues its own store
52 ** to req->reqType with the proper code (our extension code).
53 */
54 #define X_GLXSingle 0
55
56 /* Declare common variables used during a single command */
57 #define __GLX_SINGLE_DECLARE_VARIABLES() \
58 __GLXcontext *gc = __glXGetCurrentContext(); \
59 GLubyte *pc, *pixelHeaderPC; \
60 GLuint compsize, cmdlen; \
61 Display *dpy = gc->currentDpy; \
62 xGLXSingleReq *req
63
64 #define __GLX_SINGLE_LOAD_VARIABLES() \
65 pc = gc->pc; \
66 /* Muffle compilers */ \
67 pixelHeaderPC = 0; (void)pixelHeaderPC; \
68 compsize = 0; (void)compsize; \
69 cmdlen = 0; (void)cmdlen
70
71 /* Start a single command */
72 #define __GLX_SINGLE_BEGIN(opcode,bytes) \
73 if (dpy) { \
74 (void) __glXFlushRenderBuffer(gc, pc); \
75 LockDisplay(dpy); \
76 GetReqExtra(GLXSingle,bytes,req); \
77 req->reqType = gc->majorOpcode; \
78 req->glxCode = opcode; \
79 req->contextTag = gc->currentContextTag; \
80 pc = ((GLubyte *)(req) + sz_xGLXSingleReq)
81
82 /* End a single command */
83 #define __GLX_SINGLE_END() \
84 UnlockDisplay(dpy); \
85 SyncHandle(); \
86 }
87
88 /* Store data to sending for a single command */
89 #define __GLX_SINGLE_PUT_CHAR(offset,a) \
90 *((INT8 *) (pc + offset)) = a
91
92 #ifndef CRAY
93 #define __GLX_SINGLE_PUT_SHORT(offset,a) \
94 *((INT16 *) (pc + offset)) = a
95
96 #define __GLX_SINGLE_PUT_LONG(offset,a) \
97 *((INT32 *) (pc + offset)) = a
98
99 #define __GLX_SINGLE_PUT_FLOAT(offset,a) \
100 *((FLOAT32 *) (pc + offset)) = a
101
102 #else
103 #define __GLX_SINGLE_PUT_SHORT(offset,a) \
104 { GLubyte *cp = (pc+offset); \
105 int shift = (64-16) - ((int)(cp) >> (64-6)); \
106 *(int *)cp = (*(int *)cp & ~(0xffff << shift)) | ((a & 0xffff) << shift); }
107
108 #define __GLX_SINGLE_PUT_LONG(offset,a) \
109 { GLubyte *cp = (pc+offset); \
110 int shift = (64-32) - ((int)(cp) >> (64-6)); \
111 *(int *)cp = (*(int *)cp & ~(0xffffffff << shift)) | ((a & 0xffffffff) << shift); }
112
113 #define __GLX_SINGLE_PUT_FLOAT(offset,a) \
114 gl_put_float(pc + offset, a)
115 #endif
116
117 /* Read support macros */
118 #define __GLX_SINGLE_READ_XREPLY() \
119 (void) _XReply(dpy, (xReply*) &reply, 0, False)
120
121 #define __GLX_SINGLE_GET_RETVAL(a,cast) \
122 a = (cast) reply.retval
123
124 #define __GLX_SINGLE_GET_SIZE(a) \
125 a = (GLint) reply.size
126
127 #ifndef _CRAY
128 #define __GLX_SINGLE_GET_CHAR(p) \
129 *p = *(GLbyte *)&reply.pad3;
130
131 #define __GLX_SINGLE_GET_SHORT(p) \
132 *p = *(GLshort *)&reply.pad3;
133
134 #define __GLX_SINGLE_GET_LONG(p) \
135 *p = *(GLint *)&reply.pad3;
136
137 #define __GLX_SINGLE_GET_FLOAT(p) \
138 *p = *(GLfloat *)&reply.pad3;
139
140 #else
141 #define __GLX_SINGLE_GET_CHAR(p) \
142 *p = reply.pad3 >> 24;
143
144 #define __GLX_SINGLE_GET_SHORT(p) \
145 {int t = reply.pad3 >> 16; \
146 *p = (t & 0x8000) ? (t | ~0xffff) : (t & 0xffff);}
147
148 #define __GLX_SINGLE_GET_LONG(p) \
149 {int t = reply.pad3; \
150 *p = (t & 0x80000000) ? (t | ~0xffffffff) : (t & 0xffffffff);}
151
152 #define PAD3OFFSET 16
153 #define __GLX_SINGLE_GET_FLOAT(p) \
154 *p = gl_ntoh_float((GLubyte *)&reply + PAD3OFFSET);
155
156 #define __GLX_SINGLE_GET_DOUBLE(p) \
157 *p = gl_ntoh_double((GLubyte *)&reply + PAD3OFFSET);
158
159 extern float gl_ntoh_float(GLubyte *);
160 extern float gl_ntoh_double(GLubyte *);
161 #endif
162
163 #ifndef _CRAY
164
165 #ifdef __GLX_ALIGN64
166 #define __GLX_SINGLE_GET_DOUBLE(p) \
167 __GLX_MEM_COPY(p, &reply.pad3, 8)
168 #else
169 #define __GLX_SINGLE_GET_DOUBLE(p) \
170 *p = *(GLdouble *)&reply.pad3
171 #endif
172
173 #endif
174
175 /* Get an array of typed data */
176 #define __GLX_SINGLE_GET_VOID_ARRAY(a,alen) \
177 { \
178 GLint slop = alen*__GLX_SIZE_INT8 & 3; \
179 _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT8); \
180 if (slop) _XEatData(dpy,4-slop); \
181 }
182
183 #define __GLX_SINGLE_GET_CHAR_ARRAY(a,alen) \
184 { \
185 GLint slop = alen*__GLX_SIZE_INT8 & 3; \
186 _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT8); \
187 if (slop) _XEatData(dpy,4-slop); \
188 }
189
190
191 #define __GLX_SINGLE_GET_SHORT_ARRAY(a,alen) \
192 { \
193 GLint slop = (alen*__GLX_SIZE_INT16) & 3; \
194 _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT16);\
195 if (slop) _XEatData(dpy,4-slop); \
196 }
197
198 #define __GLX_SINGLE_GET_LONG_ARRAY(a,alen) \
199 _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT32);
200
201 #ifndef _CRAY
202 #define __GLX_SINGLE_GET_FLOAT_ARRAY(a,alen) \
203 _XRead(dpy,(char *)a,alen*__GLX_SIZE_FLOAT32);
204
205 #define __GLX_SINGLE_GET_DOUBLE_ARRAY(a,alen) \
206 _XRead(dpy,(char *)a,alen*__GLX_SIZE_FLOAT64);
207
208 #else
209 #define __GLX_SINGLE_GET_FLOAT_ARRAY(a,alen) \
210 gl_get_float_array(dpy,a,alen);
211
212 #define __GLX_SINGLE_GET_DOUBLE_ARRAY(a,alen) \
213 gl_get_double_array(dpy, a, alen);
214
215 extern void gl_get_float_array(Display *dpy, float *a, int alen);
216 extern void gl_get_double_array(Display *dpy, double *a, int alen);
217 #endif
218
219 #endif /* !__GLX_packsingle_h__ */