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