82f82515a66ae97963b6dca3838f94a109dc208f
[mesa.git] / src / glx / x11 / packrender.h
1 /* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */
2 #ifndef __GLX_packrender_h__
3 #define __GLX_packrender_h__
4
5 /*
6 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
7 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice including the dates of first publication and
17 * either this permission notice or a reference to
18 * http://oss.sgi.com/projects/FreeB/
19 * shall be included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
26 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * SOFTWARE.
28 *
29 * Except as contained in this notice, the name of Silicon Graphics, Inc.
30 * shall not be used in advertising or otherwise to promote the sale, use or
31 * other dealings in this Software without prior written authorization from
32 * Silicon Graphics, Inc.
33 */
34
35 #include "glxclient.h"
36
37 /*
38 ** The macros in this header convert the client machine's native data types to
39 ** wire protocol data types. The header is part of the porting layer of the
40 ** client library, and it is intended that hardware vendors will rewrite this
41 ** header to suit their own machines.
42 */
43
44 /*
45 ** Pad a count of bytes to the nearest multiple of 4. The X protocol
46 ** transfers data in 4 byte quantities, so this macro is used to
47 ** insure the right amount of data being sent.
48 */
49 #define __GLX_PAD(a) (((a)+3) & ~3)
50
51 /*
52 ** Network size parameters
53 */
54 #define sz_double 8
55
56 /* Setup for all commands */
57 #define __GLX_DECLARE_VARIABLES() \
58 __GLXcontext *gc; \
59 GLubyte *pc, *pixelHeaderPC; \
60 GLuint compsize, cmdlen
61
62 #define __GLX_LOAD_VARIABLES() \
63 gc = __glXGetCurrentContext(); \
64 pc = gc->pc; \
65 /* Muffle compilers */ \
66 cmdlen = 0; (void)cmdlen; \
67 compsize = 0; (void)compsize; \
68 pixelHeaderPC = 0; (void)pixelHeaderPC
69
70 /*
71 ** Variable sized command support macro. This macro is used by calls
72 ** that are potentially larger than __GLX_SMALL_RENDER_CMD_SIZE.
73 ** Because of their size, they may not automatically fit in the buffer.
74 ** If the buffer can't hold the command then it is flushed so that
75 ** the command will fit in the next buffer.
76 */
77 #define __GLX_BEGIN_VARIABLE(opcode,size) \
78 if (pc + (size) > gc->bufEnd) { \
79 pc = __glXFlushRenderBuffer(gc, pc); \
80 } \
81 __GLX_PUT_SHORT(0,size); \
82 __GLX_PUT_SHORT(2,opcode)
83
84 #define __GLX_BEGIN_VARIABLE_LARGE(opcode,size) \
85 pc = __glXFlushRenderBuffer(gc, pc); \
86 __GLX_PUT_LONG(0,size); \
87 __GLX_PUT_LONG(4,opcode)
88
89 #define __GLX_BEGIN_VARIABLE_WITH_PIXEL(opcode,size) \
90 if (pc + (size) > gc->bufEnd) { \
91 pc = __glXFlushRenderBuffer(gc, pc); \
92 } \
93 __GLX_PUT_SHORT(0,size); \
94 __GLX_PUT_SHORT(2,opcode); \
95 pc += __GLX_RENDER_HDR_SIZE; \
96 pixelHeaderPC = pc; \
97 pc += __GLX_PIXEL_HDR_SIZE
98
99 #define __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(opcode,size) \
100 pc = __glXFlushRenderBuffer(gc, pc); \
101 __GLX_PUT_LONG(0,size); \
102 __GLX_PUT_LONG(4,opcode); \
103 pc += __GLX_RENDER_LARGE_HDR_SIZE; \
104 pixelHeaderPC = pc; \
105 pc += __GLX_PIXEL_HDR_SIZE
106
107 #define __GLX_BEGIN_VARIABLE_WITH_PIXEL_3D(opcode,size) \
108 if (pc + (size) > gc->bufEnd) { \
109 pc = __glXFlushRenderBuffer(gc, pc); \
110 } \
111 __GLX_PUT_SHORT(0,size); \
112 __GLX_PUT_SHORT(2,opcode); \
113 pc += __GLX_RENDER_HDR_SIZE; \
114 pixelHeaderPC = pc; \
115 pc += __GLX_PIXEL_3D_HDR_SIZE
116
117 #define __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL_3D(opcode,size) \
118 pc = __glXFlushRenderBuffer(gc, pc); \
119 __GLX_PUT_LONG(0,size); \
120 __GLX_PUT_LONG(4,opcode); \
121 pc += __GLX_RENDER_LARGE_HDR_SIZE; \
122 pixelHeaderPC = pc; \
123 pc += __GLX_PIXEL_3D_HDR_SIZE
124
125 /*
126 ** Fixed size command support macro. This macro is used by calls that
127 ** are never larger than __GLX_SMALL_RENDER_CMD_SIZE. Because they
128 ** always fit in the buffer, and because the buffer promises to
129 ** maintain enough room for them, we don't need to check for space
130 ** before doing the storage work.
131 */
132 #define __GLX_BEGIN(opcode,size) \
133 __GLX_PUT_SHORT(0,size); \
134 __GLX_PUT_SHORT(2,opcode)
135
136 /*
137 ** Finish a rendering command by advancing the pc. If the pc is now past
138 ** the limit pointer then there is no longer room for a
139 ** __GLX_SMALL_RENDER_CMD_SIZE sized command, which will break the
140 ** assumptions present in the __GLX_BEGIN macro. In this case the
141 ** rendering buffer is flushed out into the X protocol stream (which may
142 ** or may not do I/O).
143 */
144 #define __GLX_END(size) \
145 pc += size; \
146 if (pc > gc->limit) { \
147 (void) __glXFlushRenderBuffer(gc, pc); \
148 } else { \
149 gc->pc = pc; \
150 }
151
152 /* Array copy macros */
153 #define __GLX_MEM_COPY(dest,src,bytes) \
154 if (src && dest) \
155 memcpy(dest, src, bytes)
156
157 /* Single item copy macros */
158 #define __GLX_PUT_CHAR(offset,a) \
159 *((INT8 *) (pc + offset)) = a
160
161 #ifndef _CRAY
162 #define __GLX_PUT_SHORT(offset,a) \
163 *((INT16 *) (pc + offset)) = a
164
165 #define __GLX_PUT_LONG(offset,a) \
166 *((INT32 *) (pc + offset)) = a
167
168 #define __GLX_PUT_FLOAT(offset,a) \
169 *((FLOAT32 *) (pc + offset)) = a
170
171 #else
172 #define __GLX_PUT_SHORT(offset,a) \
173 { GLubyte *cp = (pc+offset); \
174 int shift = (64-16) - ((int)(cp) >> (64-6)); \
175 *(int *)cp = (*(int *)cp & ~(0xffff << shift)) | ((a & 0xffff) << shift); }
176
177 #define __GLX_PUT_LONG(offset,a) \
178 { GLubyte *cp = (pc+offset); \
179 int shift = (64-32) - ((int)(cp) >> (64-6)); \
180 *(int *)cp = (*(int *)cp & ~(0xffffffff << shift)) | ((a & 0xffffffff) << shift); }
181
182 #define __GLX_PUT_FLOAT(offset,a) \
183 gl_put_float((pc + offset),a)
184
185 #define __GLX_PUT_DOUBLE(offset,a) \
186 gl_put_double(pc + offset, a)
187
188 extern void gl_put_float(/*GLubyte *, struct cray_single*/);
189 extern void gl_put_double(/*GLubyte *, struct cray_double*/);
190 #endif
191
192 #ifndef _CRAY
193
194 #ifdef __GLX_ALIGN64
195 /*
196 ** This can certainly be done better for a particular machine
197 ** architecture!
198 */
199 #define __GLX_PUT_DOUBLE(offset,a) \
200 __GLX_MEM_COPY(pc + offset, &a, 8)
201 #else
202 #define __GLX_PUT_DOUBLE(offset,a) \
203 *((FLOAT64 *) (pc + offset)) = a
204 #endif
205
206 #endif
207
208 #define __GLX_PUT_CHAR_ARRAY(offset,a,alen) \
209 __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT8)
210
211 #ifndef _CRAY
212 #define __GLX_PUT_SHORT_ARRAY(offset,a,alen) \
213 __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT16)
214
215 #define __GLX_PUT_LONG_ARRAY(offset,a,alen) \
216 __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT32)
217
218 #define __GLX_PUT_FLOAT_ARRAY(offset,a,alen) \
219 __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_FLOAT32)
220
221 #define __GLX_PUT_DOUBLE_ARRAY(offset,a,alen) \
222 __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_FLOAT64)
223
224 #else
225 #define __GLX_PUT_SHORT_ARRAY(offset,a,alen) \
226 gl_put_short_array((GLubyte *)(pc + offset), a, alen * __GLX_SIZE_INT16)
227
228 #define __GLX_PUT_LONG_ARRAY(offset,a,alen) \
229 gl_put_long_array((GLubyte *)(pc + offset), (long *)a, alen * __GLX_SIZE_INT32)
230
231 #define __GLX_PUT_FLOAT_ARRAY(offset,a,alen) \
232 gl_put_float_array((GLubyte *)(pc + offset), (float *)a, alen * __GLX_SIZE_FLOAT32)
233
234 #define __GLX_PUT_DOUBLE_ARRAY(offset,a,alen) \
235 gl_put_double_array((GLubyte *)(pc + offset), (double *)a, alen * __GLX_SIZE_FLOAT64)
236
237 extern gl_put_short_array (GLubyte *, short *, int);
238 extern gl_put_long_array (GLubyte *, long *, int);
239 extern gl_put_float_array (GLubyte *, float *, int);
240 extern gl_put_double_array (GLubyte *, double *, int);
241
242 #endif /* _CRAY */
243
244 #endif /* !__GLX_packrender_h__ */