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.
38 * $Date$ $Revision: 1.1 $
39 * $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/glu32/libnurbs/internals/backend.cc,v 1.1 2004/02/02 16:39:10 navaraf Exp $
42 /* Bezier surface backend
43 - interprets display mode (wireframe,shaded,...)
46 #include "glimports.h"
49 #include "basiccrveval.h"
50 #include "basicsurfeval.h"
51 #include "nurbsconsts.h"
56 /*-------------------------------------------------------------------------
57 * bgnsurf - preamble to surface definition and evaluations
58 *-------------------------------------------------------------------------
61 Backend::bgnsurf( int wiretris
, int wirequads
, long nuid
)
63 /*#ifndef NOWIREFRAME*/ //need this for old version
64 wireframetris
= wiretris
;
65 wireframequads
= wirequads
;
68 /*in the spec, GLU_DISPLAY_MODE is either
72 *In fact, GLU_FLL is has the same effect as
73 * set GL_FRONT_AND_BACK to be GL_FILL
74 * and GLU_OUTLINE_POLY is the same as set
75 * GL_FRONT_AND_BACK to be GL_LINE
76 *It is more efficient to do this once at the beginning of
77 *each surface than to do it for each primitive.
78 * The internal has more options: outline_triangle and outline_quad
79 *can be seperated. But since this is not in spec, and more importantly,
80 *this is not so useful, so we don't need to keep this option.
83 surfaceEvaluator
.bgnmap2f( nuid
);
86 surfaceEvaluator
.polymode(N_MESHLINE
);
88 surfaceEvaluator
.polymode(N_MESHFILL
);
92 Backend::patch( REAL ulo
, REAL uhi
, REAL vlo
, REAL vhi
)
94 surfaceEvaluator
.domain2f( ulo
, uhi
, vlo
, vhi
);
98 Backend::surfbbox( long type
, REAL
*from
, REAL
*to
)
100 surfaceEvaluator
.range2f( type
, from
, to
);
103 /*-------------------------------------------------------------------------
104 * surfpts - pass a desription of a surface map
105 *-------------------------------------------------------------------------
109 long type
, /* geometry, color, texture, normal */
110 REAL
*pts
, /* control points */
111 long ustride
, /* distance to next point in u direction */
112 long vstride
, /* distance to next point in v direction */
113 int uorder
, /* u parametric order */
114 int vorder
, /* v parametric order */
115 REAL ulo
, /* u lower bound */
116 REAL uhi
, /* u upper bound */
117 REAL vlo
, /* v lower bound */
118 REAL vhi
) /* v upper bound */
120 surfaceEvaluator
.map2f( type
,ulo
,uhi
,ustride
,uorder
,vlo
,vhi
,vstride
,vorder
,pts
);
121 surfaceEvaluator
.enable( type
);
124 /*-------------------------------------------------------------------------
125 * surfgrid - define a lattice of points with origin and offset
126 *-------------------------------------------------------------------------
129 Backend::surfgrid( REAL u0
, REAL u1
, long nu
, REAL v0
, REAL v1
, long nv
)
131 surfaceEvaluator
.mapgrid2f( nu
, u0
, u1
, nv
, v0
, v1
);
134 /*-------------------------------------------------------------------------
135 * surfmesh - evaluate a mesh of points on lattice
136 *-------------------------------------------------------------------------
139 Backend::surfmesh( long u
, long v
, long n
, long m
)
142 if( wireframequads
) {
144 long u0f
= u
, u1f
= u
+n
;
145 long v0f
= v
, v1f
= v
+m
;
146 long parity
= (u
& 1);
148 for( v0
= v0f
, v1
= v0f
++ ; v0
<v1f
; v0
= v1
, v1
++ ) {
149 surfaceEvaluator
.bgnline();
150 for( long u
= u0f
; u
<=u1f
; u
++ ) {
152 surfaceEvaluator
.evalpoint2i( u
, v0
);
153 surfaceEvaluator
.evalpoint2i( u
, v1
);
155 surfaceEvaluator
.evalpoint2i( u
, v1
);
156 surfaceEvaluator
.evalpoint2i( u
, v0
);
160 surfaceEvaluator
.endline();
163 surfaceEvaluator
.mapmesh2f( N_MESHFILL
, u
, u
+n
, v
, v
+m
);
166 if( wireframequads
) {
168 surfaceEvaluator
.mapmesh2f( N_MESHLINE
, u
, u
+n
, v
, v
+m
);
171 surfaceEvaluator
.mapmesh2f( N_MESHFILL
, u
, u
+n
, v
, v
+m
);
176 /*-------------------------------------------------------------------------
177 * endsurf - postamble to surface
178 *-------------------------------------------------------------------------
181 Backend::endsurf( void )
183 surfaceEvaluator
.endmap2f();
186 /***************************************/
188 Backend::bgntfan( void )
190 surfaceEvaluator
.bgntfan();
193 surfaceEvaluator.polymode( N_MESHLINE );
195 surfaceEvaluator.polymode( N_MESHFILL );
200 Backend::endtfan( void )
202 surfaceEvaluator
.endtfan();
206 Backend::bgnqstrip( void )
208 surfaceEvaluator
.bgnqstrip();
211 surfaceEvaluator.polymode( N_MESHLINE );
213 surfaceEvaluator.polymode( N_MESHFILL );
218 Backend::endqstrip( void )
220 surfaceEvaluator
.endqstrip();
224 Backend::evalUStrip(int n_upper
, REAL v_upper
, REAL
* upper_val
,
225 int n_lower
, REAL v_lower
, REAL
* lower_val
228 surfaceEvaluator
.evalUStrip(n_upper
, v_upper
, upper_val
,
229 n_lower
, v_lower
, lower_val
);
233 Backend::evalVStrip(int n_left
, REAL u_left
, REAL
* left_val
,
234 int n_right
, REAL u_right
, REAL
* right_val
237 surfaceEvaluator
.evalVStrip(n_left
, u_left
, left_val
,
238 n_right
, u_right
, right_val
);
241 /***************************************/
244 /*-------------------------------------------------------------------------
245 * bgntmesh - preamble to a triangle mesh
246 *-------------------------------------------------------------------------
249 Backend::bgntmesh( char * )
253 meshindex
= 0; /* I think these need to be initialized to zero */
256 if( !wireframetris
) {
257 surfaceEvaluator
.bgntmesh();
261 if( wireframetris
) {
262 surfaceEvaluator
.bgntmesh();
263 surfaceEvaluator
.polymode( N_MESHLINE
);
265 surfaceEvaluator
.bgntmesh();
266 surfaceEvaluator
.polymode( N_MESHFILL
);
272 Backend::tmeshvert( GridTrimVertex
*v
)
274 if( v
->isGridVert() ) {
282 Backend::tmeshvertNOGE(TrimVertex
*t
)
284 // surfaceEvaluator.inDoEvalCoord2NOGE( t->param[0], t->param[1], temp, ttt);
286 surfaceEvaluator
.inDoEvalCoord2NOGE( t
->param
[0], t
->param
[1], t
->cache_point
, t
->cache_normal
);
290 //opt for a line with the same u.
292 Backend::tmeshvertNOGE_BU(TrimVertex
*t
)
295 surfaceEvaluator
.inDoEvalCoord2NOGE_BU( t
->param
[0], t
->param
[1], t
->cache_point
, t
->cache_normal
);
299 //opt for a line with the same v.
301 Backend::tmeshvertNOGE_BV(TrimVertex
*t
)
304 surfaceEvaluator
.inDoEvalCoord2NOGE_BV( t
->param
[0], t
->param
[1], t
->cache_point
, t
->cache_normal
);
309 Backend::preEvaluateBU(REAL u
)
311 surfaceEvaluator
.inPreEvaluateBU_intfac(u
);
315 Backend::preEvaluateBV(REAL v
)
317 surfaceEvaluator
.inPreEvaluateBV_intfac(v
);
321 /*-------------------------------------------------------------------------
322 * tmeshvert - evaluate a point on a triangle mesh
323 *-------------------------------------------------------------------------
326 Backend::tmeshvert( TrimVertex
*t
)
328 const REAL u
= t
->param
[0];
329 const REAL v
= t
->param
[1];
332 const long nuid
= t
->nuid
;
335 if( wireframetris
) {
337 surfaceEvaluator
.bgnclosedline();
338 if( mesh
[0][2] == 0 )
339 surfaceEvaluator
.evalcoord2f( mesh
[0][3], mesh
[0][0], mesh
[0][1] );
341 surfaceEvaluator
.evalpoint2i( (long) mesh
[0][0], (long) mesh
[0][1] );
342 if( mesh
[1][2] == 0 )
343 surfaceEvaluator
.evalcoord2f( mesh
[1][3], mesh
[1][0], mesh
[1][1] );
345 surfaceEvaluator
.evalpoint2i( (long) mesh
[1][0], (long) mesh
[1][1] );
346 surfaceEvaluator
.evalcoord2f( nuid
, u
, v
);
347 surfaceEvaluator
.endclosedline();
349 mesh
[meshindex
][0] = u
;
350 mesh
[meshindex
][1] = v
;
351 mesh
[meshindex
][2] = 0;
352 mesh
[meshindex
][3] = nuid
;
353 meshindex
= (meshindex
+1) % 2;
355 surfaceEvaluator
.evalcoord2f( nuid
, u
, v
);
359 surfaceEvaluator
.evalcoord2f( 0, u
, v
);
360 //for uninitial memory read surfaceEvaluator.evalcoord2f( nuid, u, v );
364 //the same as tmeshvert(trimvertex), for efficiency purpose
366 Backend::tmeshvert( REAL u
, REAL v
)
372 if( wireframetris
) {
374 surfaceEvaluator
.bgnclosedline();
375 if( mesh
[0][2] == 0 )
376 surfaceEvaluator
.evalcoord2f( mesh
[0][3], mesh
[0][0], mesh
[0][1] );
378 surfaceEvaluator
.evalpoint2i( (long) mesh
[0][0], (long) mesh
[0][1] );
379 if( mesh
[1][2] == 0 )
380 surfaceEvaluator
.evalcoord2f( mesh
[1][3], mesh
[1][0], mesh
[1][1] );
382 surfaceEvaluator
.evalpoint2i( (long) mesh
[1][0], (long) mesh
[1][1] );
383 surfaceEvaluator
.evalcoord2f( nuid
, u
, v
);
384 surfaceEvaluator
.endclosedline();
386 mesh
[meshindex
][0] = u
;
387 mesh
[meshindex
][1] = v
;
388 mesh
[meshindex
][2] = 0;
389 mesh
[meshindex
][3] = nuid
;
390 meshindex
= (meshindex
+1) % 2;
392 surfaceEvaluator
.evalcoord2f( nuid
, u
, v
);
396 surfaceEvaluator
.evalcoord2f( 0, u
, v
);
400 /*-------------------------------------------------------------------------
401 * tmeshvert - evaluate a grid point of a triangle mesh
402 *-------------------------------------------------------------------------
405 Backend::tmeshvert( GridVertex
*g
)
407 const long u
= g
->gparam
[0];
408 const long v
= g
->gparam
[1];
412 if( wireframetris
) {
414 surfaceEvaluator
.bgnclosedline();
415 if( mesh
[0][2] == 0 )
416 surfaceEvaluator
.evalcoord2f( (long) mesh
[0][3], mesh
[0][0], mesh
[0][1] );
418 surfaceEvaluator
.evalpoint2i( (long) mesh
[0][0], (long) mesh
[0][1] );
419 if( mesh
[1][2] == 0 )
420 surfaceEvaluator
.evalcoord2f( (long) mesh
[1][3], mesh
[1][0], mesh
[1][1] );
422 surfaceEvaluator
.evalpoint2i( (long) mesh
[1][0], (long) mesh
[1][1] );
423 surfaceEvaluator
.evalpoint2i( u
, v
);
424 surfaceEvaluator
.endclosedline();
426 mesh
[meshindex
][0] = u
;
427 mesh
[meshindex
][1] = v
;
428 mesh
[meshindex
][2] = 1;
429 meshindex
= (meshindex
+1) % 2;
431 surfaceEvaluator
.evalpoint2i( u
, v
);
434 surfaceEvaluator
.evalpoint2i( u
, v
);
438 /*-------------------------------------------------------------------------
439 * swaptmesh - perform a swap of the triangle mesh pointers
440 *-------------------------------------------------------------------------
443 Backend::swaptmesh( void )
446 if( wireframetris
) {
447 meshindex
= 1 - meshindex
;
449 surfaceEvaluator
.swaptmesh();
452 surfaceEvaluator
.swaptmesh();
456 /*-------------------------------------------------------------------------
457 * endtmesh - postamble to triangle mesh
458 *-------------------------------------------------------------------------
461 Backend::endtmesh( void )
464 if( ! wireframetris
)
465 surfaceEvaluator
.endtmesh();
467 surfaceEvaluator
.endtmesh();
468 /* surfaceEvaluator.polymode( N_MESHFILL );*/
473 /*-------------------------------------------------------------------------
474 * bgnoutline - preamble to outlined rendering
475 *-------------------------------------------------------------------------
478 Backend::bgnoutline( void )
480 surfaceEvaluator
.bgnline();
483 /*-------------------------------------------------------------------------
484 * linevert - evaluate a point on an outlined contour
485 *-------------------------------------------------------------------------
488 Backend::linevert( TrimVertex
*t
)
490 surfaceEvaluator
.evalcoord2f( t
->nuid
, t
->param
[0], t
->param
[1] );
493 /*-------------------------------------------------------------------------
494 * linevert - evaluate a grid point of an outlined contour
495 *-------------------------------------------------------------------------
498 Backend::linevert( GridVertex
*g
)
500 surfaceEvaluator
.evalpoint2i( g
->gparam
[0], g
->gparam
[1] );
503 /*-------------------------------------------------------------------------
504 * endoutline - postamble to outlined rendering
505 *-------------------------------------------------------------------------
508 Backend::endoutline( void )
510 surfaceEvaluator
.endline();
513 /*-------------------------------------------------------------------------
514 * triangle - output a triangle
515 *-------------------------------------------------------------------------
518 Backend::triangle( TrimVertex
*a
, TrimVertex
*b
, TrimVertex
*c
)
520 /* bgntmesh( "spittriangle" );*/
530 Backend::bgncurv( void )
532 curveEvaluator
.bgnmap1f( 0 );
536 Backend::segment( REAL ulo
, REAL uhi
)
538 curveEvaluator
.domain1f( ulo
, uhi
);
543 long type
, /* geometry, color, texture, normal */
544 REAL
*pts
, /* control points */
545 long stride
, /* distance to next point */
546 int order
, /* parametric order */
547 REAL ulo
, /* lower parametric bound */
548 REAL uhi
) /* upper parametric bound */
551 curveEvaluator
.map1f( type
, ulo
, uhi
, stride
, order
, pts
);
552 curveEvaluator
.enable( type
);
556 Backend::curvgrid( REAL u0
, REAL u1
, long nu
)
558 curveEvaluator
.mapgrid1f( nu
, u0
, u1
);
562 Backend::curvmesh( long from
, long n
)
564 curveEvaluator
.mapmesh1f( N_MESHFILL
, from
, from
+n
);
568 Backend::curvpt(REAL u
)
570 curveEvaluator
.evalcoord1f( 0, u
);
574 Backend::bgnline( void )
576 curveEvaluator
.bgnline();
580 Backend::endline( void )
582 curveEvaluator
.endline();
586 Backend::endcurv( void )
588 curveEvaluator
.endmap1f();