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