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 /* Bezier surface backend
41 - interprets display mode (wireframe,shaded,...)
44 #include "glimports.h"
47 #include "basiccrveval.h"
48 #include "basicsurfeval.h"
53 /*-------------------------------------------------------------------------
54 * bgnsurf - preamble to surface definition and evaluations
55 *-------------------------------------------------------------------------
58 Backend::bgnsurf( int wiretris
, int wirequads
, long nuid
)
60 /*#ifndef NOWIREFRAME*/ //need this for old version
61 wireframetris
= wiretris
;
62 wireframequads
= wirequads
;
65 /*in the spec, GLU_DISPLAY_MODE is either
69 *In fact, GLU_FLL is has the same effect as
70 * set GL_FRONT_AND_BACK to be GL_FILL
71 * and GLU_OUTLINE_POLY is the same as set
72 * GL_FRONT_AND_BACK to be GL_LINE
73 *It is more efficient to do this once at the beginning of
74 *each surface than to do it for each primitive.
75 * The internal has more options: outline_triangle and outline_quad
76 *can be seperated. But since this is not in spec, and more importantly,
77 *this is not so useful, so we don't need to keep this option.
80 surfaceEvaluator
.bgnmap2f( nuid
);
83 surfaceEvaluator
.polymode(N_MESHLINE
);
85 surfaceEvaluator
.polymode(N_MESHFILL
);
89 Backend::patch( REAL ulo
, REAL uhi
, REAL vlo
, REAL vhi
)
91 surfaceEvaluator
.domain2f( ulo
, uhi
, vlo
, vhi
);
95 Backend::surfbbox( long type
, REAL
*from
, REAL
*to
)
97 surfaceEvaluator
.range2f( type
, from
, to
);
100 /*-------------------------------------------------------------------------
101 * surfpts - pass a desription of a surface map
102 *-------------------------------------------------------------------------
106 long type
, /* geometry, color, texture, normal */
107 REAL
*pts
, /* control points */
108 long ustride
, /* distance to next point in u direction */
109 long vstride
, /* distance to next point in v direction */
110 int uorder
, /* u parametric order */
111 int vorder
, /* v parametric order */
112 REAL ulo
, /* u lower bound */
113 REAL uhi
, /* u upper bound */
114 REAL vlo
, /* v lower bound */
115 REAL vhi
) /* v upper bound */
117 surfaceEvaluator
.map2f( type
,ulo
,uhi
,ustride
,uorder
,vlo
,vhi
,vstride
,vorder
,pts
);
118 surfaceEvaluator
.enable( type
);
121 /*-------------------------------------------------------------------------
122 * surfgrid - define a lattice of points with origin and offset
123 *-------------------------------------------------------------------------
126 Backend::surfgrid( REAL u0
, REAL u1
, long nu
, REAL v0
, REAL v1
, long nv
)
128 surfaceEvaluator
.mapgrid2f( nu
, u0
, u1
, nv
, v0
, v1
);
131 /*-------------------------------------------------------------------------
132 * surfmesh - evaluate a mesh of points on lattice
133 *-------------------------------------------------------------------------
136 Backend::surfmesh( long u
, long v
, long n
, long m
)
139 if( wireframequads
) {
141 long u0f
= u
, u1f
= u
+n
;
142 long v0f
= v
, v1f
= v
+m
;
143 long parity
= (u
& 1);
145 for( v0
= v0f
, v1
= v0f
++ ; v0
<v1f
; v0
= v1
, v1
++ ) {
146 surfaceEvaluator
.bgnline();
147 for( long u
= u0f
; u
<=u1f
; u
++ ) {
149 surfaceEvaluator
.evalpoint2i( u
, v0
);
150 surfaceEvaluator
.evalpoint2i( u
, v1
);
152 surfaceEvaluator
.evalpoint2i( u
, v1
);
153 surfaceEvaluator
.evalpoint2i( u
, v0
);
157 surfaceEvaluator
.endline();
160 surfaceEvaluator
.mapmesh2f( N_MESHFILL
, u
, u
+n
, v
, v
+m
);
163 if( wireframequads
) {
165 surfaceEvaluator
.mapmesh2f( N_MESHLINE
, u
, u
+n
, v
, v
+m
);
168 surfaceEvaluator
.mapmesh2f( N_MESHFILL
, u
, u
+n
, v
, v
+m
);
173 /*-------------------------------------------------------------------------
174 * endsurf - postamble to surface
175 *-------------------------------------------------------------------------
178 Backend::endsurf( void )
180 surfaceEvaluator
.endmap2f();
183 /***************************************/
185 Backend::bgntfan( void )
187 surfaceEvaluator
.bgntfan();
190 surfaceEvaluator.polymode( N_MESHLINE );
192 surfaceEvaluator.polymode( N_MESHFILL );
197 Backend::endtfan( void )
199 surfaceEvaluator
.endtfan();
203 Backend::bgnqstrip( void )
205 surfaceEvaluator
.bgnqstrip();
208 surfaceEvaluator.polymode( N_MESHLINE );
210 surfaceEvaluator.polymode( N_MESHFILL );
215 Backend::endqstrip( void )
217 surfaceEvaluator
.endqstrip();
221 Backend::evalUStrip(int n_upper
, REAL v_upper
, REAL
* upper_val
,
222 int n_lower
, REAL v_lower
, REAL
* lower_val
225 surfaceEvaluator
.evalUStrip(n_upper
, v_upper
, upper_val
,
226 n_lower
, v_lower
, lower_val
);
230 Backend::evalVStrip(int n_left
, REAL u_left
, REAL
* left_val
,
231 int n_right
, REAL u_right
, REAL
* right_val
234 surfaceEvaluator
.evalVStrip(n_left
, u_left
, left_val
,
235 n_right
, u_right
, right_val
);
238 /***************************************/
241 /*-------------------------------------------------------------------------
242 * bgntmesh - preamble to a triangle mesh
243 *-------------------------------------------------------------------------
246 Backend::bgntmesh( const char * )
250 meshindex
= 0; /* I think these need to be initialized to zero */
253 if( !wireframetris
) {
254 surfaceEvaluator
.bgntmesh();
258 if( wireframetris
) {
259 surfaceEvaluator
.bgntmesh();
260 surfaceEvaluator
.polymode( N_MESHLINE
);
262 surfaceEvaluator
.bgntmesh();
263 surfaceEvaluator
.polymode( N_MESHFILL
);
269 Backend::tmeshvert( GridTrimVertex
*v
)
271 if( v
->isGridVert() ) {
279 Backend::tmeshvertNOGE(TrimVertex
*t
)
281 // surfaceEvaluator.inDoEvalCoord2NOGE( t->param[0], t->param[1], temp, ttt);
283 surfaceEvaluator
.inDoEvalCoord2NOGE( t
->param
[0], t
->param
[1], t
->cache_point
, t
->cache_normal
);
287 //opt for a line with the same u.
289 Backend::tmeshvertNOGE_BU(TrimVertex
*t
)
292 surfaceEvaluator
.inDoEvalCoord2NOGE_BU( t
->param
[0], t
->param
[1], t
->cache_point
, t
->cache_normal
);
296 //opt for a line with the same v.
298 Backend::tmeshvertNOGE_BV(TrimVertex
*t
)
301 surfaceEvaluator
.inDoEvalCoord2NOGE_BV( t
->param
[0], t
->param
[1], t
->cache_point
, t
->cache_normal
);
306 Backend::preEvaluateBU(REAL u
)
308 surfaceEvaluator
.inPreEvaluateBU_intfac(u
);
312 Backend::preEvaluateBV(REAL v
)
314 surfaceEvaluator
.inPreEvaluateBV_intfac(v
);
318 /*-------------------------------------------------------------------------
319 * tmeshvert - evaluate a point on a triangle mesh
320 *-------------------------------------------------------------------------
323 Backend::tmeshvert( TrimVertex
*t
)
327 const long nuid
= t
->nuid
;
329 const REAL u
= t
->param
[0];
330 const REAL v
= t
->param
[1];
334 if( wireframetris
) {
336 surfaceEvaluator
.bgnclosedline();
337 if( mesh
[0][2] == 0 )
338 surfaceEvaluator
.evalcoord2f( mesh
[0][3], mesh
[0][0], mesh
[0][1] );
340 surfaceEvaluator
.evalpoint2i( (long) mesh
[0][0], (long) mesh
[0][1] );
341 if( mesh
[1][2] == 0 )
342 surfaceEvaluator
.evalcoord2f( mesh
[1][3], mesh
[1][0], mesh
[1][1] );
344 surfaceEvaluator
.evalpoint2i( (long) mesh
[1][0], (long) mesh
[1][1] );
345 surfaceEvaluator
.evalcoord2f( nuid
, u
, v
);
346 surfaceEvaluator
.endclosedline();
348 mesh
[meshindex
][0] = u
;
349 mesh
[meshindex
][1] = v
;
350 mesh
[meshindex
][2] = 0;
351 mesh
[meshindex
][3] = nuid
;
352 meshindex
= (meshindex
+1) % 2;
354 surfaceEvaluator
.evalcoord2f( nuid
, u
, v
);
358 surfaceEvaluator
.evalcoord2f( 0, u
, v
);
359 //for uninitial memory read surfaceEvaluator.evalcoord2f( nuid, u, v );
363 //the same as tmeshvert(trimvertex), for efficiency purpose
365 Backend::tmeshvert( REAL u
, REAL v
)
371 if( wireframetris
) {
373 surfaceEvaluator
.bgnclosedline();
374 if( mesh
[0][2] == 0 )
375 surfaceEvaluator
.evalcoord2f( mesh
[0][3], mesh
[0][0], mesh
[0][1] );
377 surfaceEvaluator
.evalpoint2i( (long) mesh
[0][0], (long) mesh
[0][1] );
378 if( mesh
[1][2] == 0 )
379 surfaceEvaluator
.evalcoord2f( mesh
[1][3], mesh
[1][0], mesh
[1][1] );
381 surfaceEvaluator
.evalpoint2i( (long) mesh
[1][0], (long) mesh
[1][1] );
382 surfaceEvaluator
.evalcoord2f( nuid
, u
, v
);
383 surfaceEvaluator
.endclosedline();
385 mesh
[meshindex
][0] = u
;
386 mesh
[meshindex
][1] = v
;
387 mesh
[meshindex
][2] = 0;
388 mesh
[meshindex
][3] = nuid
;
389 meshindex
= (meshindex
+1) % 2;
391 surfaceEvaluator
.evalcoord2f( nuid
, u
, v
);
395 surfaceEvaluator
.evalcoord2f( 0, u
, v
);
399 /*-------------------------------------------------------------------------
400 * tmeshvert - evaluate a grid point of a triangle mesh
401 *-------------------------------------------------------------------------
404 Backend::tmeshvert( GridVertex
*g
)
406 const long u
= g
->gparam
[0];
407 const long v
= g
->gparam
[1];
411 if( wireframetris
) {
413 surfaceEvaluator
.bgnclosedline();
414 if( mesh
[0][2] == 0 )
415 surfaceEvaluator
.evalcoord2f( (long) mesh
[0][3], mesh
[0][0], mesh
[0][1] );
417 surfaceEvaluator
.evalpoint2i( (long) mesh
[0][0], (long) mesh
[0][1] );
418 if( mesh
[1][2] == 0 )
419 surfaceEvaluator
.evalcoord2f( (long) mesh
[1][3], mesh
[1][0], mesh
[1][1] );
421 surfaceEvaluator
.evalpoint2i( (long) mesh
[1][0], (long) mesh
[1][1] );
422 surfaceEvaluator
.evalpoint2i( u
, v
);
423 surfaceEvaluator
.endclosedline();
425 mesh
[meshindex
][0] = u
;
426 mesh
[meshindex
][1] = v
;
427 mesh
[meshindex
][2] = 1;
428 meshindex
= (meshindex
+1) % 2;
430 surfaceEvaluator
.evalpoint2i( u
, v
);
433 surfaceEvaluator
.evalpoint2i( u
, v
);
437 /*-------------------------------------------------------------------------
438 * swaptmesh - perform a swap of the triangle mesh pointers
439 *-------------------------------------------------------------------------
442 Backend::swaptmesh( void )
445 if( wireframetris
) {
446 meshindex
= 1 - meshindex
;
448 surfaceEvaluator
.swaptmesh();
451 surfaceEvaluator
.swaptmesh();
455 /*-------------------------------------------------------------------------
456 * endtmesh - postamble to triangle mesh
457 *-------------------------------------------------------------------------
460 Backend::endtmesh( void )
463 if( ! wireframetris
)
464 surfaceEvaluator
.endtmesh();
466 surfaceEvaluator
.endtmesh();
467 /* surfaceEvaluator.polymode( N_MESHFILL );*/
472 /*-------------------------------------------------------------------------
473 * bgnoutline - preamble to outlined rendering
474 *-------------------------------------------------------------------------
477 Backend::bgnoutline( void )
479 surfaceEvaluator
.bgnline();
482 /*-------------------------------------------------------------------------
483 * linevert - evaluate a point on an outlined contour
484 *-------------------------------------------------------------------------
487 Backend::linevert( TrimVertex
*t
)
489 surfaceEvaluator
.evalcoord2f( t
->nuid
, t
->param
[0], t
->param
[1] );
492 /*-------------------------------------------------------------------------
493 * linevert - evaluate a grid point of an outlined contour
494 *-------------------------------------------------------------------------
497 Backend::linevert( GridVertex
*g
)
499 surfaceEvaluator
.evalpoint2i( g
->gparam
[0], g
->gparam
[1] );
502 /*-------------------------------------------------------------------------
503 * endoutline - postamble to outlined rendering
504 *-------------------------------------------------------------------------
507 Backend::endoutline( void )
509 surfaceEvaluator
.endline();
512 /*-------------------------------------------------------------------------
513 * triangle - output a triangle
514 *-------------------------------------------------------------------------
517 Backend::triangle( TrimVertex
*a
, TrimVertex
*b
, TrimVertex
*c
)
519 /* bgntmesh( "spittriangle" );*/
529 Backend::bgncurv( void )
531 curveEvaluator
.bgnmap1f( 0 );
535 Backend::segment( REAL ulo
, REAL uhi
)
537 curveEvaluator
.domain1f( ulo
, uhi
);
542 long type
, /* geometry, color, texture, normal */
543 REAL
*pts
, /* control points */
544 long stride
, /* distance to next point */
545 int order
, /* parametric order */
546 REAL ulo
, /* lower parametric bound */
547 REAL uhi
) /* upper parametric bound */
550 curveEvaluator
.map1f( type
, ulo
, uhi
, stride
, order
, pts
);
551 curveEvaluator
.enable( type
);
555 Backend::curvgrid( REAL u0
, REAL u1
, long nu
)
557 curveEvaluator
.mapgrid1f( nu
, u0
, u1
);
561 Backend::curvmesh( long from
, long n
)
563 curveEvaluator
.mapmesh1f( N_MESHFILL
, from
, from
+n
);
567 Backend::curvpt(REAL u
)
569 curveEvaluator
.evalcoord1f( 0, u
);
573 Backend::bgnline( void )
575 curveEvaluator
.bgnline();
579 Backend::endline( void )
581 curveEvaluator
.endline();
585 Backend::endcurv( void )
587 curveEvaluator
.endmap1f();