1848b8605Smrg#ifndef __GLX_packrender_h__
2848b8605Smrg#define __GLX_packrender_h__
3848b8605Smrg
4848b8605Smrg/*
5848b8605Smrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
6848b8605Smrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
7848b8605Smrg *
8848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
9848b8605Smrg * copy of this software and associated documentation files (the "Software"),
10848b8605Smrg * to deal in the Software without restriction, including without limitation
11848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the
13848b8605Smrg * Software is furnished to do so, subject to the following conditions:
14848b8605Smrg *
15848b8605Smrg * The above copyright notice including the dates of first publication and
16848b8605Smrg * either this permission notice or a reference to
17848b8605Smrg * http://oss.sgi.com/projects/FreeB/
18848b8605Smrg * shall be included in all copies or substantial portions of the Software.
19848b8605Smrg *
20848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23848b8605Smrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24848b8605Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
25848b8605Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26848b8605Smrg * SOFTWARE.
27848b8605Smrg *
28848b8605Smrg * Except as contained in this notice, the name of Silicon Graphics, Inc.
29848b8605Smrg * shall not be used in advertising or otherwise to promote the sale, use or
30848b8605Smrg * other dealings in this Software without prior written authorization from
31848b8605Smrg * Silicon Graphics, Inc.
32848b8605Smrg */
33848b8605Smrg
34848b8605Smrg#include "glxclient.h"
35848b8605Smrg
36848b8605Smrg/*
37848b8605Smrg** The macros in this header convert the client machine's native data types to
38848b8605Smrg** wire protocol data types.  The header is part of the porting layer of the
39848b8605Smrg** client library, and it is intended that hardware vendors will rewrite this
40848b8605Smrg** header to suit their own machines.
41848b8605Smrg*/
42848b8605Smrg
43848b8605Smrg/*
44848b8605Smrg** Pad a count of bytes to the nearest multiple of 4.  The X protocol
45848b8605Smrg** transfers data in 4 byte quantities, so this macro is used to
46848b8605Smrg** insure the right amount of data being sent.
47848b8605Smrg*/
48848b8605Smrg#define __GLX_PAD(a) (((a)+3) & ~3)
49848b8605Smrg
50848b8605Smrg/*
51848b8605Smrg** Network size parameters
52848b8605Smrg*/
53848b8605Smrg#define sz_double 8
54848b8605Smrg
55848b8605Smrg/* Setup for all commands */
56848b8605Smrg#define __GLX_DECLARE_VARIABLES()               \
57848b8605Smrg   struct glx_context *gc;                            \
58848b8605Smrg   GLubyte *pc, *pixelHeaderPC;                 \
59848b8605Smrg   GLuint compsize, cmdlen
60848b8605Smrg
61848b8605Smrg#define __GLX_LOAD_VARIABLES()     \
62848b8605Smrg   gc = __glXGetCurrentContext();  \
63848b8605Smrg   pc = gc->pc;                    \
64848b8605Smrg   /* Muffle compilers */                  \
65848b8605Smrg   cmdlen = 0;         (void)cmdlen;          \
66848b8605Smrg   compsize = 0;       (void)compsize;        \
67848b8605Smrg   pixelHeaderPC = 0;  (void)pixelHeaderPC
68848b8605Smrg
69848b8605Smrg/*
70848b8605Smrg** Variable sized command support macro.  This macro is used by calls
71848b8605Smrg** that are potentially larger than __GLX_SMALL_RENDER_CMD_SIZE.
72848b8605Smrg** Because of their size, they may not automatically fit in the buffer.
73848b8605Smrg** If the buffer can't hold the command then it is flushed so that
74848b8605Smrg** the command will fit in the next buffer.
75848b8605Smrg*/
76848b8605Smrg#define __GLX_BEGIN_VARIABLE(opcode,size)       \
77848b8605Smrg   if (pc + (size) > gc->bufEnd) {              \
78848b8605Smrg      pc = __glXFlushRenderBuffer(gc, pc);      \
79848b8605Smrg   }                                            \
80848b8605Smrg   __GLX_PUT_SHORT(0,size);                     \
81848b8605Smrg   __GLX_PUT_SHORT(2,opcode)
82848b8605Smrg
83848b8605Smrg#define __GLX_BEGIN_VARIABLE_LARGE(opcode,size) \
84848b8605Smrg   pc = __glXFlushRenderBuffer(gc, pc);         \
85848b8605Smrg   __GLX_PUT_LONG(0,size);                      \
86848b8605Smrg   __GLX_PUT_LONG(4,opcode)
87848b8605Smrg
88848b8605Smrg#define __GLX_BEGIN_VARIABLE_WITH_PIXEL(opcode,size)  \
89848b8605Smrg   if (pc + (size) > gc->bufEnd) {                    \
90848b8605Smrg      pc = __glXFlushRenderBuffer(gc, pc);            \
91848b8605Smrg   }                                                  \
92848b8605Smrg   __GLX_PUT_SHORT(0,size);                           \
93848b8605Smrg   __GLX_PUT_SHORT(2,opcode);                         \
94848b8605Smrg   pc += __GLX_RENDER_HDR_SIZE;                       \
95848b8605Smrg   pixelHeaderPC = pc;                                \
96848b8605Smrg   pc += __GLX_PIXEL_HDR_SIZE
97848b8605Smrg
98848b8605Smrg#define __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(opcode,size)  \
99848b8605Smrg   pc = __glXFlushRenderBuffer(gc, pc);                     \
100848b8605Smrg   __GLX_PUT_LONG(0,size);                                  \
101848b8605Smrg   __GLX_PUT_LONG(4,opcode);                                \
102848b8605Smrg   pc += __GLX_RENDER_LARGE_HDR_SIZE;                       \
103848b8605Smrg   pixelHeaderPC = pc;                                      \
104848b8605Smrg   pc += __GLX_PIXEL_HDR_SIZE
105848b8605Smrg
106848b8605Smrg#define __GLX_BEGIN_VARIABLE_WITH_PIXEL_3D(opcode,size)  \
107848b8605Smrg   if (pc + (size) > gc->bufEnd) {                       \
108848b8605Smrg      pc = __glXFlushRenderBuffer(gc, pc);               \
109848b8605Smrg   }                                                     \
110848b8605Smrg   __GLX_PUT_SHORT(0,size);                              \
111848b8605Smrg   __GLX_PUT_SHORT(2,opcode);                            \
112848b8605Smrg   pc += __GLX_RENDER_HDR_SIZE;                          \
113848b8605Smrg   pixelHeaderPC = pc;                                   \
114848b8605Smrg   pc += __GLX_PIXEL_3D_HDR_SIZE
115848b8605Smrg
116848b8605Smrg#define __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL_3D(opcode,size)  \
117848b8605Smrg   pc = __glXFlushRenderBuffer(gc, pc);                        \
118848b8605Smrg   __GLX_PUT_LONG(0,size);                                     \
119848b8605Smrg   __GLX_PUT_LONG(4,opcode);                                   \
120848b8605Smrg   pc += __GLX_RENDER_LARGE_HDR_SIZE;                          \
121848b8605Smrg   pixelHeaderPC = pc;                                         \
122848b8605Smrg   pc += __GLX_PIXEL_3D_HDR_SIZE
123848b8605Smrg
124848b8605Smrg/*
125848b8605Smrg** Fixed size command support macro.  This macro is used by calls that
126848b8605Smrg** are never larger than __GLX_SMALL_RENDER_CMD_SIZE.  Because they
127848b8605Smrg** always fit in the buffer, and because the buffer promises to
128848b8605Smrg** maintain enough room for them, we don't need to check for space
129848b8605Smrg** before doing the storage work.
130848b8605Smrg*/
131848b8605Smrg#define __GLX_BEGIN(opcode,size) \
132848b8605Smrg   __GLX_PUT_SHORT(0,size);      \
133848b8605Smrg   __GLX_PUT_SHORT(2,opcode)
134848b8605Smrg
135848b8605Smrg/*
136848b8605Smrg** Finish a rendering command by advancing the pc.  If the pc is now past
137848b8605Smrg** the limit pointer then there is no longer room for a
138848b8605Smrg** __GLX_SMALL_RENDER_CMD_SIZE sized command, which will break the
139848b8605Smrg** assumptions present in the __GLX_BEGIN macro.  In this case the
140848b8605Smrg** rendering buffer is flushed out into the X protocol stream (which may
141848b8605Smrg** or may not do I/O).
142848b8605Smrg*/
143848b8605Smrg#define __GLX_END(size)           \
144848b8605Smrg   pc += size;                       \
145848b8605Smrg   if (pc > gc->limit) {                  \
146848b8605Smrg      (void) __glXFlushRenderBuffer(gc, pc);    \
147848b8605Smrg   } else {                                     \
148848b8605Smrg      gc->pc = pc;                              \
149848b8605Smrg   }
150848b8605Smrg
151848b8605Smrg/* Array copy macros */
152848b8605Smrg#define __GLX_MEM_COPY(dest,src,bytes)          \
153848b8605Smrg   if (src && dest)                             \
154848b8605Smrg      memcpy(dest, src, bytes)
155848b8605Smrg
156848b8605Smrg/* Single item copy macros */
157848b8605Smrg#define __GLX_PUT_CHAR(offset,a)                \
158b8e80941Smrg   do {                                         \
159b8e80941Smrg      int8_t __tmp = (a);                       \
160b8e80941Smrg      memcpy((pc + (offset)), &__tmp, 1);       \
161b8e80941Smrg   } while (0)
162848b8605Smrg
163848b8605Smrg#define __GLX_PUT_SHORT(offset,a)               \
164b8e80941Smrg   do {                                         \
165b8e80941Smrg      int16_t __tmp = (a);                      \
166b8e80941Smrg      memcpy((pc + (offset)), &__tmp, 2);       \
167b8e80941Smrg   } while (0)
168848b8605Smrg
169848b8605Smrg#define __GLX_PUT_LONG(offset,a)                \
170b8e80941Smrg   do {                                         \
171b8e80941Smrg      int32_t __tmp = (a);                      \
172b8e80941Smrg      memcpy((pc + (offset)), &__tmp, 4);       \
173b8e80941Smrg   } while (0)
174848b8605Smrg
175848b8605Smrg#define __GLX_PUT_FLOAT(offset,a)               \
176b8e80941Smrg   do {                                         \
177b8e80941Smrg      float __tmp = (a);                        \
178b8e80941Smrg      memcpy((pc + (offset)), &__tmp, 4);       \
179b8e80941Smrg   } while (0)
180848b8605Smrg
181848b8605Smrg#define __GLX_PUT_DOUBLE(offset,a)              \
182b8e80941Smrg   do {                                         \
183b8e80941Smrg      double __tmp = (a);                       \
184b8e80941Smrg      memcpy((pc + (offset)), &__tmp, 8);       \
185b8e80941Smrg   } while (0)
186848b8605Smrg
187848b8605Smrg#define __GLX_PUT_CHAR_ARRAY(offset,a,alen)                 \
188848b8605Smrg   __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT8)
189848b8605Smrg
190848b8605Smrg#define __GLX_PUT_SHORT_ARRAY(offset,a,alen)                \
191848b8605Smrg   __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT16)
192848b8605Smrg
193848b8605Smrg#define __GLX_PUT_LONG_ARRAY(offset,a,alen)                 \
194848b8605Smrg   __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT32)
195848b8605Smrg
196848b8605Smrg#define __GLX_PUT_FLOAT_ARRAY(offset,a,alen)                   \
197848b8605Smrg   __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_FLOAT32)
198848b8605Smrg
199848b8605Smrg#define __GLX_PUT_DOUBLE_ARRAY(offset,a,alen)                  \
200848b8605Smrg   __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_FLOAT64)
201848b8605Smrg
202848b8605Smrg
203848b8605Smrg#endif /* !__GLX_packrender_h__ */
204