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