1
/* $XFree86: xc/programs/Xserver/GL/glx/unpack.h,v 1.3 2001/03/21 16:29:37 dawes Exp $ */
2
#ifndef __GLX_unpack_h__
3
#define __GLX_unpack_h__
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:
14
** http://oss.sgi.com/projects/FreeB
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.
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.
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.
40
#define __GLX_PAD(s) (((s)+3) & (GLuint)~3)
43
** Fetch the context-id out of a SingleReq request pointed to by pc.
45
#define __GLX_GET_SINGLE_CONTEXT_TAG(pc) (((xGLXSingleReq*)pc)->contextTag)
46
#define __GLX_GET_VENDPRIV_CONTEXT_TAG(pc) (((xGLXVendorPrivateReq*)pc)->contextTag)
49
** Fetch a double from potentially unaligned memory.
52
#define __GLX_MEM_COPY(dst,src,n) memcpy(dst,src,n)
53
#define __GLX_GET_DOUBLE(dst,src) __GLX_MEM_COPY(&dst,src,8)
55
#define __GLX_GET_DOUBLE(dst,src) (dst) = *((GLdouble*)(src))
58
extern void __glXMemInit(void);
60
extern xGLXSingleReply __glXReply;
62
#define __GLX_BEGIN_REPLY(size) \
63
__glXReply.length = __GLX_PAD(size) >> 2; \
64
__glXReply.type = X_Reply; \
65
__glXReply.sequenceNumber = client->sequence;
67
#define __GLX_SEND_HEADER() \
68
WriteToClient( client, sz_xGLXSingleReply, (char *)&__glXReply);
70
#define __GLX_PUT_RETVAL(a) \
71
__glXReply.retval = (a);
73
#define __GLX_PUT_SIZE(a) \
74
__glXReply.size = (a);
76
#define __GLX_PUT_RENDERMODE(m) \
80
** Get a buffer to hold returned data, with the given alignment. If we have
81
** to realloc, allocate size+align, in case the pointer has to be bumped for
82
** alignment. The answerBuffer should already be aligned.
84
** NOTE: the cast (long)res below assumes a long is large enough to hold a
87
#define __GLX_GET_ANSWER_BUFFER(res,cl,size,align) \
88
if ((size) > sizeof(answerBuffer)) { \
90
if ((cl)->returnBufSize < (size)+(align)) { \
91
(cl)->returnBuf = (GLbyte*)Xrealloc((cl)->returnBuf, \
93
if (!(cl)->returnBuf) { \
96
(cl)->returnBufSize = (size)+(align); \
98
res = (char*)cl->returnBuf; \
99
bump = (long)(res) % (align); \
100
if (bump) res += (align) - (bump); \
102
res = (char *)answerBuffer; \
105
#define __GLX_PUT_BYTE() \
106
*(GLbyte *)&__glXReply.pad3 = *(GLbyte *)answer
108
#define __GLX_PUT_SHORT() \
109
*(GLshort *)&__glXReply.pad3 = *(GLshort *)answer
111
#define __GLX_PUT_INT() \
112
*(GLint *)&__glXReply.pad3 = *(GLint *)answer
114
#define __GLX_PUT_FLOAT() \
115
*(GLfloat *)&__glXReply.pad3 = *(GLfloat *)answer
117
#define __GLX_PUT_DOUBLE() \
118
*(GLdouble *)&__glXReply.pad3 = *(GLdouble *)answer
120
#define __GLX_SEND_BYTE_ARRAY(len) \
121
WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT8), (char *)answer)
123
#define __GLX_SEND_SHORT_ARRAY(len) \
124
WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT16), (char *)answer)
126
#define __GLX_SEND_INT_ARRAY(len) \
127
WriteToClient(client, (len)*__GLX_SIZE_INT32, (char *)answer)
129
#define __GLX_SEND_FLOAT_ARRAY(len) \
130
WriteToClient(client, (len)*__GLX_SIZE_FLOAT32, (char *)answer)
132
#define __GLX_SEND_DOUBLE_ARRAY(len) \
133
WriteToClient(client, (len)*__GLX_SIZE_FLOAT64, (char *)answer)
136
#define __GLX_SEND_VOID_ARRAY(len) __GLX_SEND_BYTE_ARRAY(len)
137
#define __GLX_SEND_UBYTE_ARRAY(len) __GLX_SEND_BYTE_ARRAY(len)
138
#define __GLX_SEND_USHORT_ARRAY(len) __GLX_SEND_SHORT_ARRAY(len)
139
#define __GLX_SEND_UINT_ARRAY(len) __GLX_SEND_INT_ARRAY(len)
143
** Machine dependent optimizations abound here; these swapping macros can
144
** conceivably be replaced with routines that do the job faster.
146
#define __GLX_DECLARE_SWAP_VARIABLES \
152
#define __GLX_SWAP_INT(pc) \
153
sw = ((GLbyte *)(pc))[0]; \
154
((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[3]; \
155
((GLbyte *)(pc))[3] = sw; \
156
sw = ((GLbyte *)(pc))[1]; \
157
((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[2]; \
158
((GLbyte *)(pc))[2] = sw;
160
#define __GLX_SWAP_SHORT(pc) \
161
sw = ((GLbyte *)(pc))[0]; \
162
((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[1]; \
163
((GLbyte *)(pc))[1] = sw;
165
#define __GLX_SWAP_DOUBLE(pc) \
166
sw = ((GLbyte *)(pc))[0]; \
167
((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[7]; \
168
((GLbyte *)(pc))[7] = sw; \
169
sw = ((GLbyte *)(pc))[1]; \
170
((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[6]; \
171
((GLbyte *)(pc))[6] = sw; \
172
sw = ((GLbyte *)(pc))[2]; \
173
((GLbyte *)(pc))[2] = ((GLbyte *)(pc))[5]; \
174
((GLbyte *)(pc))[5] = sw; \
175
sw = ((GLbyte *)(pc))[3]; \
176
((GLbyte *)(pc))[3] = ((GLbyte *)(pc))[4]; \
177
((GLbyte *)(pc))[4] = sw;
179
#define __GLX_SWAP_FLOAT(pc) \
180
sw = ((GLbyte *)(pc))[0]; \
181
((GLbyte *)(pc))[0] = ((GLbyte *)(pc))[3]; \
182
((GLbyte *)(pc))[3] = sw; \
183
sw = ((GLbyte *)(pc))[1]; \
184
((GLbyte *)(pc))[1] = ((GLbyte *)(pc))[2]; \
185
((GLbyte *)(pc))[2] = sw;
187
#define __GLX_SWAP_INT_ARRAY(pc, count) \
188
swapPC = ((GLbyte *)(pc)); \
189
swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_INT32;\
190
while (swapPC < swapEnd) { \
191
__GLX_SWAP_INT(swapPC); \
192
swapPC += __GLX_SIZE_INT32; \
195
#define __GLX_SWAP_SHORT_ARRAY(pc, count) \
196
swapPC = ((GLbyte *)(pc)); \
197
swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_INT16;\
198
while (swapPC < swapEnd) { \
199
__GLX_SWAP_SHORT(swapPC); \
200
swapPC += __GLX_SIZE_INT16; \
203
#define __GLX_SWAP_DOUBLE_ARRAY(pc, count) \
204
swapPC = ((GLbyte *)(pc)); \
205
swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_FLOAT64;\
206
while (swapPC < swapEnd) { \
207
__GLX_SWAP_DOUBLE(swapPC); \
208
swapPC += __GLX_SIZE_FLOAT64; \
211
#define __GLX_SWAP_FLOAT_ARRAY(pc, count) \
212
swapPC = ((GLbyte *)(pc)); \
213
swapEnd = ((GLbyte *)(pc)) + (count)*__GLX_SIZE_FLOAT32;\
214
while (swapPC < swapEnd) { \
215
__GLX_SWAP_FLOAT(swapPC); \
216
swapPC += __GLX_SIZE_FLOAT32; \
219
#define __GLX_SWAP_REPLY_HEADER() \
220
__GLX_SWAP_SHORT(&__glXReply.sequenceNumber); \
221
__GLX_SWAP_INT(&__glXReply.length);
223
#define __GLX_SWAP_REPLY_RETVAL() \
224
__GLX_SWAP_INT(&__glXReply.retval)
226
#define __GLX_SWAP_REPLY_SIZE() \
227
__GLX_SWAP_INT(&__glXReply.size)
229
#endif /* !__GLX_unpack_h__ */