1 /*
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:
9 **
10 ** http://oss.sgi.com/projects/FreeB
11 **
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.
17 **
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.
23 **
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.
33 */
34
35 /*
36 * glcurveval.c++
37 *
38 */
39
40 /* Polynomial Evaluator Interface */
41
42 #include "gluos.h"
43 //#include "glimports.h"
44 #include "glrenderer.h"
45 //#include "glcurveval.h"
46 //#include "nurbsconsts.h"
47
OpenGLCurveEvaluator(void)48 OpenGLCurveEvaluator::OpenGLCurveEvaluator(void)
49 {
50 //no default callback functions
51 beginCallBackN = NULL;
52 endCallBackN = 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;
63
64 userData = NULL;
65
66 vertex_flag = 0;
67 normal_flag = 0;
68 color_flag = 0;
69 texcoord_flag = 0;
70
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
76 }
77
~OpenGLCurveEvaluator(void)78 OpenGLCurveEvaluator::~OpenGLCurveEvaluator(void)
79 {
80 }
81
82 /* added nonsense to avoid the warning messages at compile time */
83 void
addMap(CurveMap * m)84 OpenGLCurveEvaluator::addMap(CurveMap *m)
85 {
86 m = m;
87 }
88
89 void
range1f(long type,REAL * from,REAL * to)90 OpenGLCurveEvaluator::range1f(long type, REAL *from, REAL *to)
91 {
92 type = type;
93 from = from;
94 to = to;
95 }
96
97 void
domain1f(REAL ulo,REAL uhi)98 OpenGLCurveEvaluator::domain1f(REAL ulo, REAL uhi)
99 {
100 ulo = ulo;
101 uhi = uhi;
102 }
103
104 void
bgnline(void)105 OpenGLCurveEvaluator::bgnline(void)
106 {
107 if(output_triangles)
108 beginCallBack(GL_LINE_STRIP, userData);
109 else
110 glBegin((GLenum) GL_LINE_STRIP);
111 }
112
113 void
endline(void)114 OpenGLCurveEvaluator::endline(void)
115 {
116 if(output_triangles)
117 endCallBack(userData);
118 else
119 glEnd();
120 }
121
122 /*---------------------------------------------------------------------------
123 * disable - turn off a curve map
124 *---------------------------------------------------------------------------
125 */
126 void
disable(long type)127 OpenGLCurveEvaluator::disable(long type)
128 {
129 glDisable((GLenum) type);
130 }
131
132 /*---------------------------------------------------------------------------
133 * enable - turn on a curve map
134 *---------------------------------------------------------------------------
135 */
136 void
enable(long type)137 OpenGLCurveEvaluator::enable(long type)
138 {
139 glEnable((GLenum) type);
140 }
141
142 /*-------------------------------------------------------------------------
143 * mapgrid1f - define a lattice of points with origin and offset
144 *-------------------------------------------------------------------------
145 */
146 void
mapgrid1f(long nu,REAL u0,REAL u1)147 OpenGLCurveEvaluator::mapgrid1f(long nu, REAL u0, REAL u1)
148 {
149 if(output_triangles)
150 {
151 global_grid_u0 = u0;
152 global_grid_u1 = u1;
153 global_grid_nu = (int) nu;
154 }
155 else
156 glMapGrid1f((GLint) nu, (GLfloat) u0, (GLfloat) u1);
157 }
158
159 /*-------------------------------------------------------------------------
160 * bgnmap1 - preamble to curve definition and evaluations
161 *-------------------------------------------------------------------------
162 */
163 void
bgnmap1f(long)164 OpenGLCurveEvaluator::bgnmap1f(long)
165 {
166 if(output_triangles)
167 {
168 //initialized so that no maps are set initially
169 vertex_flag = 0;
170 normal_flag = 0;
171 color_flag = 0;
172 texcoord_flag = 0;
173 //no need to worry about gl states when doing callback
174 }
175 else
176 glPushAttrib((GLbitfield) GL_EVAL_BIT);
177 }
178
179 /*-------------------------------------------------------------------------
180 * endmap1 - postamble to a curve map
181 *-------------------------------------------------------------------------
182 */
183 void
endmap1f(void)184 OpenGLCurveEvaluator::endmap1f(void)
185 {
186 if(output_triangles)
187 {
188
189 }
190 else
191 glPopAttrib();
192 }
193
194 /*-------------------------------------------------------------------------
195 * map1f - pass a desription of a curve map
196 *-------------------------------------------------------------------------
197 */
198 void
map1f(long type,REAL ulo,REAL uhi,long stride,long order,REAL * pts)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 */
206 )
207 {
208 if(output_triangles)
209 {
210 int dimension = 0;
211 int which = 0;
212 switch(type){
213 case GL_MAP1_VERTEX_3:
214 which = 0;
215 dimension = 3;
216 break;
217 case GL_MAP1_VERTEX_4:
218 which=0;
219 dimension = 4;
220 break;
221 case GL_MAP1_INDEX:
222 which=2;
223 dimension = 1;
224 break;
225 case GL_MAP1_COLOR_4:
226 which=2;
227 dimension = 4;
228 break;
229 case GL_MAP1_NORMAL:
230 which=1;
231 dimension = 3;
232 break;
233 case GL_MAP1_TEXTURE_COORD_1:
234 which=3;
235 dimension = 1;
236 break;
237 case GL_MAP1_TEXTURE_COORD_2:
238 which=3;
239 dimension = 2;
240 break;
241
242 case GL_MAP1_TEXTURE_COORD_3:
243 which=3;
244 dimension = 3;
245 break;
246 case GL_MAP1_TEXTURE_COORD_4:
247 which=3;
248 dimension = 4;
249 break;
250 }
251 inMap1f(which, dimension, ulo, uhi, stride, order, pts);
252 }
253 else
254 glMap1f((GLenum) type, (GLfloat) ulo, (GLfloat) uhi, (GLint) stride,
255 (GLint) order, (const GLfloat *) pts);
256 }
257
258 /*-------------------------------------------------------------------------
259 * mapmesh1f - evaluate a mesh of points on lattice
260 *-------------------------------------------------------------------------
261 */
mapmesh1f(long style,long from,long to)262 void OpenGLCurveEvaluator::mapmesh1f(long style, long from, long to)
263 {
264 if(output_triangles)
265 {
266 inMapMesh1f((int) from, (int) to);
267 }
268 else
269 {
270 switch(style) {
271 default:
272 case N_MESHFILL:
273 case N_MESHLINE:
274 glEvalMesh1((GLenum) GL_LINE, (GLint) from, (GLint) to);
275 break;
276 case N_MESHPOINT:
277 glEvalMesh1((GLenum) GL_POINT, (GLint) from, (GLint) to);
278 break;
279 }
280 }
281 }
282
283 /*-------------------------------------------------------------------------
284 * evalpoint1i - evaluate a point on a curve
285 *-------------------------------------------------------------------------
286 */
evalpoint1i(long i)287 void OpenGLCurveEvaluator::evalpoint1i(long i)
288 {
289 glEvalPoint1((GLint) i);
290 }
291
292 /*-------------------------------------------------------------------------
293 * evalcoord1f - evaluate a point on a curve
294 *-------------------------------------------------------------------------
295 */
evalcoord1f(long,REAL u)296 void OpenGLCurveEvaluator::evalcoord1f(long, REAL u)
297 {
298 glEvalCoord1f((GLfloat) u);
299 }
300
301 void
302 #ifdef _WIN32
putCallBack(GLenum which,void (GLAPIENTRY * fn)())303 OpenGLCurveEvaluator::putCallBack(GLenum which, void (GLAPIENTRY *fn)())
304 #else
305 OpenGLCurveEvaluator::putCallBack(GLenum which, _GLUfuncptr fn)
306 #endif
307 {
308 switch(which)
309 {
310 case GLU_NURBS_BEGIN:
311 beginCallBackN = (void (GLAPIENTRY *) (GLenum)) fn;
312 break;
313 case GLU_NURBS_END:
314 endCallBackN = (void (GLAPIENTRY *) (void)) fn;
315 break;
316 case GLU_NURBS_VERTEX:
317 vertexCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn;
318 break;
319 case GLU_NURBS_NORMAL:
320 normalCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn;
321 break;
322 case GLU_NURBS_COLOR:
323 colorCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn;
324 break;
325 case GLU_NURBS_TEXTURE_COORD:
326 texcoordCallBackN = (void (GLAPIENTRY *) (const GLfloat*)) fn;
327 break;
328 case GLU_NURBS_BEGIN_DATA:
329 beginCallBackData = (void (GLAPIENTRY *) (GLenum, void*)) fn;
330 break;
331 case GLU_NURBS_END_DATA:
332 endCallBackData = (void (GLAPIENTRY *) (void*)) fn;
333 break;
334 case GLU_NURBS_VERTEX_DATA:
335 vertexCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn;
336 break;
337 case GLU_NURBS_NORMAL_DATA:
338 normalCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn;
339 break;
340 case GLU_NURBS_COLOR_DATA:
341 colorCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn;
342 break;
343 case GLU_NURBS_TEXTURE_COORD_DATA:
344 texcoordCallBackData = (void (GLAPIENTRY *) (const GLfloat*, void*)) fn;
345 break;
346 }
347 }
348
349 void
beginCallBack(GLenum which,void * data)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
endCallBack(void * data)359 OpenGLCurveEvaluator::endCallBack(void *data)
360 {
361 if(endCallBackData)
362 endCallBackData(data);
363 else if(endCallBackN)
364 endCallBackN();
365 }
366
367 void
vertexCallBack(const GLfloat * vert,void * data)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
normalCallBack(const GLfloat * normal,void * data)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
colorCallBack(const GLfloat * color,void * data)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
texcoordCallBack(const GLfloat * texcoord,void * data)396 OpenGLCurveEvaluator::texcoordCallBack(const GLfloat *texcoord, void* data)
397 {
398 if(texcoordCallBackData)
399 texcoordCallBackData(texcoord, data);
400 else if(texcoordCallBackN)
401 texcoordCallBackN(texcoord);
402 }
403