1848b8605Smrg/* 2848b8605Smrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3848b8605Smrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. 4848b8605Smrg * 5848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 6848b8605Smrg * copy of this software and associated documentation files (the "Software"), 7848b8605Smrg * to deal in the Software without restriction, including without limitation 8848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the 10848b8605Smrg * Software is furnished to do so, subject to the following conditions: 11848b8605Smrg * 12848b8605Smrg * The above copyright notice including the dates of first publication and 13848b8605Smrg * either this permission notice or a reference to 14848b8605Smrg * http://oss.sgi.com/projects/FreeB/ 15848b8605Smrg * shall be included in all copies or substantial portions of the Software. 16848b8605Smrg * 17848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20848b8605Smrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21848b8605Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 22848b8605Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23848b8605Smrg * SOFTWARE. 24848b8605Smrg * 25848b8605Smrg * Except as contained in this notice, the name of Silicon Graphics, Inc. 26848b8605Smrg * shall not be used in advertising or otherwise to promote the sale, use or 27848b8605Smrg * other dealings in this Software without prior written authorization from 28848b8605Smrg * Silicon Graphics, Inc. 29848b8605Smrg */ 30848b8605Smrg 31848b8605Smrg#ifndef GLX_USE_APPLEGL 32848b8605Smrg 33848b8605Smrg#include "packrender.h" 34848b8605Smrg#include "indirect.h" 35848b8605Smrg#include "indirect_size.h" 36848b8605Smrg 37848b8605Smrg/* 38848b8605Smrg** This file contains routines that might need to be transported as 39848b8605Smrg** GLXRender or GLXRenderLarge commands, and these commands don't 40848b8605Smrg** use the pixel header. See renderpix.c for those routines. 41848b8605Smrg*/ 42848b8605Smrg 43848b8605Smrgvoid 44848b8605Smrg__indirect_glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride, 45848b8605Smrg GLint order, const GLdouble * pnts) 46848b8605Smrg{ 47848b8605Smrg __GLX_DECLARE_VARIABLES(); 48848b8605Smrg GLint k; 49848b8605Smrg 50848b8605Smrg __GLX_LOAD_VARIABLES(); 51848b8605Smrg k = __glMap1d_size(target); 52848b8605Smrg if (k == 0) { 53848b8605Smrg __glXSetError(gc, GL_INVALID_ENUM); 54848b8605Smrg return; 55848b8605Smrg } 56848b8605Smrg else if (stride < k || order <= 0) { 57848b8605Smrg __glXSetError(gc, GL_INVALID_VALUE); 58848b8605Smrg return; 59848b8605Smrg } 60848b8605Smrg compsize = k * order * __GLX_SIZE_FLOAT64; 61848b8605Smrg cmdlen = 28 + compsize; 62848b8605Smrg if (!gc->currentDpy) 63848b8605Smrg return; 64848b8605Smrg 65848b8605Smrg if (cmdlen <= gc->maxSmallRenderCommandSize) { 66848b8605Smrg /* Use GLXRender protocol to send small command */ 67848b8605Smrg __GLX_BEGIN_VARIABLE(X_GLrop_Map1d, cmdlen); 68848b8605Smrg __GLX_PUT_DOUBLE(4, u1); 69848b8605Smrg __GLX_PUT_DOUBLE(12, u2); 70848b8605Smrg __GLX_PUT_LONG(20, target); 71848b8605Smrg __GLX_PUT_LONG(24, order); 72848b8605Smrg /* 73848b8605Smrg ** NOTE: the doubles that follow are not aligned because of 3 74848b8605Smrg ** longs preceeding 75848b8605Smrg */ 76848b8605Smrg __glFillMap1d(k, order, stride, pnts, (pc + 28)); 77848b8605Smrg __GLX_END(cmdlen); 78848b8605Smrg } 79848b8605Smrg else { 80848b8605Smrg /* Use GLXRenderLarge protocol to send command */ 81848b8605Smrg __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map1d, cmdlen + 4); 82848b8605Smrg __GLX_PUT_DOUBLE(8, u1); 83848b8605Smrg __GLX_PUT_DOUBLE(16, u2); 84848b8605Smrg __GLX_PUT_LONG(24, target); 85848b8605Smrg __GLX_PUT_LONG(28, order); 86848b8605Smrg 87848b8605Smrg /* 88848b8605Smrg ** NOTE: the doubles that follow are not aligned because of 3 89848b8605Smrg ** longs preceeding 90848b8605Smrg */ 91848b8605Smrg if (stride != k) { 92848b8605Smrg GLubyte *buf; 93848b8605Smrg 94848b8605Smrg buf = malloc(compsize); 95848b8605Smrg if (!buf) { 96848b8605Smrg __glXSetError(gc, GL_OUT_OF_MEMORY); 97848b8605Smrg return; 98848b8605Smrg } 99848b8605Smrg __glFillMap1d(k, order, stride, pnts, buf); 100848b8605Smrg __glXSendLargeCommand(gc, pc, 32, buf, compsize); 101848b8605Smrg free((char *) buf); 102848b8605Smrg } 103848b8605Smrg else { 104848b8605Smrg /* Data is already packed. Just send it out */ 105848b8605Smrg __glXSendLargeCommand(gc, pc, 32, pnts, compsize); 106848b8605Smrg } 107848b8605Smrg } 108848b8605Smrg} 109848b8605Smrg 110848b8605Smrgvoid 111848b8605Smrg__indirect_glMap1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride, 112848b8605Smrg GLint order, const GLfloat * pnts) 113848b8605Smrg{ 114848b8605Smrg __GLX_DECLARE_VARIABLES(); 115848b8605Smrg GLint k; 116848b8605Smrg 117848b8605Smrg __GLX_LOAD_VARIABLES(); 118848b8605Smrg k = __glMap1f_size(target); 119848b8605Smrg if (k == 0) { 120848b8605Smrg __glXSetError(gc, GL_INVALID_ENUM); 121848b8605Smrg return; 122848b8605Smrg } 123848b8605Smrg else if (stride < k || order <= 0) { 124848b8605Smrg __glXSetError(gc, GL_INVALID_VALUE); 125848b8605Smrg return; 126848b8605Smrg } 127848b8605Smrg compsize = k * order * __GLX_SIZE_FLOAT32; 128848b8605Smrg cmdlen = 20 + compsize; 129848b8605Smrg if (!gc->currentDpy) 130848b8605Smrg return; 131848b8605Smrg 132848b8605Smrg /* 133848b8605Smrg ** The order that arguments are packed is different from the order 134848b8605Smrg ** for glMap1d. 135848b8605Smrg */ 136848b8605Smrg if (cmdlen <= gc->maxSmallRenderCommandSize) { 137848b8605Smrg /* Use GLXRender protocol to send small command */ 138848b8605Smrg __GLX_BEGIN_VARIABLE(X_GLrop_Map1f, cmdlen); 139848b8605Smrg __GLX_PUT_LONG(4, target); 140848b8605Smrg __GLX_PUT_FLOAT(8, u1); 141848b8605Smrg __GLX_PUT_FLOAT(12, u2); 142848b8605Smrg __GLX_PUT_LONG(16, order); 143848b8605Smrg __glFillMap1f(k, order, stride, pnts, (GLubyte *) (pc + 20)); 144848b8605Smrg __GLX_END(cmdlen); 145848b8605Smrg } 146848b8605Smrg else { 147848b8605Smrg /* Use GLXRenderLarge protocol to send command */ 148848b8605Smrg __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map1f, cmdlen + 4); 149848b8605Smrg __GLX_PUT_LONG(8, target); 150848b8605Smrg __GLX_PUT_FLOAT(12, u1); 151848b8605Smrg __GLX_PUT_FLOAT(16, u2); 152848b8605Smrg __GLX_PUT_LONG(20, order); 153848b8605Smrg 154848b8605Smrg if (stride != k) { 155848b8605Smrg GLubyte *buf; 156848b8605Smrg 157848b8605Smrg buf = malloc(compsize); 158848b8605Smrg if (!buf) { 159848b8605Smrg __glXSetError(gc, GL_OUT_OF_MEMORY); 160848b8605Smrg return; 161848b8605Smrg } 162848b8605Smrg __glFillMap1f(k, order, stride, pnts, buf); 163848b8605Smrg __glXSendLargeCommand(gc, pc, 24, buf, compsize); 164848b8605Smrg free((char *) buf); 165848b8605Smrg } 166848b8605Smrg else { 167848b8605Smrg /* Data is already packed. Just send it out */ 168848b8605Smrg __glXSendLargeCommand(gc, pc, 24, pnts, compsize); 169848b8605Smrg } 170848b8605Smrg } 171848b8605Smrg} 172848b8605Smrg 173848b8605Smrgvoid 174848b8605Smrg__indirect_glMap2d(GLenum target, GLdouble u1, GLdouble u2, GLint ustr, 175848b8605Smrg GLint uord, GLdouble v1, GLdouble v2, GLint vstr, 176848b8605Smrg GLint vord, const GLdouble * pnts) 177848b8605Smrg{ 178848b8605Smrg __GLX_DECLARE_VARIABLES(); 179848b8605Smrg GLint k; 180848b8605Smrg 181848b8605Smrg __GLX_LOAD_VARIABLES(); 182848b8605Smrg k = __glMap2d_size(target); 183848b8605Smrg if (k == 0) { 184848b8605Smrg __glXSetError(gc, GL_INVALID_ENUM); 185848b8605Smrg return; 186848b8605Smrg } 187848b8605Smrg else if (vstr < k || ustr < k || vord <= 0 || uord <= 0) { 188848b8605Smrg __glXSetError(gc, GL_INVALID_VALUE); 189848b8605Smrg return; 190848b8605Smrg } 191848b8605Smrg compsize = k * uord * vord * __GLX_SIZE_FLOAT64; 192848b8605Smrg cmdlen = 48 + compsize; 193848b8605Smrg if (!gc->currentDpy) 194848b8605Smrg return; 195848b8605Smrg 196848b8605Smrg if (cmdlen <= gc->maxSmallRenderCommandSize) { 197848b8605Smrg /* Use GLXRender protocol to send small command */ 198848b8605Smrg __GLX_BEGIN_VARIABLE(X_GLrop_Map2d, cmdlen); 199848b8605Smrg __GLX_PUT_DOUBLE(4, u1); 200848b8605Smrg __GLX_PUT_DOUBLE(12, u2); 201848b8605Smrg __GLX_PUT_DOUBLE(20, v1); 202848b8605Smrg __GLX_PUT_DOUBLE(28, v2); 203848b8605Smrg __GLX_PUT_LONG(36, target); 204848b8605Smrg __GLX_PUT_LONG(40, uord); 205848b8605Smrg __GLX_PUT_LONG(44, vord); 206848b8605Smrg /* 207848b8605Smrg ** Pack into a u-major ordering. 208848b8605Smrg ** NOTE: the doubles that follow are not aligned because of 5 209848b8605Smrg ** longs preceeding 210848b8605Smrg */ 211848b8605Smrg __glFillMap2d(k, uord, vord, ustr, vstr, pnts, (GLdouble *) (pc + 48)); 212848b8605Smrg __GLX_END(cmdlen); 213848b8605Smrg } 214848b8605Smrg else { 215848b8605Smrg /* Use GLXRenderLarge protocol to send command */ 216848b8605Smrg __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map2d, cmdlen + 4); 217848b8605Smrg __GLX_PUT_DOUBLE(8, u1); 218848b8605Smrg __GLX_PUT_DOUBLE(16, u2); 219848b8605Smrg __GLX_PUT_DOUBLE(24, v1); 220848b8605Smrg __GLX_PUT_DOUBLE(32, v2); 221848b8605Smrg __GLX_PUT_LONG(40, target); 222848b8605Smrg __GLX_PUT_LONG(44, uord); 223848b8605Smrg __GLX_PUT_LONG(48, vord); 224848b8605Smrg 225848b8605Smrg /* 226848b8605Smrg ** NOTE: the doubles that follow are not aligned because of 5 227848b8605Smrg ** longs preceeding 228848b8605Smrg */ 229848b8605Smrg if ((vstr != k) || (ustr != k * vord)) { 230848b8605Smrg GLdouble *buf; 231848b8605Smrg 232848b8605Smrg buf = malloc(compsize); 233848b8605Smrg if (!buf) { 234848b8605Smrg __glXSetError(gc, GL_OUT_OF_MEMORY); 235848b8605Smrg return; 236848b8605Smrg } 237848b8605Smrg /* 238848b8605Smrg ** Pack into a u-major ordering. 239848b8605Smrg */ 240848b8605Smrg __glFillMap2d(k, uord, vord, ustr, vstr, pnts, buf); 241848b8605Smrg __glXSendLargeCommand(gc, pc, 52, buf, compsize); 242848b8605Smrg free((char *) buf); 243848b8605Smrg } 244848b8605Smrg else { 245848b8605Smrg /* Data is already packed. Just send it out */ 246848b8605Smrg __glXSendLargeCommand(gc, pc, 52, pnts, compsize); 247848b8605Smrg } 248848b8605Smrg } 249848b8605Smrg} 250848b8605Smrg 251848b8605Smrgvoid 252848b8605Smrg__indirect_glMap2f(GLenum target, GLfloat u1, GLfloat u2, GLint ustr, 253848b8605Smrg GLint uord, GLfloat v1, GLfloat v2, GLint vstr, GLint vord, 254848b8605Smrg const GLfloat * pnts) 255848b8605Smrg{ 256848b8605Smrg __GLX_DECLARE_VARIABLES(); 257848b8605Smrg GLint k; 258848b8605Smrg 259848b8605Smrg __GLX_LOAD_VARIABLES(); 260848b8605Smrg k = __glMap2f_size(target); 261848b8605Smrg if (k == 0) { 262848b8605Smrg __glXSetError(gc, GL_INVALID_ENUM); 263848b8605Smrg return; 264848b8605Smrg } 265848b8605Smrg else if (vstr < k || ustr < k || vord <= 0 || uord <= 0) { 266848b8605Smrg __glXSetError(gc, GL_INVALID_VALUE); 267848b8605Smrg return; 268848b8605Smrg } 269848b8605Smrg compsize = k * uord * vord * __GLX_SIZE_FLOAT32; 270848b8605Smrg cmdlen = 32 + compsize; 271848b8605Smrg if (!gc->currentDpy) 272848b8605Smrg return; 273848b8605Smrg 274848b8605Smrg /* 275848b8605Smrg ** The order that arguments are packed is different from the order 276848b8605Smrg ** for glMap2d. 277848b8605Smrg */ 278848b8605Smrg if (cmdlen <= gc->maxSmallRenderCommandSize) { 279848b8605Smrg /* Use GLXRender protocol to send small command */ 280848b8605Smrg __GLX_BEGIN_VARIABLE(X_GLrop_Map2f, cmdlen); 281848b8605Smrg __GLX_PUT_LONG(4, target); 282848b8605Smrg __GLX_PUT_FLOAT(8, u1); 283848b8605Smrg __GLX_PUT_FLOAT(12, u2); 284848b8605Smrg __GLX_PUT_LONG(16, uord); 285848b8605Smrg __GLX_PUT_FLOAT(20, v1); 286848b8605Smrg __GLX_PUT_FLOAT(24, v2); 287848b8605Smrg __GLX_PUT_LONG(28, vord); 288848b8605Smrg /* 289848b8605Smrg ** Pack into a u-major ordering. 290848b8605Smrg */ 291848b8605Smrg __glFillMap2f(k, uord, vord, ustr, vstr, pnts, (GLfloat *) (pc + 32)); 292848b8605Smrg __GLX_END(cmdlen); 293848b8605Smrg } 294848b8605Smrg else { 295848b8605Smrg /* Use GLXRenderLarge protocol to send command */ 296848b8605Smrg __GLX_BEGIN_VARIABLE_LARGE(X_GLrop_Map2f, cmdlen + 4); 297848b8605Smrg __GLX_PUT_LONG(8, target); 298848b8605Smrg __GLX_PUT_FLOAT(12, u1); 299848b8605Smrg __GLX_PUT_FLOAT(16, u2); 300848b8605Smrg __GLX_PUT_LONG(20, uord); 301848b8605Smrg __GLX_PUT_FLOAT(24, v1); 302848b8605Smrg __GLX_PUT_FLOAT(28, v2); 303848b8605Smrg __GLX_PUT_LONG(32, vord); 304848b8605Smrg 305848b8605Smrg if ((vstr != k) || (ustr != k * vord)) { 306848b8605Smrg GLfloat *buf; 307848b8605Smrg 308848b8605Smrg buf = malloc(compsize); 309848b8605Smrg if (!buf) { 310848b8605Smrg __glXSetError(gc, GL_OUT_OF_MEMORY); 311848b8605Smrg return; 312848b8605Smrg } 313848b8605Smrg /* 314848b8605Smrg ** Pack into a u-major ordering. 315848b8605Smrg */ 316848b8605Smrg __glFillMap2f(k, uord, vord, ustr, vstr, pnts, buf); 317848b8605Smrg __glXSendLargeCommand(gc, pc, 36, buf, compsize); 318848b8605Smrg free((char *) buf); 319848b8605Smrg } 320848b8605Smrg else { 321848b8605Smrg /* Data is already packed. Just send it out */ 322848b8605Smrg __glXSendLargeCommand(gc, pc, 36, pnts, compsize); 323848b8605Smrg } 324848b8605Smrg } 325848b8605Smrg} 326848b8605Smrg 327848b8605Smrgvoid 328848b8605Smrg__indirect_glEnable(GLenum cap) 329848b8605Smrg{ 330848b8605Smrg __GLX_DECLARE_VARIABLES(); 331848b8605Smrg 332848b8605Smrg __GLX_LOAD_VARIABLES(); 333848b8605Smrg if (!gc->currentDpy) 334848b8605Smrg return; 335848b8605Smrg 336848b8605Smrg switch (cap) { 337848b8605Smrg case GL_COLOR_ARRAY: 338848b8605Smrg case GL_EDGE_FLAG_ARRAY: 339848b8605Smrg case GL_INDEX_ARRAY: 340848b8605Smrg case GL_NORMAL_ARRAY: 341848b8605Smrg case GL_TEXTURE_COORD_ARRAY: 342848b8605Smrg case GL_VERTEX_ARRAY: 343848b8605Smrg case GL_SECONDARY_COLOR_ARRAY: 344848b8605Smrg case GL_FOG_COORD_ARRAY: 345848b8605Smrg __indirect_glEnableClientState(cap); 346848b8605Smrg return; 347848b8605Smrg default: 348848b8605Smrg break; 349848b8605Smrg } 350848b8605Smrg 351848b8605Smrg __GLX_BEGIN(X_GLrop_Enable, 8); 352848b8605Smrg __GLX_PUT_LONG(4, cap); 353848b8605Smrg __GLX_END(8); 354848b8605Smrg} 355848b8605Smrg 356848b8605Smrgvoid 357848b8605Smrg__indirect_glDisable(GLenum cap) 358848b8605Smrg{ 359848b8605Smrg __GLX_DECLARE_VARIABLES(); 360848b8605Smrg 361848b8605Smrg __GLX_LOAD_VARIABLES(); 362848b8605Smrg if (!gc->currentDpy) 363848b8605Smrg return; 364848b8605Smrg 365848b8605Smrg switch (cap) { 366848b8605Smrg case GL_COLOR_ARRAY: 367848b8605Smrg case GL_EDGE_FLAG_ARRAY: 368848b8605Smrg case GL_INDEX_ARRAY: 369848b8605Smrg case GL_NORMAL_ARRAY: 370848b8605Smrg case GL_TEXTURE_COORD_ARRAY: 371848b8605Smrg case GL_VERTEX_ARRAY: 372848b8605Smrg case GL_SECONDARY_COLOR_ARRAY: 373848b8605Smrg case GL_FOG_COORD_ARRAY: 374848b8605Smrg __indirect_glDisableClientState(cap); 375848b8605Smrg return; 376848b8605Smrg default: 377848b8605Smrg break; 378848b8605Smrg } 379848b8605Smrg 380848b8605Smrg __GLX_BEGIN(X_GLrop_Disable, 8); 381848b8605Smrg __GLX_PUT_LONG(4, cap); 382848b8605Smrg __GLX_END(8); 383848b8605Smrg} 384848b8605Smrg 385848b8605Smrg#endif 386