1 | #ifndef __GLX_unpack_h__
|
---|
2 | #define __GLX_unpack_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 | #define __GLX_PAD(s) (((s)+3) & (GLuint)~3)
|
---|
35 |
|
---|
36 | /*
|
---|
37 | ** Fetch the context-id out of a SingleReq request pointed to by pc.
|
---|
38 | */
|
---|
39 | #define __GLX_GET_SINGLE_CONTEXT_TAG(pc) (((xGLXSingleReq*)pc)->contextTag)
|
---|
40 | #define __GLX_GET_VENDPRIV_CONTEXT_TAG(pc) (((xGLXVendorPrivateReq*)pc)->contextTag)
|
---|
41 |
|
---|
42 | /*
|
---|
43 | ** Fetch a double from potentially unaligned memory.
|
---|
44 | */
|
---|
45 | #ifdef __GLX_ALIGN64
|
---|
46 | #define __GLX_MEM_COPY(dst,src,n) memcpy(dst,src,n)
|
---|
47 | #define __GLX_GET_DOUBLE(dst,src) __GLX_MEM_COPY(&dst,src,8)
|
---|
48 | #else
|
---|
49 | #define __GLX_GET_DOUBLE(dst,src) (dst) = *((GLdouble*)(src))
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | extern void __glXMemInit(void);
|
---|
53 |
|
---|
54 | extern xGLXSingleReply __glXReply;
|
---|
55 |
|
---|
56 | #define __GLX_BEGIN_REPLY(size) \
|
---|
57 | __glXReply.length = __GLX_PAD(size) >> 2; \
|
---|
58 | __glXReply.type = X_Reply; \
|
---|
59 | __glXReply.sequenceNumber = client->sequence;
|
---|
60 |
|
---|
61 | #define __GLX_SEND_HEADER() \
|
---|
62 | WriteToClient( client, sz_xGLXSingleReply, (char *)&__glXReply);
|
---|
63 |
|
---|
64 | #define __GLX_PUT_RETVAL(a) \
|
---|
65 | __glXReply.retval = (a);
|
---|
66 |
|
---|
67 | #define __GLX_PUT_SIZE(a) \
|
---|
68 | __glXReply.size = (a);
|
---|
69 |
|
---|
70 | #define __GLX_PUT_RENDERMODE(m) \
|
---|
71 | __glXReply.pad3 = (m)
|
---|
72 |
|
---|
73 | /*
|
---|
74 | ** Get a buffer to hold returned data, with the given alignment. If we have
|
---|
75 | ** to realloc, allocate size+align, in case the pointer has to be bumped for
|
---|
76 | ** alignment. The answerBuffer should already be aligned.
|
---|
77 | **
|
---|
78 | ** NOTE: the cast (long)res below assumes a long is large enough to hold a
|
---|
79 | ** pointer.
|
---|
80 | */
|
---|
81 | #define __GLX_GET_ANSWER_BUFFER(res,cl,size,align) \
|
---|
82 | if ((size) > sizeof(answerBuffer)) { \
|
---|
83 | int bump; \
|
---|
84 | if ((cl)->returnBufSize < (size)+(align)) { \
|
---|
85 | (cl)->returnBuf = (GLbyte*)realloc((cl)->returnBuf, \
|
---|
86 | (size)+(align)); \
|
---|
87 | if (!(cl)->returnBuf) { \
|
---|
88 | return BadAlloc; \
|
---|
89 | } \
|
---|
90 | (cl)->returnBufSize = (size)+(align); \
|
---|
91 | } \
|
---|
92 | res = (char*)cl->returnBuf; \
|
---|
93 | bump = (long)(res) % (align); \
|
---|
94 | if (bump) res += (align) - (bump); \
|
---|
95 | } else { \
|
---|
96 | res = (char *)answerBuffer; \
|
---|
97 | }
|
---|
98 |
|
---|
99 | #define __GLX_PUT_BYTE() \
|
---|
100 | *(GLbyte *)&__glXReply.pad3 = *(GLbyte *)answer
|
---|
101 |
|
---|
102 | #define __GLX_PUT_SHORT() \
|
---|
103 | *(GLshort *)&__glXReply.pad3 = *(GLshort *)answer
|
---|
104 |
|
---|
105 | #define __GLX_PUT_INT() \
|
---|
106 | *(GLint *)&__glXReply.pad3 = *(GLint *)answer
|
---|
107 |
|
---|
108 | #define __GLX_PUT_FLOAT() \
|
---|
109 | *(GLfloat *)&__glXReply.pad3 = *(GLfloat *)answer
|
---|
110 |
|
---|
111 | #define __GLX_PUT_DOUBLE() \
|
---|
112 | *(GLdouble *)&__glXReply.pad3 = *(GLdouble *)answer
|
---|
113 |
|
---|
114 | #define __GLX_SEND_BYTE_ARRAY(len) \
|
---|
115 | WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT8), (char *)answer)
|
---|
116 |
|
---|
117 | #define __GLX_SEND_SHORT_ARRAY(len) \
|
---|
118 | WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT16), (char *)answer)
|
---|
119 |
|
---|
120 | #define __GLX_SEND_INT_ARRAY(len) \
|
---|
121 | WriteToClient(client, (len)*__GLX_SIZE_INT32, (char *)answer)
|
---|
122 |
|
---|
123 | #define __GLX_SEND_FLOAT_ARRAY(len) \
|
---|
124 | WriteToClient(client, (len)*__GLX_SIZE_FLOAT32, (char *)answer)
|
---|
125 |
|
---|
126 | #define __GLX_SEND_DOUBLE_ARRAY(len) \
|
---|
127 | WriteToClient(client, (len)*__GLX_SIZE_FLOAT64, (char *)answer)
|
---|
128 |
|
---|
129 |
|
---|
130 | #define __GLX_SEND_VOID_ARRAY(len) __GLX_SEND_BYTE_ARRAY(len)
|
---|
131 | #define __GLX_SEND_UBYTE_ARRAY(len) __GLX_SEND_BYTE_ARRAY(len)
|
---|
132 | #define __GLX_SEND_USHORT_ARRAY(len) __GLX_SEND_SHORT_ARRAY(len)
|
---|
133 | #define __GLX_SEND_UINT_ARRAY(len) __GLX_SEND_INT_ARRAY(len)
|
---|
134 |
|
---|
135 | /*
|
---|
136 | ** PERFORMANCE NOTE:
|
---|
137 | ** Machine dependent optimizations abound here; these swapping macros can
|
---|
138 | ** conceivably be replaced with routines that do the job faster.
|
---|
139 | */
|
---|
140 | #define __GLX_DECLARE_SWAP_VARIABLES \
|
---|
141 | GLbyte sw
|
---|
142 |
|
---|
143 | #define __GLX_DECLARE_SWAP_ARRAY_VARIABLES \
|
---|
144 | GLbyte *swapPC; \
|
---|
145 | GLbyte *swapEnd
|
---|
146 |
|
---|
147 |
|
---|
148 | #define __GLX_SWAP_INT(pc) \
|
---|
149 | sw = ((GLbyte *)(pc))[0]; \
|
---|
150 | ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[3]; \
|
---|
151 | ((GLbyte *)(pc))[3] = sw; \
|
---|
152 | sw = ((GLbyte *)(pc))[1]; \
|
---|
153 | ((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[2]; \
|
---|
154 | ((GLbyte *)(pc))[2] = sw;
|
---|
155 |
|
---|
156 | #define __GLX_SWAP_SHORT(pc) \
|
---|
157 | sw = ((GLbyte *)(pc))[0]; \
|
---|
158 | ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[1]; \
|
---|
159 | ((GLbyte *)(pc))[1] = sw;
|
---|
160 |
|
---|
161 | #define __GLX_SWAP_DOUBLE(pc) \
|
---|
162 | sw = ((GLbyte *)(pc))[0]; \
|
---|
163 | ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[7]; \
|
---|
164 | ((GLbyte *)(pc))[7] = sw; \
|
---|
165 | sw = ((GLbyte *)(pc))[1]; \
|
---|
166 | ((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[6]; \
|
---|
167 | ((GLbyte *)(pc))[6] = sw; \
|
---|
168 | sw = ((GLbyte *)(pc))[2]; \
|
---|
169 | ((GLbyte *)(pc))[2] = ((GLbyte *)(pc))[5]; \
|
---|
170 | ((GLbyte *)(pc))[5] = sw; \
|
---|
171 | sw = ((GLbyte *)(pc))[3]; \
|
---|
172 | ((GLbyte *)(pc))[3] = ((GLbyte *)(pc))[4]; \
|
---|
173 | ((GLbyte *)(pc))[4] = sw;
|
---|
174 |
|
---|
175 | #define __GLX_SWAP_FLOAT(pc) \
|
---|
176 | sw = ((GLbyte *)(pc))[0]; \
|
---|
177 | ((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[3]; \
|
---|
178 | ((GLbyte *)(pc))[3] = sw; \
|
---|
179 | sw = ((GLbyte *)(pc))[1]; \
|
---|
180 | ((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[2]; \
|
---|
181 | ((GLbyte *)(pc))[2] = sw;
|
---|
182 |
|
---|
183 | #define __GLX_SWAP_INT_ARRAY(pc, count) \
|
---|
184 | swapPC = ((GLbyte *)(pc)); \
|
---|
185 | swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_INT32;\
|
---|
186 | while (swapPC < swapEnd) { \
|
---|
187 | __GLX_SWAP_INT(swapPC); \
|
---|
188 | swapPC += __GLX_SIZE_INT32; \
|
---|
189 | }
|
---|
190 |
|
---|
191 | #define __GLX_SWAP_SHORT_ARRAY(pc, count) \
|
---|
192 | swapPC = ((GLbyte *)(pc)); \
|
---|
193 | swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_INT16;\
|
---|
194 | while (swapPC < swapEnd) { \
|
---|
195 | __GLX_SWAP_SHORT(swapPC); \
|
---|
196 | swapPC += __GLX_SIZE_INT16; \
|
---|
197 | }
|
---|
198 |
|
---|
199 | #define __GLX_SWAP_DOUBLE_ARRAY(pc, count) \
|
---|
200 | swapPC = ((GLbyte *)(pc)); \
|
---|
201 | swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_FLOAT64;\
|
---|
202 | while (swapPC < swapEnd) { \
|
---|
203 | __GLX_SWAP_DOUBLE(swapPC); \
|
---|
204 | swapPC += __GLX_SIZE_FLOAT64; \
|
---|
205 | }
|
---|
206 |
|
---|
207 | #define __GLX_SWAP_FLOAT_ARRAY(pc, count) \
|
---|
208 | swapPC = ((GLbyte *)(pc)); \
|
---|
209 | swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_FLOAT32;\
|
---|
210 | while (swapPC < swapEnd) { \
|
---|
211 | __GLX_SWAP_FLOAT(swapPC); \
|
---|
212 | swapPC += __GLX_SIZE_FLOAT32; \
|
---|
213 | }
|
---|
214 |
|
---|
215 | #define __GLX_SWAP_REPLY_HEADER() \
|
---|
216 | __GLX_SWAP_SHORT(&__glXReply.sequenceNumber); \
|
---|
217 | __GLX_SWAP_INT(&__glXReply.length);
|
---|
218 |
|
---|
219 | #define __GLX_SWAP_REPLY_RETVAL() \
|
---|
220 | __GLX_SWAP_INT(&__glXReply.retval)
|
---|
221 |
|
---|
222 | #define __GLX_SWAP_REPLY_SIZE() \
|
---|
223 | __GLX_SWAP_INT(&__glXReply.size)
|
---|
224 |
|
---|
225 | #endif /* !__GLX_unpack_h__ */
|
---|
226 |
|
---|
227 |
|
---|
228 |
|
---|
229 |
|
---|
230 |
|
---|