packrender.h revision 848b8605
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) \ 158848b8605Smrg *((INT8 *) (pc + offset)) = a 159848b8605Smrg 160848b8605Smrg#ifndef _CRAY 161848b8605Smrg#define __GLX_PUT_SHORT(offset,a) \ 162848b8605Smrg *((INT16 *) (pc + offset)) = a 163848b8605Smrg 164848b8605Smrg#define __GLX_PUT_LONG(offset,a) \ 165848b8605Smrg *((INT32 *) (pc + offset)) = a 166848b8605Smrg 167848b8605Smrg#define __GLX_PUT_FLOAT(offset,a) \ 168848b8605Smrg *((FLOAT32 *) (pc + offset)) = a 169848b8605Smrg 170848b8605Smrg#else 171848b8605Smrg#define __GLX_PUT_SHORT(offset,a) \ 172848b8605Smrg { GLubyte *cp = (pc+offset); \ 173848b8605Smrg int shift = (64-16) - ((int)(cp) >> (64-6)); \ 174848b8605Smrg *(int *)cp = (*(int *)cp & ~(0xffff << shift)) | ((a & 0xffff) << shift); } 175848b8605Smrg 176848b8605Smrg#define __GLX_PUT_LONG(offset,a) \ 177848b8605Smrg { GLubyte *cp = (pc+offset); \ 178848b8605Smrg int shift = (64-32) - ((int)(cp) >> (64-6)); \ 179848b8605Smrg *(int *)cp = (*(int *)cp & ~(0xffffffff << shift)) | ((a & 0xffffffff) << shift); } 180848b8605Smrg 181848b8605Smrg#define __GLX_PUT_FLOAT(offset,a) \ 182848b8605Smrg gl_put_float((pc + offset),a) 183848b8605Smrg 184848b8605Smrg#define __GLX_PUT_DOUBLE(offset,a) \ 185848b8605Smrg gl_put_double(pc + offset, a) 186848b8605Smrg 187848b8605Smrgextern void gl_put_float( /*GLubyte *, struct cray_single */ ); 188848b8605Smrgextern void gl_put_double( /*GLubyte *, struct cray_double */ ); 189848b8605Smrg#endif 190848b8605Smrg 191848b8605Smrg#ifndef _CRAY 192848b8605Smrg 193848b8605Smrg#ifdef __GLX_ALIGN64 194848b8605Smrg/* 195848b8605Smrg** This can certainly be done better for a particular machine 196848b8605Smrg** architecture! 197848b8605Smrg*/ 198848b8605Smrg#define __GLX_PUT_DOUBLE(offset,a) \ 199848b8605Smrg __GLX_MEM_COPY(pc + offset, &a, 8) 200848b8605Smrg#else 201848b8605Smrg#define __GLX_PUT_DOUBLE(offset,a) \ 202848b8605Smrg *((FLOAT64 *) (pc + offset)) = a 203848b8605Smrg#endif 204848b8605Smrg 205848b8605Smrg#endif 206848b8605Smrg 207848b8605Smrg#define __GLX_PUT_CHAR_ARRAY(offset,a,alen) \ 208848b8605Smrg __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT8) 209848b8605Smrg 210848b8605Smrg#ifndef _CRAY 211848b8605Smrg#define __GLX_PUT_SHORT_ARRAY(offset,a,alen) \ 212848b8605Smrg __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT16) 213848b8605Smrg 214848b8605Smrg#define __GLX_PUT_LONG_ARRAY(offset,a,alen) \ 215848b8605Smrg __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_INT32) 216848b8605Smrg 217848b8605Smrg#define __GLX_PUT_FLOAT_ARRAY(offset,a,alen) \ 218848b8605Smrg __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_FLOAT32) 219848b8605Smrg 220848b8605Smrg#define __GLX_PUT_DOUBLE_ARRAY(offset,a,alen) \ 221848b8605Smrg __GLX_MEM_COPY(pc + offset, a, alen * __GLX_SIZE_FLOAT64) 222848b8605Smrg 223848b8605Smrg#else 224848b8605Smrg#define __GLX_PUT_SHORT_ARRAY(offset,a,alen) \ 225848b8605Smrg gl_put_short_array((GLubyte *)(pc + offset), a, alen * __GLX_SIZE_INT16) 226848b8605Smrg 227848b8605Smrg#define __GLX_PUT_LONG_ARRAY(offset,a,alen) \ 228848b8605Smrg gl_put_long_array((GLubyte *)(pc + offset), (long *)a, alen * __GLX_SIZE_INT32) 229848b8605Smrg 230848b8605Smrg#define __GLX_PUT_FLOAT_ARRAY(offset,a,alen) \ 231848b8605Smrg gl_put_float_array((GLubyte *)(pc + offset), (float *)a, alen * __GLX_SIZE_FLOAT32) 232848b8605Smrg 233848b8605Smrg#define __GLX_PUT_DOUBLE_ARRAY(offset,a,alen) \ 234848b8605Smrg gl_put_double_array((GLubyte *)(pc + offset), (double *)a, alen * __GLX_SIZE_FLOAT64) 235848b8605Smrg 236848b8605Smrgextern gl_put_short_array(GLubyte *, short *, int); 237848b8605Smrgextern gl_put_long_array(GLubyte *, long *, int); 238848b8605Smrgextern gl_put_float_array(GLubyte *, float *, int); 239848b8605Smrgextern gl_put_double_array(GLubyte *, double *, int); 240848b8605Smrg 241848b8605Smrg#endif /* _CRAY */ 242848b8605Smrg 243848b8605Smrg#endif /* !__GLX_packrender_h__ */ 244