Make the transition to script-genereated GLX code easier.
[mesa.git] / src / glx / x11 / packvendpriv.h
1 /* $XFree86: xc/lib/GL/glx/packvendpriv.h,v 1.5tsi Exp $ */
2 #ifndef __GLX_packvendpriv_h__
3 #define __GLX_packvendpriv_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_VENDPRIV_BEGIN issues its own store
52 ** to req->reqType with the proper code (our extension code).
53 */
54 #define X_GLXVendpriv 0
55
56 /* Declare common variables used during a single command */
57 #define __GLX_VENDPRIV_DECLARE_VARIABLES() \
58 __GLXcontext *gc = __glXGetCurrentContext(); \
59 GLubyte *pc, *pixelHeaderPC; \
60 GLuint compsize, cmdlen; \
61 Display *dpy = gc->currentDpy; \
62 xGLXVendorPrivateReq *req
63
64 #define __GLX_VENDPRIV_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 vendor private command */
72 #define __GLX_VENDPRIV_BEGIN(glxcode, opcode,bytes) \
73 if (dpy) { \
74 (void) __glXFlushRenderBuffer(gc, pc); \
75 LockDisplay(dpy); \
76 GetReqExtra(GLXVendorPrivate,bytes,req); \
77 req->reqType = gc->majorOpcode; \
78 req->glxCode = glxcode; \
79 req->vendorCode = opcode; \
80 req->contextTag = gc->currentContextTag; \
81 pc = ((GLubyte *)(req) + sz_xGLXVendorPrivateReq)
82
83 /* End a vendor private command */
84 #define __GLX_VENDPRIV_END() \
85 UnlockDisplay(dpy); \
86 SyncHandle(); \
87 }
88
89 /* Store data to sending for a vendor private command */
90 #define __GLX_VENDPRIV_PUT_CHAR(offset,a) \
91 *((INT8 *) (pc + offset)) = a
92
93 #ifndef CRAY
94 #define __GLX_VENDPRIV_PUT_SHORT(offset,a) \
95 *((INT16 *) (pc + offset)) = a
96
97 #define __GLX_VENDPRIV_PUT_LONG(offset,a) \
98 *((INT32 *) (pc + offset)) = a
99
100 #define __GLX_VENDPRIV_PUT_FLOAT(offset,a) \
101 *((FLOAT32 *) (pc + offset)) = a
102
103 #else
104 #define __GLX_VENDPRIV_PUT_SHORT(offset,a) \
105 { GLubyte *cp = (pc+offset); \
106 int shift = (64-16) - ((int)(cp) >> (64-6)); \
107 *(int *)cp = (*(int *)cp & ~(0xffff << shift)) | ((a & 0xffff) << shift); }
108
109 #define __GLX_VENDPRIV_PUT_LONG(offset,a) \
110 { GLubyte *cp = (pc+offset); \
111 int shift = (64-32) - ((int)(cp) >> (64-6)); \
112 *(int *)cp = (*(int *)cp & ~(0xffffffff << shift)) | ((a & 0xffffffff) << shift); }
113
114 #define __GLX_VENDPRIV_PUT_FLOAT(offset,a) \
115 gl_put_float(pc + offset, a)
116 #endif
117
118 /* Read support macros */
119 #define __GLX_VENDPRIV_READ_XREPLY() \
120 (void) _XReply(dpy, (xReply*) &reply, 0, False)
121
122 #define __GLX_VENDPRIV_GET_RETVAL(a,cast) \
123 a = (cast) reply.retval
124
125 #define __GLX_VENDPRIV_GET_SIZE(a) \
126 a = (GLint) reply.size
127
128 #ifndef _CRAY
129 #define __GLX_VENDPRIV_GET_CHAR(p) \
130 *p = *(GLbyte *)&reply.pad3;
131
132 #define __GLX_VENDPRIV_GET_SHORT(p) \
133 *p = *(GLshort *)&reply.pad3;
134
135 #define __GLX_VENDPRIV_GET_LONG(p) \
136 *p = *(GLint *)&reply.pad3;
137
138 #define __GLX_VENDPRIV_GET_FLOAT(p) \
139 *p = *(GLfloat *)&reply.pad3;
140
141 #else
142 #define __GLX_VENDPRIV_GET_CHAR(p) \
143 *p = reply.pad3 >> 24;
144
145 #define __GLX_VENDPRIV_GET_SHORT(p) \
146 {int t = reply.pad3 >> 16; \
147 *p = (t & 0x8000) ? (t | ~0xffff) : (t & 0xffff);}
148
149 #define __GLX_VENDPRIV_GET_LONG(p) \
150 {int t = reply.pad3; \
151 *p = (t & 0x80000000) ? (t | ~0xffffffff) : (t & 0xffffffff);}
152
153 #define PAD3OFFSET 16
154 #define __GLX_VENDPRIV_GET_FLOAT(p) \
155 *p = gl_ntoh_float((GLubyte *)&reply + PAD3OFFSET);
156
157 #define __GLX_VENDPRIV_GET_DOUBLE(p) \
158 *p = gl_ntoh_double((GLubyte *)&reply + PAD3OFFSET);
159
160 extern float gl_ntoh_float(GLubyte *);
161 extern float gl_ntoh_double(GLubyte *);
162 #endif
163
164 #ifndef _CRAY
165
166 #ifdef __GLX_ALIGN64
167 #define __GLX_VENDPRIV_GET_DOUBLE(p) \
168 __GLX_MEM_COPY(p, &reply.pad3, 8)
169 #else
170 #define __GLX_VENDPRIV_GET_DOUBLE(p) \
171 *p = *(GLdouble *)&reply.pad3
172 #endif
173
174 #endif
175
176 /* Get an array of typed data */
177 #define __GLX_VENDPRIV_GET_VOID_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 #define __GLX_VENDPRIV_GET_CHAR_ARRAY(a,alen) \
185 { \
186 GLint slop = alen*__GLX_SIZE_INT8 & 3; \
187 _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT8); \
188 if (slop) _XEatData(dpy,4-slop); \
189 }
190
191
192 #define __GLX_VENDPRIV_GET_SHORT_ARRAY(a,alen) \
193 { \
194 GLint slop = (alen*__GLX_SIZE_INT16) & 3; \
195 _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT16); \
196 if (slop) _XEatData(dpy,4-slop); \
197 }
198
199 #define __GLX_VENDPRIV_GET_LONG_ARRAY(a,alen) \
200 _XRead(dpy,(char *)a,alen*__GLX_SIZE_INT32);
201
202 #ifndef _CRAY
203 #define __GLX_VENDPRIV_GET_FLOAT_ARRAY(a,alen) \
204 _XRead(dpy,(char *)a,alen*__GLX_SIZE_FLOAT32);
205
206 #define __GLX_VENDPRIV_GET_DOUBLE_ARRAY(a,alen) \
207 _XRead(dpy,(char *)a,alen*__GLX_SIZE_FLOAT64);
208
209 #else
210 #define __GLX_VENDPRIV_GET_FLOAT_ARRAY(a,alen) \
211 gl_get_float_array(dpy,a,alen);
212
213 #define __GLX_VENDPRIV_GET_DOUBLE_ARRAY(a,alen) \
214 gl_get_double_array(dpy, a, alen);
215
216 extern void gl_get_float_array(Display *dpy, float *a, int alen);
217 extern void gl_get_double_array(Display *dpy, double *a, int alen);
218 #endif
219
220 #endif /* !__GLX_packvendpriv_h__ */