1f220fa62Smrg/* 2f220fa62Smrg** License Applicability. Except to the extent portions of this file are 3f220fa62Smrg** made subject to an alternative license as permitted in the SGI Free 4f220fa62Smrg** Software License B, Version 1.1 (the "License"), the contents of this 5f220fa62Smrg** file are subject only to the provisions of the License. You may not use 6f220fa62Smrg** this file except in compliance with the License. You may obtain a copy 7f220fa62Smrg** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 8f220fa62Smrg** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: 9f220fa62Smrg** 10f220fa62Smrg** http://oss.sgi.com/projects/FreeB 11f220fa62Smrg** 12f220fa62Smrg** Note that, as provided in the License, the Software is distributed on an 13f220fa62Smrg** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS 14f220fa62Smrg** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND 15f220fa62Smrg** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A 16f220fa62Smrg** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. 17f220fa62Smrg** 18f220fa62Smrg** Original Code. The Original Code is: OpenGL Sample Implementation, 19f220fa62Smrg** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, 20f220fa62Smrg** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. 21f220fa62Smrg** Copyright in any portions created by third parties is as indicated 22f220fa62Smrg** elsewhere herein. All Rights Reserved. 23f220fa62Smrg** 24f220fa62Smrg** Additional Notice Provisions: The application programming interfaces 25f220fa62Smrg** established by SGI in conjunction with the Original Code are The 26f220fa62Smrg** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released 27f220fa62Smrg** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version 28f220fa62Smrg** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X 29f220fa62Smrg** Window System(R) (Version 1.3), released October 19, 1998. This software 30f220fa62Smrg** was created using the OpenGL(R) version 1.2.1 Sample Implementation 31f220fa62Smrg** published by SGI, but has not been independently verified as being 32f220fa62Smrg** compliant with the OpenGL(R) version 1.2.1 Specification. 33f220fa62Smrg*/ 34f220fa62Smrg 35f220fa62Smrg/* 36f220fa62Smrg * glcurveval.c++ 37f220fa62Smrg * 38f220fa62Smrg */ 39f220fa62Smrg 40f220fa62Smrg/* Polynomial Evaluator Interface */ 41f220fa62Smrg 42f220fa62Smrg#include "gluos.h" 43f220fa62Smrg#include "glimports.h" 44f220fa62Smrg#include "glrenderer.h" 45f220fa62Smrg#include "glcurveval.h" 46f220fa62Smrg#include "nurbsconsts.h" 47f220fa62Smrg 48f220fa62SmrgOpenGLCurveEvaluator::OpenGLCurveEvaluator(void) 49f220fa62Smrg{ 50f220fa62Smrg //no default callback functions 51f220fa62Smrg beginCallBackN = NULL; 52f220fa62Smrg endCallBackN = NULL; 53f220fa62Smrg vertexCallBackN = NULL; 54f220fa62Smrg normalCallBackN = NULL; 55f220fa62Smrg colorCallBackN = NULL; 56f220fa62Smrg texcoordCallBackN = NULL; 57f220fa62Smrg beginCallBackData = NULL; 58f220fa62Smrg endCallBackData = NULL; 59f220fa62Smrg vertexCallBackData = NULL; 60f220fa62Smrg normalCallBackData = NULL; 61f220fa62Smrg colorCallBackData = NULL; 62f220fa62Smrg texcoordCallBackData = NULL; 63f220fa62Smrg 64f220fa62Smrg userData = NULL; 65f220fa62Smrg 66f220fa62Smrg vertex_flag = 0; 67f220fa62Smrg normal_flag = 0; 68f220fa62Smrg color_flag = 0; 69f220fa62Smrg texcoord_flag = 0; 70f220fa62Smrg 71f220fa62Smrg em_vertex.uprime = -1.0; 72f220fa62Smrg em_normal.uprime = -1.0; 73f220fa62Smrg em_color.uprime = -1.0; 74f220fa62Smrg em_texcoord.uprime = -1.0; 75f220fa62Smrg output_triangles = 0; // don't output triangles by default 76f220fa62Smrg} 77f220fa62Smrg 78f220fa62SmrgOpenGLCurveEvaluator::~OpenGLCurveEvaluator(void) 79f220fa62Smrg{ 80f220fa62Smrg} 81f220fa62Smrg 82f220fa62Smrg/* added nonsense to avoid the warning messages at compile time */ 83f220fa62Smrgvoid 84f220fa62SmrgOpenGLCurveEvaluator::addMap(CurveMap *m) 85f220fa62Smrg{ 86f220fa62Smrg m = m; 87f220fa62Smrg} 88f220fa62Smrg 89f220fa62Smrgvoid 90f220fa62SmrgOpenGLCurveEvaluator::range1f(long type, REAL *from, REAL *to) 91f220fa62Smrg{ 92f220fa62Smrg type = type; 93f220fa62Smrg from = from; 94f220fa62Smrg to = to; 95f220fa62Smrg} 96f220fa62Smrg 97f220fa62Smrgvoid 98f220fa62SmrgOpenGLCurveEvaluator::domain1f(REAL ulo, REAL uhi) 99f220fa62Smrg{ 100f220fa62Smrg ulo = ulo; 101f220fa62Smrg uhi = uhi; 102f220fa62Smrg} 103f220fa62Smrg 104f220fa62Smrgvoid 105f220fa62SmrgOpenGLCurveEvaluator::bgnline(void) 106f220fa62Smrg{ 107f220fa62Smrg if(output_triangles) 108f220fa62Smrg beginCallBack(GL_LINE_STRIP, userData); 109f220fa62Smrg else 110f220fa62Smrg glBegin((GLenum) GL_LINE_STRIP); 111f220fa62Smrg} 112f220fa62Smrg 113f220fa62Smrgvoid 114f220fa62SmrgOpenGLCurveEvaluator::endline(void) 115f220fa62Smrg{ 116f220fa62Smrg if(output_triangles) 117f220fa62Smrg endCallBack(userData); 118f220fa62Smrg else 119f220fa62Smrg glEnd(); 120f220fa62Smrg} 121f220fa62Smrg 122f220fa62Smrg/*--------------------------------------------------------------------------- 123f220fa62Smrg * disable - turn off a curve map 124f220fa62Smrg *--------------------------------------------------------------------------- 125f220fa62Smrg */ 126f220fa62Smrgvoid 127f220fa62SmrgOpenGLCurveEvaluator::disable(long type) 128f220fa62Smrg{ 129f220fa62Smrg glDisable((GLenum) type); 130f220fa62Smrg} 131f220fa62Smrg 132f220fa62Smrg/*--------------------------------------------------------------------------- 133f220fa62Smrg * enable - turn on a curve map 134f220fa62Smrg *--------------------------------------------------------------------------- 135f220fa62Smrg */ 136f220fa62Smrgvoid 137f220fa62SmrgOpenGLCurveEvaluator::enable(long type) 138f220fa62Smrg{ 139f220fa62Smrg glEnable((GLenum) type); 140f220fa62Smrg} 141f220fa62Smrg 142f220fa62Smrg/*------------------------------------------------------------------------- 143f220fa62Smrg * mapgrid1f - define a lattice of points with origin and offset 144f220fa62Smrg *------------------------------------------------------------------------- 145f220fa62Smrg */ 146f220fa62Smrgvoid 147f220fa62SmrgOpenGLCurveEvaluator::mapgrid1f(long nu, REAL u0, REAL u1) 148f220fa62Smrg{ 149f220fa62Smrg if(output_triangles) 150f220fa62Smrg { 151f220fa62Smrg global_grid_u0 = u0; 152f220fa62Smrg global_grid_u1 = u1; 153f220fa62Smrg global_grid_nu = (int) nu; 154f220fa62Smrg } 155f220fa62Smrg else 156f220fa62Smrg glMapGrid1f((GLint) nu, (GLfloat) u0, (GLfloat) u1); 157f220fa62Smrg} 158f220fa62Smrg 159f220fa62Smrg/*------------------------------------------------------------------------- 160f220fa62Smrg * bgnmap1 - preamble to curve definition and evaluations 161f220fa62Smrg *------------------------------------------------------------------------- 162f220fa62Smrg */ 163f220fa62Smrgvoid 164f220fa62SmrgOpenGLCurveEvaluator::bgnmap1f(long) 165f220fa62Smrg{ 166f220fa62Smrg if(output_triangles) 167f220fa62Smrg { 168f220fa62Smrg //initialized so that no maps are set initially 169f220fa62Smrg vertex_flag = 0; 170f220fa62Smrg normal_flag = 0; 171f220fa62Smrg color_flag = 0; 172f220fa62Smrg texcoord_flag = 0; 173f220fa62Smrg //no need to worry about gl states when doing callback 174f220fa62Smrg } 175f220fa62Smrg else 176f220fa62Smrg glPushAttrib((GLbitfield) GL_EVAL_BIT); 177f220fa62Smrg} 178f220fa62Smrg 179f220fa62Smrg/*------------------------------------------------------------------------- 180f220fa62Smrg * endmap1 - postamble to a curve map 181f220fa62Smrg *------------------------------------------------------------------------- 182f220fa62Smrg */ 183f220fa62Smrgvoid 184f220fa62SmrgOpenGLCurveEvaluator::endmap1f(void) 185f220fa62Smrg{ 186f220fa62Smrg if(output_triangles) 187f220fa62Smrg { 188f220fa62Smrg 189f220fa62Smrg } 190f220fa62Smrg else 191f220fa62Smrg glPopAttrib(); 192f220fa62Smrg} 193f220fa62Smrg 194f220fa62Smrg/*------------------------------------------------------------------------- 195f220fa62Smrg * map1f - pass a desription of a curve map 196f220fa62Smrg *------------------------------------------------------------------------- 197f220fa62Smrg */ 198f220fa62Smrgvoid 199f220fa62SmrgOpenGLCurveEvaluator::map1f( 200f220fa62Smrg long type, /* map type */ 201f220fa62Smrg REAL ulo, /* lower parametric bound */ 202f220fa62Smrg REAL uhi, /* upper parametric bound */ 203f220fa62Smrg long stride, /* distance to next point in REALS */ 204f220fa62Smrg long order, /* parametric order */ 205f220fa62Smrg REAL *pts /* control points */ 206f220fa62Smrg) 207f220fa62Smrg{ 208f220fa62Smrg if(output_triangles) 209f220fa62Smrg { 210f220fa62Smrg int dimension = 0; 211f220fa62Smrg int which = 0; 212f220fa62Smrg switch(type){ 213f220fa62Smrg case GL_MAP1_VERTEX_3: 214f220fa62Smrg which = 0; 215f220fa62Smrg dimension = 3; 216f220fa62Smrg break; 217f220fa62Smrg case GL_MAP1_VERTEX_4: 218f220fa62Smrg which=0; 219f220fa62Smrg dimension = 4; 220f220fa62Smrg break; 221f220fa62Smrg case GL_MAP1_INDEX: 222f220fa62Smrg which=2; 223f220fa62Smrg dimension = 1; 224f220fa62Smrg break; 225f220fa62Smrg case GL_MAP1_COLOR_4: 226f220fa62Smrg which=2; 227f220fa62Smrg dimension = 4; 228f220fa62Smrg break; 229f220fa62Smrg case GL_MAP1_NORMAL: 230f220fa62Smrg which=1; 231f220fa62Smrg dimension = 3; 232f220fa62Smrg break; 233f220fa62Smrg case GL_MAP1_TEXTURE_COORD_1: 234f220fa62Smrg which=3; 235f220fa62Smrg dimension = 1; 236f220fa62Smrg break; 237f220fa62Smrg case GL_MAP1_TEXTURE_COORD_2: 238f220fa62Smrg which=3; 239f220fa62Smrg dimension = 2; 240f220fa62Smrg break; 241f220fa62Smrg 242f220fa62Smrg case GL_MAP1_TEXTURE_COORD_3: 243f220fa62Smrg which=3; 244f220fa62Smrg dimension = 3; 245f220fa62Smrg break; 246f220fa62Smrg case GL_MAP1_TEXTURE_COORD_4: 247f220fa62Smrg which=3; 248f220fa62Smrg dimension = 4; 249f220fa62Smrg break; 250f220fa62Smrg } 251f220fa62Smrg inMap1f(which, dimension, ulo, uhi, stride, order, pts); 252f220fa62Smrg } 253f220fa62Smrg else 254f220fa62Smrg glMap1f((GLenum) type, (GLfloat) ulo, (GLfloat) uhi, (GLint) stride, 255f220fa62Smrg (GLint) order, (const GLfloat *) pts); 256f220fa62Smrg} 257f220fa62Smrg 258f220fa62Smrg/*------------------------------------------------------------------------- 259f220fa62Smrg * mapmesh1f - evaluate a mesh of points on lattice 260f220fa62Smrg *------------------------------------------------------------------------- 261f220fa62Smrg */ 262f220fa62Smrgvoid OpenGLCurveEvaluator::mapmesh1f(long style, long from, long to) 263f220fa62Smrg{ 264f220fa62Smrg if(output_triangles) 265f220fa62Smrg { 266f220fa62Smrg inMapMesh1f((int) from, (int) to); 267f220fa62Smrg } 268f220fa62Smrg else 269f220fa62Smrg { 270f220fa62Smrg switch(style) { 271f220fa62Smrg default: 272f220fa62Smrg case N_MESHFILL: 273f220fa62Smrg case N_MESHLINE: 274f220fa62Smrg glEvalMesh1((GLenum) GL_LINE, (GLint) from, (GLint) to); 275f220fa62Smrg break; 276f220fa62Smrg case N_MESHPOINT: 277f220fa62Smrg glEvalMesh1((GLenum) GL_POINT, (GLint) from, (GLint) to); 278f220fa62Smrg break; 279f220fa62Smrg } 280f220fa62Smrg } 281f220fa62Smrg} 282f220fa62Smrg 283f220fa62Smrg/*------------------------------------------------------------------------- 284f220fa62Smrg * evalpoint1i - evaluate a point on a curve 285f220fa62Smrg *------------------------------------------------------------------------- 286f220fa62Smrg */ 287f220fa62Smrgvoid OpenGLCurveEvaluator::evalpoint1i(long i) 288f220fa62Smrg{ 289f220fa62Smrg glEvalPoint1((GLint) i); 290f220fa62Smrg} 291f220fa62Smrg 292f220fa62Smrg/*------------------------------------------------------------------------- 293f220fa62Smrg * evalcoord1f - evaluate a point on a curve 294f220fa62Smrg *------------------------------------------------------------------------- 295f220fa62Smrg */ 296f220fa62Smrgvoid OpenGLCurveEvaluator::evalcoord1f(long, REAL u) 297f220fa62Smrg{ 298f220fa62Smrg glEvalCoord1f((GLfloat) u); 299f220fa62Smrg} 300f220fa62Smrg 301f220fa62Smrgvoid 302f220fa62Smrg#ifdef _WIN32 303f220fa62SmrgOpenGLCurveEvaluator::putCallBack(GLenum which, void (GLAPIENTRY *fn)()) 304f220fa62Smrg#else 305f220fa62SmrgOpenGLCurveEvaluator::putCallBack(GLenum which, _GLUfuncptr fn) 306f220fa62Smrg#endif 307f220fa62Smrg{ 308f220fa62Smrg switch(which) 309f220fa62Smrg { 310f220fa62Smrg case GLU_NURBS_BEGIN: 311f220fa62Smrg beginCallBackN = (void (GLAPIENTRY *) (GLenum)) fn; 312f220fa62Smrg break; 313f220fa62Smrg case GLU_NURBS_END: 314f220fa62Smrg endCallBackN = (void (GLAPIENTRY *) (void)) fn; 315f220fa62Smrg break; 316f220fa62Smrg case GLU_NURBS_VERTEX: 317f220fa62Smrg vertexCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn; 318f220fa62Smrg break; 319f220fa62Smrg case GLU_NURBS_NORMAL: 320f220fa62Smrg normalCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn; 321f220fa62Smrg break; 322f220fa62Smrg case GLU_NURBS_COLOR: 323f220fa62Smrg colorCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn; 324f220fa62Smrg break; 325f220fa62Smrg case GLU_NURBS_TEXTURE_COORD: 326f220fa62Smrg texcoordCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn; 327f220fa62Smrg break; 328f220fa62Smrg case GLU_NURBS_BEGIN_DATA: 329f220fa62Smrg beginCallBackData = (void (GLAPIENTRY *) (GLenum, void*)) fn; 330f220fa62Smrg break; 331f220fa62Smrg case GLU_NURBS_END_DATA: 332f220fa62Smrg endCallBackData = (void (GLAPIENTRY *) (void*)) fn; 333f220fa62Smrg break; 334f220fa62Smrg case GLU_NURBS_VERTEX_DATA: 335f220fa62Smrg vertexCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn; 336f220fa62Smrg break; 337f220fa62Smrg case GLU_NURBS_NORMAL_DATA: 338f220fa62Smrg normalCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn; 339f220fa62Smrg break; 340f220fa62Smrg case GLU_NURBS_COLOR_DATA: 341f220fa62Smrg colorCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn; 342f220fa62Smrg break; 343f220fa62Smrg case GLU_NURBS_TEXTURE_COORD_DATA: 344f220fa62Smrg texcoordCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn; 345f220fa62Smrg break; 346f220fa62Smrg } 347f220fa62Smrg} 348f220fa62Smrg 349f220fa62Smrgvoid 350f220fa62SmrgOpenGLCurveEvaluator::beginCallBack(GLenum which, void *data) 351f220fa62Smrg{ 352f220fa62Smrg if(beginCallBackData) 353f220fa62Smrg beginCallBackData(which, data); 354f220fa62Smrg else if(beginCallBackN) 355f220fa62Smrg beginCallBackN(which); 356f220fa62Smrg} 357f220fa62Smrg 358f220fa62Smrgvoid 359f220fa62SmrgOpenGLCurveEvaluator::endCallBack(void *data) 360f220fa62Smrg{ 361f220fa62Smrg if(endCallBackData) 362f220fa62Smrg endCallBackData(data); 363f220fa62Smrg else if(endCallBackN) 364f220fa62Smrg endCallBackN(); 365f220fa62Smrg} 366f220fa62Smrg 367f220fa62Smrgvoid 368f220fa62SmrgOpenGLCurveEvaluator::vertexCallBack(const GLfloat *vert, void* data) 369f220fa62Smrg{ 370f220fa62Smrg if(vertexCallBackData) 371f220fa62Smrg vertexCallBackData(vert, data); 372f220fa62Smrg else if(vertexCallBackN) 373f220fa62Smrg vertexCallBackN(vert); 374f220fa62Smrg} 375f220fa62Smrg 376f220fa62Smrg 377f220fa62Smrgvoid 378f220fa62SmrgOpenGLCurveEvaluator::normalCallBack(const GLfloat *normal, void* data) 379f220fa62Smrg{ 380f220fa62Smrg if(normalCallBackData) 381f220fa62Smrg normalCallBackData(normal, data); 382f220fa62Smrg else if(normalCallBackN) 383f220fa62Smrg normalCallBackN(normal); 384f220fa62Smrg} 385f220fa62Smrg 386f220fa62Smrgvoid 387f220fa62SmrgOpenGLCurveEvaluator::colorCallBack(const GLfloat *color, void* data) 388f220fa62Smrg{ 389f220fa62Smrg if(colorCallBackData) 390f220fa62Smrg colorCallBackData(color, data); 391f220fa62Smrg else if(colorCallBackN) 392f220fa62Smrg colorCallBackN(color); 393f220fa62Smrg} 394f220fa62Smrg 395f220fa62Smrgvoid 396f220fa62SmrgOpenGLCurveEvaluator::texcoordCallBack(const GLfloat *texcoord, void* data) 397f220fa62Smrg{ 398f220fa62Smrg if(texcoordCallBackData) 399f220fa62Smrg texcoordCallBackData(texcoord, data); 400f220fa62Smrg else if(texcoordCallBackN) 401f220fa62Smrg texcoordCallBackN(texcoord); 402f220fa62Smrg} 403