Import the GLX client side library, formerly from xc/lib/GL/glx. Build it
[mesa.git] / src / glx / x11 / packrender.h
1 /* $XFree86: xc/lib/GL/glx/packrender.h,v 1.7tsi Exp $ */
2 #ifndef __GLX_packrender_h__
3 #define __GLX_packrender_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 #define NEED_GL_FUNCS_WRAPPED
41 #include "glxclient.h"
42
43 /*
44 ** The macros in this header convert the client machine's native data types to
45 ** wire protocol data types. The header is part of the porting layer of the
46 ** client library, and it is intended that hardware vendors will rewrite this
47 ** header to suit their own machines.
48 */
49
50 /*
51 ** Pad a count of bytes to the nearest multiple of 4. The X protocol
52 ** transfers data in 4 byte quantities, so this macro is used to
53 ** insure the right amount of data being sent.
54 */
55 #define __GLX_PAD(a) (((a)+3) & ~3)
56
57 /*
58 ** Network size parameters
59 */
60 #define sz_double 8
61
62 /* Setup for all commands */
63 #define __GLX_DECLARE_VARIABLES() \
64 __GLXcontext *gc; \
65 GLubyte *pc, *pixelHeaderPC; \
66 GLuint compsize, cmdlen
67
68 #define __GLX_LOAD_VARIABLES() \
69 gc = __glXGetCurrentContext(); \
70 pc = gc->pc; \
71 /* Muffle compilers */ \
72 cmdlen = 0; (void)cmdlen; \
73 compsize = 0; (void)compsize; \
74 pixelHeaderPC = 0; (void)pixelHeaderPC
75
76 /*
77 ** Variable sized command support macro. This macro is used by calls
78 ** that are potentially larger than __GLX_SMALL_RENDER_CMD_SIZE.
79 ** Because of their size, they may not automatically fit in the buffer.
80 ** If the buffer can't hold the command then it is flushed so that
81 ** the command will fit in the next buffer.
82 */
83 #define __GLX_BEGIN_VARIABLE(opcode,size) \
84 if (pc + (size) > gc->bufEnd) { \
85 pc = __glXFlushRenderBuffer(gc, pc); \
86 } \
87 __GLX_PUT_SHORT(0,size); \
88 __GLX_PUT_SHORT(2,opcode)
89
90 #define __GLX_BEGIN_VARIABLE_LARGE(opcode,size) \
91 pc = __glXFlushRenderBuffer(gc, pc); \
92 __GLX_PUT_LONG(0,size); \
93 __GLX_PUT_LONG(4,opcode)
94
95 #define __GLX_BEGIN_VARIABLE_WITH_PIXEL(opcode,size) \
96 if (pc + (size) > gc->bufEnd) { \
97 pc = __glXFlushRenderBuffer(gc, pc); \
98 } \
99 __GLX_PUT_SHORT(0,size); \
100 __GLX_PUT_SHORT(2,opcode); \
101 pc += __GLX_RENDER_HDR_SIZE; \
102 pixelHeaderPC = pc; \
103 pc += __GLX_PIXEL_HDR_SIZE
104
105 #define __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(opcode,size) \
106 pc = __glXFlushRenderBuffer(gc, pc); \
107 __GLX_PUT_LONG(0,size); \
108 __GLX_PUT_LONG(4,opcode); \
109 pc += __GLX_RENDER_LARGE_HDR_SIZE; \
110 pixelHeaderPC = pc; \
111 pc += __GLX_PIXEL_HDR_SIZE
112
113 #define __GLX_BEGIN_VARIABLE_WITH_PIXEL_3D(opcode,size) \
114 if (pc + (size) > gc->bufEnd) { \
115 pc = __glXFlushRenderBuffer(gc, pc); \
116 } \
117 __GLX_PUT_SHORT(0,size); \
118 __GLX_PUT_SHORT(2,opcode); \
119 pc += __GLX_RENDER_HDR_SIZE; \
120 pixelHeaderPC = pc; \
121 pc += __GLX_PIXEL_3D_HDR_SIZE
122
123 #define __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL_3D(opcode,size) \
124 pc = __glXFlushRenderBuffer(gc, pc); \
125 __GLX_PUT_LONG(0,size); \
126 __GLX_PUT_LONG(4,opcode); \
127 pc += __GLX_RENDER_LARGE_HDR_SIZE; \
128 pixelHeaderPC = pc; \
129 pc += __GLX_PIXEL_3D_HDR_SIZE
130
131 /*
132 ** Fixed size command support macro. This macro is used by calls that
133 ** are never larger than __GLX_SMALL_RENDER_CMD_SIZE. Because they
134 ** always fit in the buffer, and because the buffer promises to
135 ** maintain enough room for them, we don't need to check for space
136 ** before doing the storage work.
137 */
138 #define __GLX_BEGIN(opcode,size) \
139 __GLX_PUT_SHORT(0,size); \
140 __GLX_PUT_SHORT(2,opcode)
141
142 /*
143 ** Finish a rendering command by advancing the pc. If the pc is now past
144 ** the limit pointer then there is no longer room for a
145 ** __GLX_SMALL_RENDER_CMD_SIZE sized command, which will break the
146 ** assumptions present in the __GLX_BEGIN macro. In this case the
147 ** rendering buffer is flushed out into the X protocol stream (which may
148 ** or may not do I/O).
149 */
150 #define __GLX_END(size) \
151 pc += size; \
152 if (pc > gc->limit) { \
153 (void) __glXFlushRenderBuffer(gc, pc); \
154 } else { \
155 gc->pc = pc; \
156 }
157
158 /* Array copy macros */
159 #define __GLX_MEM_COPY(dest,src,bytes) \
160 if (src && dest) \
161 memcpy(dest, src, bytes)
162
163 /* Single item copy macros */
164 #define __GLX_PUT_CHAR(offset,a) \
165 *((INT8 *) (pc + offset)) = a
166
167 #ifndef _CRAY
168 #define __GLX_PUT_SHORT(offset,a) \
169 *((INT16 *) (pc + offset)) = a
170
171 #define __GLX_PUT_LONG(offset,a) \
172 *((INT32 *) (pc + offset)) = a
173
174 #define __GLX_PUT_FLOAT(offset,a) \
175 *((FLOAT32 *) (pc + offset)) = a
176
177 #else
178 #define __GLX_PUT_SHORT(offset,a) \
179 { GLubyte *cp = (pc+offset); \
180 int shift = (64-16) - ((int)(cp) >> (64-6)); \
181 *(int *)cp = (*(int *)cp & ~(0xffff << shift)) | ((a & 0xffff) << shift); }
182
183 #define __GLX_PUT_LONG(offset,a) \
184 { GLubyte *cp = (pc+offset); \
185 int shift = (64-32) - ((int)(cp) >> (64-6)); \
186 *(int *)cp = (*(int *)cp & ~(0xffffffff << shift)) | ((a & 0xffffffff) << shift); }
187
188 #define __GLX_PUT_FLOAT(offset,a) \
189 gl_put_float((pc + offset),a)
190
191 #define __GLX_PUT_DOUBLE(offset,a) \
192 gl_put_double(pc + offset, a)
193
194 extern void gl_put_float(/*GLubyte *, struct cray_single*/);
195 extern void gl_put_double(/*GLubyte *, struct cray_double*/);
196 #endif
197
198 #ifndef _CRAY
199
200 #ifdef __GLX_ALIGN64
201 /*
202 ** This can certainly be done better for a particular machine
203 ** architecture!
204 */
205 #define __GLX_PUT_DOUBLE(offset,a) \
206 __GLX_MEM_COPY(pc + offset, &a, 8)
207 #else
208 #define __GLX_PUT_DOUBLE(offset,a) \
209 *((FLOAT64 *) (pc + offset)) = a
210 #endif
211
212 #endif
213
214 #define __GLX_PUT_CHAR_ARRAY(offset,a,alen) \
215 __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT8)
216
217 #ifndef _CRAY
218 #define __GLX_PUT_SHORT_ARRAY(offset,a,alen) \
219 __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT16)
220
221 #define __GLX_PUT_LONG_ARRAY(offset,a,alen) \
222 __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT32)
223
224 #define __GLX_PUT_FLOAT_ARRAY(offset,a,alen) \
225 __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_FLOAT32)
226
227 #define __GLX_PUT_DOUBLE_ARRAY(offset,a,alen) \
228 __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_FLOAT64)
229
230 #else
231 #define __GLX_PUT_SHORT_ARRAY(offset,a,alen) \
232 gl_put_short_array((GLubyte *)(pc + offset), a, alen * __GLX_SIZE_INT16)
233
234 #define __GLX_PUT_LONG_ARRAY(offset,a,alen) \
235 gl_put_long_array((GLubyte *)(pc + offset), (long *)a, alen * __GLX_SIZE_INT32)
236
237 #define __GLX_PUT_FLOAT_ARRAY(offset,a,alen) \
238 gl_put_float_array((GLubyte *)(pc + offset), (float *)a, alen * __GLX_SIZE_FLOAT32)
239
240 #define __GLX_PUT_DOUBLE_ARRAY(offset,a,alen) \
241 gl_put_double_array((GLubyte *)(pc + offset), (double *)a, alen * __GLX_SIZE_FLOAT64)
242
243 extern gl_put_short_array (GLubyte *, short *, int);
244 extern gl_put_long_array (GLubyte *, long *, int);
245 extern gl_put_float_array (GLubyte *, float *, int);
246 extern gl_put_double_array (GLubyte *, double *, int);
247
248 #endif /* _CRAY */
249
250 #endif /* !__GLX_packrender_h__ */