2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 ** http://oss.sgi.com/projects/FreeB
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
40 /* Polynomial Evaluator Interface */
43 #include "glimports.h"
44 #include "glrenderer.h"
45 #include "glcurveval.h"
46 #include "nurbsconsts.h"
48 OpenGLCurveEvaluator::OpenGLCurveEvaluator(void)
50 //no default callback functions
51 beginCallBackN = NULL;
53 vertexCallBackN = NULL;
54 normalCallBackN = NULL;
55 colorCallBackN = NULL;
56 texcoordCallBackN = NULL;
57 beginCallBackData = NULL;
58 endCallBackData = NULL;
59 vertexCallBackData = NULL;
60 normalCallBackData = NULL;
61 colorCallBackData = NULL;
62 texcoordCallBackData = NULL;
71 em_vertex.uprime = -1.0;
72 em_normal.uprime = -1.0;
73 em_color.uprime = -1.0;
74 em_texcoord.uprime = -1.0;
75 output_triangles = 0; // don't output triangles by default
78 OpenGLCurveEvaluator::~OpenGLCurveEvaluator(void)
82 /* added nonsense to avoid the warning messages at compile time */
84 OpenGLCurveEvaluator::addMap(CurveMap *m)
90 OpenGLCurveEvaluator::range1f(long type, REAL *from, REAL *to)
98 OpenGLCurveEvaluator::domain1f(REAL ulo, REAL uhi)
105 OpenGLCurveEvaluator::bgnline(void)
108 beginCallBack(GL_LINE_STRIP, userData);
110 glBegin((GLenum) GL_LINE_STRIP);
114 OpenGLCurveEvaluator::endline(void)
117 endCallBack(userData);
122 /*---------------------------------------------------------------------------
123 * disable - turn off a curve map
124 *---------------------------------------------------------------------------
127 OpenGLCurveEvaluator::disable(long type)
129 glDisable((GLenum) type);
132 /*---------------------------------------------------------------------------
133 * enable - turn on a curve map
134 *---------------------------------------------------------------------------
137 OpenGLCurveEvaluator::enable(long type)
139 glEnable((GLenum) type);
142 /*-------------------------------------------------------------------------
143 * mapgrid1f - define a lattice of points with origin and offset
144 *-------------------------------------------------------------------------
147 OpenGLCurveEvaluator::mapgrid1f(long nu, REAL u0, REAL u1)
153 global_grid_nu = (int) nu;
156 glMapGrid1f((GLint) nu, (GLfloat) u0, (GLfloat) u1);
159 /*-------------------------------------------------------------------------
160 * bgnmap1 - preamble to curve definition and evaluations
161 *-------------------------------------------------------------------------
164 OpenGLCurveEvaluator::bgnmap1f(long)
168 //initialized so that no maps are set initially
173 //no need to worry about gl states when doing callback
176 glPushAttrib((GLbitfield) GL_EVAL_BIT);
179 /*-------------------------------------------------------------------------
180 * endmap1 - postamble to a curve map
181 *-------------------------------------------------------------------------
184 OpenGLCurveEvaluator::endmap1f(void)
194 /*-------------------------------------------------------------------------
195 * map1f - pass a desription of a curve map
196 *-------------------------------------------------------------------------
199 OpenGLCurveEvaluator::map1f(
200 long type, /* map type */
201 REAL ulo, /* lower parametric bound */
202 REAL uhi, /* upper parametric bound */
203 long stride, /* distance to next point in REALS */
204 long order, /* parametric order */
205 REAL *pts /* control points */
213 case GL_MAP1_VERTEX_3:
217 case GL_MAP1_VERTEX_4:
225 case GL_MAP1_COLOR_4:
233 case GL_MAP1_TEXTURE_COORD_1:
237 case GL_MAP1_TEXTURE_COORD_2:
242 case GL_MAP1_TEXTURE_COORD_3:
246 case GL_MAP1_TEXTURE_COORD_4:
251 inMap1f(which, dimension, ulo, uhi, stride, order, pts);
254 glMap1f((GLenum) type, (GLfloat) ulo, (GLfloat) uhi, (GLint) stride,
255 (GLint) order, (const GLfloat *) pts);
258 /*-------------------------------------------------------------------------
259 * mapmesh1f - evaluate a mesh of points on lattice
260 *-------------------------------------------------------------------------
262 void OpenGLCurveEvaluator::mapmesh1f(long style, long from, long to)
266 inMapMesh1f((int) from, (int) to);
274 glEvalMesh1((GLenum) GL_LINE, (GLint) from, (GLint) to);
277 glEvalMesh1((GLenum) GL_POINT, (GLint) from, (GLint) to);
283 /*-------------------------------------------------------------------------
284 * evalpoint1i - evaluate a point on a curve
285 *-------------------------------------------------------------------------
287 void OpenGLCurveEvaluator::evalpoint1i(long i)
289 glEvalPoint1((GLint) i);
292 /*-------------------------------------------------------------------------
293 * evalcoord1f - evaluate a point on a curve
294 *-------------------------------------------------------------------------
296 void OpenGLCurveEvaluator::evalcoord1f(long, REAL u)
298 glEvalCoord1f((GLfloat) u);
303 OpenGLCurveEvaluator::putCallBack(GLenum which, void (GLAPIENTRY *fn)())
305 OpenGLCurveEvaluator::putCallBack(GLenum which, _GLUfuncptr fn)
310 case GLU_NURBS_BEGIN:
311 beginCallBackN = (void (GLAPIENTRY *) (GLenum)) fn;
314 endCallBackN = (void (GLAPIENTRY *) (void)) fn;
316 case GLU_NURBS_VERTEX:
317 vertexCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn;
319 case GLU_NURBS_NORMAL:
320 normalCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn;
322 case GLU_NURBS_COLOR:
323 colorCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn;
325 case GLU_NURBS_TEXTURE_COORD:
326 texcoordCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn;
328 case GLU_NURBS_BEGIN_DATA:
329 beginCallBackData = (void (GLAPIENTRY *) (GLenum, void*)) fn;
331 case GLU_NURBS_END_DATA:
332 endCallBackData = (void (GLAPIENTRY *) (void*)) fn;
334 case GLU_NURBS_VERTEX_DATA:
335 vertexCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn;
337 case GLU_NURBS_NORMAL_DATA:
338 normalCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn;
340 case GLU_NURBS_COLOR_DATA:
341 colorCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn;
343 case GLU_NURBS_TEXTURE_COORD_DATA:
344 texcoordCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn;
350 OpenGLCurveEvaluator::beginCallBack(GLenum which, void *data)
352 if(beginCallBackData)
353 beginCallBackData(which, data);
354 else if(beginCallBackN)
355 beginCallBackN(which);
359 OpenGLCurveEvaluator::endCallBack(void *data)
362 endCallBackData(data);
363 else if(endCallBackN)
368 OpenGLCurveEvaluator::vertexCallBack(const GLfloat *vert, void* data)
370 if(vertexCallBackData)
371 vertexCallBackData(vert, data);
372 else if(vertexCallBackN)
373 vertexCallBackN(vert);
378 OpenGLCurveEvaluator::normalCallBack(const GLfloat *normal, void* data)
380 if(normalCallBackData)
381 normalCallBackData(normal, data);
382 else if(normalCallBackN)
383 normalCallBackN(normal);
387 OpenGLCurveEvaluator::colorCallBack(const GLfloat *color, void* data)
389 if(colorCallBackData)
390 colorCallBackData(color, data);
391 else if(colorCallBackN)
392 colorCallBackN(color);
396 OpenGLCurveEvaluator::texcoordCallBack(const GLfloat *texcoord, void* data)
398 if(texcoordCallBackData)
399 texcoordCallBackData(texcoord, data);
400 else if(texcoordCallBackN)
401 texcoordCallBackN(texcoord);