1cdc920a0Smrg/* 2cdc920a0Smrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3cdc920a0Smrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. 4cdc920a0Smrg * 5cdc920a0Smrg * Permission is hereby granted, free of charge, to any person obtaining a 6cdc920a0Smrg * copy of this software and associated documentation files (the "Software"), 7cdc920a0Smrg * to deal in the Software without restriction, including without limitation 8cdc920a0Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9cdc920a0Smrg * and/or sell copies of the Software, and to permit persons to whom the 10cdc920a0Smrg * Software is furnished to do so, subject to the following conditions: 11cdc920a0Smrg * 12cdc920a0Smrg * The above copyright notice including the dates of first publication and 13cdc920a0Smrg * either this permission notice or a reference to 14cdc920a0Smrg * http://oss.sgi.com/projects/FreeB/ 15cdc920a0Smrg * shall be included in all copies or substantial portions of the Software. 16cdc920a0Smrg * 17cdc920a0Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18cdc920a0Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19cdc920a0Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20cdc920a0Smrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21cdc920a0Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 22cdc920a0Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23cdc920a0Smrg * SOFTWARE. 24cdc920a0Smrg * 25cdc920a0Smrg * Except as contained in this notice, the name of Silicon Graphics, Inc. 26cdc920a0Smrg * shall not be used in advertising or otherwise to promote the sale, use or 27cdc920a0Smrg * other dealings in this Software without prior written authorization from 28cdc920a0Smrg * Silicon Graphics, Inc. 29cdc920a0Smrg */ 30cdc920a0Smrg 31af69d88dSmrg#ifndef GLX_USE_APPLEGL 32af69d88dSmrg 33cdc920a0Smrg#include "packrender.h" 34cdc920a0Smrg#include "indirect.h" 35cdc920a0Smrg#include "indirect_size.h" 36cdc920a0Smrg 37cdc920a0Smrg/* 38cdc920a0Smrg** This file contains routines that might need to be transported as 39cdc920a0Smrg** GLXRender or GLXRenderLarge commands, and these commands don't 40cdc920a0Smrg** use the pixel header. See renderpix.c for those routines. 41cdc920a0Smrg*/ 42cdc920a0Smrg 43cdc920a0Smrgvoid 44cdc920a0Smrg__indirect_glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride, 45cdc920a0Smrg GLint order, const GLdouble * pnts) 46cdc920a0Smrg{ 47cdc920a0Smrg __GLX_DECLARE_VARIABLES(); 48cdc920a0Smrg GLint k; 49cdc920a0Smrg 50cdc920a0Smrg __GLX_LOAD_VARIABLES(); 51cdc920a0Smrg k = __glMap1d_size(target); 52cdc920a0Smrg if (k == 0) { 53cdc920a0Smrg __glXSetError(gc, GL_INVALID_ENUM); 54cdc920a0Smrg return; 55cdc920a0Smrg } 56cdc920a0Smrg else if (stride < k || order <= 0) { 57cdc920a0Smrg __glXSetError(gc, GL_INVALID_VALUE); 58cdc920a0Smrg return; 59cdc920a0Smrg } 60cdc920a0Smrg compsize = k * order * __GLX_SIZE_FLOAT64; 61cdc920a0Smrg cmdlen = 28 + compsize; 62cdc920a0Smrg if (!gc->currentDpy) 63cdc920a0Smrg return; 64cdc920a0Smrg 65cdc920a0Smrg if (cmdlen <= gc->maxSmallRenderCommandSize) { 66cdc920a0Smrg /* Use GLXRender protocol to send small command */ 67cdc920a0Smrg __GLX_BEGIN_VARIABLE(X_GLrop_Map1d, cmdlen); 68cdc920a0Smrg __GLX_PUT_DOUBLE(4, u1); 69cdc920a0Smrg __GLX_PUT_DOUBLE(12, u2); 70cdc920a0Smrg __GLX_PUT_LONG(20, target); 71cdc920a0Smrg __GLX_PUT_LONG(24, order); 72cdc920a0Smrg /* 73cdc920a0Smrg ** NOTE: the doubles that follow are not aligned because of 3 74cdc920a0Smrg ** longs preceeding 75cdc920a0Smrg */ 76cdc920a0Smrg __glFillMap1d(k, order, stride, pnts, (pc + 28)); 77cdc920a0Smrg __GLX_END(cmdlen); 78cdc920a0Smrg } 79cdc920a0Smrg else { 80cdc920a0Smrg /* Use GLXRenderLarge protocol to send command */ 81cdc920a0Smrg __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map1d, cmdlen + 4); 82cdc920a0Smrg __GLX_PUT_DOUBLE(8, u1); 83cdc920a0Smrg __GLX_PUT_DOUBLE(16, u2); 84cdc920a0Smrg __GLX_PUT_LONG(24, target); 85cdc920a0Smrg __GLX_PUT_LONG(28, order); 86cdc920a0Smrg 87cdc920a0Smrg /* 88cdc920a0Smrg ** NOTE: the doubles that follow are not aligned because of 3 89cdc920a0Smrg ** longs preceeding 90cdc920a0Smrg */ 91cdc920a0Smrg if (stride != k) { 92cdc920a0Smrg GLubyte *buf; 93cdc920a0Smrg 94af69d88dSmrg buf = malloc(compsize); 95cdc920a0Smrg if (!buf) { 96cdc920a0Smrg __glXSetError(gc, GL_OUT_OF_MEMORY); 97cdc920a0Smrg return; 98cdc920a0Smrg } 99cdc920a0Smrg __glFillMap1d(k, order, stride, pnts, buf); 100cdc920a0Smrg __glXSendLargeCommand(gc, pc, 32, buf, compsize); 101af69d88dSmrg free((char *) buf); 102cdc920a0Smrg } 103cdc920a0Smrg else { 104cdc920a0Smrg /* Data is already packed. Just send it out */ 105cdc920a0Smrg __glXSendLargeCommand(gc, pc, 32, pnts, compsize); 106cdc920a0Smrg } 107cdc920a0Smrg } 108cdc920a0Smrg} 109cdc920a0Smrg 110cdc920a0Smrgvoid 111cdc920a0Smrg__indirect_glMap1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride, 112cdc920a0Smrg GLint order, const GLfloat * pnts) 113cdc920a0Smrg{ 114cdc920a0Smrg __GLX_DECLARE_VARIABLES(); 115cdc920a0Smrg GLint k; 116cdc920a0Smrg 117cdc920a0Smrg __GLX_LOAD_VARIABLES(); 118cdc920a0Smrg k = __glMap1f_size(target); 119cdc920a0Smrg if (k == 0) { 120cdc920a0Smrg __glXSetError(gc, GL_INVALID_ENUM); 121cdc920a0Smrg return; 122cdc920a0Smrg } 123cdc920a0Smrg else if (stride < k || order <= 0) { 124cdc920a0Smrg __glXSetError(gc, GL_INVALID_VALUE); 125cdc920a0Smrg return; 126cdc920a0Smrg } 127cdc920a0Smrg compsize = k * order * __GLX_SIZE_FLOAT32; 128cdc920a0Smrg cmdlen = 20 + compsize; 129cdc920a0Smrg if (!gc->currentDpy) 130cdc920a0Smrg return; 131cdc920a0Smrg 132cdc920a0Smrg /* 133cdc920a0Smrg ** The order that arguments are packed is different from the order 134cdc920a0Smrg ** for glMap1d. 135cdc920a0Smrg */ 136cdc920a0Smrg if (cmdlen <= gc->maxSmallRenderCommandSize) { 137cdc920a0Smrg /* Use GLXRender protocol to send small command */ 138cdc920a0Smrg __GLX_BEGIN_VARIABLE(X_GLrop_Map1f, cmdlen); 139cdc920a0Smrg __GLX_PUT_LONG(4, target); 140cdc920a0Smrg __GLX_PUT_FLOAT(8, u1); 141cdc920a0Smrg __GLX_PUT_FLOAT(12, u2); 142cdc920a0Smrg __GLX_PUT_LONG(16, order); 143cdc920a0Smrg __glFillMap1f(k, order, stride, pnts, (GLubyte *) (pc + 20)); 144cdc920a0Smrg __GLX_END(cmdlen); 145cdc920a0Smrg } 146cdc920a0Smrg else { 147cdc920a0Smrg /* Use GLXRenderLarge protocol to send command */ 148cdc920a0Smrg __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map1f, cmdlen + 4); 149cdc920a0Smrg __GLX_PUT_LONG(8, target); 150cdc920a0Smrg __GLX_PUT_FLOAT(12, u1); 151cdc920a0Smrg __GLX_PUT_FLOAT(16, u2); 152cdc920a0Smrg __GLX_PUT_LONG(20, order); 153cdc920a0Smrg 154cdc920a0Smrg if (stride != k) { 155cdc920a0Smrg GLubyte *buf; 156cdc920a0Smrg 157af69d88dSmrg buf = malloc(compsize); 158cdc920a0Smrg if (!buf) { 159cdc920a0Smrg __glXSetError(gc, GL_OUT_OF_MEMORY); 160cdc920a0Smrg return; 161cdc920a0Smrg } 162cdc920a0Smrg __glFillMap1f(k, order, stride, pnts, buf); 163cdc920a0Smrg __glXSendLargeCommand(gc, pc, 24, buf, compsize); 164af69d88dSmrg free((char *) buf); 165cdc920a0Smrg } 166cdc920a0Smrg else { 167cdc920a0Smrg /* Data is already packed. Just send it out */ 168cdc920a0Smrg __glXSendLargeCommand(gc, pc, 24, pnts, compsize); 169cdc920a0Smrg } 170cdc920a0Smrg } 171cdc920a0Smrg} 172cdc920a0Smrg 173cdc920a0Smrgvoid 174cdc920a0Smrg__indirect_glMap2d(GLenum target, GLdouble u1, GLdouble u2, GLint ustr, 175cdc920a0Smrg GLint uord, GLdouble v1, GLdouble v2, GLint vstr, 176cdc920a0Smrg GLint vord, const GLdouble * pnts) 177cdc920a0Smrg{ 178cdc920a0Smrg __GLX_DECLARE_VARIABLES(); 179cdc920a0Smrg GLint k; 180cdc920a0Smrg 181cdc920a0Smrg __GLX_LOAD_VARIABLES(); 182cdc920a0Smrg k = __glMap2d_size(target); 183cdc920a0Smrg if (k == 0) { 184cdc920a0Smrg __glXSetError(gc, GL_INVALID_ENUM); 185cdc920a0Smrg return; 186cdc920a0Smrg } 187cdc920a0Smrg else if (vstr < k || ustr < k || vord <= 0 || uord <= 0) { 188cdc920a0Smrg __glXSetError(gc, GL_INVALID_VALUE); 189cdc920a0Smrg return; 190cdc920a0Smrg } 191cdc920a0Smrg compsize = k * uord * vord * __GLX_SIZE_FLOAT64; 192cdc920a0Smrg cmdlen = 48 + compsize; 193cdc920a0Smrg if (!gc->currentDpy) 194cdc920a0Smrg return; 195cdc920a0Smrg 196cdc920a0Smrg if (cmdlen <= gc->maxSmallRenderCommandSize) { 197cdc920a0Smrg /* Use GLXRender protocol to send small command */ 198cdc920a0Smrg __GLX_BEGIN_VARIABLE(X_GLrop_Map2d, cmdlen); 199cdc920a0Smrg __GLX_PUT_DOUBLE(4, u1); 200cdc920a0Smrg __GLX_PUT_DOUBLE(12, u2); 201cdc920a0Smrg __GLX_PUT_DOUBLE(20, v1); 202cdc920a0Smrg __GLX_PUT_DOUBLE(28, v2); 203cdc920a0Smrg __GLX_PUT_LONG(36, target); 204cdc920a0Smrg __GLX_PUT_LONG(40, uord); 205cdc920a0Smrg __GLX_PUT_LONG(44, vord); 206cdc920a0Smrg /* 207cdc920a0Smrg ** Pack into a u-major ordering. 208cdc920a0Smrg ** NOTE: the doubles that follow are not aligned because of 5 209cdc920a0Smrg ** longs preceeding 210cdc920a0Smrg */ 211cdc920a0Smrg __glFillMap2d(k, uord, vord, ustr, vstr, pnts, (GLdouble *) (pc + 48)); 212cdc920a0Smrg __GLX_END(cmdlen); 213cdc920a0Smrg } 214cdc920a0Smrg else { 215cdc920a0Smrg /* Use GLXRenderLarge protocol to send command */ 216cdc920a0Smrg __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map2d, cmdlen + 4); 217cdc920a0Smrg __GLX_PUT_DOUBLE(8, u1); 218cdc920a0Smrg __GLX_PUT_DOUBLE(16, u2); 219cdc920a0Smrg __GLX_PUT_DOUBLE(24, v1); 220cdc920a0Smrg __GLX_PUT_DOUBLE(32, v2); 221cdc920a0Smrg __GLX_PUT_LONG(40, target); 222cdc920a0Smrg __GLX_PUT_LONG(44, uord); 223cdc920a0Smrg __GLX_PUT_LONG(48, vord); 224cdc920a0Smrg 225cdc920a0Smrg /* 226cdc920a0Smrg ** NOTE: the doubles that follow are not aligned because of 5 227cdc920a0Smrg ** longs preceeding 228cdc920a0Smrg */ 229cdc920a0Smrg if ((vstr != k) || (ustr != k * vord)) { 230cdc920a0Smrg GLdouble *buf; 231cdc920a0Smrg 232af69d88dSmrg buf = malloc(compsize); 233cdc920a0Smrg if (!buf) { 234cdc920a0Smrg __glXSetError(gc, GL_OUT_OF_MEMORY); 235cdc920a0Smrg return; 236cdc920a0Smrg } 237cdc920a0Smrg /* 238cdc920a0Smrg ** Pack into a u-major ordering. 239cdc920a0Smrg */ 240cdc920a0Smrg __glFillMap2d(k, uord, vord, ustr, vstr, pnts, buf); 241cdc920a0Smrg __glXSendLargeCommand(gc, pc, 52, buf, compsize); 242af69d88dSmrg free((char *) buf); 243cdc920a0Smrg } 244cdc920a0Smrg else { 245cdc920a0Smrg /* Data is already packed. Just send it out */ 246cdc920a0Smrg __glXSendLargeCommand(gc, pc, 52, pnts, compsize); 247cdc920a0Smrg } 248cdc920a0Smrg } 249cdc920a0Smrg} 250cdc920a0Smrg 251cdc920a0Smrgvoid 252cdc920a0Smrg__indirect_glMap2f(GLenum target, GLfloat u1, GLfloat u2, GLint ustr, 253cdc920a0Smrg GLint uord, GLfloat v1, GLfloat v2, GLint vstr, GLint vord, 254cdc920a0Smrg const GLfloat * pnts) 255cdc920a0Smrg{ 256cdc920a0Smrg __GLX_DECLARE_VARIABLES(); 257cdc920a0Smrg GLint k; 258cdc920a0Smrg 259cdc920a0Smrg __GLX_LOAD_VARIABLES(); 260cdc920a0Smrg k = __glMap2f_size(target); 261cdc920a0Smrg if (k == 0) { 262cdc920a0Smrg __glXSetError(gc, GL_INVALID_ENUM); 263cdc920a0Smrg return; 264cdc920a0Smrg } 265cdc920a0Smrg else if (vstr < k || ustr < k || vord <= 0 || uord <= 0) { 266cdc920a0Smrg __glXSetError(gc, GL_INVALID_VALUE); 267cdc920a0Smrg return; 268cdc920a0Smrg } 269cdc920a0Smrg compsize = k * uord * vord * __GLX_SIZE_FLOAT32; 270cdc920a0Smrg cmdlen = 32 + compsize; 271cdc920a0Smrg if (!gc->currentDpy) 272cdc920a0Smrg return; 273cdc920a0Smrg 274cdc920a0Smrg /* 275cdc920a0Smrg ** The order that arguments are packed is different from the order 276cdc920a0Smrg ** for glMap2d. 277cdc920a0Smrg */ 278cdc920a0Smrg if (cmdlen <= gc->maxSmallRenderCommandSize) { 279cdc920a0Smrg /* Use GLXRender protocol to send small command */ 280cdc920a0Smrg __GLX_BEGIN_VARIABLE(X_GLrop_Map2f, cmdlen); 281cdc920a0Smrg __GLX_PUT_LONG(4, target); 282cdc920a0Smrg __GLX_PUT_FLOAT(8, u1); 283cdc920a0Smrg __GLX_PUT_FLOAT(12, u2); 284cdc920a0Smrg __GLX_PUT_LONG(16, uord); 285cdc920a0Smrg __GLX_PUT_FLOAT(20, v1); 286cdc920a0Smrg __GLX_PUT_FLOAT(24, v2); 287cdc920a0Smrg __GLX_PUT_LONG(28, vord); 288cdc920a0Smrg /* 289cdc920a0Smrg ** Pack into a u-major ordering. 290cdc920a0Smrg */ 291cdc920a0Smrg __glFillMap2f(k, uord, vord, ustr, vstr, pnts, (GLfloat *) (pc + 32)); 292cdc920a0Smrg __GLX_END(cmdlen); 293cdc920a0Smrg } 294cdc920a0Smrg else { 295cdc920a0Smrg /* Use GLXRenderLarge protocol to send command */ 296cdc920a0Smrg __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map2f, cmdlen + 4); 297cdc920a0Smrg __GLX_PUT_LONG(8, target); 298cdc920a0Smrg __GLX_PUT_FLOAT(12, u1); 299cdc920a0Smrg __GLX_PUT_FLOAT(16, u2); 300cdc920a0Smrg __GLX_PUT_LONG(20, uord); 301cdc920a0Smrg __GLX_PUT_FLOAT(24, v1); 302cdc920a0Smrg __GLX_PUT_FLOAT(28, v2); 303cdc920a0Smrg __GLX_PUT_LONG(32, vord); 304cdc920a0Smrg 305cdc920a0Smrg if ((vstr != k) || (ustr != k * vord)) { 306cdc920a0Smrg GLfloat *buf; 307cdc920a0Smrg 308af69d88dSmrg buf = malloc(compsize); 309cdc920a0Smrg if (!buf) { 310cdc920a0Smrg __glXSetError(gc, GL_OUT_OF_MEMORY); 311cdc920a0Smrg return; 312cdc920a0Smrg } 313cdc920a0Smrg /* 314cdc920a0Smrg ** Pack into a u-major ordering. 315cdc920a0Smrg */ 316cdc920a0Smrg __glFillMap2f(k, uord, vord, ustr, vstr, pnts, buf); 317cdc920a0Smrg __glXSendLargeCommand(gc, pc, 36, buf, compsize); 318af69d88dSmrg free((char *) buf); 319cdc920a0Smrg } 320cdc920a0Smrg else { 321cdc920a0Smrg /* Data is already packed. Just send it out */ 322cdc920a0Smrg __glXSendLargeCommand(gc, pc, 36, pnts, compsize); 323cdc920a0Smrg } 324cdc920a0Smrg } 325cdc920a0Smrg} 326cdc920a0Smrg 327cdc920a0Smrgvoid 328cdc920a0Smrg__indirect_glEnable(GLenum cap) 329cdc920a0Smrg{ 330cdc920a0Smrg __GLX_DECLARE_VARIABLES(); 331cdc920a0Smrg 332cdc920a0Smrg __GLX_LOAD_VARIABLES(); 333cdc920a0Smrg if (!gc->currentDpy) 334cdc920a0Smrg return; 335cdc920a0Smrg 336cdc920a0Smrg switch (cap) { 337cdc920a0Smrg case GL_COLOR_ARRAY: 338cdc920a0Smrg case GL_EDGE_FLAG_ARRAY: 339cdc920a0Smrg case GL_INDEX_ARRAY: 340cdc920a0Smrg case GL_NORMAL_ARRAY: 341cdc920a0Smrg case GL_TEXTURE_COORD_ARRAY: 342cdc920a0Smrg case GL_VERTEX_ARRAY: 343cdc920a0Smrg case GL_SECONDARY_COLOR_ARRAY: 344cdc920a0Smrg case GL_FOG_COORD_ARRAY: 345cdc920a0Smrg __indirect_glEnableClientState(cap); 346cdc920a0Smrg return; 347cdc920a0Smrg default: 348cdc920a0Smrg break; 349cdc920a0Smrg } 350cdc920a0Smrg 351cdc920a0Smrg __GLX_BEGIN(X_GLrop_Enable, 8); 352cdc920a0Smrg __GLX_PUT_LONG(4, cap); 353cdc920a0Smrg __GLX_END(8); 354cdc920a0Smrg} 355cdc920a0Smrg 356cdc920a0Smrgvoid 357cdc920a0Smrg__indirect_glDisable(GLenum cap) 358cdc920a0Smrg{ 359cdc920a0Smrg __GLX_DECLARE_VARIABLES(); 360cdc920a0Smrg 361cdc920a0Smrg __GLX_LOAD_VARIABLES(); 362cdc920a0Smrg if (!gc->currentDpy) 363cdc920a0Smrg return; 364cdc920a0Smrg 365cdc920a0Smrg switch (cap) { 366cdc920a0Smrg case GL_COLOR_ARRAY: 367cdc920a0Smrg case GL_EDGE_FLAG_ARRAY: 368cdc920a0Smrg case GL_INDEX_ARRAY: 369cdc920a0Smrg case GL_NORMAL_ARRAY: 370cdc920a0Smrg case GL_TEXTURE_COORD_ARRAY: 371cdc920a0Smrg case GL_VERTEX_ARRAY: 372cdc920a0Smrg case GL_SECONDARY_COLOR_ARRAY: 373cdc920a0Smrg case GL_FOG_COORD_ARRAY: 374cdc920a0Smrg __indirect_glDisableClientState(cap); 375cdc920a0Smrg return; 376cdc920a0Smrg default: 377cdc920a0Smrg break; 378cdc920a0Smrg } 379cdc920a0Smrg 380cdc920a0Smrg __GLX_BEGIN(X_GLrop_Disable, 8); 381cdc920a0Smrg __GLX_PUT_LONG(4, cap); 382cdc920a0Smrg __GLX_END(8); 383cdc920a0Smrg} 384af69d88dSmrg 385af69d88dSmrg#endif 386