1706f2543Smrg/* 2706f2543Smrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3706f2543Smrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. 4706f2543Smrg * 5706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a 6706f2543Smrg * copy of this software and associated documentation files (the "Software"), 7706f2543Smrg * to deal in the Software without restriction, including without limitation 8706f2543Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9706f2543Smrg * and/or sell copies of the Software, and to permit persons to whom the 10706f2543Smrg * Software is furnished to do so, subject to the following conditions: 11706f2543Smrg * 12706f2543Smrg * The above copyright notice including the dates of first publication and 13706f2543Smrg * either this permission notice or a reference to 14706f2543Smrg * http://oss.sgi.com/projects/FreeB/ 15706f2543Smrg * shall be included in all copies or substantial portions of the Software. 16706f2543Smrg * 17706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18706f2543Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20706f2543Smrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21706f2543Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 22706f2543Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23706f2543Smrg * SOFTWARE. 24706f2543Smrg * 25706f2543Smrg * Except as contained in this notice, the name of Silicon Graphics, Inc. 26706f2543Smrg * shall not be used in advertising or otherwise to promote the sale, use or 27706f2543Smrg * other dealings in this Software without prior written authorization from 28706f2543Smrg * Silicon Graphics, Inc. 29706f2543Smrg */ 30706f2543Smrg 31706f2543Smrg#include "glxserver.h" 32706f2543Smrg#include "unpack.h" 33706f2543Smrg#include "g_disptab.h" 34706f2543Smrg 35706f2543SmrgGLint __glEvalComputeK(GLenum target) 36706f2543Smrg{ 37706f2543Smrg switch (target) { 38706f2543Smrg case GL_MAP1_VERTEX_4: 39706f2543Smrg case GL_MAP1_COLOR_4: 40706f2543Smrg case GL_MAP1_TEXTURE_COORD_4: 41706f2543Smrg case GL_MAP2_VERTEX_4: 42706f2543Smrg case GL_MAP2_COLOR_4: 43706f2543Smrg case GL_MAP2_TEXTURE_COORD_4: 44706f2543Smrg return 4; 45706f2543Smrg case GL_MAP1_VERTEX_3: 46706f2543Smrg case GL_MAP1_TEXTURE_COORD_3: 47706f2543Smrg case GL_MAP1_NORMAL: 48706f2543Smrg case GL_MAP2_VERTEX_3: 49706f2543Smrg case GL_MAP2_TEXTURE_COORD_3: 50706f2543Smrg case GL_MAP2_NORMAL: 51706f2543Smrg return 3; 52706f2543Smrg case GL_MAP1_TEXTURE_COORD_2: 53706f2543Smrg case GL_MAP2_TEXTURE_COORD_2: 54706f2543Smrg return 2; 55706f2543Smrg case GL_MAP1_TEXTURE_COORD_1: 56706f2543Smrg case GL_MAP2_TEXTURE_COORD_1: 57706f2543Smrg case GL_MAP1_INDEX: 58706f2543Smrg case GL_MAP2_INDEX: 59706f2543Smrg return 1; 60706f2543Smrg default: 61706f2543Smrg return 0; 62706f2543Smrg } 63706f2543Smrg} 64706f2543Smrg 65706f2543Smrgvoid __glXDispSwap_Map1f(GLbyte *pc) 66706f2543Smrg{ 67706f2543Smrg GLint order, k; 68706f2543Smrg GLfloat u1, u2, *points; 69706f2543Smrg GLenum target; 70706f2543Smrg GLint compsize; 71706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 72706f2543Smrg __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 73706f2543Smrg 74706f2543Smrg __GLX_SWAP_INT(pc + 0); 75706f2543Smrg __GLX_SWAP_INT(pc + 12); 76706f2543Smrg __GLX_SWAP_FLOAT(pc + 4); 77706f2543Smrg __GLX_SWAP_FLOAT(pc + 8); 78706f2543Smrg 79706f2543Smrg target = *(GLenum *)(pc + 0); 80706f2543Smrg order = *(GLint *)(pc + 12); 81706f2543Smrg u1 = *(GLfloat *)(pc + 4); 82706f2543Smrg u2 = *(GLfloat *)(pc + 8); 83706f2543Smrg points = (GLfloat *)(pc + 16); 84706f2543Smrg k = __glEvalComputeK(target); 85706f2543Smrg 86706f2543Smrg if (order <= 0 || k < 0) { 87706f2543Smrg /* Erroneous command. */ 88706f2543Smrg compsize = 0; 89706f2543Smrg } else { 90706f2543Smrg compsize = order * k; 91706f2543Smrg } 92706f2543Smrg __GLX_SWAP_FLOAT_ARRAY(points, compsize); 93706f2543Smrg 94706f2543Smrg} 95706f2543Smrg 96706f2543Smrgvoid __glXDispSwap_Map2f(GLbyte *pc) 97706f2543Smrg{ 98706f2543Smrg GLint uorder, vorder, ustride, vstride, k; 99706f2543Smrg GLfloat u1, u2, v1, v2, *points; 100706f2543Smrg GLenum target; 101706f2543Smrg GLint compsize; 102706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 103706f2543Smrg __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 104706f2543Smrg 105706f2543Smrg __GLX_SWAP_INT(pc + 0); 106706f2543Smrg __GLX_SWAP_INT(pc + 12); 107706f2543Smrg __GLX_SWAP_INT(pc + 24); 108706f2543Smrg __GLX_SWAP_FLOAT(pc + 4); 109706f2543Smrg __GLX_SWAP_FLOAT(pc + 8); 110706f2543Smrg __GLX_SWAP_FLOAT(pc + 16); 111706f2543Smrg __GLX_SWAP_FLOAT(pc + 20); 112706f2543Smrg 113706f2543Smrg target = *(GLenum *)(pc + 0); 114706f2543Smrg uorder = *(GLint *)(pc + 12); 115706f2543Smrg vorder = *(GLint *)(pc + 24); 116706f2543Smrg u1 = *(GLfloat *)(pc + 4); 117706f2543Smrg u2 = *(GLfloat *)(pc + 8); 118706f2543Smrg v1 = *(GLfloat *)(pc + 16); 119706f2543Smrg v2 = *(GLfloat *)(pc + 20); 120706f2543Smrg points = (GLfloat *)(pc + 28); 121706f2543Smrg 122706f2543Smrg k = __glEvalComputeK(target); 123706f2543Smrg ustride = vorder * k; 124706f2543Smrg vstride = k; 125706f2543Smrg 126706f2543Smrg if (vorder <= 0 || uorder <= 0 || k < 0) { 127706f2543Smrg /* Erroneous command. */ 128706f2543Smrg compsize = 0; 129706f2543Smrg } else { 130706f2543Smrg compsize = uorder * vorder * k; 131706f2543Smrg } 132706f2543Smrg __GLX_SWAP_FLOAT_ARRAY(points, compsize); 133706f2543Smrg 134706f2543Smrg} 135706f2543Smrg 136706f2543Smrgvoid __glXDispSwap_Map1d(GLbyte *pc) 137706f2543Smrg{ 138706f2543Smrg GLint order, k, compsize; 139706f2543Smrg GLenum target; 140706f2543Smrg GLdouble u1, u2, *points; 141706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 142706f2543Smrg __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 143706f2543Smrg 144706f2543Smrg __GLX_SWAP_DOUBLE(pc + 0); 145706f2543Smrg __GLX_SWAP_DOUBLE(pc + 8); 146706f2543Smrg __GLX_SWAP_INT(pc + 16); 147706f2543Smrg __GLX_SWAP_INT(pc + 20); 148706f2543Smrg 149706f2543Smrg target = *(GLenum*) (pc + 16); 150706f2543Smrg order = *(GLint*) (pc + 20); 151706f2543Smrg k = __glEvalComputeK(target); 152706f2543Smrg if (order <= 0 || k < 0) { 153706f2543Smrg /* Erroneous command. */ 154706f2543Smrg compsize = 0; 155706f2543Smrg } else { 156706f2543Smrg compsize = order * k; 157706f2543Smrg } 158706f2543Smrg __GLX_GET_DOUBLE(u1,pc); 159706f2543Smrg __GLX_GET_DOUBLE(u2,pc+8); 160706f2543Smrg __GLX_SWAP_DOUBLE_ARRAY(pc+24, compsize); 161706f2543Smrg pc += 24; 162706f2543Smrg 163706f2543Smrg#ifdef __GLX_ALIGN64 164706f2543Smrg if (((unsigned long)pc) & 7) { 165706f2543Smrg /* 166706f2543Smrg ** Copy the doubles up 4 bytes, trashing the command but aligning 167706f2543Smrg ** the data in the process 168706f2543Smrg */ 169706f2543Smrg __GLX_MEM_COPY(pc-4, pc, compsize*8); 170706f2543Smrg points = (GLdouble*) (pc - 4); 171706f2543Smrg } else { 172706f2543Smrg points = (GLdouble*) pc; 173706f2543Smrg } 174706f2543Smrg#else 175706f2543Smrg points = (GLdouble*) pc; 176706f2543Smrg#endif 177706f2543Smrg} 178706f2543Smrg 179706f2543Smrgvoid __glXDispSwap_Map2d(GLbyte *pc) 180706f2543Smrg{ 181706f2543Smrg GLdouble u1, u2, v1, v2, *points; 182706f2543Smrg GLint uorder, vorder, ustride, vstride, k, compsize; 183706f2543Smrg GLenum target; 184706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 185706f2543Smrg __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 186706f2543Smrg 187706f2543Smrg __GLX_SWAP_DOUBLE(pc + 0); 188706f2543Smrg __GLX_SWAP_DOUBLE(pc + 8); 189706f2543Smrg __GLX_SWAP_DOUBLE(pc + 16); 190706f2543Smrg __GLX_SWAP_DOUBLE(pc + 24); 191706f2543Smrg __GLX_SWAP_INT(pc + 32); 192706f2543Smrg __GLX_SWAP_INT(pc + 36); 193706f2543Smrg __GLX_SWAP_INT(pc + 40); 194706f2543Smrg 195706f2543Smrg target = *(GLenum *)(pc + 32); 196706f2543Smrg uorder = *(GLint *)(pc + 36); 197706f2543Smrg vorder = *(GLint *)(pc + 40); 198706f2543Smrg k = __glEvalComputeK(target); 199706f2543Smrg if (vorder <= 0 || uorder <= 0 || k < 0) { 200706f2543Smrg /* Erroneous command. */ 201706f2543Smrg compsize = 0; 202706f2543Smrg } else { 203706f2543Smrg compsize = uorder * vorder * k; 204706f2543Smrg } 205706f2543Smrg __GLX_GET_DOUBLE(u1,pc); 206706f2543Smrg __GLX_GET_DOUBLE(u2,pc+8); 207706f2543Smrg __GLX_GET_DOUBLE(v1,pc+16); 208706f2543Smrg __GLX_GET_DOUBLE(v2,pc+24); 209706f2543Smrg __GLX_SWAP_DOUBLE_ARRAY(pc+44, compsize); 210706f2543Smrg pc += 44; 211706f2543Smrg ustride = vorder * k; 212706f2543Smrg vstride = k; 213706f2543Smrg 214706f2543Smrg#ifdef __GLX_ALIGN64 215706f2543Smrg if (((unsigned long)pc) & 7) { 216706f2543Smrg /* 217706f2543Smrg ** Copy the doubles up 4 bytes, trashing the command but aligning 218706f2543Smrg ** the data in the process 219706f2543Smrg */ 220706f2543Smrg __GLX_MEM_COPY(pc-4, pc, compsize*8); 221706f2543Smrg points = (GLdouble*) (pc - 4); 222706f2543Smrg } else { 223706f2543Smrg points = (GLdouble*) pc; 224706f2543Smrg } 225706f2543Smrg#else 226706f2543Smrg points = (GLdouble*) pc; 227706f2543Smrg#endif 228706f2543Smrg} 229706f2543Smrg 230706f2543Smrgvoid __glXDispSwap_CallLists(GLbyte *pc) 231706f2543Smrg{ 232706f2543Smrg GLenum type; 233706f2543Smrg GLsizei n; 234706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 235706f2543Smrg __GLX_DECLARE_SWAP_ARRAY_VARIABLES; 236706f2543Smrg 237706f2543Smrg __GLX_SWAP_INT(pc + 4); 238706f2543Smrg __GLX_SWAP_INT(pc + 0); 239706f2543Smrg type = *(GLenum *)(pc + 4); 240706f2543Smrg n = *(GLsizei *)(pc + 0); 241706f2543Smrg 242706f2543Smrg switch (type) { 243706f2543Smrg case GL_BYTE: 244706f2543Smrg case GL_UNSIGNED_BYTE: 245706f2543Smrg case GL_2_BYTES: 246706f2543Smrg case GL_3_BYTES: 247706f2543Smrg case GL_4_BYTES: 248706f2543Smrg break; 249706f2543Smrg case GL_SHORT: 250706f2543Smrg case GL_UNSIGNED_SHORT: 251706f2543Smrg __GLX_SWAP_SHORT_ARRAY(pc+8, n); 252706f2543Smrg break; 253706f2543Smrg case GL_INT: 254706f2543Smrg case GL_UNSIGNED_INT: 255706f2543Smrg __GLX_SWAP_INT_ARRAY(pc+8, n); 256706f2543Smrg break; 257706f2543Smrg case GL_FLOAT: 258706f2543Smrg __GLX_SWAP_FLOAT_ARRAY(pc+8, n); 259706f2543Smrg break; 260706f2543Smrg } 261706f2543Smrg 262706f2543Smrg} 263706f2543Smrg 264706f2543Smrgvoid __glXDispSwap_DrawArrays(GLbyte *pc) 265706f2543Smrg{ 266706f2543Smrg __GLXdispatchDrawArraysHeader *hdr = (__GLXdispatchDrawArraysHeader *)pc; 267706f2543Smrg __GLXdispatchDrawArraysComponentHeader *compHeader; 268706f2543Smrg int i; 269706f2543Smrg __GLX_DECLARE_SWAP_VARIABLES; 270706f2543Smrg 271706f2543Smrg __GLX_SWAP_INT(&hdr->numVertexes); 272706f2543Smrg __GLX_SWAP_INT(&hdr->numComponents); 273706f2543Smrg __GLX_SWAP_INT(&hdr->primType); 274706f2543Smrg 275706f2543Smrg pc += sizeof(__GLXdispatchDrawArraysHeader); 276706f2543Smrg compHeader = (__GLXdispatchDrawArraysComponentHeader *) pc; 277706f2543Smrg 278706f2543Smrg /* compute stride (same for all component arrays) */ 279706f2543Smrg for (i=0; i<hdr->numComponents; i++) { 280706f2543Smrg __GLX_SWAP_INT(&compHeader[i].datatype); 281706f2543Smrg __GLX_SWAP_INT(&compHeader[i].numVals); 282706f2543Smrg __GLX_SWAP_INT(&compHeader[i].component); 283706f2543Smrg 284706f2543Smrg } 285706f2543Smrg 286706f2543Smrg} 287