First import
[xorg_rtime.git] / xorg-server-1.4 / hw / dmx / glxProxy / unpack.h
blob713e3aaa25f7b326fc5a0341b6e600f3b7264117
1 #ifndef __GLX_unpack_h__
2 #define __GLX_unpack_h__
4 /*
5 ** License Applicability. Except to the extent portions of this file are
6 ** made subject to an alternative license as permitted in the SGI Free
7 ** Software License B, Version 1.1 (the "License"), the contents of this
8 ** file are subject only to the provisions of the License. You may not use
9 ** this file except in compliance with the License. You may obtain a copy
10 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
11 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
12 **
13 ** http://oss.sgi.com/projects/FreeB
14 **
15 ** Note that, as provided in the License, the Software is distributed on an
16 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
17 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
18 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
19 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
20 **
21 ** Original Code. The Original Code is: OpenGL Sample Implementation,
22 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
23 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
24 ** Copyright in any portions created by third parties is as indicated
25 ** elsewhere herein. All Rights Reserved.
26 **
27 ** Additional Notice Provisions: The application programming interfaces
28 ** established by SGI in conjunction with the Original Code are The
29 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
30 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
31 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
32 ** Window System(R) (Version 1.3), released October 19, 1998. This software
33 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
34 ** published by SGI, but has not been independently verified as being
35 ** compliant with the OpenGL(R) version 1.2.1 Specification.
39 #define __GLX_PAD(s) (((s)+3) & (GLuint)~3)
42 ** Fetch the context-id out of a SingleReq request pointed to by pc.
44 #define __GLX_GET_SINGLE_CONTEXT_TAG(pc) (((xGLXSingleReq*)pc)->contextTag)
45 #define __GLX_GET_VENDPRIV_CONTEXT_TAG(pc) (((xGLXVendorPrivateReq*)pc)->contextTag)
48 ** Fetch a double from potentially unaligned memory.
50 #ifdef __GLX_ALIGN64
51 #define __GLX_MEM_COPY(dst,src,n) memcpy(dst,src,n)
52 #define __GLX_GET_DOUBLE(dst,src) __GLX_MEM_COPY(&dst,src,8)
53 #else
54 #define __GLX_GET_DOUBLE(dst,src) (dst) = *((GLdouble*)(src))
55 #endif
57 extern void __glXMemInit(void);
59 extern xGLXSingleReply __glXReply;
61 #define __GLX_BEGIN_REPLY(size) \
62 __glXReply.length = __GLX_PAD(size) >> 2; \
63 __glXReply.type = X_Reply; \
64 __glXReply.sequenceNumber = client->sequence;
66 #define __GLX_SEND_HEADER() \
67 WriteToClient( client, sz_xGLXSingleReply, (char *)&__glXReply);
69 #define __GLX_PUT_RETVAL(a) \
70 __glXReply.retval = (a);
72 #define __GLX_PUT_SIZE(a) \
73 __glXReply.size = (a);
75 #define __GLX_PUT_RENDERMODE(m) \
76 __glXReply.pad3 = (m)
79 ** Get a buffer to hold returned data, with the given alignment. If we have
80 ** to realloc, allocate size+align, in case the pointer has to be bumped for
81 ** alignment. The answerBuffer should already be aligned.
83 ** NOTE: the cast (long)res below assumes a long is large enough to hold a
84 ** pointer.
86 #define __GLX_GET_ANSWER_BUFFER(res,cl,size,align) \
87 if ((size) > sizeof(answerBuffer)) { \
88 int bump; \
89 if ((cl)->returnBufSize < (size)+(align)) { \
90 (cl)->returnBuf = (GLbyte*)Xrealloc((cl)->returnBuf, \
91 (size)+(align)); \
92 if (!(cl)->returnBuf) { \
93 return BadAlloc; \
94 } \
95 (cl)->returnBufSize = (size)+(align); \
96 } \
97 res = (char*)cl->returnBuf; \
98 bump = (long)(res) % (align); \
99 if (bump) res += (align) - (bump); \
100 } else { \
101 res = (char *)answerBuffer; \
104 #define __GLX_PUT_BYTE() \
105 *(GLbyte *)&__glXReply.pad3 = *(GLbyte *)answer
107 #define __GLX_PUT_SHORT() \
108 *(GLshort *)&__glXReply.pad3 = *(GLshort *)answer
110 #define __GLX_PUT_INT() \
111 *(GLint *)&__glXReply.pad3 = *(GLint *)answer
113 #define __GLX_PUT_FLOAT() \
114 *(GLfloat *)&__glXReply.pad3 = *(GLfloat *)answer
116 #define __GLX_PUT_DOUBLE() \
117 *(GLdouble *)&__glXReply.pad3 = *(GLdouble *)answer
119 #define __GLX_SEND_BYTE_ARRAY(len) \
120 WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT8), (char *)answer)
122 #define __GLX_SEND_SHORT_ARRAY(len) \
123 WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT16), (char *)answer)
125 #define __GLX_SEND_INT_ARRAY(len) \
126 WriteToClient(client, (len)*__GLX_SIZE_INT32, (char *)answer)
128 #define __GLX_SEND_FLOAT_ARRAY(len) \
129 WriteToClient(client, (len)*__GLX_SIZE_FLOAT32, (char *)answer)
131 #define __GLX_SEND_DOUBLE_ARRAY(len) \
132 WriteToClient(client, (len)*__GLX_SIZE_FLOAT64, (char *)answer)
135 #define __GLX_SEND_VOID_ARRAY(len) __GLX_SEND_BYTE_ARRAY(len)
136 #define __GLX_SEND_UBYTE_ARRAY(len) __GLX_SEND_BYTE_ARRAY(len)
137 #define __GLX_SEND_USHORT_ARRAY(len) __GLX_SEND_SHORT_ARRAY(len)
138 #define __GLX_SEND_UINT_ARRAY(len) __GLX_SEND_INT_ARRAY(len)
141 ** PERFORMANCE NOTE:
142 ** Machine dependent optimizations abound here; these swapping macros can
143 ** conceivably be replaced with routines that do the job faster.
145 #define __GLX_DECLARE_SWAP_VARIABLES \
146 GLbyte sw; \
147 GLbyte *swapPC; \
148 GLbyte *swapEnd
151 #define __GLX_SWAP_INT(pc) \
152 sw = ((GLbyte *)(pc))[0]; \
153 ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[3]; \
154 ((GLbyte *)(pc))[3] = sw; \
155 sw = ((GLbyte *)(pc))[1]; \
156 ((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[2]; \
157 ((GLbyte *)(pc))[2] = sw;
159 #define __GLX_SWAP_SHORT(pc) \
160 sw = ((GLbyte *)(pc))[0]; \
161 ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[1]; \
162 ((GLbyte *)(pc))[1] = sw;
164 #define __GLX_SWAP_DOUBLE(pc) \
165 sw = ((GLbyte *)(pc))[0]; \
166 ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[7]; \
167 ((GLbyte *)(pc))[7] = sw; \
168 sw = ((GLbyte *)(pc))[1]; \
169 ((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[6]; \
170 ((GLbyte *)(pc))[6] = sw; \
171 sw = ((GLbyte *)(pc))[2]; \
172 ((GLbyte *)(pc))[2] = ((GLbyte *)(pc))[5]; \
173 ((GLbyte *)(pc))[5] = sw; \
174 sw = ((GLbyte *)(pc))[3]; \
175 ((GLbyte *)(pc))[3] = ((GLbyte *)(pc))[4]; \
176 ((GLbyte *)(pc))[4] = sw;
178 #define __GLX_SWAP_FLOAT(pc) \
179 sw = ((GLbyte *)(pc))[0]; \
180 ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[3]; \
181 ((GLbyte *)(pc))[3] = sw; \
182 sw = ((GLbyte *)(pc))[1]; \
183 ((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[2]; \
184 ((GLbyte *)(pc))[2] = sw;
186 #define __GLX_SWAP_INT_ARRAY(pc, count) \
187 swapPC = ((GLbyte *)(pc)); \
188 swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_INT32;\
189 while (swapPC < swapEnd) { \
190 __GLX_SWAP_INT(swapPC); \
191 swapPC += __GLX_SIZE_INT32; \
194 #define __GLX_SWAP_SHORT_ARRAY(pc, count) \
195 swapPC = ((GLbyte *)(pc)); \
196 swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_INT16;\
197 while (swapPC < swapEnd) { \
198 __GLX_SWAP_SHORT(swapPC); \
199 swapPC += __GLX_SIZE_INT16; \
202 #define __GLX_SWAP_DOUBLE_ARRAY(pc, count) \
203 swapPC = ((GLbyte *)(pc)); \
204 swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_FLOAT64;\
205 while (swapPC < swapEnd) { \
206 __GLX_SWAP_DOUBLE(swapPC); \
207 swapPC += __GLX_SIZE_FLOAT64; \
210 #define __GLX_SWAP_FLOAT_ARRAY(pc, count) \
211 swapPC = ((GLbyte *)(pc)); \
212 swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_FLOAT32;\
213 while (swapPC < swapEnd) { \
214 __GLX_SWAP_FLOAT(swapPC); \
215 swapPC += __GLX_SIZE_FLOAT32; \
218 #define __GLX_SWAP_REPLY_HEADER() \
219 __GLX_SWAP_SHORT(&__glXReply.sequenceNumber); \
220 __GLX_SWAP_INT(&__glXReply.length);
222 #define __GLX_SWAP_REPLY_RETVAL() \
223 __GLX_SWAP_INT(&__glXReply.retval)
225 #define __GLX_SWAP_REPLY_SIZE() \
226 __GLX_SWAP_INT(&__glXReply.size)
228 #endif /* !__GLX_unpack_h__ */