aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/glu/sgi/libnurbs/internals
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/glu/sgi/libnurbs/internals')
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/arc.cc347
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/arc.h133
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/arcsorter.cc172
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/arcsorter.h73
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/arctess.cc611
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/arctess.h66
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/backend.cc589
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/backend.h113
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/basiccrveval.cc138
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/basiccrveval.h62
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/basicsurfeval.cc232
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/basicsurfeval.h90
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/bezierarc.h51
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/bin.cc166
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/bin.h121
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/bufpool.cc110
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/bufpool.h141
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/cachingeval.cc78
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/cachingeval.h51
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/ccw.cc565
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/coveandtiler.cc440
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/coveandtiler.h72
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/curve.cc198
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/curve.h70
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/curvelist.cc110
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/curvelist.h62
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/curvesub.cc103
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/dataTransform.cc209
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/dataTransform.h59
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/defines.h50
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/displaylist.cc82
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/displaylist.h78
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/displaymode.h40
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/flist.cc118
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/flist.h59
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/flistsorter.cc81
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/flistsorter.h53
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/gridline.h46
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/gridtrimvertex.h89
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/gridvertex.h48
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/hull.cc165
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/hull.h69
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/intersect.cc665
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/jarcloc.h87
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/knotvector.cc139
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/knotvector.h62
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/mapdesc.cc841
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/mapdesc.h271
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/mapdescv.cc243
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/maplist.cc117
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/maplist.h81
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/mesher.cc486
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/mesher.h83
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/monoTriangulationBackend.cc397
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/monotonizer.cc260
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/monotonizer.h64
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/myassert.h51
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/mycode.cc67
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/mymath.h68
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/mysetjmp.h85
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/mystring.h56
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/nurbsconsts.h120
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/nurbsinterfac.cc537
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/nurbstess.cc691
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/nurbstess.h172
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/patch.cc504
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/patch.h94
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/patchlist.cc170
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/patchlist.h92
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/pwlarc.h78
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/quilt.cc276
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/quilt.h92
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/reader.cc146
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/reader.h132
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/renderhints.cc133
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/renderhints.h60
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/simplemath.h50
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/slicer.cc1300
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/slicer.h84
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/sorter.cc139
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/sorter.h51
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/splitarcs.cc293
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/subdivider.cc910
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/subdivider.h200
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/tobezier.cc687
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/trimline.cc223
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/trimline.h103
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/trimregion.cc114
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/trimregion.h84
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/trimvertex.h63
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/trimvertpool.cc119
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/trimvertpool.h57
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/types.h47
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/uarray.cc72
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/uarray.h55
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/varray.cc144
-rw-r--r--mesalib/src/glu/sgi/libnurbs/internals/varray.h68
97 files changed, 18493 insertions, 0 deletions
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/arc.cc b/mesalib/src/glu/sgi/libnurbs/internals/arc.cc
new file mode 100644
index 000000000..b85139de9
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/arc.cc
@@ -0,0 +1,347 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * arc.c++
+ *
+ */
+
+#include <stdio.h>
+#include "glimports.h"
+#include "mystdio.h"
+#include "myassert.h"
+#include "arc.h"
+#include "bin.h"
+#include "bezierarc.h"
+#include "pwlarc.h"
+#include "simplemath.h"
+
+/* local preprocessor definitions */
+#define ZERO 0.00001/*0.000001*/
+
+const int Arc::bezier_tag = (1<<13);
+const int Arc::arc_tag = (1<<3);
+const int Arc::tail_tag = (1<<6);
+
+/*--------------------------------------------------------------------------
+ * makeSide - attach a pwl arc to an arc and mark it as a border arc
+ *--------------------------------------------------------------------------
+ */
+
+void
+Arc::makeSide( PwlArc *pwl, arc_side side )
+{
+ assert( pwl != 0);
+ assert( pwlArc == 0 );
+ assert( pwl->npts > 0 );
+ assert( pwl->pts != 0);
+ pwlArc = pwl;
+ clearbezier();
+ setside( side );
+}
+
+
+/*--------------------------------------------------------------------------
+ * numpts - count number of points on arc loop
+ *--------------------------------------------------------------------------
+ */
+
+int
+Arc::numpts( void )
+{
+ Arc_ptr jarc = this;
+ int npts = 0;
+ do {
+ npts += jarc->pwlArc->npts;
+ jarc = jarc->next;
+ } while( jarc != this );
+ return npts;
+}
+
+/*--------------------------------------------------------------------------
+ * markverts - mark each point with id of arc
+ *--------------------------------------------------------------------------
+ */
+
+void
+Arc::markverts( void )
+{
+ Arc_ptr jarc = this;
+
+ do {
+ TrimVertex *p = jarc->pwlArc->pts;
+ for( int i=0; i<jarc->pwlArc->npts; i++ )
+ p[i].nuid = jarc->nuid;
+ jarc = jarc->next;
+ } while( jarc != this );
+}
+
+/*--------------------------------------------------------------------------
+ * getextrema - find axis extrema on arc loop
+ *--------------------------------------------------------------------------
+ */
+
+void
+Arc::getextrema( Arc_ptr extrema[4] )
+{
+ REAL leftpt, botpt, rightpt, toppt;
+
+ extrema[0] = extrema[1] = extrema[2] = extrema[3] = this;
+
+ leftpt = rightpt = this->tail()[0];
+ botpt = toppt = this->tail()[1];
+
+ for( Arc_ptr jarc = this->next; jarc != this; jarc = jarc->next ) {
+ if ( jarc->tail()[0] < leftpt ||
+ (jarc->tail()[0] <= leftpt && jarc->rhead()[0]<=leftpt)) {
+ leftpt = jarc->pwlArc->pts->param[0];
+ extrema[1] = jarc;
+ }
+ if ( jarc->tail()[0] > rightpt ||
+ (jarc->tail()[0] >= rightpt && jarc->rhead()[0] >= rightpt)) {
+ rightpt = jarc->pwlArc->pts->param[0];
+ extrema[3] = jarc;
+ }
+ if ( jarc->tail()[1] < botpt ||
+ (jarc->tail()[1] <= botpt && jarc->rhead()[1] <= botpt )) {
+ botpt = jarc->pwlArc->pts->param[1];
+ extrema[2] = jarc;
+ }
+ if ( jarc->tail()[1] > toppt ||
+ (jarc->tail()[1] >= toppt && jarc->rhead()[1] >= toppt)) {
+ toppt = jarc->pwlArc->pts->param[1];
+ extrema[0] = jarc;
+ }
+ }
+}
+
+
+/*-------------------------------------------------------------------------
+ * show - print to the stdout the vertices of a pwl arc
+ *-------------------------------------------------------------------------
+ */
+
+void
+Arc::show()
+{
+#ifndef NDEBUG
+ _glu_dprintf( "\tPWLARC NP: %d FL: 1\n", pwlArc->npts );
+ for( int i = 0; i < pwlArc->npts; i++ ) {
+ _glu_dprintf( "\t\tVERTEX %f %f\n", pwlArc->pts[i].param[0],
+ pwlArc->pts[i].param[1] );
+ }
+#endif
+}
+
+/*-------------------------------------------------------------------------
+ * print - print out the vertices of all pwl arcs on a loop
+ *-------------------------------------------------------------------------
+ */
+
+void
+Arc::print( void )
+{
+ Arc_ptr jarc = this;
+
+#ifndef NDEBUG
+ _glu_dprintf( "BGNTRIM\n" );
+#endif
+ do {
+ jarc->show( );
+ jarc = jarc->next;
+ } while (jarc != this);
+#ifndef NDEBUG
+ _glu_dprintf("ENDTRIM\n" );
+#endif
+}
+
+/*-------------------------------------------------------------------------
+ * isDisconnected - check if tail of arc and head of prev meet
+ *-------------------------------------------------------------------------
+ */
+
+int
+Arc::isDisconnected( void )
+{
+ if( pwlArc == 0 ) return 0;
+ if( prev->pwlArc == 0 ) return 0;
+
+ REAL *p0 = tail();
+ REAL *p1 = prev->rhead();
+
+ if( ((p0[0] - p1[0]) > ZERO) || ((p1[0] - p0[0]) > ZERO) ||
+ ((p0[1] - p1[1]) > ZERO) || ((p1[1] - p0[1]) > ZERO) ) {
+#ifndef NDEBUG
+ _glu_dprintf( "x coord = %f %f %f\n", p0[0], p1[0], p0[0] - p1[0] );
+ _glu_dprintf( "y coord = %f %f %f\n", p0[1], p1[1], p0[1] - p1[1] );
+#endif
+ return 1;
+ } else {
+ /* average two points together */
+ p0[0] = p1[0] = (p1[0] + p0[0]) * 0.5;
+ p0[1] = p1[1] = (p1[1] + p0[1]) * 0.5;
+ return 0;
+ }
+}
+
+/*-------------------------------------------------------------------------
+ * neq_vert - assert that two 2D vertices are not equal
+ *-------------------------------------------------------------------------
+ */
+
+inline static int
+neq_vert( REAL *v1, REAL *v2 )
+{
+ return ((v1[0] != v2[0]) || (v1[1] != v2[1] )) ? 1 : 0;
+}
+
+/*-------------------------------------------------------------------------
+ * check - verify consistency of a loop, including
+ * 1) if pwl, no two consecutive vertices are identical
+ * 2) the circular link pointers are valid
+ * 3) the geometric info at the head and tail are consistent
+ *-------------------------------------------------------------------------
+ */
+
+int
+Arc::check( void )
+{
+ if( this == 0 ) return 1;
+ Arc_ptr jarc = this;
+ do {
+ assert( (jarc->pwlArc != 0) || (jarc->bezierArc != 0) );
+
+ if (jarc->prev == 0 || jarc->next == 0) {
+#ifndef NDEBUG
+ _glu_dprintf( "checkjarc:null next/prev pointer\n");
+ jarc->print( );
+#endif
+ return 0;
+ }
+
+ if (jarc->next->prev != jarc) {
+#ifndef NDEBUG
+ _glu_dprintf( "checkjarc: pointer linkage screwed up\n");
+ jarc->print( );
+#endif
+ return 0;
+ }
+
+ if( jarc->pwlArc ) {
+#ifndef NDEBUG
+ assert( jarc->pwlArc->npts >= 1 );
+ assert( jarc->pwlArc->npts < 100000 );
+/*
+ for( int i=0; i < jarc->pwlArc->npts-1; i++ )
+ assert( neq_vert( jarc->pwlArc->pts[i].param,
+ jarc->pwlArc->pts[i+1].param) );
+*/
+#endif
+ if( jarc->prev->pwlArc ) {
+ if( jarc->tail()[1] != jarc->prev->rhead()[1] ) {
+#ifndef NDEBUG
+ _glu_dprintf( "checkjarc: geometric linkage screwed up 1\n");
+ jarc->prev->show();
+ jarc->show();
+#endif
+ return 0;
+ }
+ if( jarc->tail()[0] != jarc->prev->rhead()[0] ) {
+
+#ifndef NDEBUG
+ _glu_dprintf( "checkjarc: geometric linkage screwed up 2\n");
+ jarc->prev->show();
+ jarc->show();
+#endif
+ return 0;
+ }
+ }
+ if( jarc->next->pwlArc ) {
+ if( jarc->next->tail()[0] != jarc->rhead()[0] ) {
+#ifndef NDEBUG
+ _glu_dprintf( "checkjarc: geometric linkage screwed up 3\n");
+ jarc->show();
+ jarc->next->show();
+#endif
+ return 0;
+ }
+ if( jarc->next->tail()[1] != jarc->rhead()[1] ) {
+#ifndef NDEBUG
+ _glu_dprintf( "checkjarc: geometric linkage screwed up 4\n");
+ jarc->show();
+ jarc->next->show();
+#endif
+ return 0;
+ }
+ }
+ if( jarc->isbezier() ) {
+ assert( jarc->pwlArc->npts == 2 );
+ assert( (jarc->pwlArc->pts[0].param[0] == \
+ jarc->pwlArc->pts[1].param[0]) ||\
+ (jarc->pwlArc->pts[0].param[1] == \
+ jarc->pwlArc->pts[1].param[1]) );
+ }
+ }
+ jarc = jarc->next;
+ } while (jarc != this);
+ return 1;
+}
+
+
+#define TOL 0.00001
+
+inline long tooclose( REAL x, REAL y )
+{
+ return (glu_abs(x-y) < TOL) ? 1 : 0;
+}
+
+
+/*--------------------------------------------------------------------------
+ * append - append a jordan arc to a circularly linked list
+ *--------------------------------------------------------------------------
+ */
+
+Arc_ptr
+Arc::append( Arc_ptr jarc )
+{
+ if( jarc != 0 ) {
+ next = jarc->next;
+ prev = jarc;
+ next->prev = prev->next = this;
+ } else {
+ next = prev = this;
+ }
+ return this;
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/arc.h b/mesalib/src/glu/sgi/libnurbs/internals/arc.h
new file mode 100644
index 000000000..e986019c3
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/arc.h
@@ -0,0 +1,133 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * arc.h
+ *
+ */
+
+#ifndef __gluarc_h_
+#define __gluarc_h_
+
+#include "myassert.h"
+#include "bufpool.h"
+#include "mystdio.h"
+#include "types.h"
+#include "pwlarc.h"
+#include "trimvertex.h"
+
+class Bin;
+class Arc;
+struct BezierArc;
+
+typedef class Arc *Arc_ptr;
+
+enum arc_side { arc_none = 0, arc_right, arc_top, arc_left, arc_bottom };
+
+
+class Arc: public PooledObj { /* an arc, in two list, the trim list and bin */
+
+public:
+ static const int bezier_tag;
+ static const int arc_tag;
+ static const int tail_tag;
+ Arc_ptr prev; /* trim list pointer */
+ Arc_ptr next; /* trim list pointer */
+ Arc_ptr link; /* bin pointers */
+ BezierArc * bezierArc; /* associated bezier arc */
+ PwlArc * pwlArc; /* associated pwl arc */
+ long type; /* curve type */
+ long nuid;
+
+ inline Arc( Arc *, PwlArc * );
+ inline Arc( arc_side, long );
+
+ Arc_ptr append( Arc_ptr );
+ int check( void );
+ int isMonotone( void );
+ int isDisconnected( void );
+ int numpts( void );
+ void markverts( void );
+ void getextrema( Arc_ptr[4] );
+ void print( void );
+ void show( void );
+ void makeSide( PwlArc *, arc_side );
+ inline int isTessellated() { return pwlArc ? 1 : 0; }
+ inline long isbezier() { return type & bezier_tag; }
+ inline void setbezier() { type |= bezier_tag; }
+ inline void clearbezier() { type &= ~bezier_tag; }
+ inline long npts() { return pwlArc->npts; }
+ inline TrimVertex * pts() { return pwlArc->pts; }
+ inline REAL * tail() { return pwlArc->pts[0].param; }
+ inline REAL * head() { return next->pwlArc->pts[0].param; }
+ inline REAL * rhead() { return pwlArc->pts[pwlArc->npts-1].param; }
+ inline long ismarked() { return type & arc_tag; }
+ inline void setmark() { type |= arc_tag; }
+ inline void clearmark() { type &= (~arc_tag); }
+ inline void clearside() { type &= ~(0x7 << 8); }
+ inline void setside( arc_side s ) { clearside(); type |= (((long)s)<<8); }
+ inline arc_side getside() { return (arc_side) ((type>>8) & 0x7); }
+ inline int getitail() { return type & tail_tag; }
+ inline void setitail() { type |= tail_tag; }
+ inline void clearitail() { type &= (~tail_tag); }
+};
+
+/*--------------------------------------------------------------------------
+ * Arc - initialize a new Arc with the same type and uid of
+ * a given Arc and a given pwl arc
+ *--------------------------------------------------------------------------
+ */
+
+inline
+Arc::Arc( Arc *j, PwlArc *p )
+{
+ bezierArc = NULL;
+ pwlArc = p;
+ type = j->type;
+ nuid = j->nuid;
+}
+
+/*--------------------------------------------------------------------------
+ * Arc - initialize a new Arc with the same type and uid of
+ * a given Arc and a given pwl arc
+ *--------------------------------------------------------------------------
+ */
+
+inline
+Arc::Arc( arc_side side, long _nuid )
+{
+ bezierArc = NULL;
+ pwlArc = NULL;
+ type = 0;
+ setside( side );
+ nuid = _nuid;
+}
+
+#endif /* __gluarc_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/arcsorter.cc b/mesalib/src/glu/sgi/libnurbs/internals/arcsorter.cc
new file mode 100644
index 000000000..1f85cb710
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/arcsorter.cc
@@ -0,0 +1,172 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * arcsorter.c++
+ *
+ */
+
+#ifndef __gluarcsorter_c_
+#define __gluarcsorter_c_
+
+#include "glimports.h"
+#include "arc.h"
+#include "arcsorter.h"
+#include "subdivider.h"
+
+ArcSorter::ArcSorter(Subdivider &s) : Sorter( sizeof( Arc ** ) ), subdivider(s)
+{
+}
+
+int
+ArcSorter::qscmp( char *, char * )
+{
+ _glu_dprintf( "ArcSorter::qscmp: pure virtual called\n" );
+ return 0;
+}
+
+void
+ArcSorter::qsort( Arc **a, int n )
+{
+ Sorter::qsort( (void *) a, n );
+}
+
+void
+ArcSorter::qsexc( char *i, char *j )// i<-j, j<-i
+{
+ Arc **jarc1 = (Arc **) i;
+ Arc **jarc2 = (Arc **) j;
+ Arc *tmp = *jarc1;
+ *jarc1 = *jarc2;
+ *jarc2 = tmp;
+}
+
+void
+ArcSorter::qstexc( char *i, char *j, char *k )// i<-k, k<-j, j<-i
+{
+ Arc **jarc1 = (Arc **) i;
+ Arc **jarc2 = (Arc **) j;
+ Arc **jarc3 = (Arc **) k;
+ Arc *tmp = *jarc1;
+ *jarc1 = *jarc3;
+ *jarc3 = *jarc2;
+ *jarc2 = tmp;
+}
+
+
+ArcSdirSorter::ArcSdirSorter( Subdivider &s ) : ArcSorter(s)
+{
+}
+
+int
+ArcSdirSorter::qscmp( char *i, char *j )
+{
+ Arc *jarc1 = *(Arc **) i;
+ Arc *jarc2 = *(Arc **) j;
+
+ int v1 = (jarc1->getitail() ? 0 : (jarc1->pwlArc->npts - 1));
+ int v2 = (jarc2->getitail() ? 0 : (jarc2->pwlArc->npts - 1));
+
+ REAL diff = jarc1->pwlArc->pts[v1].param[1] -
+ jarc2->pwlArc->pts[v2].param[1];
+
+ if( diff < 0.0)
+ return -1;
+ else if( diff > 0.0)
+ return 1;
+ else {
+ if( v1 == 0 ) {
+ if( jarc2->tail()[0] < jarc1->tail()[0] ) {
+ return subdivider.ccwTurn_sl( jarc2, jarc1 ) ? 1 : -1;
+ } else {
+ return subdivider.ccwTurn_sr( jarc2, jarc1 ) ? -1 : 1;
+ }
+ } else {
+ if( jarc2->head()[0] < jarc1->head()[0] ) {
+ return subdivider.ccwTurn_sl( jarc1, jarc2 ) ? -1 : 1;
+ } else {
+ return subdivider.ccwTurn_sr( jarc1, jarc2 ) ? 1 : -1;
+ }
+ }
+ }
+}
+
+ArcTdirSorter::ArcTdirSorter( Subdivider &s ) : ArcSorter(s)
+{
+}
+
+/*----------------------------------------------------------------------------
+ * ArcTdirSorter::qscmp -
+ * compare two axis monotone arcs that are incident
+ * to the line T == compare_value. Determine which of the
+ * two intersects that line with a LESSER S value. If
+ * jarc1 does, return 1. If jarc2 does, return -1.
+ *----------------------------------------------------------------------------
+ */
+int
+ArcTdirSorter::qscmp( char *i, char *j )
+{
+ Arc *jarc1 = *(Arc **) i;
+ Arc *jarc2 = *(Arc **) j;
+
+ int v1 = (jarc1->getitail() ? 0 : (jarc1->pwlArc->npts - 1));
+ int v2 = (jarc2->getitail() ? 0 : (jarc2->pwlArc->npts - 1));
+
+ REAL diff = jarc1->pwlArc->pts[v1].param[0] -
+ jarc2->pwlArc->pts[v2].param[0];
+
+ if( diff < 0.0)
+ return 1;
+ else if( diff > 0.0)
+ return -1;
+ else {
+ if( v1 == 0 ) {
+ if (jarc2->tail()[1] < jarc1->tail()[1]) {
+ return subdivider.ccwTurn_tl( jarc2, jarc1 ) ? 1 : -1;
+ } else {
+ return subdivider.ccwTurn_tr( jarc2, jarc1 ) ? -1 : 1;
+ }
+ } else {
+ if( jarc2->head()[1] < jarc1->head()[1] ) {
+ return subdivider.ccwTurn_tl( jarc1, jarc2 ) ? -1 : 1;
+ } else {
+ return subdivider.ccwTurn_tr( jarc1, jarc2 ) ? 1 : -1;
+ }
+ }
+ }
+}
+
+
+
+#endif /* __gluarcsorter_c_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/arcsorter.h b/mesalib/src/glu/sgi/libnurbs/internals/arcsorter.h
new file mode 100644
index 000000000..d72dd1e86
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/arcsorter.h
@@ -0,0 +1,73 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * arcsorter.h
+ *
+ */
+
+#ifndef __gluarcsorter_h_
+#define __gluarcsorter_h_
+
+#include "sorter.h"
+#include "arcsorter.h"
+
+class Arc;
+class Subdivider;
+
+class ArcSorter : private Sorter {
+public:
+ ArcSorter(Subdivider &);
+ void qsort( Arc **a, int n );
+protected:
+ virtual int qscmp( char *, char * );
+ Subdivider& subdivider;
+private:
+ void qsexc( char *i, char *j ); // i<-j, j<-i
+ void qstexc( char *i, char *j, char *k ); // i<-k, k<-j, j<-i
+};
+
+
+class ArcSdirSorter : public ArcSorter {
+public:
+ ArcSdirSorter( Subdivider & );
+private:
+ int qscmp( char *, char * );
+};
+
+
+class ArcTdirSorter : public ArcSorter {
+public:
+ ArcTdirSorter( Subdivider & );
+private:
+ int qscmp( char *, char * );
+};
+
+#endif /* __gluarcsorter_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/arctess.cc b/mesalib/src/glu/sgi/libnurbs/internals/arctess.cc
new file mode 100644
index 000000000..29e7cf4c0
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/arctess.cc
@@ -0,0 +1,611 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * arctessellator.c++
+ *
+ */
+
+#include "glimports.h"
+#include "mystdio.h"
+#include "myassert.h"
+#include "arctess.h"
+#include "bufpool.h"
+#include "simplemath.h"
+#include "bezierarc.h"
+#include "trimvertex.h"
+#include "trimvertpool.h"
+
+#define NOELIMINATION
+
+#define steps_function(large, small, rate) (max(1, 1+ (int) ((large-small)/rate)));
+
+/*-----------------------------------------------------------------------------
+ * ArcTessellator - construct an ArcTessellator
+ *-----------------------------------------------------------------------------
+ */
+
+ArcTessellator::ArcTessellator( TrimVertexPool& t, Pool& p )
+ : pwlarcpool(p), trimvertexpool(t)
+{
+}
+
+/*-----------------------------------------------------------------------------
+ * ~ArcTessellator - destroy an ArcTessellator
+ *-----------------------------------------------------------------------------
+ */
+
+ArcTessellator::~ArcTessellator( void )
+{
+}
+
+/*-----------------------------------------------------------------------------
+ * bezier - construct a bezier arc and attach it to an Arc
+ *-----------------------------------------------------------------------------
+ */
+
+void
+ArcTessellator::bezier( Arc *arc, REAL s1, REAL s2, REAL t1, REAL t2 )
+{
+ assert( arc != 0 );
+ assert( ! arc->isTessellated() );
+
+#ifndef NDEBUG
+ switch( arc->getside() ) {
+ case arc_left:
+ assert( s1 == s2 );
+ assert( t2 < t1 );
+ break;
+ case arc_right:
+ assert( s1 == s2 );
+ assert( t1 < t2 );
+ break;
+ case arc_top:
+ assert( t1 == t2 );
+ assert( s2 < s1 );
+ break;
+ case arc_bottom:
+ assert( t1 == t2 );
+ assert( s1 < s2 );
+ break;
+ case arc_none:
+ (void) abort();
+ break;
+ }
+#endif
+
+ TrimVertex *p = trimvertexpool.get(2);
+ arc->pwlArc = new(pwlarcpool) PwlArc( 2, p );
+ p[0].param[0] = s1;
+ p[0].param[1] = t1;
+ p[1].param[0] = s2;
+ p[1].param[1] = t2;
+ assert( (s1 == s2) || (t1 == t2) );
+ arc->setbezier();
+}
+
+
+/*-----------------------------------------------------------------------------
+ * pwl_left - construct a left boundary pwl arc and attach it to an arc
+ *-----------------------------------------------------------------------------
+ */
+
+void
+ArcTessellator::pwl_left( Arc *arc, REAL s, REAL t1, REAL t2, REAL rate )
+{
+ assert( t2 < t1 );
+
+/* if(rate <= 0.06) rate = 0.06;*/
+/* int nsteps = 1 + (int) ((t1 - t2) / rate ); */
+ int nsteps = steps_function(t1, t2, rate);
+
+
+ REAL stepsize = (t1 - t2) / (REAL) nsteps;
+
+ TrimVertex *newvert = trimvertexpool.get( nsteps+1 );
+ int i;
+ for( i = nsteps; i > 0; i-- ) {
+ newvert[i].param[0] = s;
+ newvert[i].param[1] = t2;
+ t2 += stepsize;
+ }
+ newvert[i].param[0] = s;
+ newvert[i].param[1] = t1;
+
+ arc->makeSide( new(pwlarcpool) PwlArc( nsteps+1, newvert ), arc_left );
+}
+
+/*-----------------------------------------------------------------------------
+ * pwl_right - construct a right boundary pwl arc and attach it to an arc
+ *-----------------------------------------------------------------------------
+ */
+
+void
+ArcTessellator::pwl_right( Arc *arc, REAL s, REAL t1, REAL t2, REAL rate )
+{
+ assert( t1 < t2 );
+
+/* if(rate <= 0.06) rate = 0.06;*/
+
+/* int nsteps = 1 + (int) ((t2 - t1) / rate ); */
+ int nsteps = steps_function(t2,t1,rate);
+ REAL stepsize = (t2 - t1) / (REAL) nsteps;
+
+ TrimVertex *newvert = trimvertexpool.get( nsteps+1 );
+ int i;
+ for( i = 0; i < nsteps; i++ ) {
+ newvert[i].param[0] = s;
+ newvert[i].param[1] = t1;
+ t1 += stepsize;
+ }
+ newvert[i].param[0] = s;
+ newvert[i].param[1] = t2;
+
+ arc->makeSide( new(pwlarcpool) PwlArc( nsteps+1, newvert ), arc_right );
+}
+
+
+/*-----------------------------------------------------------------------------
+ * pwl_top - construct a top boundary pwl arc and attach it to an arc
+ *-----------------------------------------------------------------------------
+ */
+
+void
+ArcTessellator::pwl_top( Arc *arc, REAL t, REAL s1, REAL s2, REAL rate )
+{
+ assert( s2 < s1 );
+
+/* if(rate <= 0.06) rate = 0.06;*/
+
+/* int nsteps = 1 + (int) ((s1 - s2) / rate ); */
+ int nsteps = steps_function(s1,s2,rate);
+ REAL stepsize = (s1 - s2) / (REAL) nsteps;
+
+ TrimVertex *newvert = trimvertexpool.get( nsteps+1 );
+ int i;
+ for( i = nsteps; i > 0; i-- ) {
+ newvert[i].param[0] = s2;
+ newvert[i].param[1] = t;
+ s2 += stepsize;
+ }
+ newvert[i].param[0] = s1;
+ newvert[i].param[1] = t;
+
+ arc->makeSide( new(pwlarcpool) PwlArc( nsteps+1, newvert ), arc_top );
+}
+
+/*-----------------------------------------------------------------------------
+ * pwl_bottom - construct a bottom boundary pwl arc and attach it to an arc
+ *-----------------------------------------------------------------------------
+ */
+
+void
+ArcTessellator::pwl_bottom( Arc *arc, REAL t, REAL s1, REAL s2, REAL rate )
+{
+ assert( s1 < s2 );
+
+/* if(rate <= 0.06) rate = 0.06;*/
+
+/* int nsteps = 1 + (int) ((s2 - s1) / rate ); */
+ int nsteps = steps_function(s2,s1,rate);
+ REAL stepsize = (s2 - s1) / (REAL) nsteps;
+
+ TrimVertex *newvert = trimvertexpool.get( nsteps+1 );
+ int i;
+ for( i = 0; i < nsteps; i++ ) {
+ newvert[i].param[0] = s1;
+ newvert[i].param[1] = t;
+ s1 += stepsize;
+ }
+ newvert[i].param[0] = s2;
+ newvert[i].param[1] = t;
+
+ arc->makeSide( new(pwlarcpool) PwlArc( nsteps+1, newvert ), arc_bottom );
+}
+
+/*-----------------------------------------------------------------------------
+ * pwl - construct a pwl arc and attach it to an arc
+ *-----------------------------------------------------------------------------
+ */
+
+void
+ArcTessellator::pwl( Arc *arc, REAL s1, REAL s2, REAL t1, REAL t2, REAL rate )
+{
+
+/* if(rate <= 0.06) rate = 0.06;*/
+
+ int snsteps = 1 + (int) (glu_abs(s2 - s1) / rate );
+ int tnsteps = 1 + (int) (glu_abs(t2 - t1) / rate );
+ int nsteps = max(1,max( snsteps, tnsteps ));
+
+ REAL sstepsize = (s2 - s1) / (REAL) nsteps;
+ REAL tstepsize = (t2 - t1) / (REAL) nsteps;
+ TrimVertex *newvert = trimvertexpool.get( nsteps+1 );
+ long i;
+ for( i = 0; i < nsteps; i++ ) {
+ newvert[i].param[0] = s1;
+ newvert[i].param[1] = t1;
+ s1 += sstepsize;
+ t1 += tstepsize;
+ }
+ newvert[i].param[0] = s2;
+ newvert[i].param[1] = t2;
+
+ /* arc->makeSide( new(pwlarcpool) PwlArc( nsteps+1, newvert ), arc_bottom ); */
+ arc->pwlArc = new(pwlarcpool) PwlArc( nsteps+1, newvert );
+
+ arc->clearbezier();
+ arc->clearside( );
+}
+
+
+/*-----------------------------------------------------------------------------
+ * tessellateLinear - constuct a linear pwl arc and attach it to an Arc
+ *-----------------------------------------------------------------------------
+ */
+
+void
+ArcTessellator::tessellateLinear( Arc *arc, REAL geo_stepsize, REAL arc_stepsize, int isrational )
+{
+ assert( arc->pwlArc == NULL );
+ REAL s1, s2, t1, t2;
+
+ //we don't need to scale by arc_stepsize if the trim curve
+ //is piecewise linear. Reason: In pwl_right, pwl_left, pwl_top, pwl_left,
+ //and pwl, the nsteps is computed by deltaU (or V) /stepsize.
+ //The quantity deltaU/arc_stepsize doesn't have any meaning. And
+ //it causes problems: see bug 517641
+ REAL stepsize = geo_stepsize; /* * arc_stepsize*/;
+
+ BezierArc *b = arc->bezierArc;
+
+ if( isrational ) {
+ s1 = b->cpts[0] / b->cpts[2];
+ t1 = b->cpts[1] / b->cpts[2];
+ s2 = b->cpts[b->stride+0] / b->cpts[b->stride+2];
+ t2 = b->cpts[b->stride+1] / b->cpts[b->stride+2];
+ } else {
+ s1 = b->cpts[0];
+ t1 = b->cpts[1];
+ s2 = b->cpts[b->stride+0];
+ t2 = b->cpts[b->stride+1];
+ }
+ if( s1 == s2 )
+ if( t1 < t2 )
+ pwl_right( arc, s1, t1, t2, stepsize );
+ else
+ pwl_left( arc, s1, t1, t2, stepsize );
+ else if( t1 == t2 )
+ if( s1 < s2 )
+ pwl_bottom( arc, t1, s1, s2, stepsize );
+ else
+ pwl_top( arc, t1, s1, s2, stepsize );
+ else
+ pwl( arc, s1, s2, t1, t2, stepsize );
+}
+
+/*-----------------------------------------------------------------------------
+ * tessellateNonlinear - constuct a nonlinear pwl arc and attach it to an Arc
+ *-----------------------------------------------------------------------------
+ */
+
+void
+ArcTessellator::tessellateNonlinear( Arc *arc, REAL geo_stepsize, REAL arc_stepsize, int isrational )
+{
+ assert( arc->pwlArc == NULL );
+
+ REAL stepsize = geo_stepsize * arc_stepsize;
+
+ BezierArc *bezierArc = arc->bezierArc;
+
+ REAL size; //bounding box size of the curve in UV
+ {
+ int i,j;
+ REAL min_u, min_v, max_u,max_v;
+ min_u = max_u = bezierArc->cpts[0];
+ min_v = max_v = bezierArc->cpts[1];
+ for(i=1, j=bezierArc->stride; i<bezierArc->order; i++, j+= bezierArc->stride)
+ {
+ if(bezierArc->cpts[j] < min_u)
+ min_u = bezierArc->cpts[j];
+ if(bezierArc->cpts[j] > max_u)
+ max_u = bezierArc->cpts[j];
+ if(bezierArc->cpts[j+1] < min_v)
+ min_v = bezierArc->cpts[j+1];
+ if(bezierArc->cpts[j+1] > max_v)
+ max_v = bezierArc->cpts[j+1];
+ }
+
+ size = max_u - min_u;
+ if(size < max_v - min_v)
+ size = max_v - min_v;
+ }
+
+ /*int nsteps = 1 + (int) (1.0/stepsize);*/
+
+ int nsteps = (int) (size/stepsize);
+ if(nsteps <=0)
+ nsteps=1;
+
+ TrimVertex *vert = trimvertexpool.get( nsteps+1 );
+ REAL dp = 1.0/nsteps;
+
+
+ arc->pwlArc = new(pwlarcpool) PwlArc();
+ arc->pwlArc->pts = vert;
+
+ if( isrational ) {
+ REAL pow_u[MAXORDER], pow_v[MAXORDER], pow_w[MAXORDER];
+ trim_power_coeffs( bezierArc, pow_u, 0 );
+ trim_power_coeffs( bezierArc, pow_v, 1 );
+ trim_power_coeffs( bezierArc, pow_w, 2 );
+
+ /* compute first point exactly */
+ REAL *b = bezierArc->cpts;
+ vert->param[0] = b[0]/b[2];
+ vert->param[1] = b[1]/b[2];
+
+ /* strength reduction on p = dp * step would introduce error */
+ int step;
+#ifndef NOELIMINATION
+ int ocanremove = 0;
+#endif
+ register long order = bezierArc->order;
+ for( step=1, ++vert; step<nsteps; step++, vert++ ) {
+ register REAL p = dp * step;
+ register REAL u = pow_u[0];
+ register REAL v = pow_v[0];
+ register REAL w = pow_w[0];
+ for( register int i = 1; i < order; i++ ) {
+ u = u * p + pow_u[i];
+ v = v * p + pow_v[i];
+ w = w * p + pow_w[i];
+ }
+ vert->param[0] = u/w;
+ vert->param[1] = v/w;
+#ifndef NOELIMINATION
+ REAL ds = glu_abs(vert[0].param[0] - vert[-1].param[0]);
+ REAL dt = glu_abs(vert[0].param[1] - vert[-1].param[1]);
+ int canremove = (ds<geo_stepsize && dt<geo_stepsize) ? 1 : 0;
+ REAL ods=0.0, odt=0.0;
+
+ if( ocanremove && canremove ) {
+ REAL nds = ds + ods;
+ REAL ndt = dt + odt;
+ if( nds<geo_stepsize && ndt<geo_stepsize ) {
+ // remove previous point
+ --vert;
+ vert[0].param[0] = vert[1].param[0];
+ vert[0].param[1] = vert[1].param[1];
+ ods = nds;
+ odt = ndt;
+ ocanremove = 1;
+ } else {
+ ocanremove = canremove;
+ ods = ds;
+ odt = dt;
+ }
+ } else {
+ ocanremove = canremove;
+ ods = ds;
+ odt = dt;
+ }
+#endif
+ }
+
+ /* compute last point exactly */
+ b += (order - 1) * bezierArc->stride;
+ vert->param[0] = b[0]/b[2];
+ vert->param[1] = b[1]/b[2];
+
+ } else {
+ REAL pow_u[MAXORDER], pow_v[MAXORDER];
+ trim_power_coeffs( bezierArc, pow_u, 0 );
+ trim_power_coeffs( bezierArc, pow_v, 1 );
+
+ /* compute first point exactly */
+ REAL *b = bezierArc->cpts;
+ vert->param[0] = b[0];
+ vert->param[1] = b[1];
+
+ /* strength reduction on p = dp * step would introduce error */
+ int step;
+#ifndef NOELIMINATION
+ int ocanremove = 0;
+#endif
+ register long order = bezierArc->order;
+ for( step=1, ++vert; step<nsteps; step++, vert++ ) {
+ register REAL p = dp * step;
+ register REAL u = pow_u[0];
+ register REAL v = pow_v[0];
+ for( register int i = 1; i < bezierArc->order; i++ ) {
+ u = u * p + pow_u[i];
+ v = v * p + pow_v[i];
+ }
+ vert->param[0] = u;
+ vert->param[1] = v;
+#ifndef NOELIMINATION
+ REAL ds = glu_abs(vert[0].param[0] - vert[-1].param[0]);
+ REAL dt = glu_abs(vert[0].param[1] - vert[-1].param[1]);
+ int canremove = (ds<geo_stepsize && dt<geo_stepsize) ? 1 : 0;
+ REAL ods=0.0, odt=0.0;
+
+ if( ocanremove && canremove ) {
+ REAL nds = ds + ods;
+ REAL ndt = dt + odt;
+ if( nds<geo_stepsize && ndt<geo_stepsize ) {
+ // remove previous point
+ --vert;
+ vert[0].param[0] = vert[1].param[0];
+ vert[0].param[1] = vert[1].param[1];
+ ods = nds;
+ odt = ndt;
+ ocanremove = 1;
+ } else {
+ ocanremove = canremove;
+ ods = ds;
+ odt = dt;
+ }
+ } else {
+ ocanremove = canremove;
+ ods = ds;
+ odt = dt;
+ }
+#endif
+ }
+
+ /* compute last point exactly */
+ b += (order - 1) * bezierArc->stride;
+ vert->param[0] = b[0];
+ vert->param[1] = b[1];
+ }
+ arc->pwlArc->npts = vert - arc->pwlArc->pts + 1;
+/*
+ for( TrimVertex *vt=pwlArc->pts; vt != vert-1; vt++ ) {
+ if( tooclose( vt[0].param[0], vt[1].param[0] ) )
+ vt[1].param[0] = vt[0].param[0];
+ if( tooclose( vt[0].param[1], vt[1].param[1] ) )
+ vt[1].param[1] = vt[0].param[1];
+ }
+*/
+}
+
+const REAL ArcTessellator::gl_Bernstein[][MAXORDER][MAXORDER] = {
+ {
+ {1, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 }
+ },
+ {
+ {-1, 1, 0, 0, 0, 0, 0, 0 },
+ {1, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 }
+ },
+ {
+ {1, -2, 1, 0, 0, 0, 0, 0 },
+ {-2, 2, 0, 0, 0, 0, 0, 0 },
+ {1, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 }
+ },
+ {
+ {-1, 3, -3, 1, 0, 0, 0, 0 },
+ {3, -6, 3, 0, 0, 0, 0, 0 },
+ {-3, 3, 0, 0, 0, 0, 0, 0 },
+ {1, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 }
+ },
+ {
+ {1, -4, 6, -4, 1, 0, 0, 0 },
+ {-4, 12, -12, 4, 0, 0, 0, 0 },
+ {6, -12, 6, 0, 0, 0, 0, 0 },
+ {-4, 4, 0, 0, 0, 0, 0, 0 },
+ {1, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 }
+ },
+ {
+ {-1, 5, -10, 10, -5, 1, 0, 0 },
+ {5, -20, 30, -20, 5, 0, 0, 0 },
+ {-10, 30, -30, 10, 0, 0, 0, 0 },
+ {10, -20, 10, 0, 0, 0, 0, 0 },
+ {-5, 5, 0, 0, 0, 0, 0, 0 },
+ {1, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 }
+ },
+ {
+ {1, -6, 15, -20, 15, -6, 1, 0 },
+ {-6, 30, -60, 60, -30, 6, 0, 0 },
+ {15, -60, 90, -60, 15, 0, 0, 0 },
+ {-20, 60, -60, 20, 0, 0, 0, 0 },
+ {15, -30, 15, 0, 0, 0, 0, 0 },
+ {-6, 6, 0, 0, 0, 0, 0, 0 },
+ {1, 0, 0, 0, 0, 0, 0, 0 },
+ {0, 0, 0, 0, 0, 0, 0, 0 }
+ },
+ {
+ {-1, 7, -21, 35, -35, 21, -7, 1 },
+ {7, -42, 105, -140, 105, -42, 7, 0 },
+ {-21, 105, -210, 210, -105, 21, 0, 0 },
+ {35, -140, 210, -140, 35, 0, 0, 0 },
+ {-35, 105, -105, 35, 0, 0, 0, 0 },
+ {21, -42, 21, 0, 0, 0, 0, 0 },
+ {-7, 7, 0, 0, 0, 0, 0, 0 },
+ {1, 0, 0, 0, 0, 0, 0, 0 }
+ }};
+
+
+/*-----------------------------------------------------------------------------
+ * trim_power_coeffs - compute power basis coefficients from bezier coeffients
+ *-----------------------------------------------------------------------------
+ */
+void
+ArcTessellator::trim_power_coeffs( BezierArc *bez_arc, REAL *p, int coord )
+{
+ register int stride = bez_arc->stride;
+ register int order = bez_arc->order;
+ register REAL *base = bez_arc->cpts + coord;
+
+ REAL const (*mat)[MAXORDER][MAXORDER] = &gl_Bernstein[order-1];
+ REAL const (*lrow)[MAXORDER] = &(*mat)[order];
+
+ /* WIN32 didn't like the following line within the for-loop */
+ REAL const (*row)[MAXORDER] = &(*mat)[0];
+ for( ; row != lrow; row++ ) {
+ register REAL s = 0.0;
+ register REAL *point = base;
+ register REAL const *mlast = *row + order;
+ for( REAL const *m = *row; m != mlast; m++, point += stride )
+ s += *(m) * (*point);
+ *(p++) = s;
+ }
+}
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/arctess.h b/mesalib/src/glu/sgi/libnurbs/internals/arctess.h
new file mode 100644
index 000000000..7802af90c
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/arctess.h
@@ -0,0 +1,66 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * arctess.h
+ *
+ */
+
+#ifndef __gluarctess_h_
+#define __gluarctess_h_
+
+#include "defines.h"
+#include "types.h"
+#include "arc.h"
+
+struct BezierArc;
+class Pool;
+class TrimVertexPool;
+
+class ArcTessellator {
+public:
+ ArcTessellator( TrimVertexPool&, Pool& );
+ ~ArcTessellator( void );
+ void bezier( Arc_ptr, REAL, REAL, REAL, REAL );
+ void pwl( Arc_ptr, REAL, REAL, REAL, REAL, REAL );
+ void pwl_left( Arc_ptr, REAL, REAL, REAL, REAL );
+ void pwl_right( Arc_ptr, REAL, REAL, REAL, REAL );
+ void pwl_top( Arc_ptr, REAL, REAL, REAL, REAL );
+ void pwl_bottom( Arc_ptr, REAL, REAL, REAL, REAL );
+ void tessellateLinear( Arc_ptr, REAL, REAL, int );
+ void tessellateNonlinear( Arc_ptr, REAL, REAL, int );
+private:
+ static const REAL gl_Bernstein[][MAXORDER][MAXORDER];
+ Pool& pwlarcpool;
+ TrimVertexPool& trimvertexpool;
+ static void trim_power_coeffs( BezierArc *, REAL[MAXORDER], int );
+};
+
+#endif /* __gluarctess_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/backend.cc b/mesalib/src/glu/sgi/libnurbs/internals/backend.cc
new file mode 100644
index 000000000..88dc3f516
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/backend.cc
@@ -0,0 +1,589 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * backend.c++
+ *
+ */
+
+/* Bezier surface backend
+ - interprets display mode (wireframe,shaded,...)
+*/
+#include <stdio.h>
+#include "glimports.h"
+#include "mystdio.h"
+#include "backend.h"
+#include "basiccrveval.h"
+#include "basicsurfeval.h"
+#include "nurbsconsts.h"
+
+#define NOWIREFRAME
+
+
+/*-------------------------------------------------------------------------
+ * bgnsurf - preamble to surface definition and evaluations
+ *-------------------------------------------------------------------------
+ */
+void
+Backend::bgnsurf( int wiretris, int wirequads, long nuid )
+{
+/*#ifndef NOWIREFRAME*/ //need this for old version
+ wireframetris = wiretris;
+ wireframequads = wirequads;
+/*#endif*/
+
+ /*in the spec, GLU_DISPLAY_MODE is either
+ * GLU_FILL
+ * GLU_OUTLINE_POLY
+ * GLU_OUTLINE_PATCH.
+ *In fact, GLU_FLL is has the same effect as
+ * set GL_FRONT_AND_BACK to be GL_FILL
+ * and GLU_OUTLINE_POLY is the same as set
+ * GL_FRONT_AND_BACK to be GL_LINE
+ *It is more efficient to do this once at the beginning of
+ *each surface than to do it for each primitive.
+ * The internal has more options: outline_triangle and outline_quad
+ *can be seperated. But since this is not in spec, and more importantly,
+ *this is not so useful, so we don't need to keep this option.
+ */
+
+ surfaceEvaluator.bgnmap2f( nuid );
+
+ if(wiretris)
+ surfaceEvaluator.polymode(N_MESHLINE);
+ else
+ surfaceEvaluator.polymode(N_MESHFILL);
+}
+
+void
+Backend::patch( REAL ulo, REAL uhi, REAL vlo, REAL vhi )
+{
+ surfaceEvaluator.domain2f( ulo, uhi, vlo, vhi );
+}
+
+void
+Backend::surfbbox( long type, REAL *from, REAL *to )
+{
+ surfaceEvaluator.range2f( type, from, to );
+}
+
+/*-------------------------------------------------------------------------
+ * surfpts - pass a desription of a surface map
+ *-------------------------------------------------------------------------
+ */
+void
+Backend::surfpts(
+ long type, /* geometry, color, texture, normal */
+ REAL *pts, /* control points */
+ long ustride, /* distance to next point in u direction */
+ long vstride, /* distance to next point in v direction */
+ int uorder, /* u parametric order */
+ int vorder, /* v parametric order */
+ REAL ulo, /* u lower bound */
+ REAL uhi, /* u upper bound */
+ REAL vlo, /* v lower bound */
+ REAL vhi ) /* v upper bound */
+{
+ surfaceEvaluator.map2f( type,ulo,uhi,ustride,uorder,vlo,vhi,vstride,vorder,pts );
+ surfaceEvaluator.enable( type );
+}
+
+/*-------------------------------------------------------------------------
+ * surfgrid - define a lattice of points with origin and offset
+ *-------------------------------------------------------------------------
+ */
+void
+Backend::surfgrid( REAL u0, REAL u1, long nu, REAL v0, REAL v1, long nv )
+{
+ surfaceEvaluator.mapgrid2f( nu, u0, u1, nv, v0, v1 );
+}
+
+/*-------------------------------------------------------------------------
+ * surfmesh - evaluate a mesh of points on lattice
+ *-------------------------------------------------------------------------
+ */
+void
+Backend::surfmesh( long u, long v, long n, long m )
+{
+#ifndef NOWIREFRAME
+ if( wireframequads ) {
+ long v0, v1;
+ long u0f = u, u1f = u+n;
+ long v0f = v, v1f = v+m;
+ long parity = (u & 1);
+
+ for( v0 = v0f, v1 = v0f++ ; v0<v1f; v0 = v1, v1++ ) {
+ surfaceEvaluator.bgnline();
+ for( long u = u0f; u<=u1f; u++ ) {
+ if( parity ) {
+ surfaceEvaluator.evalpoint2i( u, v0 );
+ surfaceEvaluator.evalpoint2i( u, v1 );
+ } else {
+ surfaceEvaluator.evalpoint2i( u, v1 );
+ surfaceEvaluator.evalpoint2i( u, v0 );
+ }
+ parity = 1 - parity;
+ }
+ surfaceEvaluator.endline();
+ }
+ } else {
+ surfaceEvaluator.mapmesh2f( N_MESHFILL, u, u+n, v, v+m );
+ }
+#else
+ if( wireframequads ) {
+
+ surfaceEvaluator.mapmesh2f( N_MESHLINE, u, u+n, v, v+m );
+ } else {
+
+ surfaceEvaluator.mapmesh2f( N_MESHFILL, u, u+n, v, v+m );
+ }
+#endif
+}
+
+/*-------------------------------------------------------------------------
+ * endsurf - postamble to surface
+ *-------------------------------------------------------------------------
+ */
+void
+Backend::endsurf( void )
+{
+ surfaceEvaluator.endmap2f();
+}
+
+/***************************************/
+void
+Backend::bgntfan( void )
+{
+ surfaceEvaluator.bgntfan();
+/*
+ if(wireframetris)
+ surfaceEvaluator.polymode( N_MESHLINE );
+ else
+ surfaceEvaluator.polymode( N_MESHFILL );
+*/
+}
+
+void
+Backend::endtfan( void )
+{
+ surfaceEvaluator.endtfan();
+}
+
+void
+Backend::bgnqstrip( void )
+{
+ surfaceEvaluator.bgnqstrip();
+/*
+ if(wireframequads)
+ surfaceEvaluator.polymode( N_MESHLINE );
+ else
+ surfaceEvaluator.polymode( N_MESHFILL );
+*/
+}
+
+void
+Backend::endqstrip( void )
+{
+ surfaceEvaluator.endqstrip();
+}
+
+void
+Backend::evalUStrip(int n_upper, REAL v_upper, REAL* upper_val,
+ int n_lower, REAL v_lower, REAL* lower_val
+ )
+{
+ surfaceEvaluator.evalUStrip(n_upper, v_upper, upper_val,
+ n_lower, v_lower, lower_val);
+}
+
+void
+Backend::evalVStrip(int n_left, REAL u_left, REAL* left_val,
+ int n_right, REAL u_right, REAL* right_val
+ )
+{
+ surfaceEvaluator.evalVStrip(n_left, u_left, left_val,
+ n_right, u_right, right_val);
+}
+
+/***************************************/
+
+
+/*-------------------------------------------------------------------------
+ * bgntmesh - preamble to a triangle mesh
+ *-------------------------------------------------------------------------
+ */
+void
+Backend::bgntmesh( const char * )
+{
+#ifndef NOWIREFRAME
+
+ meshindex = 0; /* I think these need to be initialized to zero */
+ npts = 0;
+
+ if( !wireframetris ) {
+ surfaceEvaluator.bgntmesh();
+ }
+#else
+
+ if( wireframetris ) {
+ surfaceEvaluator.bgntmesh();
+ surfaceEvaluator.polymode( N_MESHLINE );
+ } else {
+ surfaceEvaluator.bgntmesh();
+ surfaceEvaluator.polymode( N_MESHFILL );
+ }
+#endif
+}
+
+void
+Backend::tmeshvert( GridTrimVertex *v )
+{
+ if( v->isGridVert() ) {
+ tmeshvert( v->g );
+ } else {
+ tmeshvert( v->t );
+ }
+}
+
+void
+Backend::tmeshvertNOGE(TrimVertex *t)
+{
+// surfaceEvaluator.inDoEvalCoord2NOGE( t->param[0], t->param[1], temp, ttt);
+#ifdef USE_OPTTT
+ surfaceEvaluator.inDoEvalCoord2NOGE( t->param[0], t->param[1], t->cache_point, t->cache_normal);
+#endif
+}
+
+//opt for a line with the same u.
+void
+Backend::tmeshvertNOGE_BU(TrimVertex *t)
+{
+#ifdef USE_OPTTT
+ surfaceEvaluator.inDoEvalCoord2NOGE_BU( t->param[0], t->param[1], t->cache_point, t->cache_normal);
+#endif
+}
+
+//opt for a line with the same v.
+void
+Backend::tmeshvertNOGE_BV(TrimVertex *t)
+{
+#ifdef USE_OPTTT
+ surfaceEvaluator.inDoEvalCoord2NOGE_BV( t->param[0], t->param[1], t->cache_point, t->cache_normal);
+#endif
+}
+
+void
+Backend::preEvaluateBU(REAL u)
+{
+ surfaceEvaluator.inPreEvaluateBU_intfac(u);
+}
+
+void
+Backend::preEvaluateBV(REAL v)
+{
+ surfaceEvaluator.inPreEvaluateBV_intfac(v);
+}
+
+
+/*-------------------------------------------------------------------------
+ * tmeshvert - evaluate a point on a triangle mesh
+ *-------------------------------------------------------------------------
+ */
+void
+Backend::tmeshvert( TrimVertex *t )
+{
+
+#ifndef NOWIREFRAME
+ const long nuid = t->nuid;
+#endif
+ const REAL u = t->param[0];
+ const REAL v = t->param[1];
+
+#ifndef NOWIREFRAME
+ npts++;
+ if( wireframetris ) {
+ if( npts >= 3 ) {
+ surfaceEvaluator.bgnclosedline();
+ if( mesh[0][2] == 0 )
+ surfaceEvaluator.evalcoord2f( mesh[0][3], mesh[0][0], mesh[0][1] );
+ else
+ surfaceEvaluator.evalpoint2i( (long) mesh[0][0], (long) mesh[0][1] );
+ if( mesh[1][2] == 0 )
+ surfaceEvaluator.evalcoord2f( mesh[1][3], mesh[1][0], mesh[1][1] );
+ else
+ surfaceEvaluator.evalpoint2i( (long) mesh[1][0], (long) mesh[1][1] );
+ surfaceEvaluator.evalcoord2f( nuid, u, v );
+ surfaceEvaluator.endclosedline();
+ }
+ mesh[meshindex][0] = u;
+ mesh[meshindex][1] = v;
+ mesh[meshindex][2] = 0;
+ mesh[meshindex][3] = nuid;
+ meshindex = (meshindex+1) % 2;
+ } else {
+ surfaceEvaluator.evalcoord2f( nuid, u, v );
+ }
+#else
+
+ surfaceEvaluator.evalcoord2f( 0, u, v );
+//for uninitial memory read surfaceEvaluator.evalcoord2f( nuid, u, v );
+#endif
+}
+
+//the same as tmeshvert(trimvertex), for efficiency purpose
+void
+Backend::tmeshvert( REAL u, REAL v )
+{
+#ifndef NOWIREFRAME
+ const long nuid = 0;
+
+ npts++;
+ if( wireframetris ) {
+ if( npts >= 3 ) {
+ surfaceEvaluator.bgnclosedline();
+ if( mesh[0][2] == 0 )
+ surfaceEvaluator.evalcoord2f( mesh[0][3], mesh[0][0], mesh[0][1] );
+ else
+ surfaceEvaluator.evalpoint2i( (long) mesh[0][0], (long) mesh[0][1] );
+ if( mesh[1][2] == 0 )
+ surfaceEvaluator.evalcoord2f( mesh[1][3], mesh[1][0], mesh[1][1] );
+ else
+ surfaceEvaluator.evalpoint2i( (long) mesh[1][0], (long) mesh[1][1] );
+ surfaceEvaluator.evalcoord2f( nuid, u, v );
+ surfaceEvaluator.endclosedline();
+ }
+ mesh[meshindex][0] = u;
+ mesh[meshindex][1] = v;
+ mesh[meshindex][2] = 0;
+ mesh[meshindex][3] = nuid;
+ meshindex = (meshindex+1) % 2;
+ } else {
+ surfaceEvaluator.evalcoord2f( nuid, u, v );
+ }
+#else
+
+ surfaceEvaluator.evalcoord2f( 0, u, v );
+#endif
+}
+
+/*-------------------------------------------------------------------------
+ * tmeshvert - evaluate a grid point of a triangle mesh
+ *-------------------------------------------------------------------------
+ */
+void
+Backend::tmeshvert( GridVertex *g )
+{
+ const long u = g->gparam[0];
+ const long v = g->gparam[1];
+
+#ifndef NOWIREFRAME
+ npts++;
+ if( wireframetris ) {
+ if( npts >= 3 ) {
+ surfaceEvaluator.bgnclosedline();
+ if( mesh[0][2] == 0 )
+ surfaceEvaluator.evalcoord2f( (long) mesh[0][3], mesh[0][0], mesh[0][1] );
+ else
+ surfaceEvaluator.evalpoint2i( (long) mesh[0][0], (long) mesh[0][1] );
+ if( mesh[1][2] == 0 )
+ surfaceEvaluator.evalcoord2f( (long) mesh[1][3], mesh[1][0], mesh[1][1] );
+ else
+ surfaceEvaluator.evalpoint2i( (long) mesh[1][0], (long) mesh[1][1] );
+ surfaceEvaluator.evalpoint2i( u, v );
+ surfaceEvaluator.endclosedline();
+ }
+ mesh[meshindex][0] = u;
+ mesh[meshindex][1] = v;
+ mesh[meshindex][2] = 1;
+ meshindex = (meshindex+1) % 2;
+ } else {
+ surfaceEvaluator.evalpoint2i( u, v );
+ }
+#else
+ surfaceEvaluator.evalpoint2i( u, v );
+#endif
+}
+
+/*-------------------------------------------------------------------------
+ * swaptmesh - perform a swap of the triangle mesh pointers
+ *-------------------------------------------------------------------------
+ */
+void
+Backend::swaptmesh( void )
+{
+#ifndef NOWIREFRAME
+ if( wireframetris ) {
+ meshindex = 1 - meshindex;
+ } else {
+ surfaceEvaluator.swaptmesh();
+ }
+#else
+ surfaceEvaluator.swaptmesh();
+#endif
+}
+
+/*-------------------------------------------------------------------------
+ * endtmesh - postamble to triangle mesh
+ *-------------------------------------------------------------------------
+ */
+void
+Backend::endtmesh( void )
+{
+#ifndef NOWIREFRAME
+ if( ! wireframetris )
+ surfaceEvaluator.endtmesh();
+#else
+ surfaceEvaluator.endtmesh();
+/* surfaceEvaluator.polymode( N_MESHFILL );*/
+#endif
+}
+
+
+/*-------------------------------------------------------------------------
+ * bgnoutline - preamble to outlined rendering
+ *-------------------------------------------------------------------------
+ */
+void
+Backend::bgnoutline( void )
+{
+ surfaceEvaluator.bgnline();
+}
+
+/*-------------------------------------------------------------------------
+ * linevert - evaluate a point on an outlined contour
+ *-------------------------------------------------------------------------
+ */
+void
+Backend::linevert( TrimVertex *t )
+{
+ surfaceEvaluator.evalcoord2f( t->nuid, t->param[0], t->param[1] );
+}
+
+/*-------------------------------------------------------------------------
+ * linevert - evaluate a grid point of an outlined contour
+ *-------------------------------------------------------------------------
+ */
+void
+Backend::linevert( GridVertex *g )
+{
+ surfaceEvaluator.evalpoint2i( g->gparam[0], g->gparam[1] );
+}
+
+/*-------------------------------------------------------------------------
+ * endoutline - postamble to outlined rendering
+ *-------------------------------------------------------------------------
+ */
+void
+Backend::endoutline( void )
+{
+ surfaceEvaluator.endline();
+}
+
+/*-------------------------------------------------------------------------
+ * triangle - output a triangle
+ *-------------------------------------------------------------------------
+ */
+void
+Backend::triangle( TrimVertex *a, TrimVertex *b, TrimVertex *c )
+{
+/* bgntmesh( "spittriangle" );*/
+ bgntfan();
+ tmeshvert( a );
+ tmeshvert( b );
+ tmeshvert( c );
+ endtfan();
+/* endtmesh();*/
+}
+
+void
+Backend::bgncurv( void )
+{
+ curveEvaluator.bgnmap1f( 0 );
+}
+
+void
+Backend::segment( REAL ulo, REAL uhi )
+{
+ curveEvaluator.domain1f( ulo, uhi );
+}
+
+void
+Backend::curvpts(
+ long type, /* geometry, color, texture, normal */
+ REAL *pts, /* control points */
+ long stride, /* distance to next point */
+ int order, /* parametric order */
+ REAL ulo, /* lower parametric bound */
+ REAL uhi ) /* upper parametric bound */
+
+{
+ curveEvaluator.map1f( type, ulo, uhi, stride, order, pts );
+ curveEvaluator.enable( type );
+}
+
+void
+Backend::curvgrid( REAL u0, REAL u1, long nu )
+{
+ curveEvaluator.mapgrid1f( nu, u0, u1 );
+}
+
+void
+Backend::curvmesh( long from, long n )
+{
+ curveEvaluator.mapmesh1f( N_MESHFILL, from, from+n );
+}
+
+void
+Backend::curvpt(REAL u)
+{
+ curveEvaluator.evalcoord1f( 0, u );
+}
+
+void
+Backend::bgnline( void )
+{
+ curveEvaluator.bgnline();
+}
+
+void
+Backend::endline( void )
+{
+ curveEvaluator.endline();
+}
+
+void
+Backend::endcurv( void )
+{
+ curveEvaluator.endmap1f();
+}
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/backend.h b/mesalib/src/glu/sgi/libnurbs/internals/backend.h
new file mode 100644
index 000000000..6840cb19e
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/backend.h
@@ -0,0 +1,113 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * backend.h
+ *
+ */
+
+#ifndef __glubackend_h_
+#define __glubackend_h_
+
+#include "trimvertex.h"
+#include "gridvertex.h"
+#include "gridtrimvertex.h"
+
+class BasicCurveEvaluator;
+class BasicSurfaceEvaluator;
+
+class Backend {
+private:
+ BasicCurveEvaluator& curveEvaluator;
+ BasicSurfaceEvaluator& surfaceEvaluator;
+public:
+ Backend( BasicCurveEvaluator &c, BasicSurfaceEvaluator& e )
+ : curveEvaluator(c), surfaceEvaluator(e) {}
+
+ /* surface backend routines */
+ void bgnsurf( int, int, long );
+ void patch( REAL, REAL, REAL, REAL );
+ void surfpts( long, REAL *, long, long, int, int,
+ REAL, REAL, REAL, REAL );
+ void surfbbox( long, REAL *, REAL * );
+ void surfgrid( REAL, REAL, long, REAL, REAL, long );
+ void surfmesh( long, long, long, long );
+ void bgntmesh( const char * );
+ void endtmesh( void );
+ void swaptmesh( void );
+ void tmeshvert( GridTrimVertex * );
+ void tmeshvert( TrimVertex * );
+ void tmeshvert( GridVertex * );
+ void tmeshvert( REAL u, REAL v );
+ void linevert( TrimVertex * );
+ void linevert( GridVertex * );
+ void bgnoutline( void );
+ void endoutline( void );
+ void endsurf( void );
+ void triangle( TrimVertex*, TrimVertex*, TrimVertex* );
+
+ void bgntfan();
+ void endtfan();
+ void bgnqstrip();
+ void endqstrip();
+ void evalUStrip(int n_upper, REAL v_upper, REAL* upper_val,
+ int n_lower, REAL v_lower, REAL* lower_val
+ );
+ void evalVStrip(int n_left, REAL u_left, REAL* left_val,
+ int n_right, REAL v_right, REAL* right_val
+ );
+ void tmeshvertNOGE(TrimVertex *t);
+ void tmeshvertNOGE_BU(TrimVertex *t);
+ void tmeshvertNOGE_BV(TrimVertex *t);
+ void preEvaluateBU(REAL u);
+ void preEvaluateBV(REAL v);
+
+
+ /* curve backend routines */
+ void bgncurv( void );
+ void segment( REAL, REAL );
+ void curvpts( long, REAL *, long, int, REAL, REAL );
+ void curvgrid( REAL, REAL, long );
+ void curvmesh( long, long );
+ void curvpt( REAL );
+ void bgnline( void );
+ void endline( void );
+ void endcurv( void );
+private:
+#ifndef NOWIREFRAME
+ int wireframetris;
+ int wireframequads;
+ int npts;
+ REAL mesh[3][4];
+ int meshindex;
+#endif
+};
+
+#endif /* __glubackend_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/basiccrveval.cc b/mesalib/src/glu/sgi/libnurbs/internals/basiccrveval.cc
new file mode 100644
index 000000000..cc473e4c2
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/basiccrveval.cc
@@ -0,0 +1,138 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * basiccrveval.c++
+ *
+ */
+
+#include "mystdio.h"
+#include "types.h"
+#include "basiccrveval.h"
+
+void
+BasicCurveEvaluator::domain1f( REAL, REAL )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "domain1f\n" );
+#endif
+}
+
+void
+BasicCurveEvaluator::range1f( long , REAL *, REAL * )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "range1f\n" );
+#endif
+}
+
+void
+BasicCurveEvaluator::enable( long )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "enable\n" );
+#endif
+}
+
+void
+BasicCurveEvaluator::disable( long )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "disable\n" );
+#endif
+}
+
+void
+BasicCurveEvaluator::bgnmap1f( long )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "bgnmap1f\n" );
+#endif
+}
+
+void
+BasicCurveEvaluator::map1f( long, REAL, REAL, long, long, REAL * )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "map1f\n" );
+#endif
+}
+
+void
+BasicCurveEvaluator::mapgrid1f( long, REAL, REAL )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "mapgrid1f\n" );
+#endif
+}
+
+void
+BasicCurveEvaluator::mapmesh1f( long, long, long )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "mapmesh1f\n" );
+#endif
+}
+
+void
+BasicCurveEvaluator::evalcoord1f( long, REAL )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "evalcoord1f\n" );
+#endif
+}
+
+void
+BasicCurveEvaluator::endmap1f( void )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "endmap1f\n" );
+#endif
+}
+
+void
+BasicCurveEvaluator::bgnline( void )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "bgnline\n" );
+#endif
+}
+
+void
+BasicCurveEvaluator::endline( void )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "endline\n" );
+#endif
+}
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/basiccrveval.h b/mesalib/src/glu/sgi/libnurbs/internals/basiccrveval.h
new file mode 100644
index 000000000..277dc8dc9
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/basiccrveval.h
@@ -0,0 +1,62 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * basiccurveeval.h
+ *
+ */
+
+#ifndef __glubasiccrveval_h_
+#define __glubasiccrveval_h_
+
+#include "types.h"
+#include "displaymode.h"
+#include "cachingeval.h"
+
+class BasicCurveEvaluator : public CachingEvaluator {
+public:
+ virtual ~BasicCurveEvaluator() { /* silence warning*/ }
+ virtual void domain1f( REAL, REAL );
+ virtual void range1f( long, REAL *, REAL * );
+
+ virtual void enable( long );
+ virtual void disable( long );
+ virtual void bgnmap1f( long );
+ virtual void map1f( long, REAL, REAL, long, long, REAL * );
+ virtual void mapgrid1f( long, REAL, REAL );
+ virtual void mapmesh1f( long, long, long );
+ virtual void evalcoord1f( long, REAL );
+ virtual void endmap1f( void );
+
+ virtual void bgnline( void );
+ virtual void endline( void );
+};
+
+#endif /* __glubasiccrveval_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/basicsurfeval.cc b/mesalib/src/glu/sgi/libnurbs/internals/basicsurfeval.cc
new file mode 100644
index 000000000..fad5dd0ad
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/basicsurfeval.cc
@@ -0,0 +1,232 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * basicsurfaceevaluator.c++
+ *
+ */
+
+#include "mystdio.h"
+#include "types.h"
+#include "basicsurfeval.h"
+
+#ifdef __WATCOMC__
+#pragma warning 726 10
+#endif
+
+void
+BasicSurfaceEvaluator::domain2f( REAL, REAL, REAL, REAL )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "domain2f\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::polymode( long )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "polymode\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::range2f( long type, REAL *from, REAL *to )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "range2f type %ld, from (%g,%g), to (%g,%g)\n",
+ type, from[0], from[1], to[0], to[1] );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::enable( long )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "enable\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::disable( long )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "disable\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::bgnmap2f( long )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "bgnmap2f\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::endmap2f( void )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "endmap2f\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::map2f( long, REAL, REAL, long, long,
+ REAL, REAL, long, long,
+ REAL * )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "map2f\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::mapgrid2f( long, REAL, REAL, long, REAL, REAL )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "mapgrid2f\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::mapmesh2f( long, long, long, long, long )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "mapmesh2f\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::evalcoord2f( long, REAL, REAL )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "evalcoord2f\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::evalpoint2i( long, long )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "evalpoint2i\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::bgnline( void )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "bgnline\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::endline( void )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "endline\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::bgnclosedline( void )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "bgnclosedline\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::endclosedline( void )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "endclosedline\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::bgntfan( void )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "bgntfan\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::endtfan( void )
+{
+}
+
+
+void
+BasicSurfaceEvaluator::bgntmesh( void )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "bgntmesh\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::swaptmesh( void )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "swaptmesh\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::endtmesh( void )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "endtmesh\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::bgnqstrip( void )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "bgnqstrip\n" );
+#endif
+}
+
+void
+BasicSurfaceEvaluator::endqstrip( void )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "endqstrip\n" );
+#endif
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/basicsurfeval.h b/mesalib/src/glu/sgi/libnurbs/internals/basicsurfeval.h
new file mode 100644
index 000000000..8fe18a67f
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/basicsurfeval.h
@@ -0,0 +1,90 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * basicsurfeval.h
+ *
+ */
+
+#ifndef __glubasicsurfeval_h_
+#define __glubasicsurfeval_h_
+
+#include "types.h"
+#include "displaymode.h"
+#include "cachingeval.h"
+
+class BasicSurfaceEvaluator : public CachingEvaluator {
+public:
+ virtual ~BasicSurfaceEvaluator() { /* silence warning*/ }
+ virtual void range2f( long, REAL *, REAL * );
+ virtual void domain2f( REAL, REAL, REAL, REAL );
+
+ virtual void enable( long );
+ virtual void disable( long );
+ virtual void bgnmap2f( long );
+ virtual void map2f( long, REAL, REAL, long, long,
+ REAL, REAL, long, long,
+ REAL * );
+ virtual void mapgrid2f( long, REAL, REAL, long, REAL, REAL );
+ virtual void mapmesh2f( long, long, long, long, long );
+ virtual void evalcoord2f( long, REAL, REAL );
+ virtual void evalpoint2i( long, long );
+ virtual void endmap2f( void );
+
+ virtual void polymode( long );
+ virtual void bgnline( void );
+ virtual void endline( void );
+ virtual void bgnclosedline( void );
+ virtual void endclosedline( void );
+ virtual void bgntmesh( void );
+ virtual void swaptmesh( void );
+ virtual void endtmesh( void );
+ virtual void bgnqstrip( void );
+ virtual void endqstrip( void );
+
+ virtual void bgntfan( void );
+ virtual void endtfan( void );
+
+ virtual void evalUStrip(int n_upper, REAL v_upper, REAL* upper_val,
+ int n_lower, REAL v_lower, REAL* lower_val
+ ) = 0;
+
+ virtual void evalVStrip(int n_left, REAL u_left, REAL* left_val,
+ int n_right, REAL u_right, REAL* right_val
+ ) = 0;
+ virtual void inDoEvalCoord2NOGE(REAL u, REAL v, REAL* ret_point, REAL* ret_normal) = 0;
+ virtual void inDoEvalCoord2NOGE_BU(REAL u, REAL v, REAL* ret_point, REAL* ret_normal) = 0;
+ virtual void inDoEvalCoord2NOGE_BV(REAL u, REAL v, REAL* ret_point, REAL* ret_normal) = 0;
+ virtual void inPreEvaluateBV_intfac(REAL v ) = 0;
+ virtual void inPreEvaluateBU_intfac(REAL u ) = 0;
+
+};
+
+#endif /* __glubasicsurfeval_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/bezierarc.h b/mesalib/src/glu/sgi/libnurbs/internals/bezierarc.h
new file mode 100644
index 000000000..4acfb0948
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/bezierarc.h
@@ -0,0 +1,51 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * bezierarc.h
+ *
+ */
+
+#ifndef __glubezierarc_h
+#define __glubezierarc_h
+
+#include "myassert.h"
+
+class Mapdesc;
+
+struct BezierArc : public PooledObj { /* a bezier arc */
+ REAL * cpts; /* control points of arc */
+ int order; /* order of arc */
+ int stride; /* REAL distance between points */
+ long type; /* curve type */
+ Mapdesc * mapdesc;
+};
+
+#endif /* __glubezierarc_h */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/bin.cc b/mesalib/src/glu/sgi/libnurbs/internals/bin.cc
new file mode 100644
index 000000000..54b406147
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/bin.cc
@@ -0,0 +1,166 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * bin.c++
+ *
+ */
+
+#include "glimports.h"
+#include "mystdio.h"
+#include "myassert.h"
+#include "bin.h"
+
+/*----------------------------------------------------------------------------
+ * Constructor and destructor
+ *----------------------------------------------------------------------------
+ */
+Bin::Bin()
+{
+ head = NULL;
+}
+
+Bin::~Bin()
+{
+ assert( head == NULL);
+}
+
+/*----------------------------------------------------------------------------
+ * remove_this_arc - remove given Arc_ptr from bin
+ *----------------------------------------------------------------------------
+ */
+
+void
+Bin::remove_this_arc( Arc_ptr arc )
+{
+ Arc_ptr *j;
+ for( j = &(head); (*j != 0) && (*j != arc); j = &((*j)->link) );
+
+ if( *j != 0 ) {
+ if( *j == current )
+ current = (*j)->link;
+ *j = (*j)->link;
+ }
+}
+
+/*----------------------------------------------------------------------------
+ * numarcs - count number of arcs in bin
+ *----------------------------------------------------------------------------
+ */
+
+int
+Bin::numarcs()
+{
+ long count = 0;
+ for( Arc_ptr jarc = firstarc(); jarc; jarc = nextarc() )
+ count++;
+ return count;
+}
+
+/*----------------------------------------------------------------------------
+ * adopt - place an orphaned arcs into their new parents bin
+ *----------------------------------------------------------------------------
+ */
+
+void
+Bin::adopt()
+{
+ markall();
+
+ Arc_ptr orphan;
+ while( (orphan = removearc()) != NULL ) {
+ for( Arc_ptr parent = orphan->next; parent != orphan; parent = parent->next ) {
+ if (! parent->ismarked() ) {
+ orphan->link = parent->link;
+ parent->link = orphan;
+ orphan->clearmark();
+ break;
+ }
+ }
+ }
+}
+
+
+/*----------------------------------------------------------------------------
+ * show - print out descriptions of the arcs in the bin
+ *----------------------------------------------------------------------------
+ */
+
+void
+Bin::show( char *name )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "%s\n", name );
+ for( Arc_ptr jarc = firstarc(); jarc; jarc = nextarc() )
+ jarc->show( );
+#endif
+}
+
+
+
+/*----------------------------------------------------------------------------
+ * markall - mark all arcs with an identifying tag
+ *----------------------------------------------------------------------------
+ */
+
+void
+Bin::markall()
+{
+ for( Arc_ptr jarc=firstarc(); jarc; jarc=nextarc() )
+ jarc->setmark();
+}
+
+/*----------------------------------------------------------------------------
+ * listBezier - print out all arcs that are untessellated border arcs
+ *----------------------------------------------------------------------------
+ */
+
+void
+Bin::listBezier( void )
+{
+ for( Arc_ptr jarc=firstarc(); jarc; jarc=nextarc() ) {
+ if( jarc->isbezier( ) ) {
+ assert( jarc->pwlArc->npts == 2 );
+#ifndef NDEBUG
+ TrimVertex *pts = jarc->pwlArc->pts;
+ REAL s1 = pts[0].param[0];
+ REAL t1 = pts[0].param[1];
+ REAL s2 = pts[1].param[0];
+ REAL t2 = pts[1].param[1];
+ _glu_dprintf( "arc (%g,%g) (%g,%g)\n", s1, t1, s2, t2 );
+#endif
+ }
+ }
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/bin.h b/mesalib/src/glu/sgi/libnurbs/internals/bin.h
new file mode 100644
index 000000000..2f976eb9b
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/bin.h
@@ -0,0 +1,121 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * bin.h
+ *
+ */
+
+#ifndef __glubin_h_
+#define __glubin_h_
+
+#include "myassert.h"
+#include "arc.h"
+#include "defines.h"
+
+class Bin
+{ /* a linked list of jordan arcs */
+private:
+ Arc_ptr head;/*first arc on list */
+ Arc_ptr current; /* current arc on list */
+public:
+ Bin();
+ ~Bin();
+ inline Arc_ptr firstarc( void );
+ inline Arc_ptr nextarc( void );
+ inline Arc_ptr removearc( void );
+ inline int isnonempty( void ) { return (head ? 1 : 0); }
+ inline void addarc( Arc_ptr );
+ void remove_this_arc( Arc_ptr );
+ int numarcs( void );
+ void adopt( void );
+ void markall( void );
+ void show( char * );
+ void listBezier( void );
+};
+
+/*----------------------------------------------------------------------------
+ * Bin::addarc - add an Arc_ptr to head of linked list of Arc_ptr
+ *----------------------------------------------------------------------------
+ */
+
+inline void
+Bin::addarc( Arc_ptr jarc )
+{
+ jarc->link = head;
+ head = jarc;
+}
+
+/*----------------------------------------------------------------------------
+ * Bin::removearc - remove first Arc_ptr from bin
+ *----------------------------------------------------------------------------
+ */
+
+inline Arc_ptr
+Bin::removearc( void )
+{
+ Arc_ptr jarc = head;
+
+ if( jarc ) head = jarc->link;
+ return jarc;
+}
+
+
+/*----------------------------------------------------------------------------
+ * BinIter::nextarc - return current arc in bin and advance pointer to next arc
+ *----------------------------------------------------------------------------
+ */
+
+inline Arc_ptr
+Bin::nextarc( void )
+{
+ Arc_ptr jarc = current;
+
+#ifdef DEBUG
+ assert( jarc->check() != 0 );
+#endif
+
+ if( jarc ) current = jarc->link;
+ return jarc;
+}
+
+/*----------------------------------------------------------------------------
+ * BinIter::firstarc - set current arc to first arc of bin advance to next arc
+ *----------------------------------------------------------------------------
+ */
+
+inline Arc_ptr
+Bin::firstarc( void )
+{
+ current = head;
+ return nextarc( );
+}
+
+#endif /* __glubin_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/bufpool.cc b/mesalib/src/glu/sgi/libnurbs/internals/bufpool.cc
new file mode 100644
index 000000000..8cc847ab2
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/bufpool.cc
@@ -0,0 +1,110 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * bufpool.c++
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "bufpool.h"
+
+
+/*-----------------------------------------------------------------------------
+ * Pool - allocate a new pool of buffers
+ *-----------------------------------------------------------------------------
+ */
+Pool::Pool( int _buffersize, int initpoolsize, const char *n )
+{
+ if((unsigned)_buffersize < sizeof(Buffer))
+ buffersize = sizeof(Buffer);
+ else
+ buffersize = _buffersize;
+ initsize = initpoolsize * buffersize;
+ nextsize = initsize;
+ name = n;
+ magic = is_allocated;
+ nextblock = 0;
+ curblock = 0;
+ freelist = 0;
+ nextfree = 0;
+}
+
+/*-----------------------------------------------------------------------------
+ * ~Pool - free a pool of buffers and the pool itself
+ *-----------------------------------------------------------------------------
+ */
+
+Pool::~Pool( void )
+{
+ assert( (this != 0) && (magic == is_allocated) );
+
+ while( nextblock ) {
+ delete [] blocklist[--nextblock];
+ blocklist[nextblock] = 0;
+ }
+ magic = is_free;
+}
+
+
+void Pool::grow( void )
+{
+ assert( (this != 0) && (magic == is_allocated) );
+ curblock = new char[nextsize];
+ blocklist[nextblock++] = curblock;
+ nextfree = nextsize;
+ nextsize *= 2;
+}
+
+/*-----------------------------------------------------------------------------
+ * Pool::clear - free buffers associated with pool but keep pool
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Pool::clear( void )
+{
+ assert( (this != 0) && (magic == is_allocated) );
+
+ while( nextblock ) {
+ delete [] blocklist[--nextblock];
+ blocklist[nextblock] = 0;
+ }
+ curblock = 0;
+ freelist = 0;
+ nextfree = 0;
+ if( nextsize > initsize )
+ nextsize /= 2;
+}
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/bufpool.h b/mesalib/src/glu/sgi/libnurbs/internals/bufpool.h
new file mode 100644
index 000000000..0fa943375
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/bufpool.h
@@ -0,0 +1,141 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * bufpool.h
+ *
+ */
+
+#ifndef __glubufpool_h_
+#define __glubufpool_h_
+
+#include "gluos.h"
+#include "myassert.h"
+#include "mystdlib.h"
+
+#define NBLOCKS 32
+
+class Buffer {
+ friend class Pool;
+ Buffer * next; /* next buffer on free list */
+};
+
+class Pool {
+public:
+ Pool( int, int, const char * );
+ ~Pool( void );
+ inline void* new_buffer( void );
+ inline void free_buffer( void * );
+ void clear( void );
+
+private:
+ void grow( void );
+
+protected:
+ Buffer *freelist; /* linked list of free buffers */
+ char *blocklist[NBLOCKS]; /* blocks of malloced memory */
+ int nextblock; /* next free block index */
+ char *curblock; /* last malloced block */
+ int buffersize; /* bytes per buffer */
+ int nextsize; /* size of next block of memory */
+ int nextfree; /* byte offset past next free buffer */
+ int initsize;
+ enum Magic { is_allocated = 0xf3a1, is_free = 0xf1a2 };
+ const char *name; /* name of the pool */
+ Magic magic; /* marker for valid pool */
+};
+
+/*-----------------------------------------------------------------------------
+ * Pool::free_buffer - return a buffer to a pool
+ *-----------------------------------------------------------------------------
+ */
+
+inline void
+Pool::free_buffer( void *b )
+{
+ assert( (this != 0) && (magic == is_allocated) );
+
+ /* add buffer to singly connected free list */
+
+ ((Buffer *) b)->next = freelist;
+ freelist = (Buffer *) b;
+}
+
+
+/*-----------------------------------------------------------------------------
+ * Pool::new_buffer - allocate a buffer from a pool
+ *-----------------------------------------------------------------------------
+ */
+
+inline void *
+Pool::new_buffer( void )
+{
+ void *buffer;
+
+ assert( (this != 0) && (magic == is_allocated) );
+
+ /* find free buffer */
+
+ if( freelist ) {
+ buffer = (void *) freelist;
+ freelist = freelist->next;
+ } else {
+ if( ! nextfree )
+ grow( );
+ nextfree -= buffersize;;
+ buffer = (void *) (curblock + nextfree);
+ }
+ return buffer;
+}
+
+class PooledObj {
+public:
+ inline void * operator new( size_t, Pool & );
+ inline void * operator new( size_t, void *);
+ inline void * operator new( size_t s)
+ { return ::new char[s]; }
+ inline void operator delete( void * ) { assert( 0 ); }
+ inline void operator delete( void *, Pool & ) { assert( 0 ); }
+ inline void deleteMe( Pool & );
+};
+
+inline void *
+PooledObj::operator new( size_t, Pool& pool )
+{
+ return pool.new_buffer();
+}
+
+inline void
+PooledObj::deleteMe( Pool& pool )
+{
+ pool.free_buffer( (void *) this );
+}
+
+#endif /* __glubufpool_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/cachingeval.cc b/mesalib/src/glu/sgi/libnurbs/internals/cachingeval.cc
new file mode 100644
index 000000000..3fab38c10
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/cachingeval.cc
@@ -0,0 +1,78 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * cachingeval.c++
+ *
+ */
+
+#include "cachingeval.h"
+
+int
+CachingEvaluator::canRecord( void )
+{
+ return 0;
+}
+
+int
+CachingEvaluator::canPlayAndRecord( void )
+{
+ return 0;
+}
+
+int
+CachingEvaluator::createHandle( int )
+{
+ return 0;
+}
+
+void
+CachingEvaluator::beginOutput( ServiceMode, int )
+{
+}
+
+void
+CachingEvaluator::endOutput( void )
+{
+}
+
+void
+CachingEvaluator::discardRecording( int )
+{
+}
+
+void
+CachingEvaluator::playRecording( int )
+{
+}
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/cachingeval.h b/mesalib/src/glu/sgi/libnurbs/internals/cachingeval.h
new file mode 100644
index 000000000..b390067a2
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/cachingeval.h
@@ -0,0 +1,51 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * cachingeval.h
+ *
+ */
+
+#ifndef __glucachingval_h_
+#define __glucachingval_h_
+
+class CachingEvaluator {
+public:
+ virtual ~CachingEvaluator() { /* silence warning*/ }
+ enum ServiceMode { play, record, playAndRecord };
+ virtual int canRecord( void );
+ virtual int canPlayAndRecord( void );
+ virtual int createHandle( int handle );
+ virtual void beginOutput( ServiceMode, int handle );
+ virtual void endOutput( void );
+ virtual void discardRecording( int handle );
+ virtual void playRecording( int handle );
+};
+#endif /* __glucachingval_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/ccw.cc b/mesalib/src/glu/sgi/libnurbs/internals/ccw.cc
new file mode 100644
index 000000000..eb01b7781
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/ccw.cc
@@ -0,0 +1,565 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * ccw.c++
+ *
+ */
+
+#include "glimports.h"
+#include "mystdio.h"
+#include "myassert.h"
+#include "subdivider.h"
+#include "types.h"
+#include "arc.h"
+#include "trimvertex.h"
+#include "simplemath.h"
+
+inline int
+Subdivider::bbox( TrimVertex *a, TrimVertex *b, TrimVertex *c, int p )
+{
+ return bbox( a->param[p], b->param[p], c->param[p],
+ a->param[1-p], b->param[1-p], c->param[1-p] );
+}
+
+int
+Subdivider::ccwTurn_sr( Arc_ptr j1, Arc_ptr j2 ) // dir = 1
+{
+ register TrimVertex *v1 = &j1->pwlArc->pts[j1->pwlArc->npts-1];
+ register TrimVertex *v1last = &j1->pwlArc->pts[0];
+ register TrimVertex *v2 = &j2->pwlArc->pts[0];
+ register TrimVertex *v2last = &j2->pwlArc->pts[j2->pwlArc->npts-1];
+ register TrimVertex *v1next = v1-1;
+ register TrimVertex *v2next = v2+1;
+ int sgn;
+
+ assert( v1 != v1last );
+ assert( v2 != v2last );
+
+#ifndef NDEBUG
+ _glu_dprintf( "arc_ccw_turn, p = %d\n", 0 );
+#endif
+
+ // the arcs lie on the line (0 == v1->param[0])
+ if( v1->param[0] == v1next->param[0] && v2->param[0] == v2next->param[0] )
+ return 0;
+
+ if( v2next->param[0] < v2->param[0] || v1next->param[0] < v1->param[0] )
+ ::mylongjmp( jumpbuffer, 28 );
+
+ if( v1->param[1] < v2->param[1] )
+ return 0;
+ else if( v1->param[1] > v2->param[1] )
+ return 1;
+
+ while( 1 ) {
+ if( v1next->param[0] < v2next->param[0] ) {
+#ifndef NDEBUG
+ _glu_dprintf( "case a\n" );
+#endif
+ assert( v1->param[0] <= v1next->param[0] );
+ assert( v2->param[0] <= v1next->param[0] );
+ switch( bbox( v2, v2next, v1next, 1 ) ) {
+ case -1:
+ return 0;
+ case 0:
+ sgn = ccw( v1next, v2, v2next );
+ if( sgn != -1 ) {
+ return sgn;
+ } else {
+#ifdef DEBUG
+ _glu_dprintf( "decr\n" );
+#endif
+ v1 = v1next--;
+ if( v1 == v1last ) {
+#ifdef DEBUG
+ _glu_dprintf( "no good results\n" );
+#endif
+ return 0; // ill-conditioned, guess answer
+ }
+ }
+ break;
+ case 1:
+ return 1;
+ }
+ } else if( v1next->param[0] > v2next->param[0] ) {
+#ifndef NDEBUG
+ _glu_dprintf( "case b\n" );
+#endif
+ assert( v1->param[0] <= v2next->param[0] );
+ assert( v2->param[0] <= v2next->param[0] );
+ switch( bbox( v1, v1next, v2next, 1 ) ) {
+ case -1:
+ return 1;
+ case 0:
+ sgn = ccw( v1next, v1, v2next );
+ if( sgn != -1 ) {
+ return sgn;
+ } else {
+#ifdef DEBUG
+ _glu_dprintf( "incr\n" );
+#endif
+ v2 = v2next++;
+ if( v2 == v2last ) {
+#ifdef DEBUG
+ _glu_dprintf( "no good results\n" );
+#endif
+ return 0; // ill-conditioned, guess answer
+ }
+ }
+ break;
+ case 1:
+ return 0;
+ }
+ } else {
+#ifndef NDEBUG
+ _glu_dprintf( "case ab\n" );
+#endif
+ if( v1next->param[1] < v2next->param[1] )
+ return 0;
+ else if( v1next->param[1] > v2next->param[1] )
+ return 1;
+ else {
+#ifdef DEBUG
+ _glu_dprintf( "incr\n" );
+#endif
+ v2 = v2next++;
+ if( v2 == v2last ) {
+#ifdef DEBUG
+ _glu_dprintf( "no good results\n" );
+#endif
+ return 0; // ill-conditioned, guess answer
+ }
+ }
+ }
+ }
+}
+
+int
+Subdivider::ccwTurn_sl( Arc_ptr j1, Arc_ptr j2 ) // dir = 0
+{
+ register TrimVertex *v1 = &j1->pwlArc->pts[j1->pwlArc->npts-1];
+ register TrimVertex *v1last = &j1->pwlArc->pts[0];
+ register TrimVertex *v2 = &j2->pwlArc->pts[0];
+ register TrimVertex *v2last = &j2->pwlArc->pts[j2->pwlArc->npts-1];
+ register TrimVertex *v1next = v1-1;
+ register TrimVertex *v2next = v2+1;
+ int sgn;
+
+ assert( v1 != v1last );
+ assert( v2 != v2last );
+
+#ifndef NDEBUG
+ _glu_dprintf( "arc_ccw_turn, p = %d\n", 0 );
+#endif
+
+ // the arcs lie on the line (0 == v1->param[0])
+ if( v1->param[0] == v1next->param[0] && v2->param[0] == v2next->param[0] )
+ return 0;
+
+ if( v2next->param[0] > v2->param[0] || v1next->param[0] > v1->param[0] )
+ ::mylongjmp( jumpbuffer, 28 );
+
+ if( v1->param[1] < v2->param[1] )
+ return 1;
+ else if( v1->param[1] > v2->param[1] )
+ return 0;
+
+ while( 1 ) {
+ if( v1next->param[0] > v2next->param[0] ) {
+#ifndef NDEBUG
+ _glu_dprintf( "case c\n" );
+#endif
+ assert( v1->param[0] >= v1next->param[0] );
+ assert( v2->param[0] >= v1next->param[0] );
+ switch( bbox( v2next, v2, v1next, 1 ) ) {
+ case -1:
+ return 1;
+ case 0:
+ sgn = ccw( v1next, v2, v2next );
+ if( sgn != -1 )
+ return sgn;
+ else {
+ v1 = v1next--;
+#ifdef DEBUG
+ _glu_dprintf( "decr\n" );
+#endif
+ if( v1 == v1last ) {
+#ifdef DEBUG
+ _glu_dprintf( "no good results\n" );
+#endif
+ return 0; // ill-conditioned, guess answer
+ }
+ }
+ break;
+ case 1:
+ return 0;
+ }
+ } else if( v1next->param[0] < v2next->param[0] ) {
+#ifndef NDEBUG
+ _glu_dprintf( "case d\n" );
+#endif
+ assert( v1->param[0] >= v2next->param[0] );
+ assert( v2->param[0] >= v2next->param[0] );
+ switch( bbox( v1next, v1, v2next, 1 ) ) {
+ case -1:
+ return 0;
+ case 0:
+ sgn = ccw( v1next, v1, v2next );
+ if( sgn != -1 )
+ return sgn;
+ else {
+ v2 = v2next++;
+#ifdef DEBUG
+ _glu_dprintf( "incr\n" );
+#endif
+ if( v2 == v2last ) {
+#ifdef DEBUG
+ _glu_dprintf( "no good results\n" );
+#endif
+ return 0; // ill-conditioned, guess answer
+ }
+ }
+ break;
+ case 1:
+ return 1;
+ }
+ } else {
+#ifdef DEBUG
+ _glu_dprintf( "case cd\n" );
+#endif
+ if( v1next->param[1] < v2next->param[1] )
+ return 1;
+ else if( v1next->param[1] > v2next->param[1] )
+ return 0;
+ else {
+ v2 = v2next++;
+#ifdef DEBUG
+ _glu_dprintf( "incr\n" );
+#endif
+ if( v2 == v2last ) {
+#ifdef DEBUG
+ _glu_dprintf( "no good results\n" );
+#endif
+ return 0; // ill-conditioned, guess answer
+ }
+ }
+ }
+ }
+}
+
+int
+Subdivider::ccwTurn_tr( Arc_ptr j1, Arc_ptr j2 ) // dir = 1
+{
+ register TrimVertex *v1 = &j1->pwlArc->pts[j1->pwlArc->npts-1];
+ register TrimVertex *v1last = &j1->pwlArc->pts[0];
+ register TrimVertex *v2 = &j2->pwlArc->pts[0];
+ register TrimVertex *v2last = &j2->pwlArc->pts[j2->pwlArc->npts-1];
+ register TrimVertex *v1next = v1-1;
+ register TrimVertex *v2next = v2+1;
+ int sgn;
+
+ assert( v1 != v1last );
+ assert( v2 != v2last );
+
+#ifndef NDEBUG
+ _glu_dprintf( "arc_ccw_turn, p = %d\n", 1 );
+#endif
+
+ // the arcs lie on the line (1 == v1->param[1])
+ if( v1->param[1] == v1next->param[1] && v2->param[1] == v2next->param[1] )
+ return 0;
+
+ if( v2next->param[1] < v2->param[1] || v1next->param[1] < v1->param[1] )
+ ::mylongjmp( jumpbuffer, 28 );
+
+ if( v1->param[0] < v2->param[0] )
+ return 1;
+ else if( v1->param[0] > v2->param[0] )
+ return 0;
+
+ while( 1 ) {
+ if( v1next->param[1] < v2next->param[1] ) {
+#ifndef NDEBUG
+ _glu_dprintf( "case a\n" );
+#endif
+ assert( v1->param[1] <= v1next->param[1] );
+ assert( v2->param[1] <= v1next->param[1] );
+ switch( bbox( v2, v2next, v1next, 0 ) ) {
+ case -1:
+ return 1;
+ case 0:
+ sgn = ccw( v1next, v2, v2next );
+ if( sgn != -1 ) {
+ return sgn;
+ } else {
+#ifdef DEBUG
+ _glu_dprintf( "decr\n" );
+#endif
+ v1 = v1next--;
+ if( v1 == v1last ) {
+#ifdef DEBUG
+ _glu_dprintf( "no good results\n" );
+#endif
+ return 0; // ill-conditioned, guess answer
+ }
+ }
+ break;
+ case 1:
+ return 0;
+ }
+ } else if( v1next->param[1] > v2next->param[1] ) {
+#ifndef NDEBUG
+ _glu_dprintf( "case b\n" );
+#endif
+ assert( v1->param[1] <= v2next->param[1] );
+ assert( v2->param[1] <= v2next->param[1] );
+ switch( bbox( v1, v1next, v2next, 0 ) ) {
+ case -1:
+ return 0;
+ case 0:
+ sgn = ccw( v1next, v1, v2next );
+ if( sgn != -1 ) {
+ return sgn;
+ } else {
+#ifdef DEBUG
+ _glu_dprintf( "incr\n" );
+#endif
+ v2 = v2next++;
+ if( v2 == v2last ) {
+#ifdef DEBUG
+ _glu_dprintf( "no good results\n" );
+#endif
+ return 0; // ill-conditioned, guess answer
+ }
+ }
+ break;
+ case 1:
+ return 1;
+ }
+ } else {
+#ifdef DEBUG
+ _glu_dprintf( "case ab\n" );
+#endif
+ if( v1next->param[0] < v2next->param[0] )
+ return 1;
+ else if( v1next->param[0] > v2next->param[0] )
+ return 0;
+ else {
+#ifdef DEBUG
+ _glu_dprintf( "incr\n" );
+#endif
+ v2 = v2next++;
+ if( v2 == v2last ) {
+#ifdef DEBUG
+ _glu_dprintf( "no good results\n" );
+#endif
+ return 0; // ill-conditioned, guess answer
+ }
+ }
+ }
+ }
+}
+
+int
+Subdivider::ccwTurn_tl( Arc_ptr j1, Arc_ptr j2 )
+{
+ register TrimVertex *v1 = &j1->pwlArc->pts[j1->pwlArc->npts-1];
+ register TrimVertex *v1last = &j1->pwlArc->pts[0];
+ register TrimVertex *v2 = &j2->pwlArc->pts[0];
+ register TrimVertex *v2last = &j2->pwlArc->pts[j2->pwlArc->npts-1];
+ register TrimVertex *v1next = v1-1;
+ register TrimVertex *v2next = v2+1;
+ int sgn;
+
+ assert( v1 != v1last );
+ assert( v2 != v2last );
+
+#ifndef NDEBUG
+ _glu_dprintf( "arc_ccw_turn, p = %d\n", 1 );
+#endif
+
+ // the arcs lie on the line (1 == v1->param[1])
+ if( v1->param[1] == v1next->param[1] && v2->param[1] == v2next->param[1] )
+ return 0;
+
+ if( v2next->param[1] > v2->param[1] || v1next->param[1] > v1->param[1] )
+ ::mylongjmp( jumpbuffer, 28 );
+
+ if( v1->param[0] < v2->param[0] )
+ return 0;
+ else if( v1->param[0] > v2->param[0] )
+ return 1;
+
+ while( 1 ) {
+ if( v1next->param[1] > v2next->param[1] ) {
+#ifndef NDEBUG
+ _glu_dprintf( "case c\n" );
+#endif
+ assert( v1->param[1] >= v1next->param[1] );
+ assert( v2->param[1] >= v1next->param[1] );
+ switch( bbox( v2next, v2, v1next, 0 ) ) {
+ case -1:
+ return 0;
+ case 0:
+ sgn = ccw( v1next, v2, v2next );
+ if( sgn != -1 )
+ return sgn;
+ else {
+ v1 = v1next--;
+#ifdef DEBUG
+ _glu_dprintf( "decr\n" );
+#endif
+ if( v1 == v1last ) {
+#ifdef DEBUG
+ _glu_dprintf( "no good results\n" );
+#endif
+ return 0; // ill-conditioned, guess answer
+ }
+ }
+ break;
+ case 1:
+ return 1;
+ }
+ } else if( v1next->param[1] < v2next->param[1] ) {
+#ifndef NDEBUG
+ _glu_dprintf( "case d\n" );
+ assert( v1->param[1] >= v2next->param[1] );
+ assert( v2->param[1] >= v2next->param[1] );
+#endif
+ switch( bbox( v1next, v1, v2next, 0 ) ) {
+ case -1:
+ return 1;
+ case 0:
+ sgn = ccw( v1next, v1, v2next );
+ if( sgn != -1 )
+ return sgn;
+ else {
+ v2 = v2next++;
+#ifdef DEBUG
+ _glu_dprintf( "incr\n" );
+#endif
+ if( v2 == v2last ) {
+#ifdef DEBUG
+ _glu_dprintf( "no good results\n" );
+#endif
+ return 0; // ill-conditioned, guess answer
+ }
+ }
+ break;
+ case 1:
+ return 0;
+ }
+ } else {
+#ifdef DEBUG
+ _glu_dprintf( "case cd\n" );
+#endif
+ if( v1next->param[0] < v2next->param[0] )
+ return 0;
+ else if( v1next->param[0] > v2next->param[0] )
+ return 1;
+ else {
+ v2 = v2next++;
+#ifdef DEBUG
+ _glu_dprintf( "incr\n" );
+#endif
+ if( v2 == v2last ) {
+#ifdef DEBUG
+ _glu_dprintf( "no good results\n" );
+#endif
+ return 0; // ill-conditioned, guess answer
+ }
+ }
+ }
+ }
+}
+
+
+#ifndef NDEBUG
+int
+Subdivider::bbox( register REAL sa, register REAL sb, register REAL sc,
+ register REAL ta, register REAL tb, register REAL tc )
+#else
+int
+Subdivider::bbox( register REAL sa, register REAL sb, register REAL sc,
+ register REAL , register REAL , register REAL )
+#endif
+{
+#ifndef NDEBUG
+ assert( tc >= ta );
+ assert( tc <= tb );
+#endif
+
+ if( sa < sb ) {
+ if( sc <= sa ) {
+ return -1;
+ } else if( sb <= sc ) {
+ return 1;
+ } else {
+ return 0;
+ }
+ } else if( sa > sb ) {
+ if( sc >= sa ) {
+ return 1;
+ } else if( sb >= sc ) {
+ return -1;
+ } else {
+ return 0;
+ }
+ } else {
+ if( sc > sa ) {
+ return 1;
+ } else if( sb > sc ) {
+ return -1;
+ } else {
+ return 0;
+ }
+ }
+}
+
+/*----------------------------------------------------------------------------
+ * ccw - determine how three points are oriented by computing their
+ * determinant.
+ * Return 1 if the vertices are ccw oriented,
+ * 0 if they are cw oriented, or
+ * -1 if the computation is ill-conditioned.
+ *----------------------------------------------------------------------------
+ */
+int
+Subdivider::ccw( TrimVertex *a, TrimVertex *b, TrimVertex *c )
+{
+ REAL d = det3( a, b, c );
+ if( glu_abs(d) < 0.0001 ) return -1;
+ return (d < 0.0) ? 0 : 1;
+}
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/coveandtiler.cc b/mesalib/src/glu/sgi/libnurbs/internals/coveandtiler.cc
new file mode 100644
index 000000000..ca5bf36b3
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/coveandtiler.cc
@@ -0,0 +1,440 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * coveandtiler.c++
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "mystdio.h"
+#include "coveandtiler.h"
+#include "gridvertex.h"
+#include "gridtrimvertex.h"
+#include "uarray.h"
+#include "backend.h"
+
+
+const int CoveAndTiler::MAXSTRIPSIZE = 1000;
+
+CoveAndTiler::CoveAndTiler( Backend& b )
+ : backend( b )
+{ }
+
+CoveAndTiler::~CoveAndTiler( void )
+{ }
+
+inline void
+CoveAndTiler::output( GridVertex &gv )
+{
+ backend.tmeshvert( &gv );
+}
+
+inline void
+CoveAndTiler::output( TrimVertex *tv )
+{
+ backend.tmeshvert( tv );
+}
+
+inline void
+CoveAndTiler::output( GridTrimVertex& g )
+{
+ backend.tmeshvert( &g );
+}
+
+void
+CoveAndTiler::coveAndTile( void )
+{
+ long ustart = (top.ustart >= bot.ustart) ? top.ustart : bot.ustart;
+ long uend = (top.uend <= bot.uend) ? top.uend : bot.uend;
+ if( ustart <= uend ) {
+ tile( bot.vindex, ustart, uend );
+ if( top.ustart >= bot.ustart )
+ coveUpperLeft();
+ else
+ coveLowerLeft();
+
+ if( top.uend <= bot.uend )
+ coveUpperRight();
+ else
+ coveLowerRight();
+ } else {
+ TrimVertex blv, tlv, *bl, *tl;
+ GridTrimVertex bllv, tllv;
+ TrimVertex *lf = left.first();
+ TrimVertex *ll = left.last();
+ if( lf->param[0] >= ll->param[0] ) {
+ blv.param[0] = lf->param[0];
+ blv.param[1] = ll->param[1];
+ blv.nuid = 0; // XXX
+ assert( blv.param[1] == bot.vval );
+ bl = &blv;
+ tl = lf;
+ tllv.set( lf );
+ if( ll->param[0] > uarray.uarray[top.ustart-1] ) {
+ bllv.set( ll );
+ assert( ll->param[0] <= uarray.uarray[bot.ustart] );
+ } else {
+ bllv.set( top.ustart-1, bot.vindex );
+ }
+ coveUpperLeftNoGrid( bl );
+ } else {
+ tlv.param[0] = ll->param[0];
+ tlv.param[1] = lf->param[1];
+ tlv.nuid = 0; // XXX
+ assert( tlv.param[1] == top.vval );
+ tl = &tlv;
+ bl = ll;
+ bllv.set( ll );
+ if( lf->param[0] > uarray.uarray[bot.ustart-1] ) {
+ assert( lf->param[0] <= uarray.uarray[bot.ustart] );
+ tllv.set( lf );
+ } else {
+ tllv.set( bot.ustart-1, top.vindex );
+ }
+ coveLowerLeftNoGrid( tl );
+ }
+
+ TrimVertex brv, trv, *br, *tr;
+ GridTrimVertex brrv, trrv;
+ TrimVertex *rf = right.first();
+ TrimVertex *rl = right.last();
+
+ if( rf->param[0] <= rl->param[0] ) {
+ brv.param[0] = rf->param[0];
+ brv.param[1] = rl->param[1];
+ brv.nuid = 0; // XXX
+ assert( brv.param[1] == bot.vval );
+ br = &brv;
+ tr = rf;
+ trrv.set( rf );
+ if( rl->param[0] < uarray.uarray[top.uend+1] ) {
+ assert( rl->param[0] >= uarray.uarray[top.uend] );
+ brrv.set( rl );
+ } else {
+ brrv.set( top.uend+1, bot.vindex );
+ }
+ coveUpperRightNoGrid( br );
+ } else {
+ trv.param[0] = rl->param[0];
+ trv.param[1] = rf->param[1];
+ trv.nuid = 0; // XXX
+ assert( trv.param[1] == top.vval );
+ tr = &trv;
+ br = rl;
+ brrv.set( rl );
+ if( rf->param[0] < uarray.uarray[bot.uend+1] ) {
+ assert( rf->param[0] >= uarray.uarray[bot.uend] );
+ trrv.set( rf );
+ } else {
+ trrv.set( bot.uend+1, top.vindex );
+ }
+ coveLowerRightNoGrid( tr );
+ }
+
+ backend.bgntmesh( "doit" );
+ output(trrv);
+ output(tllv);
+ output( tr );
+ output( tl );
+ output( br );
+ output( bl );
+ output(brrv);
+ output(bllv);
+ backend.endtmesh();
+ }
+}
+
+void
+CoveAndTiler::tile( long vindex, long ustart, long uend )
+{
+ long numsteps = uend - ustart;
+
+ if( numsteps == 0 ) return;
+
+ if( numsteps > MAXSTRIPSIZE ) {
+ long umid = ustart + (uend - ustart) / 2;
+ tile( vindex, ustart, umid );
+ tile( vindex, umid, uend );
+ } else {
+ backend.surfmesh( ustart, vindex-1, numsteps, 1 );
+ }
+}
+
+void
+CoveAndTiler::coveUpperRight( void )
+{
+ GridVertex tgv( top.uend, top.vindex );
+ GridVertex gv( top.uend, bot.vindex );
+
+ right.first();
+ backend.bgntmesh( "coveUpperRight" );
+ output( right.next() );
+ output( tgv );
+ backend.swaptmesh();
+ output( gv );
+ coveUR();
+ backend.endtmesh();
+}
+
+void
+CoveAndTiler::coveUpperRightNoGrid( TrimVertex* br )
+{
+ backend.bgntmesh( "coveUpperRight" );
+ output( right.first() );
+ output( right.next() );
+ backend.swaptmesh();
+ output( br );
+ coveUR();
+ backend.endtmesh();
+}
+
+void
+CoveAndTiler::coveUR( )
+{
+ GridVertex gv( top.uend, bot.vindex );
+ TrimVertex *vert = right.next();
+ if( vert == NULL ) return;
+
+ assert( vert->param[0] >= uarray.uarray[gv.gparam[0]] );
+
+ if( gv.nextu() >= bot.uend ) {
+ for( ; vert; vert = right.next() ) {
+ output( vert );
+ backend.swaptmesh();
+ }
+ } else while( 1 ) {
+ if( vert->param[0] < uarray.uarray[gv.gparam[0]] ) {
+ output( vert );
+ backend.swaptmesh();
+ vert = right.next();
+ if( vert == NULL ) break;
+ } else {
+ backend.swaptmesh();
+ output( gv );
+ if( gv.nextu() == bot.uend ) {
+ for( ; vert; vert = right.next() ) {
+ output( vert );
+ backend.swaptmesh();
+ }
+ break;
+ }
+ }
+ }
+}
+
+void
+CoveAndTiler::coveUpperLeft( void )
+{
+ GridVertex tgv( top.ustart, top.vindex );
+ GridVertex gv( top.ustart, bot.vindex );
+
+ left.first();
+ backend.bgntmesh( "coveUpperLeft" );
+ output( tgv );
+ output( left.next() );
+ output( gv );
+ backend.swaptmesh();
+ coveUL();
+ backend.endtmesh();
+}
+
+void
+CoveAndTiler::coveUpperLeftNoGrid( TrimVertex* bl )
+{
+ backend.bgntmesh( "coveUpperLeftNoGrid" );
+ output( left.first() );
+ output( left.next() );
+ output( bl );
+ backend.swaptmesh();
+ coveUL();
+ backend.endtmesh();
+}
+
+void
+CoveAndTiler::coveUL()
+{
+ GridVertex gv( top.ustart, bot.vindex );
+ TrimVertex *vert = left.next();
+ if( vert == NULL ) return;
+ assert( vert->param[0] <= uarray.uarray[gv.gparam[0]] );
+
+ if( gv.prevu() <= bot.ustart ) {
+ for( ; vert; vert = left.next() ) {
+ backend.swaptmesh();
+ output( vert );
+ }
+ } else while( 1 ) {
+ if( vert->param[0] > uarray.uarray[gv.gparam[0]] ) {
+ backend.swaptmesh();
+ output( vert );
+ vert = left.next();
+ if( vert == NULL ) break;
+ } else {
+ output( gv );
+ backend.swaptmesh();
+ if( gv.prevu() == bot.ustart ) {
+ for( ; vert; vert = left.next() ) {
+ backend.swaptmesh();
+ output( vert );
+ }
+ break;
+ }
+ }
+ }
+}
+
+void
+CoveAndTiler::coveLowerLeft( void )
+{
+ GridVertex bgv( bot.ustart, bot.vindex );
+ GridVertex gv( bot.ustart, top.vindex );
+
+ left.last();
+ backend.bgntmesh( "coveLowerLeft" );
+ output( left.prev() );
+ output( bgv );
+ backend.swaptmesh();
+ output( gv );
+ coveLL();
+ backend.endtmesh();
+}
+
+void
+CoveAndTiler::coveLowerLeftNoGrid( TrimVertex* tl )
+{
+ backend.bgntmesh( "coveLowerLeft" );
+ output( left.last() );
+ output( left.prev() );
+ backend.swaptmesh();
+ output( tl );
+ coveLL( );
+ backend.endtmesh();
+}
+
+void
+CoveAndTiler::coveLL()
+{
+ GridVertex gv( bot.ustart, top.vindex );
+ TrimVertex *vert = left.prev();
+ if( vert == NULL ) return;
+ assert( vert->param[0] <= uarray.uarray[gv.gparam[0]] );
+
+ if( gv.prevu() <= top.ustart ) {
+ for( ; vert; vert = left.prev() ) {
+ output( vert );
+ backend.swaptmesh();
+ }
+ } else while( 1 ) {
+ if( vert->param[0] > uarray.uarray[gv.gparam[0]] ){
+ output( vert );
+ backend.swaptmesh();
+ vert = left.prev();
+ if( vert == NULL ) break;
+ } else {
+ backend.swaptmesh();
+ output( gv );
+ if( gv.prevu() == top.ustart ) {
+ for( ; vert; vert = left.prev() ) {
+ output( vert );
+ backend.swaptmesh();
+ }
+ break;
+ }
+ }
+ }
+}
+
+void
+CoveAndTiler::coveLowerRight( void )
+{
+ GridVertex bgv( bot.uend, bot.vindex );
+ GridVertex gv( bot.uend, top.vindex );
+
+ right.last();
+ backend.bgntmesh( "coveLowerRight" );
+ output( bgv );
+ output( right.prev() );
+ output( gv );
+ backend.swaptmesh();
+ coveLR();
+ backend.endtmesh( );
+}
+
+void
+CoveAndTiler::coveLowerRightNoGrid( TrimVertex* tr )
+{
+ backend.bgntmesh( "coveLowerRIght" );
+ output( right.last() );
+ output( right.prev() );
+ output( tr );
+ backend.swaptmesh();
+ coveLR();
+ backend.endtmesh();
+}
+
+void
+CoveAndTiler::coveLR( )
+{
+ GridVertex gv( bot.uend, top.vindex );
+ TrimVertex *vert = right.prev();
+ if( vert == NULL ) return;
+ assert( vert->param[0] >= uarray.uarray[gv.gparam[0]] );
+
+ if( gv.nextu() >= top.uend ) {
+ for( ; vert; vert = right.prev() ) {
+ backend.swaptmesh();
+ output( vert );
+ }
+ } else while( 1 ) {
+ if( vert->param[0] < uarray.uarray[gv.gparam[0]] ) {
+ backend.swaptmesh();
+ output( vert );
+ vert = right.prev();
+ if( vert == NULL ) break;
+ } else {
+ output( gv );
+ backend.swaptmesh();
+ if( gv.nextu() == top.uend ) {
+ for( ; vert; vert = right.prev() ) {
+ backend.swaptmesh();
+ output( vert );
+ }
+ break;
+ }
+ }
+ }
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/coveandtiler.h b/mesalib/src/glu/sgi/libnurbs/internals/coveandtiler.h
new file mode 100644
index 000000000..d454202e6
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/coveandtiler.h
@@ -0,0 +1,72 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * coveandtiler.h
+ *
+ */
+
+#ifndef __glucoveandtiler_h
+#define __glucoveandtiler_h
+
+#include "trimregion.h"
+#include "trimvertex.h"
+#include "gridvertex.h"
+
+class Backend;
+class GridTrimVertex;
+
+class CoveAndTiler : virtual public TrimRegion {
+public:
+ CoveAndTiler( Backend& );
+ ~CoveAndTiler( void );
+ void coveAndTile( void );
+private:
+ Backend& backend;
+ static const int MAXSTRIPSIZE;
+ void tile( long, long, long );
+ void coveLowerLeft( void );
+ void coveLowerRight( void );
+ void coveUpperLeft( void );
+ void coveUpperRight( void );
+ void coveUpperLeftNoGrid( TrimVertex * );
+ void coveUpperRightNoGrid( TrimVertex * );
+ void coveLowerLeftNoGrid( TrimVertex * );
+ void coveLowerRightNoGrid( TrimVertex * );
+ void coveLL( void );
+ void coveLR( void );
+ void coveUL( void );
+ void coveUR( void );
+ inline void output( GridTrimVertex& );
+ inline void output( GridVertex& );
+ inline void output( TrimVertex* );
+};
+
+#endif /* __glucoveandtiler_h */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/curve.cc b/mesalib/src/glu/sgi/libnurbs/internals/curve.cc
new file mode 100644
index 000000000..33e275264
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/curve.cc
@@ -0,0 +1,198 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * curve.c++
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "mystdio.h"
+#include "mymath.h"
+#include "curve.h"
+#include "mapdesc.h"
+#include "types.h"
+#include "quilt.h"
+#include "nurbsconsts.h"
+
+/*--------------------------------------------------------------------------
+ * Curve::Curve - copy curve from quilt and transform control points
+ *--------------------------------------------------------------------------
+ */
+
+Curve::Curve( Quilt_ptr geo, REAL pta, REAL ptb, Curve *c )
+{
+ mapdesc = geo->mapdesc;
+ next = c;
+ needsSampling = mapdesc->isRangeSampling() ? 1 : 0;
+ cullval = mapdesc->isCulling() ? CULL_ACCEPT : CULL_TRIVIAL_ACCEPT;
+ order = geo->qspec[0].order;
+ stride = MAXCOORDS;
+
+ REAL *ps = geo->cpts;
+ Quiltspec_ptr qs = geo->qspec;
+ ps += qs->offset;
+ ps += qs->index * qs->order * qs->stride;
+
+ if( needsSampling )
+ mapdesc->xformSampling( ps, qs->order, qs->stride, spts, stride );
+
+ if( cullval == CULL_ACCEPT )
+ mapdesc->xformCulling( ps, qs->order, qs->stride, cpts, stride );
+
+ /* set untrimmed curve range */
+ range[0] = qs->breakpoints[qs->index];
+ range[1] = qs->breakpoints[qs->index+1];
+ range[2] = range[1] - range[0];
+
+ if( range[0] != pta ) {
+ Curve lower( *this, pta, 0 );
+ lower.next = next;
+ *this = lower;
+ }
+ if( range[1] != ptb ) {
+ Curve lower( *this, ptb, 0 );
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * Curve::Curve - subdivide a curve along an isoparametric line
+ *--------------------------------------------------------------------------
+ */
+
+Curve::Curve( Curve& upper, REAL value, Curve *c )
+{
+ Curve &lower = *this;
+
+ lower.next = c;
+ lower.mapdesc = upper.mapdesc;
+ lower.needsSampling = upper.needsSampling;
+ lower.order = upper.order;
+ lower.stride = upper.stride;
+ lower.cullval = upper.cullval;
+
+ REAL d = (value - upper.range[0]) / upper.range[2];
+
+ if( needsSampling )
+ mapdesc->subdivide( upper.spts, lower.spts, d, upper.stride, upper.order );
+
+ if( cullval == CULL_ACCEPT )
+ mapdesc->subdivide( upper.cpts, lower.cpts, d, upper.stride, upper.order );
+
+ lower.range[0] = upper.range[0];
+ lower.range[1] = value;
+ lower.range[2] = value - upper.range[0];
+ upper.range[0] = value;
+ upper.range[2] = upper.range[1] - value;
+}
+
+
+/*--------------------------------------------------------------------------
+ * Curve::clamp - clamp the sampling rate to a given maximum
+ *--------------------------------------------------------------------------
+ */
+
+void
+Curve::clamp( void )
+{
+ if( stepsize < minstepsize )
+ stepsize = mapdesc->clampfactor * minstepsize;
+}
+
+void
+Curve::setstepsize( REAL max )
+{
+ stepsize = ( max >= 1.0 ) ? (range[2] / max) : range[2];
+ minstepsize = stepsize;
+}
+
+void
+Curve::getstepsize( void )
+{
+ minstepsize= 0;
+
+ if( mapdesc->isConstantSampling() ) {
+ // fixed number of samples per patch in each direction
+ // maxrate is number of s samples per patch
+ setstepsize( mapdesc->maxrate );
+ } else if( mapdesc->isDomainSampling() ) {
+ // maxrate is number of s samples per unit s length of domain
+ setstepsize( mapdesc->maxrate * range[2] );
+ } else {
+ // upper bound on path length between sample points
+
+ assert( order <= MAXORDER );
+
+ /* points have been transformed, therefore they are homogeneous */
+ REAL tmp[MAXORDER][MAXCOORDS];
+ const int tstride = sizeof(tmp[0]) / sizeof(REAL);
+ int val = mapdesc->project( spts, stride, &tmp[0][0], tstride, order );
+
+ if( val == 0 ) {
+ // control points cross infinity, therefore derivatives are undefined
+ setstepsize( mapdesc->maxrate );
+ } else {
+ REAL t = mapdesc->getProperty( N_PIXEL_TOLERANCE );
+ if( mapdesc->isParametricDistanceSampling() ) {
+ REAL d = mapdesc->calcPartialVelocity( &tmp[0][0], tstride, order, 2, range[2] );
+ stepsize = (d > 0.0) ? sqrtf( 8.0 * t / d ) : range[2];
+ minstepsize = ( mapdesc->maxrate > 0.0 ) ? (range[2] / mapdesc->maxrate) : 0.0;
+ } else if( mapdesc->isPathLengthSampling() ) {
+ // t is upper bound on path (arc) length
+ REAL d = mapdesc->calcPartialVelocity( &tmp[0][0], tstride, order, 1, range[2] );
+ stepsize = ( d > 0.0 ) ? (t / d) : range[2];
+ minstepsize = ( mapdesc->maxrate > 0.0 ) ? (range[2] / mapdesc->maxrate) : 0.0;
+ } else {
+ // control points cross infinity, therefore partials are undefined
+ setstepsize( mapdesc->maxrate );
+ }
+ }
+ }
+}
+
+int
+Curve::needsSamplingSubdivision( void )
+{
+ return ( stepsize < minstepsize ) ? 1 : 0;
+}
+
+int
+Curve::cullCheck( void )
+{
+ if( cullval == CULL_ACCEPT )
+ cullval = mapdesc->cullCheck( cpts, order, stride );
+ return cullval;
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/curve.h b/mesalib/src/glu/sgi/libnurbs/internals/curve.h
new file mode 100644
index 000000000..0da81c721
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/curve.h
@@ -0,0 +1,70 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * curve.h
+ *
+ */
+
+#ifndef __glucurve_h_
+#define __glucurve_h_
+
+#include "types.h"
+#include "defines.h"
+
+class Mapdesc;
+class Quilt;
+
+
+class Curve {
+public:
+friend class Curvelist;
+ Curve( Quilt *, REAL, REAL, Curve * );
+ Curve( Curve&, REAL, Curve * );
+ Curve * next;
+private:
+ Mapdesc * mapdesc;
+ int stride;
+ int order;
+ int cullval;
+ int needsSampling;
+ REAL cpts[MAXORDER*MAXCOORDS];
+ REAL spts[MAXORDER*MAXCOORDS];
+ REAL stepsize;
+ REAL minstepsize;
+ REAL range[3];
+
+ void clamp( void );
+ void setstepsize( REAL );
+ void getstepsize( void );
+ int cullCheck( void );
+ int needsSamplingSubdivision( void );
+};
+#endif /* __glucurve_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/curvelist.cc b/mesalib/src/glu/sgi/libnurbs/internals/curvelist.cc
new file mode 100644
index 000000000..872eb5816
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/curvelist.cc
@@ -0,0 +1,110 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * curvelist.c++
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "mystdio.h"
+#include "quilt.h"
+#include "curvelist.h"
+#include "curve.h"
+#include "nurbsconsts.h"
+#include "types.h"
+
+Curvelist::Curvelist( Quilt *quilts, REAL pta, REAL ptb )
+{
+ curve = 0;
+ for( Quilt *q = quilts; q; q = q->next )
+ curve = new Curve( q, pta, ptb, curve );
+ range[0] = pta;
+ range[1] = ptb;
+ range[2] = ptb - pta;
+}
+
+Curvelist::Curvelist( Curvelist &upper, REAL value )
+{
+ Curvelist &lower = *this;
+ curve = 0;
+ for( Curve *c = upper.curve; c; c = c->next )
+ curve = new Curve( *c, value, curve );
+
+ lower.range[0] = upper.range[0];
+ lower.range[1] = value;
+ lower.range[2] = value - upper.range[0];
+ upper.range[0] = value;
+ upper.range[2] = upper.range[1] - value;
+}
+
+Curvelist::~Curvelist()
+{
+ while( curve ) {
+ Curve *c = curve;
+ curve = curve->next;
+ delete c;
+ }
+}
+
+int
+Curvelist::cullCheck( void )
+{
+ for( Curve *c = curve; c; c = c->next )
+ if( c->cullCheck() == CULL_TRIVIAL_REJECT )
+ return CULL_TRIVIAL_REJECT;
+ return CULL_ACCEPT;
+}
+
+void
+Curvelist::getstepsize( void )
+{
+ stepsize = range[2];
+ Curve *c;
+ for( c = curve; c; c = c->next ) {
+ c->getstepsize();
+ c->clamp();
+ stepsize = ((c->stepsize < stepsize) ? c->stepsize : stepsize);
+ if( c->needsSamplingSubdivision() ) break;
+ }
+ needsSubdivision = ( c ) ? 1 : 0;
+}
+
+int
+Curvelist::needsSamplingSubdivision( void )
+{
+ return needsSubdivision;
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/curvelist.h b/mesalib/src/glu/sgi/libnurbs/internals/curvelist.h
new file mode 100644
index 000000000..733a5115d
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/curvelist.h
@@ -0,0 +1,62 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * curvelist.h
+ *
+ */
+
+#ifndef __glucurvelist_h_
+#define __glucurvelist_h_
+
+#include "types.h"
+#include "defines.h"
+
+class Mapdesc;
+class Quilt;
+class Curve;
+
+class Curvelist
+{
+friend class Subdivider;
+public:
+ Curvelist( Quilt *, REAL, REAL );
+ Curvelist( Curvelist &, REAL );
+ ~Curvelist( void );
+ int cullCheck( void );
+ void getstepsize( void );
+ int needsSamplingSubdivision();
+private:
+ Curve *curve;
+ float range[3];
+ int needsSubdivision;
+ float stepsize;
+};
+#endif /* __glucurvelist_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/curvesub.cc b/mesalib/src/glu/sgi/libnurbs/internals/curvesub.cc
new file mode 100644
index 000000000..f85acc269
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/curvesub.cc
@@ -0,0 +1,103 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * curvesub.c++
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "mystdio.h"
+#include "subdivider.h"
+#include "renderhints.h"
+#include "backend.h"
+#include "quilt.h"
+#include "curvelist.h"
+#include "curve.h"
+#include "nurbsconsts.h"
+
+/*--------------------------------------------------------------------------
+ * drawCurves - main curve rendering entry point
+ *--------------------------------------------------------------------------
+ */
+
+void
+Subdivider::drawCurves( void )
+{
+ REAL from[1], to[1];
+ Flist bpts;
+ qlist->getRange( from, to, bpts );
+
+ renderhints.init( );
+
+ backend.bgncurv();
+ for( int i=bpts.start; i<bpts.end-1; i++ ) {
+ REAL pta, ptb;
+ pta = bpts.pts[i];
+ ptb = bpts.pts[i+1];
+
+ qlist->downloadAll( &pta, &ptb, backend );
+
+ Curvelist curvelist( qlist, pta, ptb );
+ samplingSplit( curvelist, renderhints.maxsubdivisions );
+ }
+ backend.endcurv();
+}
+
+
+/*--------------------------------------------------------------------------
+ * samplingSplit - recursively subdivide patch, cull check each subpatch
+ *--------------------------------------------------------------------------
+ */
+
+void
+Subdivider::samplingSplit( Curvelist& curvelist, int subdivisions )
+{
+ if( curvelist.cullCheck() == CULL_TRIVIAL_REJECT ) return;
+
+ curvelist.getstepsize();
+
+ if( curvelist.needsSamplingSubdivision() && (subdivisions > 0) ) {
+ REAL mid = ( curvelist.range[0] + curvelist.range[1] ) * 0.5;
+ Curvelist lowerlist( curvelist, mid );
+ samplingSplit( lowerlist, subdivisions-1 ); // lower
+ samplingSplit( curvelist, subdivisions-1 ); // upper
+ } else {
+ long nu = 1 + ((long) (curvelist.range[2] / curvelist.stepsize));
+ backend.curvgrid( curvelist.range[0], curvelist.range[1], nu );
+ backend.curvmesh( 0, nu );
+ }
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/dataTransform.cc b/mesalib/src/glu/sgi/libnurbs/internals/dataTransform.cc
new file mode 100644
index 000000000..55c0fbb15
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/dataTransform.cc
@@ -0,0 +1,209 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+**
+*/
+/*
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "glimports.h"
+#include "myassert.h"
+#include "nurbsconsts.h"
+#include "trimvertex.h"
+#include "dataTransform.h"
+
+extern directedLine* arcLoopToDLineLoop(Arc_ptr loop);
+
+#if 0 // UNUSED
+static directedLine* copy_loop(Arc_ptr loop, Real2* vertArray, int& index, directedLine dline_buf[], sampledLine sline_buf[], int& index_dline)
+{
+ directedLine *ret;
+ int old_index = index;
+ int i = index;
+ int j;
+ for(j=0; j<loop->pwlArc->npts-1; j++, i++)
+ {
+ vertArray[i][0] = loop->pwlArc->pts[j].param[0];
+ vertArray[i][1] = loop->pwlArc->pts[j].param[1];
+ }
+ loop->clearmark();
+
+ for(Arc_ptr jarc = loop->next; jarc != loop; jarc=jarc->next)
+ {
+ for(j=0; j<jarc->pwlArc->npts-1; j++, i++)
+ {
+ vertArray[i][0] = jarc->pwlArc->pts[j].param[0];
+ vertArray[i][1] = jarc->pwlArc->pts[j].param[1];
+ }
+ jarc->clearmark();
+ }
+ //copy the first vertex again
+ vertArray[i][0] = loop->pwlArc->pts[0].param[0];
+ vertArray[i][1] = loop->pwlArc->pts[0].param[1];
+ i++;
+ index=i;
+
+ directedLine* dline;
+ sampledLine* sline;
+ sline = &sline_buf[index_dline];
+ dline = &dline_buf[index_dline];
+ sline->init(2, &vertArray[old_index]);
+ dline->init(INCREASING, sline);
+ ret = dline;
+ index_dline++;
+
+ for(i=old_index+1; i<= index-2; i++)
+ {
+ sline = &sline_buf[index_dline];
+ dline = &dline_buf[index_dline];
+ sline->init(2, &vertArray[i]);
+ dline->init(INCREASING, sline);
+ ret->insert(dline);
+ index_dline++;
+ }
+ return ret;
+}
+#endif
+
+#if 0 // UNUSED
+static int num_edges(Bin& bin)
+{
+ int sum=0;
+ for(Arc_ptr jarc = bin.firstarc(); jarc; jarc=bin.nextarc())
+ sum += jarc->pwlArc->npts-1;
+ return sum;
+}
+#endif
+
+/*
+directedLine* bin_to_DLineLoops(Bin& bin)
+{
+ directedLine *ret=NULL;
+ directedLine *temp;
+
+ int numedges = num_edges(bin);
+ directedLine* dline_buf = new directedLine[numedges]; //not work for N32?
+ sampledLine* sline_buf=new sampledLine[numedges];
+
+ Real2* vertArray = new Real2[numedges*2];
+ int index = 0;
+ int index_dline = 0;
+ bin.markall();
+
+ for(Arc_ptr jarc = bin.firstarc(); jarc; jarc=bin.nextarc())
+ {
+ if(jarc->ismarked())
+ {
+ assert(jarc->check() != 0);
+ Arc_ptr jarchead = jarc;
+ do {
+ jarc->clearmark();
+ jarc = jarc->next;
+ } while(jarc != jarchead);
+ temp=copy_loop(jarchead, vertArray, index, dline_buf, sline_buf, index_dline);
+ ret = temp->insertPolygon(ret);
+ }
+ }
+
+ return ret;
+}
+*/
+
+
+directedLine* bin_to_DLineLoops(Bin& bin)
+{
+ directedLine *ret=NULL;
+ directedLine *temp;
+ bin.markall();
+ for(Arc_ptr jarc=bin.firstarc(); jarc; jarc=bin.nextarc()){
+ if(jarc->ismarked()) {
+ assert(jarc->check() != 0);
+ Arc_ptr jarchead = jarc;
+ do {
+ jarc->clearmark();
+ jarc = jarc->next;
+ } while(jarc != jarchead);
+ temp = arcLoopToDLineLoop(jarc);
+ ret = temp->insertPolygon(ret);
+ }
+ }
+ return ret;
+}
+
+directedLine* o_pwlcurve_to_DLines(directedLine* original, O_pwlcurve* pwl)
+{
+ directedLine* ret = original;
+ for(Int i=0; i<pwl->npts-1; i++)
+ {
+ sampledLine* sline = new sampledLine(2);
+ sline->setPoint(0, pwl->pts[i].param);
+ sline->setPoint(1, pwl->pts[i+1].param);
+ directedLine* dline = new directedLine(INCREASING, sline);
+ if(ret == NULL)
+ ret = dline;
+ else
+ ret->insert(dline);
+ }
+ return ret;
+}
+
+directedLine* o_curve_to_DLineLoop(O_curve* cur)
+{
+ directedLine *ret;
+ if(cur == NULL)
+ return NULL;
+ assert(cur->curvetype == ct_pwlcurve);
+ ret = o_pwlcurve_to_DLines(NULL, cur->curve.o_pwlcurve);
+ for(O_curve* temp = cur->next; temp != NULL; temp = temp->next)
+ {
+ assert(temp->curvetype == ct_pwlcurve);
+ ret = o_pwlcurve_to_DLines(ret, temp->curve.o_pwlcurve);
+ }
+ return ret;
+}
+
+directedLine* o_trim_to_DLineLoops(O_trim* trim)
+{
+ O_trim* temp;
+ directedLine *ret;
+ if(trim == NULL)
+ return NULL;
+ ret = o_curve_to_DLineLoop(trim->o_curve);
+
+ for(temp=trim->next; temp != NULL; temp = temp->next)
+ {
+ ret = ret->insertPolygon(o_curve_to_DLineLoop(temp->o_curve));
+ }
+ return ret;
+}
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/dataTransform.h b/mesalib/src/glu/sgi/libnurbs/internals/dataTransform.h
new file mode 100644
index 000000000..7898df754
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/dataTransform.h
@@ -0,0 +1,59 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+/*
+*/
+
+#ifndef _DATA_TRANSFORM_H
+#define _DATA_TRANSFORM_H
+
+#include "reader.h"
+#include "directedLine.h"
+#include "bin.h"
+directedLine* bin_to_DLineLoops(Bin& bin);
+
+/*transform the pwlcurve into a number of directedline lines
+ *insert these directedlines into orignal which is supposed to be
+ *the part of the trimming loop obtained so far.
+ *return the updated trimkming loop.
+ */
+directedLine* o_pwlcurve_to_DLines(directedLine* original, O_pwlcurve* pwl);
+
+/*transform a trim loop (curve) into a directedLine loop
+ */
+directedLine* o_curve_to_DLineLoop(O_curve* curve);
+
+/*transform a list of trim loops (trim) into
+ *a list of polygons represented as directedLine*.
+ */
+directedLine* o_trim_to_DLineLoops(O_trim* trim);
+
+
+#endif
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/defines.h b/mesalib/src/glu/sgi/libnurbs/internals/defines.h
new file mode 100644
index 000000000..32950d613
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/defines.h
@@ -0,0 +1,50 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * defines.h
+ *
+ */
+
+#ifndef __gludefines_h_
+#define __gludefines_h_
+
+/* culling constants */
+#define CULL_TRIVIAL_REJECT 0
+#define CULL_TRIVIAL_ACCEPT 1
+#define CULL_ACCEPT 2
+
+/* maximum order of a B-Spline */
+#define MAXORDER 24
+
+/* maximum dimension of any B-spline range space */
+#define MAXCOORDS 5
+
+#endif /* __gludefines_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/displaylist.cc b/mesalib/src/glu/sgi/libnurbs/internals/displaylist.cc
new file mode 100644
index 000000000..48593c637
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/displaylist.cc
@@ -0,0 +1,82 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * displaylist.c++
+ *
+ */
+
+#include "glimports.h"
+#include "mystdio.h"
+#include "nurbstess.h"
+#include "displaylist.h"
+
+
+DisplayList::DisplayList( NurbsTessellator *_nt ) :
+ dlnodePool( sizeof( Dlnode ), 1, "dlnodepool" )
+{
+ lastNode = &nodes;
+ nt = _nt;
+}
+
+DisplayList::~DisplayList( void )
+{
+ for( Dlnode *nextNode; nodes; nodes = nextNode ) {
+ nextNode = nodes->next;
+ if( nodes->cleanup != 0 ) (nt->*nodes->cleanup)( nodes->arg );
+ //nodes->deleteMe(dlnodePool);
+ }
+}
+
+void
+DisplayList::play( void )
+{
+ for( Dlnode *node = nodes; node; node = node->next )
+ if( node->work != 0 ) (nt->*node->work)( node->arg );
+}
+
+void
+DisplayList::endList( void )
+{
+ *lastNode = 0;
+}
+
+void
+DisplayList::append( PFVS work, void *arg, PFVS cleanup )
+{
+ Dlnode *node = new(dlnodePool) Dlnode( work, arg, cleanup );
+ *lastNode = node;
+ lastNode = &(node->next);
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/displaylist.h b/mesalib/src/glu/sgi/libnurbs/internals/displaylist.h
new file mode 100644
index 000000000..22cbec378
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/displaylist.h
@@ -0,0 +1,78 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * displaylist.h
+ *
+ */
+
+#ifndef __gludisplaylist_h_
+#define __gludisplaylist_h_
+
+#include "glimports.h"
+#include "mysetjmp.h"
+#include "mystdio.h"
+#include "bufpool.h"
+
+class NurbsTessellator;
+
+typedef void (NurbsTessellator::*PFVS)( void * );
+
+struct Dlnode : public PooledObj {
+ Dlnode( PFVS, void *, PFVS );
+ PFVS work;
+ void * arg;
+ PFVS cleanup;
+ Dlnode * next;
+};
+
+inline
+Dlnode::Dlnode( PFVS _work, void *_arg, PFVS _cleanup )
+{
+ work = _work;
+ arg = _arg;
+ cleanup = _cleanup;
+}
+
+class DisplayList {
+public:
+ DisplayList( NurbsTessellator * );
+ ~DisplayList( void );
+ void play( void );
+ void append( PFVS work, void *arg, PFVS cleanup );
+ void endList( void );
+private:
+ Dlnode *nodes;
+ Pool dlnodePool;
+ Dlnode **lastNode;
+ NurbsTessellator *nt;
+};
+
+#endif /* __gludisplaylist_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/displaymode.h b/mesalib/src/glu/sgi/libnurbs/internals/displaymode.h
new file mode 100644
index 000000000..53968b2f1
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/displaymode.h
@@ -0,0 +1,40 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+/*
+*/
+
+#ifndef __gludisplaymode_h_
+#define __gludisplaymode_h_
+
+#define N_MESHFILL 0
+#define N_MESHLINE 1
+#define N_MESHPOINT 2
+
+#endif /* __gludisplaymode_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/flist.cc b/mesalib/src/glu/sgi/libnurbs/internals/flist.cc
new file mode 100644
index 000000000..d3162b9f5
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/flist.cc
@@ -0,0 +1,118 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * flist.c++
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "mystdio.h"
+#include "flist.h"
+
+/*----------------------------------------------------------------------------
+ * Flist::Flist - initialize a REAL number array
+ *----------------------------------------------------------------------------
+ */
+Flist::Flist( void )
+{
+ npts = 0;
+ pts = 0;
+ start = end = 0;
+}
+
+/*----------------------------------------------------------------------------
+ * Flist::~Flist - free a REAL number array
+ *----------------------------------------------------------------------------
+ */
+Flist::~Flist( void )
+{
+ if( npts ) delete[] pts;
+}
+
+void
+Flist::add( REAL x )
+{
+ pts[end++] = x;
+ assert( end <= npts );
+}
+
+/*----------------------------------------------------------------------------
+ * Flist::filter - remove duplicate numbers from array
+ *----------------------------------------------------------------------------
+ */
+void Flist::filter( void )
+{
+ sorter.qsort( pts, end );
+ start = 0;
+
+ int j = 0;
+ for( int i = 1; i < end; i++ ) {
+ if( pts[i] == pts[i-j-1] )
+ j++;
+ pts[i-j] = pts[i];
+ }
+ end -= j;
+}
+
+/*----------------------------------------------------------------------------
+ * Flist::grow - ensure that array is large enough
+ *----------------------------------------------------------------------------
+ */
+void Flist::grow( int maxpts )
+{
+ if( npts < maxpts ) {
+ if( npts ) delete[] pts;
+ npts = 2 * maxpts;
+ pts = new REAL[npts];
+ assert( pts != 0 );
+ }
+ start = end = 0;
+}
+
+/*----------------------------------------------------------------------------
+ * Flist::taper - ignore head and tail of array
+ *----------------------------------------------------------------------------
+ */
+void Flist::taper( REAL from, REAL to )
+{
+ while( pts[start] != from )
+ start++;
+
+ while( pts[end-1] != to )
+ end--;
+}
+
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/flist.h b/mesalib/src/glu/sgi/libnurbs/internals/flist.h
new file mode 100644
index 000000000..014273ebe
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/flist.h
@@ -0,0 +1,59 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * flist.h
+ *
+ */
+
+#ifndef __gluflist_h_
+#define __gluflist_h_
+
+#include "types.h"
+#include "flistsorter.h"
+
+class Flist {
+public:
+ REAL * pts; /* head of array */
+ int npts; /* number of points in array */
+ int start; /* first important point index */
+ int end; /* last important point index */
+
+ Flist( void );
+ ~Flist( void );
+ void add( REAL x );
+ void filter( void );
+ void grow( int);
+ void taper( REAL , REAL );
+protected:
+ FlistSorter sorter;
+};
+
+#endif /* __gluflist_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/flistsorter.cc b/mesalib/src/glu/sgi/libnurbs/internals/flistsorter.cc
new file mode 100644
index 000000000..d49bdea3e
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/flistsorter.cc
@@ -0,0 +1,81 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * flistsorter.c++
+ *
+ */
+
+#include "glimports.h"
+#include "flistsorter.h"
+
+FlistSorter::FlistSorter( void ) : Sorter( sizeof( REAL ) )
+{
+}
+
+void
+FlistSorter::qsort( REAL *p, int n )
+{
+ Sorter::qsort( (char *)p, n );
+}
+
+int
+FlistSorter::qscmp( char *i, char *j )
+{
+ REAL f0 = *(REAL *)i;
+ REAL f1 = *(REAL *)j;
+ return (f0 < f1) ? -1 : 1;
+}
+
+void
+FlistSorter::qsexc( char *i, char *j )
+{
+ REAL *f0 = (REAL *)i;
+ REAL *f1 = (REAL *)j;
+ REAL tmp = *f0;
+ *f0 = *f1;
+ *f1 = tmp;
+}
+
+void
+FlistSorter::qstexc( char *i, char *j, char *k )
+{
+ REAL *f0 = (REAL *)i;
+ REAL *f1 = (REAL *)j;
+ REAL *f2 = (REAL *)k;
+ REAL tmp = *f0;
+ *f0 = *f2;
+ *f2 = *f1;
+ *f1 = tmp;
+}
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/flistsorter.h b/mesalib/src/glu/sgi/libnurbs/internals/flistsorter.h
new file mode 100644
index 000000000..65e6a572e
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/flistsorter.h
@@ -0,0 +1,53 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * flistsorter.h
+ *
+ */
+
+#ifndef __gluflistsorter_h_
+#define __gluflistsorter_h_
+
+#include "sorter.h"
+#include "types.h"
+
+class FlistSorter : public Sorter {
+public:
+ FlistSorter(void);
+ virtual ~FlistSorter() { /* silence warning*/ }
+ void qsort( REAL *a, int n );
+
+protected:
+ virtual int qscmp( char *, char * );
+ virtual void qsexc( char *i, char *j ); // i<-j, j<-i
+ virtual void qstexc( char *i, char *j, char *k ); // i<-k, k<-j, j<-i
+};
+#endif /* __gluflistsorter_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/gridline.h b/mesalib/src/glu/sgi/libnurbs/internals/gridline.h
new file mode 100644
index 000000000..1a92e3b13
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/gridline.h
@@ -0,0 +1,46 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * gridline.h
+ *
+ */
+
+#ifndef __glugridline_h_
+#define __glugridline_h_
+
+struct Gridline {
+ long v;
+ REAL vval;
+ long vindex;
+ long ustart;
+ long uend;
+ };
+#endif /* __glugridline_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/gridtrimvertex.h b/mesalib/src/glu/sgi/libnurbs/internals/gridtrimvertex.h
new file mode 100644
index 000000000..707f649d2
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/gridtrimvertex.h
@@ -0,0 +1,89 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * gridtrimvertex.h
+ *
+ */
+
+#ifndef __glugridtrimvertex_h_
+#define __glugridtrimvertex_h_
+
+#include "mystdlib.h"
+#include "bufpool.h"
+#include "trimvertex.h"
+#include "gridvertex.h"
+
+class GridTrimVertex : public PooledObj
+{
+private:
+ TrimVertex dummyt;
+ GridVertex dummyg;
+public:
+ GridTrimVertex() { g = 0; t = 0; }
+ TrimVertex *t;
+ GridVertex *g;
+
+ inline void set( long, long );
+ inline void set( REAL, REAL );
+ inline void set( TrimVertex * );
+ inline void clear( void ) { t = 0; g = 0; };
+ inline int isGridVert() { return g ? 1 : 0 ; }
+ inline int isTrimVert() { return t ? 1 : 0 ; }
+ inline void output();
+};
+
+inline void
+GridTrimVertex::set( long x, long y )
+{
+ g = &dummyg;
+ dummyg.gparam[0] = x;
+ dummyg.gparam[1] = y;
+}
+
+inline void
+GridTrimVertex::set( REAL x, REAL y )
+{
+ g = 0;
+ t = &dummyt;
+ dummyt.param[0] = x;
+ dummyt.param[1] = y;
+ dummyt.nuid = 0;
+}
+
+inline void
+GridTrimVertex::set( TrimVertex *v )
+{
+ g = 0;
+ t = v;
+}
+
+typedef GridTrimVertex *GridTrimVertex_p;
+#endif /* __glugridtrimvertex_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/gridvertex.h b/mesalib/src/glu/sgi/libnurbs/internals/gridvertex.h
new file mode 100644
index 000000000..36a65c7bd
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/gridvertex.h
@@ -0,0 +1,48 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * gridvertex.h
+ *
+ */
+
+#ifndef __glugridvertex_h_
+#define __glugridvertex_h_
+
+struct GridVertex {
+ long gparam[2];
+ GridVertex( void ) {}
+ GridVertex( long u, long v ) { gparam[0] = u, gparam[1] = v; }
+ void set( long u, long v ) { gparam[0] = u, gparam[1] = v; }
+ long nextu() { return gparam[0]++; }
+ long prevu() { return gparam[0]--; }
+};
+
+#endif /* __glugridvertex_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/hull.cc b/mesalib/src/glu/sgi/libnurbs/internals/hull.cc
new file mode 100644
index 000000000..389ba66fb
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/hull.cc
@@ -0,0 +1,165 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * hull.c++
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "mystdio.h"
+#include "hull.h"
+#include "gridvertex.h"
+#include "gridtrimvertex.h"
+#include "gridline.h"
+#include "trimline.h"
+#include "uarray.h"
+#include "trimregion.h"
+
+Hull::Hull( void )
+{}
+
+Hull::~Hull( void )
+{}
+
+/*----------------------------------------------------------------------
+ * Hull:init - this routine does the initialization needed before any
+ * calls to nextupper or nextlower can be made.
+ *----------------------------------------------------------------------
+ */
+void
+Hull::init( void )
+{
+ TrimVertex *lfirst = left.first();
+ TrimVertex *llast = left.last();
+ if( lfirst->param[0] <= llast->param[0] ) {
+ fakeleft.init( left.first() );
+ upper.left = &fakeleft;
+ lower.left = &left;
+ } else {
+ fakeleft.init( left.last() );
+ lower.left = &fakeleft;
+ upper.left = &left;
+ }
+ upper.left->last();
+ lower.left->first();
+
+ if( top.ustart <= top.uend ) {
+ upper.line = &top;
+ upper.index = top.ustart;
+ } else
+ upper.line = 0;
+
+ if( bot.ustart <= bot.uend ) {
+ lower.line = &bot;
+ lower.index = bot.ustart;
+ } else
+ lower.line = 0;
+
+ TrimVertex *rfirst = right.first();
+ TrimVertex *rlast = right.last();
+ if( rfirst->param[0] <= rlast->param[0] ) {
+ fakeright.init( right.last() );
+ lower.right = &fakeright;
+ upper.right = &right;
+ } else {
+ fakeright.init( right.first() );
+ upper.right = &fakeright;
+ lower.right = &right;
+ }
+ upper.right->first();
+ lower.right->last();
+}
+
+/*----------------------------------------------------------------------
+ * nextupper - find next vertex on upper hull of trim region.
+ * - if vertex is on trim curve, set vtop point to
+ * that vertex. if vertex is on grid, set vtop to
+ * point to temporary area and stuff coordinants into
+ * temporary vertex. Also, place grid coords in temporary
+ * grid vertex.
+ *----------------------------------------------------------------------
+ */
+GridTrimVertex *
+Hull::nextupper( GridTrimVertex *gv )
+{
+ if( upper.left ) {
+ gv->set( upper.left->prev() );
+ if( gv->isTrimVert() ) return gv;
+ upper.left = 0;
+ }
+
+ if( upper.line ) {
+ assert( upper.index <= upper.line->uend );
+ gv->set( uarray.uarray[upper.index], upper.line->vval );
+ gv->set( upper.index, upper.line->vindex );
+ if( upper.index++ == upper.line->uend ) upper.line = 0;
+ return gv;
+ }
+
+ if( upper.right ) {
+ gv->set( upper.right->next() );
+ if( gv->isTrimVert() ) return gv;
+ upper.right = 0;
+ }
+
+ return 0;
+}
+
+GridTrimVertex *
+Hull::nextlower( register GridTrimVertex *gv )
+{
+ if( lower.left ) {
+ gv->set( lower.left->next() );
+ if( gv->isTrimVert() ) return gv;
+ lower.left = 0;
+ }
+
+ if( lower.line ) {
+ gv->set( uarray.uarray[lower.index], lower.line->vval );
+ gv->set( lower.index, lower.line->vindex );
+ if( lower.index++ == lower.line->uend ) lower.line = 0;
+ return gv;
+ }
+
+ if( lower.right ) {
+ gv->set( lower.right->prev() );
+ if( gv->isTrimVert() ) return gv;
+ lower.right = 0;
+ }
+
+ return 0;
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/hull.h b/mesalib/src/glu/sgi/libnurbs/internals/hull.h
new file mode 100644
index 000000000..dfe865267
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/hull.h
@@ -0,0 +1,69 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * hull.h
+ *
+ */
+
+#ifndef __gluhull_h_
+#define __gluhull_h_
+
+#include "trimline.h"
+#include "trimregion.h"
+#include "trimvertex.h"
+#include "gridtrimvertex.h"
+
+struct Gridline;
+class Uarray;
+
+class Hull : virtual public TrimRegion {
+public:
+ Hull( void );
+ ~Hull( void );
+ void init( void );
+ GridTrimVertex * nextlower( GridTrimVertex * );
+ GridTrimVertex * nextupper( GridTrimVertex * );
+private:
+ struct Side {
+ Trimline *left;
+ Gridline *line;
+ Trimline *right;
+ long index;
+ };
+
+ Side lower;
+ Side upper;
+ Trimline fakeleft;
+ Trimline fakeright;
+};
+
+
+#endif /* __gluhull_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/intersect.cc b/mesalib/src/glu/sgi/libnurbs/internals/intersect.cc
new file mode 100644
index 000000000..b39ea2121
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/intersect.cc
@@ -0,0 +1,665 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * intersect.c++
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "mystdio.h"
+#include "subdivider.h"
+#include "arc.h"
+#include "bin.h"
+#include "backend.h"
+#include "trimvertpool.h"
+
+/*#define NOTDEF*/
+
+enum i_result { INTERSECT_VERTEX, INTERSECT_EDGE };
+
+/* local functions */
+#ifndef NDEBUG // for asserts only
+static int arc_classify( Arc_ptr, int, REAL );
+#endif
+static enum i_result pwlarc_intersect( PwlArc *, int, REAL, int, int[3] );
+
+
+void
+Subdivider::partition( Bin & bin, Bin & left, Bin & intersections,
+ Bin & right, Bin & unknown, int param, REAL value )
+{
+ Bin headonleft, headonright, tailonleft, tailonright;
+
+ for( Arc_ptr jarc = bin.removearc(); jarc; jarc = bin.removearc() ) {
+
+ REAL tdiff = jarc->tail()[param] - value;
+ REAL hdiff = jarc->head()[param] - value;
+
+ if( tdiff > 0.0 ) {
+ if( hdiff > 0.0 ) {
+ right.addarc( jarc );
+ } else if( hdiff == 0.0 ) {
+ tailonright.addarc( jarc );
+ } else {
+ Arc_ptr jtemp;
+ switch( arc_split(jarc, param, value, 0) ) {
+ case 2:
+ tailonright.addarc( jarc );
+ headonleft.addarc( jarc->next );
+ break;
+ case 31:
+ assert( jarc->head()[param] > value );
+ right.addarc( jarc );
+ tailonright.addarc( jtemp = jarc->next );
+ headonleft.addarc( jtemp->next );
+ break;
+ case 32:
+ assert( jarc->head()[param] <= value );
+ tailonright .addarc( jarc );
+ headonleft.addarc( jtemp = jarc->next );
+ left.addarc( jtemp->next );
+ break;
+ case 4:
+ right.addarc( jarc );
+ tailonright.addarc( jtemp = jarc->next );
+ headonleft.addarc( jtemp = jtemp->next );
+ left.addarc( jtemp->next );
+ }
+ }
+ } else if( tdiff == 0.0 ) {
+ if( hdiff > 0.0 ) {
+ headonright.addarc( jarc );
+ } else if( hdiff == 0.0 ) {
+ unknown.addarc( jarc );
+ } else {
+ headonleft.addarc( jarc );
+ }
+ } else {
+ if( hdiff > 0.0 ) {
+ Arc_ptr jtemp;
+ switch( arc_split(jarc, param, value, 1) ) {
+ case 2:
+ tailonleft.addarc( jarc );
+ headonright.addarc( jarc->next );
+ break;
+ case 31:
+ assert( jarc->head()[param] < value );
+ left.addarc( jarc );
+ tailonleft.addarc( jtemp = jarc->next );
+ headonright.addarc( jtemp->next );
+ break;
+ case 32:
+ assert( jarc->head()[param] >= value );
+ tailonleft.addarc( jarc );
+ headonright.addarc( jtemp = jarc->next );
+ right.addarc( jtemp->next );
+ break;
+ case 4:
+ left.addarc( jarc );
+ tailonleft.addarc( jtemp = jarc->next );
+ headonright.addarc( jtemp = jtemp->next );
+ right.addarc( jtemp->next );
+ }
+ } else if( hdiff == 0.0 ) {
+ tailonleft.addarc( jarc );
+ } else {
+ left.addarc( jarc );
+ }
+ }
+ }
+ if( param == 0 ) {
+ classify_headonleft_s( headonleft, intersections, left, value );
+ classify_tailonleft_s( tailonleft, intersections, left, value );
+ classify_headonright_s( headonright, intersections, right, value );
+ classify_tailonright_s( tailonright, intersections, right, value );
+ } else {
+ classify_headonleft_t( headonleft, intersections, left, value );
+ classify_tailonleft_t( tailonleft, intersections, left, value );
+ classify_headonright_t( headonright, intersections, right, value );
+ classify_tailonright_t( tailonright, intersections, right, value );
+ }
+}
+
+inline static void
+vert_interp( TrimVertex *n, TrimVertex *l, TrimVertex *r, int p, REAL val )
+{
+ assert( val > l->param[p]);
+ assert( val < r->param[p]);
+
+ n->nuid = l->nuid;
+
+ n->param[p] = val;
+ if( l->param[1-p] != r->param[1-p] ) {
+ REAL ratio = (val - l->param[p]) / (r->param[p] - l->param[p]);
+ n->param[1-p] = l->param[1-p] +
+ ratio * (r->param[1-p] - l->param[1-p]);
+ } else {
+ n->param[1-p] = l->param[1-p];
+ }
+}
+
+int
+Subdivider::arc_split( Arc_ptr jarc, int param, REAL value, int dir )
+{
+ int maxvertex = jarc->pwlArc->npts;
+ Arc_ptr jarc1;
+ TrimVertex* v = jarc->pwlArc->pts;
+
+ int loc[3];
+ switch( pwlarc_intersect( jarc->pwlArc, param, value, dir, loc ) ) {
+
+ // When the parameter value lands on a vertex, life is sweet
+ case INTERSECT_VERTEX: {
+ jarc1 = new(arcpool) Arc( jarc, new( pwlarcpool) PwlArc( maxvertex-loc[1], &v[loc[1]] ) );
+ jarc->pwlArc->npts = loc[1] + 1;
+ jarc1->next = jarc->next;
+ jarc1->next->prev = jarc1;
+ jarc->next = jarc1;
+ jarc1->prev = jarc;
+ assert(jarc->check() != 0);
+ return 2;
+ }
+
+ // When the parameter value intersects an edge, we have to
+ // interpolate a new vertex. There are special cases
+ // if the new vertex is adjacent to one or both of the
+ // endpoints of the arc.
+ case INTERSECT_EDGE: {
+ int i, j;
+ if( dir == 0 ) {
+ i = loc[0];
+ j = loc[2];
+ } else {
+ i = loc[2];
+ j = loc[0];
+ }
+
+#ifndef NOTDEF
+ // The split is between vertices at index j and i, in that
+ // order (j < i)
+
+ // JEB: This code is my idea of how to do the split without
+ // increasing the number of links. I'm doing this so that
+ // the is_rect routine can recognize rectangles created by
+ // subdivision. In exchange for simplifying the curve list,
+ // however, it costs in allocated space and vertex copies.
+
+ TrimVertex *newjunk = trimvertexpool.get(maxvertex -i+1 /*-j*/);
+ int k;
+ for(k=0; k<maxvertex-i; k++)
+ {
+ newjunk[k+1] = v[i+k];
+ newjunk[k+1].nuid = jarc->nuid;
+ }
+
+ TrimVertex *vcopy = trimvertexpool.get(maxvertex);
+ for(k=0; k<maxvertex; k++)
+ {
+ vcopy[k].param[0] = v[k].param[0];
+ vcopy[k].param[1] = v[k].param[1];
+ }
+ jarc->pwlArc->pts=vcopy;
+
+ v[i].nuid = jarc->nuid;
+ v[j].nuid = jarc->nuid;
+ vert_interp( &newjunk[0], &v[loc[0]], &v[loc[2]], param, value );
+
+ if( showingDegenerate() )
+ backend.triangle( &v[i], &newjunk[0], &v[j] );
+
+ vcopy[j+1].param[0]=newjunk[0].param[0];
+ vcopy[j+1].param[1]=newjunk[0].param[1];
+
+
+ jarc1 = new(arcpool) Arc( jarc,
+ new(pwlarcpool) PwlArc(maxvertex-i+1 , newjunk ) );
+
+ jarc->pwlArc->npts = j+2;
+ jarc1->next = jarc->next;
+ jarc1->next->prev = jarc1;
+ jarc->next = jarc1;
+ jarc1->prev = jarc;
+ assert(jarc->check() != 0);
+
+ return 2;
+#endif //not NOTDEF
+ // JEB: This is the original version:
+#ifdef NOTDEF
+ Arc_ptr jarc2, jarc3;
+
+ TrimVertex *newjunk = trimvertexpool.get(3);
+ v[i].nuid = jarc->nuid;
+ v[j].nuid = jarc->nuid;
+ newjunk[0] = v[j];
+ newjunk[2] = v[i];
+ vert_interp( &newjunk[1], &v[loc[0]], &v[loc[2]], param, value );
+
+ if( showingDegenerate() )
+ backend.triangle( &newjunk[2], &newjunk[1], &newjunk[0] );
+
+ // New vertex adjacent to both endpoints
+ if (maxvertex == 2) {
+ jarc1 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk+1 ) );
+ jarc->pwlArc->npts = 2;
+ jarc->pwlArc->pts = newjunk;
+ jarc1->next = jarc->next;
+ jarc1->next->prev = jarc1;
+ jarc->next = jarc1;
+ jarc1->prev = jarc;
+ assert(jarc->check() != 0);
+
+ return 2;
+
+ // New vertex adjacent to ending point of arc
+ } else if (maxvertex - j == 2) {
+ jarc1 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk ) );
+ jarc2 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk+1 ) );
+ jarc->pwlArc->npts = maxvertex-1;
+ jarc2->next = jarc->next;
+ jarc2->next->prev = jarc2;
+ jarc->next = jarc1;
+ jarc1->prev = jarc;
+ jarc1->next = jarc2;
+ jarc2->prev = jarc1;
+ assert(jarc->check() != 0);
+ return 31;
+
+ // New vertex adjacent to starting point of arc
+ } else if (i == 1) {
+ jarc1 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk+1 ) );
+ jarc2 = new(arcpool) Arc( jarc,
+ new(pwlarcpool) PwlArc( maxvertex-1, &jarc->pwlArc->pts[1] ) );
+ jarc->pwlArc->npts = 2;
+ jarc->pwlArc->pts = newjunk;
+ jarc2->next = jarc->next;
+ jarc2->next->prev = jarc2;
+ jarc->next = jarc1;
+ jarc1->prev = jarc;
+ jarc1->next = jarc2;
+ jarc2->prev = jarc1;
+ assert(jarc->check() != 0);
+ return 32;
+
+ // It's somewhere in the middle
+ } else {
+ jarc1 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk ) );
+ jarc2 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( 2, newjunk+1 ) );
+ jarc3 = new(arcpool) Arc( jarc, new(pwlarcpool) PwlArc( maxvertex-i, v+i ) );
+ jarc->pwlArc->npts = j + 1;
+ jarc3->next = jarc->next;
+ jarc3->next->prev = jarc3;
+ jarc->next = jarc1;
+ jarc1->prev = jarc;
+ jarc1->next = jarc2;
+ jarc2->prev = jarc1;
+ jarc2->next = jarc3;
+ jarc3->prev = jarc2;
+ assert(jarc->check() != 0);
+ return 4;
+ }
+#endif // NOTDEF
+ }
+ default:
+ return -1; //picked -1 since it's not used
+ }
+}
+
+/*----------------------------------------------------------------------------
+ * pwlarc_intersect - find intersection of pwlArc and isoparametric line
+ *----------------------------------------------------------------------------
+ */
+
+static enum i_result
+pwlarc_intersect(
+ PwlArc *pwlArc,
+ int param,
+ REAL value,
+ int dir,
+ int loc[3] )
+{
+ assert( pwlArc->npts > 0 );
+
+ if( dir ) {
+ TrimVertex *v = pwlArc->pts;
+ int imin = 0;
+ int imax = pwlArc->npts - 1;
+ assert( value > v[imin].param[param] );
+ assert( value < v[imax].param[param] );
+ while( (imax - imin) > 1 ) {
+ int imid = (imax + imin)/2;
+ if( v[imid].param[param] > value )
+ imax = imid;
+ else if( v[imid].param[param] < value )
+ imin = imid;
+ else {
+ loc[1] = imid;
+ return INTERSECT_VERTEX;
+ }
+ }
+ loc[0] = imin;
+ loc[2] = imax;
+ return INTERSECT_EDGE;
+ } else {
+ TrimVertex *v = pwlArc->pts;
+ int imax = 0;
+ int imin = pwlArc->npts - 1;
+ assert( value > v[imin].param[param] );
+ assert( value < v[imax].param[param] );
+ while( (imin - imax) > 1 ) {
+ int imid = (imax + imin)/2;
+ if( v[imid].param[param] > value )
+ imax = imid;
+ else if( v[imid].param[param] < value )
+ imin = imid;
+ else {
+ loc[1] = imid;
+ return INTERSECT_VERTEX;
+ }
+ }
+ loc[0] = imin;
+ loc[2] = imax;
+ return INTERSECT_EDGE;
+ }
+}
+
+/*----------------------------------------------------------------------------
+ * arc_classify - determine which side of a line a jarc lies
+ *----------------------------------------------------------------------------
+ */
+
+#ifndef NDEBUG // for asserts only
+static int
+arc_classify( Arc_ptr jarc, int param, REAL value )
+{
+ REAL tdiff, hdiff;
+ if( param == 0 ) {
+ tdiff = jarc->tail()[0] - value;
+ hdiff = jarc->head()[0] - value;
+ } else {
+ tdiff = jarc->tail()[1] - value;
+ hdiff = jarc->head()[1] - value;
+ }
+
+ if( tdiff > 0.0 ) {
+ if( hdiff > 0.0 ) {
+ return 0x11;
+ } else if( hdiff == 0.0 ) {
+ return 0x12;
+ } else {
+ return 0x10;
+ }
+ } else if( tdiff == 0.0 ) {
+ if( hdiff > 0.0 ) {
+ return 0x21;
+ } else if( hdiff == 0.0 ) {
+ return 0x22;
+ } else {
+ return 0x20;
+ }
+ } else {
+ if( hdiff > 0.0 ) {
+ return 0x01;
+ } else if( hdiff == 0.0 ) {
+ return 0x02;
+ } else {
+ return 0;
+ }
+ }
+}
+#endif
+
+void
+Subdivider::classify_tailonleft_s( Bin& bin, Bin& in, Bin& out, REAL val )
+{
+ /* tail at left, head on line */
+ Arc_ptr j;
+
+ while( (j = bin.removearc()) != NULL ) {
+ assert( arc_classify( j, 0, val ) == 0x02 );
+ j->clearitail();
+
+ REAL diff = j->next->head()[0] - val;
+ if( diff > 0.0 ) {
+ in.addarc( j );
+ } else if( diff < 0.0 ) {
+ if( ccwTurn_sl( j, j->next ) )
+ out.addarc( j );
+ else
+ in.addarc( j );
+ } else {
+ if( j->next->tail()[1] > j->next->head()[1] )
+ in.addarc(j);
+ else
+ out.addarc(j);
+ }
+ }
+}
+
+void
+Subdivider::classify_tailonleft_t( Bin& bin, Bin& in, Bin& out, REAL val )
+{
+ /* tail at left, head on line */
+ Arc_ptr j;
+
+ while( (j = bin.removearc()) != NULL ) {
+ assert( arc_classify( j, 1, val ) == 0x02 );
+ j->clearitail();
+
+ REAL diff = j->next->head()[1] - val;
+ if( diff > 0.0 ) {
+ in.addarc( j );
+ } else if( diff < 0.0 ) {
+ if( ccwTurn_tl( j, j->next ) )
+ out.addarc( j );
+ else
+ in.addarc( j );
+ } else {
+ if (j->next->tail()[0] > j->next->head()[0] )
+ out.addarc( j );
+ else
+ in.addarc( j );
+ }
+ }
+}
+
+void
+Subdivider::classify_headonleft_s( Bin& bin, Bin& in, Bin& out, REAL val )
+{
+ /* tail on line, head at left */
+ Arc_ptr j;
+
+ while( (j = bin.removearc()) != NULL ) {
+ assert( arc_classify( j, 0, val ) == 0x20 );
+
+ j->setitail();
+
+ REAL diff = j->prev->tail()[0] - val;
+ if( diff > 0.0 ) {
+ out.addarc( j );
+ } else if( diff < 0.0 ) {
+ if( ccwTurn_sl( j->prev, j ) )
+ out.addarc( j );
+ else
+ in.addarc( j );
+ } else {
+ if( j->prev->tail()[1] > j->prev->head()[1] )
+ in.addarc( j );
+ else
+ out.addarc( j );
+ }
+ }
+}
+
+void
+Subdivider::classify_headonleft_t( Bin& bin, Bin& in, Bin& out, REAL val )
+{
+ /* tail on line, head at left */
+ Arc_ptr j;
+
+ while( (j = bin.removearc()) != NULL ) {
+ assert( arc_classify( j, 1, val ) == 0x20 );
+ j->setitail();
+
+ REAL diff = j->prev->tail()[1] - val;
+ if( diff > 0.0 ) {
+ out.addarc( j );
+ } else if( diff < 0.0 ) {
+ if( ccwTurn_tl( j->prev, j ) )
+ out.addarc( j );
+ else
+ in.addarc( j );
+ } else {
+ if( j->prev->tail()[0] > j->prev->head()[0] )
+ out.addarc( j );
+ else
+ in.addarc( j );
+ }
+ }
+}
+
+
+void
+Subdivider::classify_tailonright_s( Bin& bin, Bin& in, Bin& out, REAL val )
+{
+ /* tail at right, head on line */
+ Arc_ptr j;
+
+ while( (j = bin.removearc()) != NULL ) {
+ assert( arc_classify( j, 0, val ) == 0x12);
+
+ j->clearitail();
+
+ REAL diff = j->next->head()[0] - val;
+ if( diff > 0.0 ) {
+ if( ccwTurn_sr( j, j->next ) )
+ out.addarc( j );
+ else
+ in.addarc( j );
+ } else if( diff < 0.0 ) {
+ in.addarc( j );
+ } else {
+ if( j->next->tail()[1] > j->next->head()[1] )
+ out.addarc( j );
+ else
+ in.addarc( j );
+ }
+ }
+}
+
+void
+Subdivider::classify_tailonright_t( Bin& bin, Bin& in, Bin& out, REAL val )
+{
+ /* tail at right, head on line */
+ Arc_ptr j;
+
+ while( (j = bin.removearc()) != NULL ) {
+ assert( arc_classify( j, 1, val ) == 0x12);
+
+ j->clearitail();
+
+ REAL diff = j->next->head()[1] - val;
+ if( diff > 0.0 ) {
+ if( ccwTurn_tr( j, j->next ) )
+ out.addarc( j );
+ else
+ in.addarc( j );
+ } else if( diff < 0.0 ) {
+ in.addarc( j );
+ } else {
+ if( j->next->tail()[0] > j->next->head()[0] )
+ in.addarc( j );
+ else
+ out.addarc( j );
+ }
+ }
+}
+
+void
+Subdivider::classify_headonright_s( Bin& bin, Bin& in, Bin& out, REAL val )
+{
+ /* tail on line, head at right */
+ Arc_ptr j;
+
+ while( (j = bin.removearc()) != NULL ) {
+ assert( arc_classify( j, 0, val ) == 0x21 );
+
+ j->setitail();
+
+ REAL diff = j->prev->tail()[0] - val;
+ if( diff > 0.0 ) {
+ if( ccwTurn_sr( j->prev, j ) )
+ out.addarc( j );
+ else
+ in.addarc( j );
+ } else if( diff < 0.0 ) {
+ out.addarc( j );
+ } else {
+ if( j->prev->tail()[1] > j->prev->head()[1] )
+ out.addarc( j );
+ else
+ in.addarc( j );
+ }
+ }
+}
+
+void
+Subdivider::classify_headonright_t( Bin& bin, Bin& in, Bin& out, REAL val )
+{
+ /* tail on line, head at right */
+ Arc_ptr j;
+
+ while( (j = bin.removearc()) != NULL ) {
+ assert( arc_classify( j, 1, val ) == 0x21 );
+
+ j->setitail();
+
+ REAL diff = j->prev->tail()[1] - val;
+ if( diff > 0.0 ) {
+ if( ccwTurn_tr( j->prev, j ) )
+ out.addarc( j );
+ else
+ in.addarc( j );
+ } else if( diff < 0.0 ) {
+ out.addarc( j );
+ } else {
+ if( j->prev->tail()[0] > j->prev->head()[0] )
+ in.addarc( j );
+ else
+ out.addarc( j );
+ }
+ }
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/jarcloc.h b/mesalib/src/glu/sgi/libnurbs/internals/jarcloc.h
new file mode 100644
index 000000000..5297036fa
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/jarcloc.h
@@ -0,0 +1,87 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * jarcloc.h
+ *
+ */
+
+#ifndef __glujarcloc_h_
+#define __glujarcloc_h_
+
+#include "arc.h"
+
+class Jarcloc {
+private:
+ Arc_ptr arc;
+ TrimVertex *p;
+ TrimVertex *plast;
+public:
+ inline void init( Arc_ptr a, long first, long last ) { arc = a; p=&a->pwlArc->pts[first]; plast = &a->pwlArc->pts[last]; }
+ inline TrimVertex * getnextpt( void );
+ inline TrimVertex * getprevpt( void );
+ inline void reverse();
+};
+
+inline void
+Jarcloc::reverse()
+{
+ if( plast == &arc->pwlArc->pts[0] )
+ plast = &arc->pwlArc->pts[arc->pwlArc->npts - 1];
+ else
+ plast = &arc->pwlArc->pts[0];
+}
+
+inline TrimVertex *
+Jarcloc::getnextpt()
+{
+ assert( p <= plast );
+ if( p == plast ) {
+ arc = arc->next;
+ p = &arc->pwlArc->pts[0];
+ plast = &arc->pwlArc->pts[arc->pwlArc->npts - 1];
+ assert( p < plast );
+ }
+ return p++;
+}
+
+inline TrimVertex *
+Jarcloc::getprevpt()
+{
+ assert( p >= plast );
+ if( p == plast ) {
+ arc = arc->prev;
+ p = &arc->pwlArc->pts[arc->pwlArc->npts - 1];
+ plast = &arc->pwlArc->pts[0];
+ assert( p > plast );
+ }
+ return p--;
+}
+#endif /* __glujarcloc_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/knotvector.cc b/mesalib/src/glu/sgi/libnurbs/internals/knotvector.cc
new file mode 100644
index 000000000..9eb5cbace
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/knotvector.cc
@@ -0,0 +1,139 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * knotvector.c++
+ *
+ */
+
+#include "glimports.h"
+#include "mystdio.h"
+#include "myassert.h"
+#include "knotvector.h"
+#include "defines.h"
+
+#ifdef __WATCOMC__
+#pragma warning 726 10
+#endif
+
+void Knotvector::init( long _knotcount, long _stride, long _order, INREAL *_knotlist )
+{
+ knotcount = _knotcount;
+ stride = _stride;
+ order = _order;
+ knotlist = new Knot[_knotcount];
+ assert( knotlist != 0 );
+
+ for( int i = 0; i != _knotcount; i++ )
+ knotlist[i] = (Knot) _knotlist[i];
+}
+
+Knotvector::Knotvector( void )
+{
+ knotlist = 0;
+}
+
+Knotvector::~Knotvector( void )
+{
+ if( knotlist ) delete[] knotlist;
+}
+
+int Knotvector::validate( void )
+{
+ /* kindex is used as an array index so subtract one first,
+ * this propagates throughout the code so study carefully */
+ long kindex = knotcount-1;
+
+ if( order < 1 || order > MAXORDER ) {
+ // spline order un-supported
+ return( 1 );
+ }
+
+ if( knotcount < (2 * order) ) {
+ // too few knots
+ return( 2 );
+ }
+
+ if( identical( knotlist[kindex-(order-1)], knotlist[order-1]) ) {
+ // valid knot range is empty
+ return( 3 );
+ }
+
+ for( long i = 0; i < kindex; i++)
+ if( knotlist[i] > knotlist[i+1] ) {
+ // decreasing knot sequence
+ return( 4 );
+ }
+
+ /* check for valid multiplicity */
+
+ /* kindex is currently the index of the last knot.
+ * In the next loop it is decremented to ignore the last knot
+ * and the loop stops when kindex is 2 so as to ignore the first
+ * knot as well. These knots are not used in computing
+ * knot multiplicities.
+ */
+
+ long multi = 1;
+ for( ; kindex >= 1; kindex-- ) {
+ if( knotlist[kindex] - knotlist[kindex-1] < TOLERANCE ) {
+ multi++;
+ continue;
+ }
+ if ( multi > order ) {
+ // knot multiplicity greater than order of spline
+ return( 5 );
+ }
+ multi = 1;
+ }
+
+ if ( multi > order ) {
+ // knot multiplicity greater than order of spline
+ return( 5 );
+ }
+
+ return 0;
+}
+
+void Knotvector::show( const char *msg )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "%s\n", msg );
+ _glu_dprintf( "order = %ld, count = %ld\n", order, knotcount );
+
+ for( int i=0; i<knotcount; i++ )
+ _glu_dprintf( "knot[%d] = %g\n", i, knotlist[i] );
+#endif
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/knotvector.h b/mesalib/src/glu/sgi/libnurbs/internals/knotvector.h
new file mode 100644
index 000000000..85b162f6f
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/knotvector.h
@@ -0,0 +1,62 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * knotvector.h
+ *
+ */
+
+#ifndef __gluknotvector_h_
+#define __gluknotvector_h_
+
+#include "types.h"
+
+struct Knotvector { /* a knot vector */
+ Knotvector( void );
+ ~Knotvector( void );
+ void init( long, long, long, INREAL * );
+ int validate( void );
+ void show( const char * );
+
+ long order; /* order of spline */
+ long knotcount; /* number of knots */
+ long stride; /* bytes between points */
+ Knot * knotlist; /* global knot vector */
+};
+
+/* tolerance to test knot coincidence */
+#define TOLERANCE 1.0e-5
+
+inline int
+identical( Knot x, Knot y )
+{
+ return ((x-y) < TOLERANCE) ? 1 : 0;
+}
+#endif /* __gluknotvector_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/mapdesc.cc b/mesalib/src/glu/sgi/libnurbs/internals/mapdesc.cc
new file mode 100644
index 000000000..d59f8fd39
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/mapdesc.cc
@@ -0,0 +1,841 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * mapdesc.c++
+ *
+ */
+
+#include <stdio.h>
+#include "glimports.h"
+#include "mystdio.h"
+#include "myassert.h"
+#include "mystring.h"
+#include "mymath.h"
+#include "backend.h"
+#include "nurbsconsts.h"
+#include "mapdesc.h"
+
+Mapdesc::Mapdesc( long _type, int _israt, int _ncoords, Backend& b )
+ : backend( b )
+{
+ type = _type;
+ isrational = _israt;
+ ncoords = _ncoords;
+ hcoords = _ncoords + (_israt ? 0 : 1 );
+ inhcoords = _ncoords - (_israt ? 1 : 0 );
+ mask = ((1<<(inhcoords*2))-1);
+ next = 0;
+
+ assert( hcoords <= MAXCOORDS );
+ assert( inhcoords >= 1 );
+
+ pixel_tolerance = 1.0;
+ error_tolerance = 1.0;
+ bbox_subdividing = N_NOBBOXSUBDIVISION;
+ culling_method = N_NOCULLING;
+ sampling_method = N_NOSAMPLING;
+ clampfactor = N_NOCLAMPING;
+ minsavings = N_NOSAVINGSSUBDIVISION;
+ s_steps = 0.0;
+ t_steps = 0.0;
+ maxrate = ( s_steps < 0.0 ) ? 0.0 : s_steps;
+ maxsrate = ( s_steps < 0.0 ) ? 0.0 : s_steps;
+ maxtrate = ( t_steps < 0.0 ) ? 0.0 : t_steps;
+ identify( bmat );
+ identify( cmat );
+ identify( smat );
+ for( int i = 0; i != inhcoords; i++ )
+ bboxsize[i] = 1.0;
+}
+
+void
+Mapdesc::setBboxsize( INREAL *mat )
+{
+ for( int i = 0; i != inhcoords; i++ )
+ bboxsize[i] = (REAL) mat[i];
+}
+
+void
+Mapdesc::identify( REAL dest[MAXCOORDS][MAXCOORDS] )
+{
+ memset( dest, 0, sizeof( dest ) );
+ for( int i=0; i != hcoords; i++ )
+ dest[i][i] = 1.0;
+}
+
+void
+Mapdesc::surfbbox( REAL bb[2][MAXCOORDS] )
+{
+ backend.surfbbox( type, bb[0], bb[1] );
+}
+
+void
+Mapdesc::copy( REAL dest[MAXCOORDS][MAXCOORDS], long n, INREAL *src,
+ long rstride, long cstride )
+{
+ assert( n >= 0 );
+ for( int i=0; i != n; i++ )
+ for( int j=0; j != n; j++ )
+ dest[i][j] = src[i*rstride + j*cstride];
+}
+
+/*--------------------------------------------------------------------------
+ * copyPt - copy a homogeneous point
+ *--------------------------------------------------------------------------
+ */
+void
+Mapdesc::copyPt( REAL *d, REAL *s )
+{
+ assert( hcoords > 0 );
+ switch( hcoords ) {
+ case 4:
+ d[3] = s[3];
+ d[2] = s[2];
+ d[1] = s[1];
+ d[0] = s[0];
+ break;
+ case 3:
+ d[2] = s[2];
+ d[1] = s[1];
+ d[0] = s[0];
+ break;
+ case 2:
+ d[1] = s[1];
+ d[0] = s[0];
+ break;
+ case 1:
+ d[0] = s[0];
+ break;
+ case 5:
+ d[4] = s[4];
+ d[3] = s[3];
+ d[2] = s[2];
+ d[1] = s[1];
+ d[0] = s[0];
+ break;
+ default:
+ memcpy( d, s, hcoords * sizeof( REAL ) );
+ break;
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * sumPt - compute affine combination of two homogeneous points
+ *--------------------------------------------------------------------------
+ */
+void
+Mapdesc::sumPt( REAL *dst, REAL *src1, REAL *src2, register REAL alpha, register REAL beta )
+{
+ assert( hcoords > 0 );
+ switch( hcoords ) {
+ case 4:
+ dst[3] = src1[3] * alpha + src2[3] * beta;
+ dst[2] = src1[2] * alpha + src2[2] * beta;
+ dst[1] = src1[1] * alpha + src2[1] * beta;
+ dst[0] = src1[0] * alpha + src2[0] * beta;
+ break;
+ case 3:
+ dst[2] = src1[2] * alpha + src2[2] * beta;
+ dst[1] = src1[1] * alpha + src2[1] * beta;
+ dst[0] = src1[0] * alpha + src2[0] * beta;
+ break;
+ case 2:
+ dst[1] = src1[1] * alpha + src2[1] * beta;
+ dst[0] = src1[0] * alpha + src2[0] * beta;
+ break;
+ case 1:
+ dst[0] = src1[0] * alpha + src2[0] * beta;
+ break;
+ case 5:
+ dst[4] = src1[4] * alpha + src2[4] * beta;
+ dst[3] = src1[3] * alpha + src2[3] * beta;
+ dst[2] = src1[2] * alpha + src2[2] * beta;
+ dst[1] = src1[1] * alpha + src2[1] * beta;
+ dst[0] = src1[0] * alpha + src2[0] * beta;
+ break;
+ default: {
+ for( int i = 0; i != hcoords; i++ )
+ dst[i] = src1[i] * alpha + src2[i] * beta;
+ }
+ break;
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * clipbits - compute bit-vector indicating point/window position
+ * of a (transformed) homogeneous point
+ *--------------------------------------------------------------------------
+ */
+unsigned int
+Mapdesc::clipbits( REAL *p )
+{
+ assert( inhcoords >= 0 );
+ assert( inhcoords <= 3 );
+
+ register int nc = inhcoords;
+ register REAL pw = p[nc];
+ register REAL nw = -pw;
+ register unsigned int bits = 0;
+
+ if( pw == 0.0 ) return mask;
+
+ if( pw > 0.0 ) {
+ switch( nc ) {
+ case 3:
+ if( p[2] <= pw ) bits |= (1<<5);
+ if( p[2] >= nw ) bits |= (1<<4);
+ if( p[1] <= pw ) bits |= (1<<3);
+ if( p[1] >= nw ) bits |= (1<<2);
+ if( p[0] <= pw ) bits |= (1<<1);
+ if( p[0] >= nw ) bits |= (1<<0);
+ return bits;
+ case 2:
+ if( p[1] <= pw ) bits |= (1<<3);
+ if( p[1] >= nw ) bits |= (1<<2);
+ if( p[0] <= pw ) bits |= (1<<1);
+ if( p[0] >= nw ) bits |= (1<<0);
+ return bits;
+ case 1:
+ if( p[0] <= pw ) bits |= (1<<1);
+ if( p[0] >= nw ) bits |= (1<<0);
+ return bits;
+ default: {
+ int bit = 1;
+ for( int i=0; i<nc; i++ ) {
+ if( p[i] >= nw ) bits |= bit;
+ bit <<= 1;
+ if( p[i] <= pw ) bits |= bit;
+ bit <<= 1;
+ }
+ abort();
+ break;
+ }
+ }
+ } else {
+ switch( nc ) {
+ case 3:
+ if( p[2] <= nw ) bits |= (1<<5);
+ if( p[2] >= pw ) bits |= (1<<4);
+ if( p[1] <= nw ) bits |= (1<<3);
+ if( p[1] >= pw ) bits |= (1<<2);
+ if( p[0] <= nw ) bits |= (1<<1);
+ if( p[0] >= pw ) bits |= (1<<0);
+ return bits;
+ case 2:
+ if( p[1] <= nw ) bits |= (1<<3);
+ if( p[1] >= pw ) bits |= (1<<2);
+ if( p[0] <= nw ) bits |= (1<<1);
+ if( p[0] >= pw ) bits |= (1<<0);
+ return bits;
+ case 1:
+ if( p[0] <= nw ) bits |= (1<<1);
+ if( p[0] >= pw ) bits |= (1<<0);
+ return bits;
+ default: {
+ int bit = 1;
+ for( int i=0; i<nc; i++ ) {
+ if( p[i] >= pw ) bits |= bit;
+ bit <<= 1;
+ if( p[i] <= nw ) bits |= bit;
+ bit <<= 1;
+ }
+ abort();
+ break;
+ }
+ }
+ }
+ return bits;
+}
+
+/*--------------------------------------------------------------------------
+ * xformRational - transform a homogeneous point
+ *--------------------------------------------------------------------------
+ */
+void
+Mapdesc::xformRational( Maxmatrix mat, REAL *d, REAL *s )
+{
+ assert( hcoords >= 0 );
+
+ if( hcoords == 3 ) {
+ REAL x = s[0];
+ REAL y = s[1];
+ REAL z = s[2];
+ d[0] = x*mat[0][0]+y*mat[1][0]+z*mat[2][0];
+ d[1] = x*mat[0][1]+y*mat[1][1]+z*mat[2][1];
+ d[2] = x*mat[0][2]+y*mat[1][2]+z*mat[2][2];
+ } else if( hcoords == 4 ) {
+ REAL x = s[0];
+ REAL y = s[1];
+ REAL z = s[2];
+ REAL w = s[3];
+ d[0] = x*mat[0][0]+y*mat[1][0]+z*mat[2][0]+w*mat[3][0];
+ d[1] = x*mat[0][1]+y*mat[1][1]+z*mat[2][1]+w*mat[3][1];
+ d[2] = x*mat[0][2]+y*mat[1][2]+z*mat[2][2]+w*mat[3][2];
+ d[3] = x*mat[0][3]+y*mat[1][3]+z*mat[2][3]+w*mat[3][3];
+ } else {
+ for( int i=0; i != hcoords; i++ ) {
+ d[i] = 0;
+ for( int j = 0; j != hcoords; j++ )
+ d[i] += s[j] * mat[j][i];
+ }
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * xformNonrational - transform a inhomogeneous point to a homogeneous point
+ *--------------------------------------------------------------------------
+ */
+void
+Mapdesc::xformNonrational( Maxmatrix mat, REAL *d, REAL *s )
+{
+ if( inhcoords == 2 ) {
+ REAL x = s[0];
+ REAL y = s[1];
+ d[0] = x*mat[0][0]+y*mat[1][0]+mat[2][0];
+ d[1] = x*mat[0][1]+y*mat[1][1]+mat[2][1];
+ d[2] = x*mat[0][2]+y*mat[1][2]+mat[2][2];
+ } else if( inhcoords == 3 ) {
+ REAL x = s[0];
+ REAL y = s[1];
+ REAL z = s[2];
+ d[0] = x*mat[0][0]+y*mat[1][0]+z*mat[2][0]+mat[3][0];
+ d[1] = x*mat[0][1]+y*mat[1][1]+z*mat[2][1]+mat[3][1];
+ d[2] = x*mat[0][2]+y*mat[1][2]+z*mat[2][2]+mat[3][2];
+ d[3] = x*mat[0][3]+y*mat[1][3]+z*mat[2][3]+mat[3][3];
+ } else {
+ assert( inhcoords >= 0 );
+ for( int i=0; i != hcoords; i++ ) {
+ d[i] = mat[inhcoords][i];
+ for( int j = 0; j < inhcoords; j++ )
+ d[i] += s[j] * mat[j][i];
+ }
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * xformAndCullCheck - transform a set of points that may be EITHER
+ * homogeneous or inhomogeneous depending on the map description and
+ * check if they are either completely inside, completely outside,
+ * or intersecting the viewing frustrum.
+ *--------------------------------------------------------------------------
+ */
+int
+Mapdesc::xformAndCullCheck(
+ REAL *pts, int uorder, int ustride, int vorder, int vstride )
+{
+ assert( uorder > 0 );
+ assert( vorder > 0 );
+
+ unsigned int inbits = mask;
+ unsigned int outbits = 0;
+
+ REAL *p = pts;
+ for( REAL *pend = p + uorder * ustride; p != pend; p += ustride ) {
+ REAL *q = p;
+ for( REAL *qend = q + vorder * vstride; q != qend; q += vstride ) {
+ REAL cpts[MAXCOORDS];
+ xformCulling( cpts, q );
+ unsigned int bits = clipbits( cpts );
+ outbits |= bits;
+ inbits &= bits;
+ if( ( outbits == (unsigned int)mask ) && ( inbits != (unsigned int)mask ) ) return CULL_ACCEPT;
+ }
+ }
+
+ if( outbits != (unsigned int)mask ) {
+ return CULL_TRIVIAL_REJECT;
+ } else if( inbits == (unsigned int)mask ) {
+ return CULL_TRIVIAL_ACCEPT;
+ } else {
+ return CULL_ACCEPT;
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * cullCheck - check if a set of homogeneous transformed points are
+ * either completely inside, completely outside,
+ * or intersecting the viewing frustrum.
+ *--------------------------------------------------------------------------
+ */
+int
+Mapdesc::cullCheck( REAL *pts, int uorder, int ustride, int vorder, int vstride )
+{
+ unsigned int inbits = mask;
+ unsigned int outbits = 0;
+
+ REAL *p = pts;
+ for( REAL *pend = p + uorder * ustride; p != pend; p += ustride ) {
+ REAL *q = p;
+ for( REAL *qend = q + vorder * vstride; q != qend; q += vstride ) {
+ unsigned int bits = clipbits( q );
+ outbits |= bits;
+ inbits &= bits;
+ if( ( outbits == (unsigned int)mask ) && ( inbits != (unsigned int)mask ) ) return CULL_ACCEPT;
+ }
+ }
+
+ if( outbits != (unsigned int)mask ) {
+ return CULL_TRIVIAL_REJECT;
+ } else if( inbits == (unsigned int)mask ) {
+ return CULL_TRIVIAL_ACCEPT;
+ } else {
+ return CULL_ACCEPT;
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * cullCheck - check if a set of homogeneous transformed points are
+ * either completely inside, completely outside,
+ * or intersecting the viewing frustrum.
+ *--------------------------------------------------------------------------
+ */
+int
+Mapdesc::cullCheck( REAL *pts, int order, int stride )
+{
+ unsigned int inbits = mask;
+ unsigned int outbits = 0;
+
+ REAL *p = pts;
+ for( REAL *pend = p + order * stride; p != pend; p += stride ) {
+ unsigned int bits = clipbits( p );
+ outbits |= bits;
+ inbits &= bits;
+ if( ( outbits == (unsigned int)mask ) && ( inbits != (unsigned int)mask ) ) return CULL_ACCEPT;
+ }
+
+ if( outbits != (unsigned int)mask ) {
+ return CULL_TRIVIAL_REJECT;
+ } else if( inbits == (unsigned int)mask ) {
+ return CULL_TRIVIAL_ACCEPT;
+ } else {
+ return CULL_ACCEPT;
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * xformSampling - transform a set of points that may be EITHER
+ * homogeneous or inhomogeneous depending on the map description
+ * into sampling space
+ *--------------------------------------------------------------------------
+ */
+void
+Mapdesc::xformSampling( REAL *pts, int order, int stride, REAL *sp, int outstride )
+{
+ xformMat( smat, pts, order, stride, sp, outstride );
+}
+
+void
+Mapdesc::xformBounding( REAL *pts, int order, int stride, REAL *sp, int outstride )
+{
+ xformMat( bmat, pts, order, stride, sp, outstride );
+}
+
+/*--------------------------------------------------------------------------
+ * xformCulling - transform a set of points that may be EITHER
+ * homogeneous or inhomogeneous depending on the map description
+ * into culling space
+ *--------------------------------------------------------------------------
+ */
+void
+Mapdesc::xformCulling( REAL *pts, int order, int stride, REAL *cp, int outstride )
+{
+ xformMat( cmat, pts, order, stride, cp, outstride );
+}
+
+/*--------------------------------------------------------------------------
+ * xformCulling - transform a set of points that may be EITHER
+ * homogeneous or inhomogeneous depending on the map description
+ * into culling space
+ *--------------------------------------------------------------------------
+ */
+void
+Mapdesc::xformCulling( REAL *pts,
+ int uorder, int ustride,
+ int vorder, int vstride,
+ REAL *cp, int outustride, int outvstride )
+{
+ xformMat( cmat, pts, uorder, ustride, vorder, vstride, cp, outustride, outvstride );
+}
+
+/*--------------------------------------------------------------------------
+ * xformSampling - transform a set of points that may be EITHER
+ * homogeneous or inhomogeneous depending on the map description
+ * into sampling space
+ *--------------------------------------------------------------------------
+ */
+void
+Mapdesc::xformSampling( REAL *pts,
+ int uorder, int ustride,
+ int vorder, int vstride,
+ REAL *sp, int outustride, int outvstride )
+{
+ xformMat( smat, pts, uorder, ustride, vorder, vstride, sp, outustride, outvstride );
+}
+
+void
+Mapdesc::xformBounding( REAL *pts,
+ int uorder, int ustride,
+ int vorder, int vstride,
+ REAL *sp, int outustride, int outvstride )
+{
+ xformMat( bmat, pts, uorder, ustride, vorder, vstride, sp, outustride, outvstride );
+}
+
+void
+Mapdesc::xformMat(
+ Maxmatrix mat,
+ REAL * pts,
+ int order,
+ int stride,
+ REAL * cp,
+ int outstride )
+{
+ if( isrational ) {
+ REAL *pend = pts + order * stride;
+ for( REAL *p = pts ; p != pend; p += stride ) {
+ xformRational( mat, cp, p );
+ cp += outstride;
+ }
+ } else {
+ REAL *pend = pts + order * stride;
+ for( REAL *p = pts ; p != pend; p += stride ) {
+ xformNonrational( mat, cp, p );
+ cp += outstride;
+ }
+ }
+}
+
+void
+Mapdesc::xformMat( Maxmatrix mat, REAL *pts,
+ int uorder, int ustride,
+ int vorder, int vstride,
+ REAL *cp, int outustride, int outvstride )
+{
+ if( isrational ) {
+ REAL *pend = pts + uorder * ustride;
+ for( REAL *p = pts ; p != pend; p += ustride ) {
+ REAL *cpts2 = cp;
+ REAL *qend = p + vorder * vstride;
+ for( REAL *q = p; q != qend; q += vstride ) {
+ xformRational( mat, cpts2, q );
+ cpts2 += outvstride;
+ }
+ cp += outustride;
+ }
+ } else {
+ REAL *pend = pts + uorder * ustride;
+ for( REAL *p = pts ; p != pend; p += ustride ) {
+ REAL *cpts2 = cp;
+ REAL *qend = p + vorder * vstride;
+ for( REAL *q = p; q != qend; q += vstride ) {
+ xformNonrational( mat, cpts2, q );
+ cpts2 += outvstride;
+ }
+ cp += outustride;
+ }
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * subdivide - subdivide a curve along an isoparametric line
+ *--------------------------------------------------------------------------
+ */
+
+void
+Mapdesc::subdivide( REAL *src, REAL *dst, REAL v, int stride, int order )
+{
+ REAL mv = 1.0 - v;
+
+ for( REAL *send=src+stride*order; src!=send; send-=stride, dst+=stride ) {
+ copyPt( dst, src );
+ REAL *qpnt = src + stride;
+ for( REAL *qp=src; qpnt!=send; qp=qpnt, qpnt+=stride )
+ sumPt( qp, qp, qpnt, mv, v );
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * subdivide - subdivide a patch along an isoparametric line
+ *--------------------------------------------------------------------------
+ */
+
+void
+Mapdesc::subdivide( REAL *src, REAL *dst, REAL v,
+ int so, int ss, int to, int ts )
+{
+ REAL mv = 1.0 - v;
+
+ for( REAL *slast = src+ss*so; src != slast; src += ss, dst += ss ) {
+ REAL *sp = src;
+ REAL *dp = dst;
+ for( REAL *send = src+ts*to; sp != send; send -= ts, dp += ts ) {
+ copyPt( dp, sp );
+ REAL *qp = sp;
+ for( REAL *qpnt = sp+ts; qpnt != send; qp = qpnt, qpnt += ts )
+ sumPt( qp, qp, qpnt, mv, v );
+ }
+ }
+}
+
+
+#define sign(x) ((x > 0) ? 1 : ((x < 0.0) ? -1 : 0))
+
+/*--------------------------------------------------------------------------
+ * project - project a set of homogeneous coordinates into inhomogeneous ones
+ *--------------------------------------------------------------------------
+ */
+int
+Mapdesc::project( REAL *src, int rstride, int cstride,
+ REAL *dest, int trstride, int tcstride,
+ int nrows, int ncols )
+{
+ int s = sign( src[inhcoords] );
+ REAL *rlast = src + nrows * rstride;
+ REAL *trptr = dest;
+ for( REAL *rptr=src; rptr != rlast; rptr+=rstride, trptr+=trstride ) {
+ REAL *clast = rptr + ncols * cstride;
+ REAL *tcptr = trptr;
+ for( REAL *cptr = rptr; cptr != clast; cptr+=cstride, tcptr+=tcstride ) {
+ REAL *coordlast = cptr + inhcoords;
+ if( sign( *coordlast ) != s ) return 0;
+ REAL *tcoord = tcptr;
+ for( REAL *coord = cptr; coord != coordlast; coord++, tcoord++ ) {
+ *tcoord = *coord / *coordlast;
+ }
+ }
+ }
+ return 1;
+}
+
+/*--------------------------------------------------------------------------
+ * project - project a set of homogeneous coordinates into inhomogeneous ones
+ *--------------------------------------------------------------------------
+ */
+int
+Mapdesc::project( REAL *src, int stride, REAL *dest, int tstride, int ncols )
+{
+ int s = sign( src[inhcoords] );
+
+ REAL *clast = src + ncols * stride;
+ for( REAL *cptr = src, *tcptr = dest; cptr != clast; cptr+=stride, tcptr+=tstride ) {
+ REAL *coordlast = cptr + inhcoords;
+ if( sign( *coordlast ) != s ) return 0;
+ for( REAL *coord = cptr, *tcoord = tcptr; coord != coordlast; coord++, tcoord++ )
+ *tcoord = *coord / *coordlast;
+ }
+
+ return 1;
+}
+
+int
+Mapdesc::bboxTooBig(
+ REAL *p,
+ int rstride,
+ int cstride,
+ int nrows,
+ int ncols,
+ REAL bb[2][MAXCOORDS] )
+{
+ REAL bbpts[MAXORDER][MAXORDER][MAXCOORDS];
+ const int trstride = sizeof(bbpts[0]) / sizeof(REAL);
+ const int tcstride = sizeof(bbpts[0][0]) / sizeof(REAL);
+
+ // points have been transformed, therefore they are homogeneous
+ // project points
+ int val = project( p, rstride, cstride,
+ &bbpts[0][0][0], trstride, tcstride, nrows, ncols );
+ if( val == 0 ) return -1;
+
+ // compute bounding box
+ bbox( bb, &bbpts[0][0][0], trstride, tcstride, nrows, ncols );
+
+ // find out if bounding box can't fit in unit cube
+ if( bbox_subdividing == N_BBOXROUND ) {
+ for( int k=0; k != inhcoords; k++ )
+ if( ceilf(bb[1][k]) - floorf(bb[0][k]) > bboxsize[k] ) return 1;
+ } else {
+ for( int k=0; k != inhcoords; k++ )
+ if( bb[1][k] - bb[0][k] > bboxsize[k] ) return 1;
+ }
+ return 0;
+}
+
+void
+Mapdesc::bbox(
+ REAL bb[2][MAXCOORDS],
+ REAL *p,
+ int rstride,
+ int cstride,
+ int nrows,
+ int ncols )
+{
+ int k;
+ for( k=0; k != inhcoords; k++ )
+ bb[0][k] = bb[1][k] = p[k];
+
+ for( int i=0; i != nrows; i++ )
+ for( int j=0; j != ncols; j++ )
+ for( k=0; k != inhcoords; k++ ) {
+ REAL x = p[i*rstride + j*cstride + k];
+ if( x < bb[0][k] ) bb[0][k] = x;
+ else if( x > bb[1][k] ) bb[1][k] = x;
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * calcVelocityRational - calculate upper bound on first partial derivative
+ * of a homogeneous set of points and bounds on each row of points.
+ *--------------------------------------------------------------------------
+ */
+REAL
+Mapdesc::calcVelocityRational( REAL *p, int stride, int ncols )
+{
+ REAL tmp[MAXORDER][MAXCOORDS];
+
+ assert( ncols <= MAXORDER );
+
+ const int tstride = sizeof(tmp[0]) / sizeof(REAL);
+
+ if( project( p, stride, &tmp[0][0], tstride, ncols ) ) {
+ return calcPartialVelocity( &tmp[0][0], tstride, ncols, 1, 1.0 );
+ } else { /* XXX */
+ return calcPartialVelocity( &tmp[0][0], tstride, ncols, 1, 1.0 );
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * calcVelocityNonrational - calculate upper bound on first partial
+ * derivative of a inhomogeneous set of points.
+ *--------------------------------------------------------------------------
+ */
+REAL
+Mapdesc::calcVelocityNonrational( REAL *pts, int stride, int ncols )
+{
+ return calcPartialVelocity( pts, stride, ncols, 1, 1.0 );
+}
+
+int
+Mapdesc::isProperty( long property )
+{
+ switch ( property ) {
+ case N_PIXEL_TOLERANCE:
+ case N_ERROR_TOLERANCE:
+ case N_CULLING:
+ case N_BBOX_SUBDIVIDING:
+ case N_S_STEPS:
+ case N_T_STEPS:
+ case N_SAMPLINGMETHOD:
+ case N_CLAMPFACTOR:
+ case N_MINSAVINGS:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+REAL
+Mapdesc::getProperty( long property )
+{
+ switch ( property ) {
+ case N_PIXEL_TOLERANCE:
+ return pixel_tolerance;
+ case N_ERROR_TOLERANCE:
+ return error_tolerance;
+ case N_CULLING:
+ return culling_method;
+ case N_BBOX_SUBDIVIDING:
+ return bbox_subdividing;
+ case N_S_STEPS:
+ return s_steps;
+ case N_T_STEPS:
+ return t_steps;
+ case N_SAMPLINGMETHOD:
+ return sampling_method;
+ case N_CLAMPFACTOR:
+ return clampfactor;
+ case N_MINSAVINGS:
+ return minsavings;
+ default:
+ abort();
+ return -1; //not necessary, needed to shut up compiler
+ }
+}
+
+void
+Mapdesc::setProperty( long property, REAL value )
+{
+
+ switch ( property ) {
+ case N_PIXEL_TOLERANCE:
+ pixel_tolerance = value;
+ break;
+ case N_ERROR_TOLERANCE:
+ error_tolerance = value;
+ break;
+ case N_CULLING:
+ culling_method = value;
+ break;
+ case N_BBOX_SUBDIVIDING:
+ if( value <= 0.0 ) value = N_NOBBOXSUBDIVISION;
+ bbox_subdividing = value;
+ break;
+ case N_S_STEPS:
+ if( value < 0.0 ) value = 0.0;
+ s_steps = value;
+ maxrate = ( value < 0.0 ) ? 0.0 : value;
+ maxsrate = ( value < 0.0 ) ? 0.0 : value;
+ break;
+ case N_T_STEPS:
+ if( value < 0.0 ) value = 0.0;
+ t_steps = value;
+ maxtrate = ( value < 0.0 ) ? 0.0 : value;
+ break;
+ case N_SAMPLINGMETHOD:
+ sampling_method = value;
+ break;
+ case N_CLAMPFACTOR:
+ if( value <= 0.0 ) value = N_NOCLAMPING;
+ clampfactor = value;
+ break;
+ case N_MINSAVINGS:
+ if( value <= 0.0 ) value = N_NOSAVINGSSUBDIVISION;
+ minsavings = value;
+ break;
+ default:
+ abort();
+ break;
+ }
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/mapdesc.h b/mesalib/src/glu/sgi/libnurbs/internals/mapdesc.h
new file mode 100644
index 000000000..6f06154f9
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/mapdesc.h
@@ -0,0 +1,271 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * mapdesc.h
+ *
+ */
+
+#ifndef __glumapdesc_h_
+#define __glumapdesc_h_
+
+#include "mystdio.h"
+#include "types.h"
+#include "defines.h"
+#include "bufpool.h"
+#include "nurbsconsts.h"
+
+typedef REAL Maxmatrix[MAXCOORDS][MAXCOORDS];
+
+class Backend;
+
+class Mapdesc : public PooledObj {
+ friend class Maplist;
+
+public:
+ Mapdesc( long, int, int, Backend & );
+ int isProperty( long );
+ REAL getProperty( long );
+ void setProperty( long, REAL );
+ int isConstantSampling( void );
+ int isDomainSampling( void );
+ int isRangeSampling( void );
+ int isSampling( void );
+ int isParametricDistanceSampling( void );
+ int isObjectSpaceParaSampling( void );
+ int isObjectSpacePathSampling( void );
+ int isSurfaceAreaSampling( void );
+ int isPathLengthSampling( void );
+ int isCulling( void );
+ int isBboxSubdividing( void );
+ long getType( void );
+
+ /* curve routines */
+ void subdivide( REAL *, REAL *, REAL, int, int );
+ int cullCheck( REAL *, int, int );
+ void xformBounding( REAL *, int, int, REAL *, int );
+ void xformCulling( REAL *, int, int, REAL *, int );
+ void xformSampling( REAL *, int, int, REAL *, int );
+ void xformMat( Maxmatrix, REAL *, int, int, REAL *, int );
+ REAL calcPartialVelocity ( REAL *, int, int, int, REAL );
+ int project( REAL *, int, REAL *, int, int );
+ REAL calcVelocityRational( REAL *, int, int );
+ REAL calcVelocityNonrational( REAL *, int, int );
+
+ /* surface routines */
+ void subdivide( REAL *, REAL *, REAL, int, int, int, int );
+ int cullCheck( REAL *, int, int, int, int );
+ void xformBounding( REAL *, int, int, int, int, REAL *, int, int );
+ void xformCulling( REAL *, int, int, int, int, REAL *, int, int );
+ void xformSampling( REAL *, int, int, int, int, REAL *, int, int );
+ void xformMat( Maxmatrix, REAL *, int, int, int, int, REAL *, int, int );
+ REAL calcPartialVelocity ( REAL *, REAL *, int, int, int, int, int, int, REAL, REAL, int );
+ int project( REAL *, int, int, REAL *, int, int, int, int);
+ void surfbbox( REAL bb[2][MAXCOORDS] );
+
+ int bboxTooBig( REAL *, int, int, int, int, REAL [2][MAXCOORDS] );
+ int xformAndCullCheck( REAL *, int, int, int, int );
+
+ void identify( REAL[MAXCOORDS][MAXCOORDS] );
+ void setBboxsize( INREAL *);
+ inline void setBmat( INREAL*, long, long );
+ inline void setCmat( INREAL*, long, long );
+ inline void setSmat( INREAL*, long, long );
+ inline int isRational( void );
+ inline int getNcoords( void );
+
+ REAL pixel_tolerance; /* pathlength sampling tolerance */
+ REAL error_tolerance; /* parametric error sampling tolerance*/
+ REAL object_space_error_tolerance; /* object space tess*/
+ REAL clampfactor;
+ REAL minsavings;
+ REAL maxrate;
+ REAL maxsrate;
+ REAL maxtrate;
+ REAL bboxsize[MAXCOORDS];
+
+private:
+ long type;
+ int isrational;
+ int ncoords;
+ int hcoords;
+ int inhcoords;
+ int mask;
+ Maxmatrix bmat;
+ Maxmatrix cmat;
+ Maxmatrix smat;
+ REAL s_steps; /* max samples in s direction */
+ REAL t_steps; /* max samples in t direction */
+ REAL sampling_method;
+ REAL culling_method; /* check for culling */
+ REAL bbox_subdividing;
+ Mapdesc * next;
+ Backend & backend;
+
+ void bbox( REAL [2][MAXCOORDS], REAL *, int, int, int, int );
+ REAL maxDifference( int, REAL *, int );
+ static void copy( Maxmatrix, long, INREAL *, long, long );
+
+ /* individual control point routines */
+ static void transform4d( float[4], float[4], float[4][4] );
+ static void multmatrix4d ( float[4][4], const float[4][4],
+ const float[4][4] );
+ void copyPt( REAL *, REAL * );
+ void sumPt( REAL *, REAL *, REAL *, REAL, REAL );
+ void xformSampling( REAL *, REAL * );
+ void xformCulling( REAL *, REAL * );
+ void xformRational( Maxmatrix, REAL *, REAL * );
+ void xformNonrational( Maxmatrix, REAL *, REAL * );
+ unsigned int clipbits( REAL * );
+};
+
+inline void
+Mapdesc::setBmat( INREAL *mat, long rstride, long cstride )
+{
+ copy( bmat, hcoords, mat, rstride, cstride );
+}
+
+inline void
+Mapdesc::setCmat( INREAL *mat, long rstride, long cstride )
+{
+ copy( cmat, hcoords, mat, rstride, cstride );
+}
+
+inline void
+Mapdesc::setSmat( INREAL *mat, long rstride, long cstride )
+{
+ copy( smat, hcoords, mat, rstride, cstride );
+}
+
+inline long
+Mapdesc::getType( void )
+{
+ return type;
+}
+
+inline void
+Mapdesc::xformCulling( REAL *d, REAL *s )
+{
+ if( isrational )
+ xformRational( cmat, d, s );
+ else
+ xformNonrational( cmat, d, s );
+}
+
+inline void
+Mapdesc::xformSampling( REAL *d, REAL *s )
+{
+ if( isrational )
+ xformRational( smat, d, s );
+ else
+ xformNonrational( smat, d, s );
+}
+
+inline int
+Mapdesc::isRational( void )
+{
+ return isrational ? 1 : 0;
+}
+
+inline int
+Mapdesc::getNcoords( void )
+{
+ return ncoords;
+}
+
+inline int
+Mapdesc::isConstantSampling( void )
+{
+ return ((sampling_method == N_FIXEDRATE) ? 1 : 0);
+}
+
+inline int
+Mapdesc::isDomainSampling( void )
+{
+ return ((sampling_method == N_DOMAINDISTANCE) ? 1 : 0);
+}
+
+inline int
+Mapdesc::isParametricDistanceSampling( void )
+{
+ return ((sampling_method == N_PARAMETRICDISTANCE) ? 1 : 0);
+}
+
+inline int
+Mapdesc::isObjectSpaceParaSampling( void )
+{
+ return ((sampling_method == N_OBJECTSPACE_PARA) ? 1 : 0);
+}
+
+inline int
+Mapdesc::isObjectSpacePathSampling( void )
+{
+ return ((sampling_method == N_OBJECTSPACE_PATH) ? 1 : 0);
+}
+
+inline int
+Mapdesc::isSurfaceAreaSampling( void )
+{
+ return ((sampling_method == N_SURFACEAREA) ? 1 : 0);
+}
+
+inline int
+Mapdesc::isPathLengthSampling( void )
+{
+ return ((sampling_method == N_PATHLENGTH) ? 1 : 0);
+}
+
+inline int
+Mapdesc::isRangeSampling( void )
+{
+ return ( isParametricDistanceSampling() || isPathLengthSampling() ||
+ isSurfaceAreaSampling() ||
+ isObjectSpaceParaSampling() ||
+ isObjectSpacePathSampling());
+}
+
+inline int
+Mapdesc::isSampling( void )
+{
+ return isRangeSampling() || isConstantSampling() || isDomainSampling();
+}
+
+inline int
+Mapdesc::isCulling( void )
+{
+ return ((culling_method != N_NOCULLING) ? 1 : 0);
+}
+
+inline int
+Mapdesc::isBboxSubdividing( void )
+{
+ return ((bbox_subdividing != N_NOBBOXSUBDIVISION) ? 1 : 0);
+}
+#endif /* __glumapdesc_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/mapdescv.cc b/mesalib/src/glu/sgi/libnurbs/internals/mapdescv.cc
new file mode 100644
index 000000000..35b38b141
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/mapdescv.cc
@@ -0,0 +1,243 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * mapdescv.c++
+ *
+ */
+
+#include "glimports.h"
+#include "mystdio.h"
+#include "myassert.h"
+#include "mystring.h"
+#include "mymath.h"
+#include "nurbsconsts.h"
+#include "mapdesc.h"
+
+/*--------------------------------------------------------------------------
+ * calcPartialVelocity - calculate maximum magnitude of a given partial
+ * derivative
+ *--------------------------------------------------------------------------
+ */
+REAL
+Mapdesc::calcPartialVelocity (
+ REAL *p,
+ int stride,
+ int ncols,
+ int partial,
+ REAL range )
+{
+ REAL tmp[MAXORDER][MAXCOORDS];
+ REAL mag[MAXORDER];
+
+ assert( ncols <= MAXORDER );
+
+ int j, k, t;
+ // copy inhomogeneous control points into temporary array
+ for( j=0; j != ncols; j++ )
+ for( k=0; k != inhcoords; k++ )
+ tmp[j][k] = p[j*stride + k];
+
+ for( t=0; t != partial; t++ )
+ for( j=0; j != ncols-t-1; j++ )
+ for( k=0; k != inhcoords; k++ )
+ tmp[j][k] = tmp[j+1][k] - tmp[j][k];
+
+ // compute magnitude and store in mag array
+ for( j=0; j != ncols-partial; j++ ) {
+ mag[j] = 0.0;
+ for( k=0; k != inhcoords; k++ )
+ mag[j] += tmp[j][k] * tmp[j][k];
+ }
+
+ // compute scale factor
+ REAL fac = 1;
+ REAL invt = 1.0 / range;
+ for( t = ncols-1; t != ncols-1-partial; t-- )
+ fac *= t * invt;
+
+ // compute max magnitude of all entries in array
+ REAL max = 0.0;
+ for( j=0; j != ncols-partial; j++ )
+ if( mag[j] > max ) max = mag[j];
+ max = fac * sqrtf( (float) max );
+
+ return max;
+}
+
+/*--------------------------------------------------------------------------
+ * calcPartialVelocity - calculate maximum magnitude of a given partial
+ * derivative
+ *--------------------------------------------------------------------------
+ */
+REAL
+Mapdesc::calcPartialVelocity (
+ REAL *dist,
+ REAL *p,
+ int rstride,
+ int cstride,
+ int nrows,
+ int ncols,
+ int spartial,
+ int tpartial,
+ REAL srange,
+ REAL trange,
+ int side )
+{
+ REAL tmp[MAXORDER][MAXORDER][MAXCOORDS];
+ REAL mag[MAXORDER][MAXORDER];
+
+ assert( nrows <= MAXORDER );
+ assert( ncols <= MAXORDER );
+
+ REAL *tp = &tmp[0][0][0];
+ REAL *mp = &mag[0][0];
+ const int istride = sizeof( tmp[0]) / sizeof( tmp[0][0][0] );
+ const int jstride = sizeof( tmp[0][0]) / sizeof( tmp[0][0][0] );
+ /*
+ const int kstride = sizeof( tmp[0][0][0]) / sizeof( tmp[0][0][0] );
+ */
+ const int mistride = sizeof( mag[0]) / sizeof( mag[0][0] );
+ const int mjstride = sizeof( mag[0][0]) / sizeof( mag[0][0] );
+ const int idist = nrows * istride;
+ const int jdist = ncols * jstride;
+ /*
+ const int kdist = inhcoords * kstride;
+ */
+ const int id = idist - spartial * istride;
+ const int jd = jdist - tpartial * jstride;
+
+ {
+ // copy control points
+ REAL *ti = tp;
+ REAL *qi = p;
+ REAL *til = tp + idist;
+ for( ; ti != til; ) {
+ REAL *tj = ti;
+ REAL *qj = qi;
+ REAL *tjl = ti + jdist;
+ for( ; tj != tjl; ) {
+ for( int k=0; k != inhcoords; k++ ) {
+ tj[k] = qj[k];
+ }
+ tj += jstride;
+ qj += cstride;
+ }
+ ti += istride;
+ qi += rstride;
+ }
+ }
+
+ {
+ // compute (s)-partial derivative control points
+ REAL *til = tp + idist - istride;
+ const REAL *till = til - ( spartial * istride );
+ for( ; til != till; til -= istride )
+ for( REAL *ti = tp; ti != til; ti += istride )
+ for( REAL *tj = ti, *tjl = tj + jdist; tj != tjl; tj += jstride )
+ for( int k=0; k != inhcoords; k++ )
+ tj[k] = tj[k+istride] - tj[k];
+ }
+
+ {
+ // compute (s,t)-partial derivative control points
+ REAL *tjl = tp + jdist - jstride;
+ const REAL *tjll = tjl - ( tpartial * jstride );
+ for( ; tjl != tjll; tjl -= jstride )
+ for( REAL *tj = tp; tj != tjl; tj += jstride )
+ for( REAL *ti = tj, *til = ti + id; ti != til; ti += istride )
+ for( int k=0; k != inhcoords; k++ )
+ ti[k] = ti[k+jstride] - ti[k];
+
+ }
+
+ REAL max = 0.0;
+ {
+ // compute magnitude and store in mag array
+ memset( (void *) mp, 0, sizeof( mag ) );
+ for( REAL *ti = tp, *mi = mp, *til = tp + id; ti != til; ti += istride, mi += mistride )
+ for( REAL *tj = ti, *mj = mi, *tjl = ti + jd; tj != tjl; tj += jstride, mj += mjstride ) {
+ for( int k=0; k != inhcoords; k++ )
+ *mj += tj[k] * tj[k];
+ if( *mj > max ) max = *mj;
+ }
+
+ }
+
+ int i, j;
+
+ // compute scale factor
+ REAL fac = 1.0;
+ {
+ REAL invs = 1.0 / srange;
+ REAL invt = 1.0 / trange;
+ for( int s = nrows-1, slast = s-spartial; s != slast; s-- )
+ fac *= s * invs;
+ for( int t = ncols-1, tlast = t-tpartial; t != tlast; t-- )
+ fac *= t * invt;
+ }
+
+ if( side == 0 ) {
+ // compute max magnitude of first and last column
+ dist[0] = 0.0;
+ dist[1] = 0.0;
+ for( i=0; i != nrows-spartial; i++ ) {
+ j = 0;
+ if( mag[i][j] > dist[0] ) dist[0] = mag[i][j];
+
+ j = ncols-tpartial-1;
+ if( mag[i][j] > dist[1] ) dist[1] = mag[i][j];
+ }
+ dist[0] = fac * sqrtf( dist[0] );
+ dist[1] = fac * sqrtf( dist[1] );
+ } else if( side == 1 ) {
+ // compute max magnitude of first and last row
+ dist[0] = 0.0;
+ dist[1] = 0.0;
+ for( j=0; j != ncols-tpartial; j++ ) {
+ i = 0;
+ if( mag[i][j] > dist[0] ) dist[0] = mag[i][j];
+
+ i = nrows-spartial-1;
+ if( mag[i][j] > dist[1] ) dist[1] = mag[i][j];
+ }
+ dist[0] = fac * sqrtf( dist[0] );
+ dist[1] = fac * sqrtf( dist[1] );
+ }
+
+ max = fac * sqrtf( (float) max );
+
+ return max;
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/maplist.cc b/mesalib/src/glu/sgi/libnurbs/internals/maplist.cc
new file mode 100644
index 000000000..f944d1529
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/maplist.cc
@@ -0,0 +1,117 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * maplist.c++
+ *
+ */
+
+#include "glimports.h"
+#include "mystdio.h"
+#include "myassert.h"
+#include "mymath.h"
+#include "nurbsconsts.h"
+#include "maplist.h"
+#include "mapdesc.h"
+#include "backend.h"
+
+Maplist::Maplist( Backend& b )
+ : mapdescPool( sizeof( Mapdesc ), 10, "mapdesc pool" ),
+ backend( b )
+{
+ maps = 0; lastmap = &maps;
+}
+
+void
+Maplist::initialize( void )
+{
+ freeMaps();
+ define( N_P2D, 0, 2 );
+ define( N_P2DR, 1, 3 );
+}
+
+void
+Maplist::add( long type, int israt, int ncoords )
+{
+ *lastmap = new(mapdescPool) Mapdesc( type, israt, ncoords, backend );
+ lastmap = &((*lastmap)->next);
+}
+
+void
+Maplist::define( long type, int israt, int ncoords )
+{
+#ifndef NDEBUG // to avoid warning
+ Mapdesc *m = locate( type );
+ assert( m == NULL || ( m->isrational == israt && m->ncoords == ncoords ) );
+#endif
+ add( type, israt, ncoords );
+}
+
+void
+Maplist::remove( Mapdesc *m )
+{
+ for( Mapdesc **curmap = &maps; *curmap; curmap = &((*curmap)->next) ) {
+ if( *curmap == m ) {
+ *curmap = m->next;
+ m->deleteMe( mapdescPool );
+ return;
+ }
+ }
+ abort();
+}
+
+void
+Maplist::freeMaps( void )
+{
+ mapdescPool.clear();
+ maps = 0;
+ lastmap = &maps;
+}
+
+Mapdesc *
+Maplist::find( long type )
+{
+ Mapdesc *val = locate( type );
+ assert( val != 0 );
+ return val;
+}
+
+Mapdesc *
+Maplist::locate( long type )
+{
+ Mapdesc *m;
+ for( m = maps; m; m = m->next )
+ if( m->getType() == type ) break;
+ return m;
+}
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/maplist.h b/mesalib/src/glu/sgi/libnurbs/internals/maplist.h
new file mode 100644
index 000000000..49720e49b
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/maplist.h
@@ -0,0 +1,81 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * maplist.h
+ *
+ */
+
+#ifndef __glumaplist_h_
+#define __glumaplist_h_
+
+#include "types.h"
+#include "defines.h"
+#include "bufpool.h"
+
+class Backend;
+class Mapdesc;
+
+class Maplist {
+public:
+ Maplist( Backend & );
+ void define( long, int, int );
+ inline void undefine( long );
+ inline int isMap( long );
+
+ void initialize( void );
+ Mapdesc * find( long );
+ Mapdesc * locate( long );
+
+private:
+ Pool mapdescPool;
+ Mapdesc * maps;
+ Mapdesc ** lastmap;
+ Backend & backend;
+
+ void add( long, int, int );
+ void remove( Mapdesc * );
+ void freeMaps( void );
+};
+
+inline int
+Maplist::isMap( long type )
+{
+ return (locate( type ) ? 1 : 0);
+}
+
+inline void
+Maplist::undefine( long type )
+{
+ Mapdesc *m = locate( type );
+ assert( m != 0 );
+ remove( m );
+}
+#endif /* __glumaplist_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/mesher.cc b/mesalib/src/glu/sgi/libnurbs/internals/mesher.cc
new file mode 100644
index 000000000..9cc436adb
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/mesher.cc
@@ -0,0 +1,486 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * mesher.c++
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "mystdio.h"
+#include "gridvertex.h"
+#include "gridtrimvertex.h"
+#include "jarcloc.h"
+#include "gridline.h"
+#include "trimline.h"
+#include "uarray.h"
+#include "backend.h"
+#include "mesher.h"
+
+
+const float Mesher::ZERO = 0.0;
+
+Mesher::Mesher( Backend& b )
+ : backend( b ),
+ p( sizeof( GridTrimVertex ), 100, "GridTrimVertexPool" )
+{
+ stacksize = 0;
+ vdata = 0;
+ lastedge = 0; //needed to prevent purify UMR
+}
+
+Mesher::~Mesher( void )
+{
+ if( vdata ) delete[] vdata;
+}
+
+void
+Mesher::init( unsigned int npts )
+{
+ p.clear();
+ if( stacksize < npts ) {
+ stacksize = 2 * npts;
+ if( vdata ) delete[] vdata;
+ vdata = new GridTrimVertex_p[stacksize];
+ }
+}
+
+inline void
+Mesher::push( GridTrimVertex *gt )
+{
+ assert( itop+1 != (int)stacksize );
+ vdata[++itop] = gt;
+}
+
+inline void
+Mesher::pop( long )
+{
+}
+
+inline void
+Mesher::openMesh()
+{
+ backend.bgntmesh( "addedge" );
+}
+
+inline void
+Mesher::closeMesh()
+{
+ backend.endtmesh();
+}
+
+inline void
+Mesher::swapMesh()
+{
+ backend.swaptmesh();
+}
+
+inline void
+Mesher::clearStack()
+{
+ itop = -1;
+ last[0] = 0;
+}
+
+void
+Mesher::finishLower( GridTrimVertex *gtlower )
+{
+ for( push(gtlower);
+ nextlower( gtlower=new(p) GridTrimVertex );
+ push(gtlower) )
+ addLower();
+ addLast();
+}
+
+void
+Mesher::finishUpper( GridTrimVertex *gtupper )
+{
+ for( push(gtupper);
+ nextupper( gtupper=new(p) GridTrimVertex );
+ push(gtupper) )
+ addUpper();
+ addLast();
+}
+
+void
+Mesher::mesh( void )
+{
+ GridTrimVertex *gtlower, *gtupper;
+
+ Hull::init( );
+ nextupper( gtupper = new(p) GridTrimVertex );
+ nextlower( gtlower = new(p) GridTrimVertex );
+
+ clearStack();
+ openMesh();
+ push(gtupper);
+
+ nextupper( gtupper = new(p) GridTrimVertex );
+ nextlower( gtlower );
+
+ assert( gtupper->t && gtlower->t );
+
+ if( gtupper->t->param[0] < gtlower->t->param[0] ) {
+ push(gtupper);
+ lastedge = 1;
+ if( nextupper( gtupper=new(p) GridTrimVertex ) == 0 ) {
+ finishLower(gtlower);
+ return;
+ }
+ } else if( gtupper->t->param[0] > gtlower->t->param[0] ) {
+ push(gtlower);
+ lastedge = 0;
+ if( nextlower( gtlower=new(p) GridTrimVertex ) == 0 ) {
+ finishUpper(gtupper);
+ return;
+ }
+ } else {
+ if( lastedge == 0 ) {
+ push(gtupper);
+ lastedge = 1;
+ if( nextupper(gtupper=new(p) GridTrimVertex) == 0 ) {
+ finishLower(gtlower);
+ return;
+ }
+ } else {
+ push(gtlower);
+ lastedge = 0;
+ if( nextlower( gtlower=new(p) GridTrimVertex ) == 0 ) {
+ finishUpper(gtupper);
+ return;
+ }
+ }
+ }
+
+ while ( 1 ) {
+ if( gtupper->t->param[0] < gtlower->t->param[0] ) {
+ push(gtupper);
+ addUpper();
+ if( nextupper( gtupper=new(p) GridTrimVertex ) == 0 ) {
+ finishLower(gtlower);
+ return;
+ }
+ } else if( gtupper->t->param[0] > gtlower->t->param[0] ) {
+ push(gtlower);
+ addLower();
+ if( nextlower( gtlower=new(p) GridTrimVertex ) == 0 ) {
+ finishUpper(gtupper);
+ return;
+ }
+ } else {
+ if( lastedge == 0 ) {
+ push(gtupper);
+ addUpper();
+ if( nextupper( gtupper=new(p) GridTrimVertex ) == 0 ) {
+ finishLower(gtlower);
+ return;
+ }
+ } else {
+ push(gtlower);
+ addLower();
+ if( nextlower( gtlower=new(p) GridTrimVertex ) == 0 ) {
+ finishUpper(gtupper);
+ return;
+ }
+ }
+ }
+ }
+}
+
+inline int
+Mesher::isCcw( int ilast )
+{
+ REAL area = det3( vdata[ilast]->t, vdata[itop-1]->t, vdata[itop-2]->t );
+ return (area < ZERO) ? 0 : 1;
+}
+
+inline int
+Mesher::isCw( int ilast )
+{
+ REAL area = det3( vdata[ilast]->t, vdata[itop-1]->t, vdata[itop-2]->t );
+ return (area > -ZERO) ? 0 : 1;
+}
+
+inline int
+Mesher::equal( int x, int y )
+{
+ return( last[0] == vdata[x] && last[1] == vdata[y] );
+}
+
+inline void
+Mesher::copy( int x, int y )
+{
+ last[0] = vdata[x]; last[1] = vdata[y];
+}
+
+inline void
+Mesher::move( int x, int y )
+{
+ vdata[x] = vdata[y];
+}
+
+inline void
+Mesher::output( int x )
+{
+ backend.tmeshvert( vdata[x] );
+}
+
+/*---------------------------------------------------------------------------
+ * addedge - addedge an edge to the triangulation
+ *
+ * This code has been re-written to generate large triangle meshes
+ * from a monotone polygon. Although smaller triangle meshes
+ * could be generated faster and with less code, larger meshes
+ * actually give better SYSTEM performance. This is because
+ * vertices are processed in the backend slower than they are
+ * generated by this code and any decrease in the number of vertices
+ * results in a decrease in the time spent in the backend.
+ *---------------------------------------------------------------------------
+ */
+
+void
+Mesher::addLast( )
+{
+ register int ilast = itop;
+
+ if( lastedge == 0 ) {
+ if( equal( 0, 1 ) ) {
+ output( ilast );
+ swapMesh();
+ for( register int i = 2; i < ilast; i++ ) {
+ swapMesh();
+ output( i );
+ }
+ copy( ilast, ilast-1 );
+ } else if( equal( ilast-2, ilast-1) ) {
+ swapMesh();
+ output( ilast );
+ for( register int i = ilast-3; i >= 0; i-- ) {
+ output( i );
+ swapMesh();
+ }
+ copy( 0, ilast );
+ } else {
+ closeMesh(); openMesh();
+ output( ilast );
+ output( 0 );
+ for( register int i = 1; i < ilast; i++ ) {
+ swapMesh();
+ output( i );
+ }
+ copy( ilast, ilast-1 );
+ }
+ } else {
+ if( equal( 1, 0) ) {
+ swapMesh();
+ output( ilast );
+ for( register int i = 2; i < ilast; i++ ) {
+ output( i );
+ swapMesh();
+ }
+ copy( ilast-1, ilast );
+ } else if( equal( ilast-1, ilast-2) ) {
+ output( ilast );
+ swapMesh();
+ for( register int i = ilast-3; i >= 0; i-- ) {
+ swapMesh();
+ output( i );
+ }
+ copy( ilast, 0 );
+ } else {
+ closeMesh(); openMesh();
+ output( 0 );
+ output( ilast );
+ for( register int i = 1; i < ilast; i++ ) {
+ output( i );
+ swapMesh();
+ }
+ copy( ilast-1, ilast );
+ }
+ }
+ closeMesh();
+ //for( register long k=0; k<=ilast; k++ ) pop( k );
+}
+
+void
+Mesher::addUpper( )
+{
+ register int ilast = itop;
+
+ if( lastedge == 0 ) {
+ if( equal( 0, 1 ) ) {
+ output( ilast );
+ swapMesh();
+ for( register int i = 2; i < ilast; i++ ) {
+ swapMesh();
+ output( i );
+ }
+ copy( ilast, ilast-1 );
+ } else if( equal( ilast-2, ilast-1) ) {
+ swapMesh();
+ output( ilast );
+ for( register int i = ilast-3; i >= 0; i-- ) {
+ output( i );
+ swapMesh();
+ }
+ copy( 0, ilast );
+ } else {
+ closeMesh(); openMesh();
+ output( ilast );
+ output( 0 );
+ for( register int i = 1; i < ilast; i++ ) {
+ swapMesh();
+ output( i );
+ }
+ copy( ilast, ilast-1 );
+ }
+ lastedge = 1;
+ //for( register long k=0; k<ilast-1; k++ ) pop( k );
+ move( 0, ilast-1 );
+ move( 1, ilast );
+ itop = 1;
+ } else {
+ if( ! isCcw( ilast ) ) return;
+ do {
+ itop--;
+ } while( (itop > 1) && isCcw( ilast ) );
+
+ if( equal( ilast-1, ilast-2 ) ) {
+ output( ilast );
+ swapMesh();
+ for( register int i=ilast-3; i>=itop-1; i-- ) {
+ swapMesh();
+ output( i );
+ }
+ copy( ilast, itop-1 );
+ } else if( equal( itop, itop-1 ) ) {
+ swapMesh();
+ output( ilast );
+ for( register int i = itop+1; i < ilast; i++ ) {
+ output( i );
+ swapMesh();
+ }
+ copy( ilast-1, ilast );
+ } else {
+ closeMesh(); openMesh();
+ output( ilast );
+ output( ilast-1 );
+ for( register int i=ilast-2; i>=itop-1; i-- ) {
+ swapMesh();
+ output( i );
+ }
+ copy( ilast, itop-1 );
+ }
+ //for( register int k=itop; k<ilast; k++ ) pop( k );
+ move( itop, ilast );
+ }
+}
+
+void
+Mesher::addLower()
+{
+ register int ilast = itop;
+
+ if( lastedge == 1 ) {
+ if( equal( 1, 0) ) {
+ swapMesh();
+ output( ilast );
+ for( register int i = 2; i < ilast; i++ ) {
+ output( i );
+ swapMesh();
+ }
+ copy( ilast-1, ilast );
+ } else if( equal( ilast-1, ilast-2) ) {
+ output( ilast );
+ swapMesh();
+ for( register int i = ilast-3; i >= 0; i-- ) {
+ swapMesh();
+ output( i );
+ }
+ copy( ilast, 0 );
+ } else {
+ closeMesh(); openMesh();
+ output( 0 );
+ output( ilast );
+ for( register int i = 1; i < ilast; i++ ) {
+ output( i );
+ swapMesh();
+ }
+ copy( ilast-1, ilast );
+ }
+
+ lastedge = 0;
+ //for( register long k=0; k<ilast-1; k++ ) pop( k );
+ move( 0, ilast-1 );
+ move( 1, ilast );
+ itop = 1;
+ } else {
+ if( ! isCw( ilast ) ) return;
+ do {
+ itop--;
+ } while( (itop > 1) && isCw( ilast ) );
+
+ if( equal( ilast-2, ilast-1) ) {
+ swapMesh();
+ output( ilast );
+ for( register int i=ilast-3; i>=itop-1; i--) {
+ output( i );
+ swapMesh( );
+ }
+ copy( itop-1, ilast );
+ } else if( equal( itop-1, itop) ) {
+ output( ilast );
+ swapMesh();
+ for( register int i=itop+1; i<ilast; i++ ) {
+ swapMesh( );
+ output( i );
+ }
+ copy( ilast, ilast-1 );
+ } else {
+ closeMesh(); openMesh();
+ output( ilast-1 );
+ output( ilast );
+ for( register int i=ilast-2; i>=itop-1; i-- ) {
+ output( i );
+ swapMesh( );
+ }
+ copy( itop-1, ilast );
+ }
+ //for( register int k=itop; k<ilast; k++ ) pop( k );
+ move( itop, ilast );
+ }
+}
+
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/mesher.h b/mesalib/src/glu/sgi/libnurbs/internals/mesher.h
new file mode 100644
index 000000000..bb65d0f1c
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/mesher.h
@@ -0,0 +1,83 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * mesher.h
+ *
+ */
+
+#ifndef __glumesher_h_
+#define __glumesher_h_
+
+#include "hull.h"
+
+class TrimRegion;
+class Backend;
+class Pool;
+// struct GridTrimVertex;
+
+
+class Mesher : virtual public TrimRegion, public Hull {
+public:
+ Mesher( Backend & );
+ ~Mesher( void );
+ void init( unsigned int );
+ void mesh( void );
+
+private:
+ static const float ZERO;
+ Backend& backend;
+
+ Pool p;
+ unsigned int stacksize;
+ GridTrimVertex ** vdata;
+ GridTrimVertex * last[2];
+ int itop;
+ int lastedge;
+
+ inline void openMesh( void );
+ inline void swapMesh( void );
+ inline void closeMesh( void );
+ inline int isCcw( int );
+ inline int isCw( int );
+ inline void clearStack( void );
+ inline void push( GridTrimVertex * );
+ inline void pop( long );
+ inline void move( int, int );
+ inline int equal( int, int );
+ inline void copy( int, int );
+ inline void output( int );
+ void addUpper( void );
+ void addLower( void );
+ void addLast( void );
+ void finishUpper( GridTrimVertex * );
+ void finishLower( GridTrimVertex * );
+};
+#endif /* __glumesher_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/monoTriangulationBackend.cc b/mesalib/src/glu/sgi/libnurbs/internals/monoTriangulationBackend.cc
new file mode 100644
index 000000000..2830cc743
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/monoTriangulationBackend.cc
@@ -0,0 +1,397 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+**
+*/
+/*
+*/
+
+#include "monoTriangulation.h"
+#include "polyUtil.h"
+#include "backend.h"
+#include "arc.h"
+
+void reflexChain::outputFan(Real v[2], Backend* backend)
+{
+ Int i;
+ /*
+ TrimVertex trimVert;
+ */
+ backend->bgntfan();
+
+ /*
+ trimVert.param[0]=v[0];
+ trimVert.param[1]=v[1];
+ backend->tmeshvert(&trimVert);
+ */
+ backend->tmeshvert(v[0], v[1]);
+
+ if(isIncreasing) {
+ for(i=0; i<index_queue; i++)
+ {
+ /*
+ trimVert.param[0]=queue[i][0];
+ trimVert.param[1]=queue[i][1];
+ backend->tmeshvert(&trimVert);
+ */
+ backend->tmeshvert(queue[i][0], queue[i][1]);
+ }
+ }
+ else {
+ for(i=index_queue-1; i>=0; i--)
+ {
+ /*
+ trimVert.param[0]=queue[i][0];
+ trimVert.param[1]=queue[i][1];
+ backend->tmeshvert(&trimVert);
+ */
+ backend->tmeshvert(queue[i][0], queue[i][1]);
+ }
+ }
+ backend->endtfan();
+}
+
+void reflexChain::processNewVertex(Real v[2], Backend* backend)
+{
+ Int i,j,k;
+ Int isReflex;
+ /*TrimVertex trimVert;*/
+ /*if there are at most one vertex in the queue, then simply insert
+ */
+ if(index_queue <=1){
+ insert(v);
+ return;
+ }
+
+ /*there are at least two vertices in the queue*/
+ j=index_queue-1;
+
+ for(i=j; i>=1; i--) {
+ if(isIncreasing) {
+ isReflex = (area(queue[i-1], queue[i], v) <= 0.0);
+ }
+ else /*decreasing*/{
+ isReflex = (area(v, queue[i], queue[i-1]) <= 0.0);
+ }
+ if(isReflex) {
+ break;
+ }
+ }
+
+ /*
+ *if i<j then vertices: i+1--j are convex
+ * output triangle fan:
+ * v, and queue[i], i+1, ..., j
+ */
+ if(i<j)
+ {
+ backend->bgntfan();
+ /*
+ trimVert.param[0]=v[0];
+ trimVert.param[1]=v[1];
+ backend->tmeshvert(& trimVert);
+ */
+ backend->tmeshvert(v[0], v[1]);
+
+ if(isIncreasing) {
+ for(k=i; k<=j; k++)
+ {
+ /*
+ trimVert.param[0]=queue[k][0];
+ trimVert.param[1]=queue[k][1];
+ backend->tmeshvert(& trimVert);
+ */
+ backend->tmeshvert(queue[k][0], queue[k][1]);
+ }
+ }
+ else {
+ for(k=j; k>=i; k--)
+ {
+ /*
+ trimVert.param[0]=queue[k][0];
+ trimVert.param[1]=queue[k][1];
+ backend->tmeshvert(& trimVert);
+ */
+ backend->tmeshvert(queue[k][0], queue[k][1]);
+ }
+ }
+
+ backend->endtfan();
+ }
+
+ /*delete vertices i+1--j from the queue*/
+ index_queue = i+1;
+ /*finally insert v at the end of the queue*/
+ insert(v);
+
+}
+
+
+void monoTriangulationRec(Real* topVertex, Real* botVertex,
+ vertexArray* inc_chain, Int inc_current,
+ vertexArray* dec_chain, Int dec_current,
+ Backend* backend)
+{
+ assert( inc_chain != NULL && dec_chain != NULL);
+ assert( ! (inc_current>=inc_chain->getNumElements() &&
+ dec_current>=dec_chain->getNumElements()));
+ Int inc_nVertices;
+ Int dec_nVertices;
+ Real** inc_array ;
+ Real** dec_array ;
+ Int i;
+ assert( ! ( (inc_chain==NULL) && (dec_chain==NULL)));
+
+ if(inc_current>=inc_chain->getNumElements()) /*no more vertices on inc_chain*/
+ {
+
+ dec_array = dec_chain->getArray();
+ dec_nVertices = dec_chain->getNumElements();
+ reflexChain rChain(20,0);
+ /*put the top vertex into the reflex chain*/
+ rChain.processNewVertex(topVertex, backend);
+ /*process all the vertices on the dec_chain*/
+ for(i=dec_current; i<dec_nVertices; i++){
+ rChain.processNewVertex(dec_array[i], backend);
+ }
+ /*process the bottom vertex*/
+ rChain.processNewVertex(botVertex, backend);
+
+ }
+ else if(dec_current>= dec_chain->getNumElements()) /*no more vertices on dec_chain*/
+ {
+ inc_array = inc_chain->getArray();
+ inc_nVertices= inc_chain->getNumElements();
+ reflexChain rChain(20,1);
+ /*put the top vertex into the reflex chain*/
+ rChain.processNewVertex(topVertex, backend);
+ /*process all the vertices on the inc_chain*/
+ for(i=inc_current; i<inc_nVertices; i++){
+ rChain.processNewVertex(inc_array[i], backend);
+ }
+ /*process the bottom vertex*/
+ rChain.processNewVertex(botVertex, backend);
+ }
+ else /*neither chain is empty*/
+ {
+ inc_array = inc_chain -> getArray();
+ dec_array = dec_chain -> getArray();
+ inc_nVertices= inc_chain->getNumElements();
+ dec_nVertices= dec_chain->getNumElements();
+ /*if top of inc_chain is 'lower' than top of dec_chain, process all the
+ *vertices on the dec_chain which are higher than top of inc_chain
+ */
+ if(compV2InY(inc_array[inc_current], dec_array[dec_current]) <= 0)
+ {
+
+ reflexChain rChain(20, 0);
+ rChain.processNewVertex(topVertex, backend);
+ for(i=dec_current; i<dec_nVertices; i++)
+ {
+ if(compV2InY(inc_array[inc_current], dec_array[i]) <= 0)
+ rChain.processNewVertex(dec_array[i], backend);
+ else
+ break;
+ }
+ rChain.outputFan(inc_array[inc_current], backend);
+ monoTriangulationRec(dec_array[i-1], botVertex,
+ inc_chain, inc_current,
+ dec_chain, i,
+ backend);
+ }
+ else /*compV2InY(inc_array[inc_current], dec_array[dec_current]) > 0*/
+ {
+
+ reflexChain rChain(20, 1);
+ rChain.processNewVertex(topVertex, backend);
+ for(i=inc_current; i<inc_nVertices; i++)
+ {
+ if(compV2InY(inc_array[i], dec_array[dec_current]) >0)
+ rChain.processNewVertex(inc_array[i], backend);
+ else
+ break;
+ }
+ rChain.outputFan(dec_array[dec_current], backend);
+ monoTriangulationRec(inc_array[i-1], botVertex,
+ inc_chain, i,
+ dec_chain, dec_current,
+ backend);
+ }
+ }/*end case neither is empty*/
+}
+
+
+void monoTriangulationFunBackend(Arc_ptr loop, Int (*compFun)(Real*, Real*), Backend* backend)
+{
+ Int i;
+ /*find the top vertex, bottom vertex, inccreasing chain, and decreasing chain,
+ *then call monoTriangulationRec
+ */
+ Arc_ptr tempV;
+ Arc_ptr topV;
+ Arc_ptr botV;
+ topV = botV = loop;
+ for(tempV = loop->next; tempV != loop; tempV = tempV->next)
+ {
+ if(compFun(topV->tail(), tempV->tail())<0) {
+ topV = tempV;
+ }
+ if(compFun(botV->tail(), tempV->tail())>0) {
+ botV = tempV;
+ }
+ }
+
+ /*creat increase and decrease chains*/
+ vertexArray inc_chain(20); /*this is a dynamic array*/
+ for(i=1; i<=topV->pwlArc->npts-2; i++) { /*the first vertex is the top vertex which doesn't belong to inc_chain*/
+ inc_chain.appendVertex(topV->pwlArc->pts[i].param);
+ }
+ for(tempV = topV->next; tempV != botV; tempV = tempV->next)
+ {
+ for(i=0; i<=tempV->pwlArc->npts-2; i++){
+ inc_chain.appendVertex(tempV->pwlArc->pts[i].param);
+ }
+ }
+
+ vertexArray dec_chain(20);
+ for(tempV = topV->prev; tempV != botV; tempV = tempV->prev)
+ {
+ for(i=tempV->pwlArc->npts-2; i>=0; i--){
+ dec_chain.appendVertex(tempV->pwlArc->pts[i].param);
+ }
+ }
+ for(i=botV->pwlArc->npts-2; i>=1; i--){
+ dec_chain.appendVertex(tempV->pwlArc->pts[i].param);
+ }
+
+ monoTriangulationRecFunBackend(topV->tail(), botV->tail(), &inc_chain, 0, &dec_chain, 0, compFun, backend);
+
+}
+
+/*if compFun == compV2InY, top to bottom: V-monotone
+ *if compFun == compV2InX, right to left: U-monotone
+ */
+void monoTriangulationRecFunBackend(Real* topVertex, Real* botVertex,
+ vertexArray* inc_chain, Int inc_current,
+ vertexArray* dec_chain, Int dec_current,
+ Int (*compFun)(Real*, Real*),
+ Backend* backend)
+{
+ assert( inc_chain != NULL && dec_chain != NULL);
+ assert( ! (inc_current>=inc_chain->getNumElements() &&
+ dec_current>=dec_chain->getNumElements()));
+ Int inc_nVertices;
+ Int dec_nVertices;
+ Real** inc_array ;
+ Real** dec_array ;
+ Int i;
+ assert( ! ( (inc_chain==NULL) && (dec_chain==NULL)));
+
+ if(inc_current>=inc_chain->getNumElements()) /*no more vertices on inc_chain*/
+ {
+
+ dec_array = dec_chain->getArray();
+ dec_nVertices = dec_chain->getNumElements();
+ reflexChain rChain(20,0);
+ /*put the top vertex into the reflex chain*/
+ rChain.processNewVertex(topVertex, backend);
+ /*process all the vertices on the dec_chain*/
+ for(i=dec_current; i<dec_nVertices; i++){
+ rChain.processNewVertex(dec_array[i], backend);
+ }
+ /*process the bottom vertex*/
+ rChain.processNewVertex(botVertex, backend);
+
+ }
+ else if(dec_current>= dec_chain->getNumElements()) /*no more vertices on dec_chain*/
+ {
+ inc_array = inc_chain->getArray();
+ inc_nVertices= inc_chain->getNumElements();
+ reflexChain rChain(20,1);
+ /*put the top vertex into the reflex chain*/
+ rChain.processNewVertex(topVertex, backend);
+ /*process all the vertices on the inc_chain*/
+ for(i=inc_current; i<inc_nVertices; i++){
+ rChain.processNewVertex(inc_array[i], backend);
+ }
+ /*process the bottom vertex*/
+ rChain.processNewVertex(botVertex, backend);
+ }
+ else /*neither chain is empty*/
+ {
+ inc_array = inc_chain -> getArray();
+ dec_array = dec_chain -> getArray();
+ inc_nVertices= inc_chain->getNumElements();
+ dec_nVertices= dec_chain->getNumElements();
+ /*if top of inc_chain is 'lower' than top of dec_chain, process all the
+ *vertices on the dec_chain which are higher than top of inc_chain
+ */
+ if(compFun(inc_array[inc_current], dec_array[dec_current]) <= 0)
+ {
+
+ reflexChain rChain(20, 0);
+ rChain.processNewVertex(topVertex, backend);
+ for(i=dec_current; i<dec_nVertices; i++)
+ {
+ if(compFun(inc_array[inc_current], dec_array[i]) <= 0)
+ rChain.processNewVertex(dec_array[i], backend);
+ else
+ break;
+ }
+ rChain.outputFan(inc_array[inc_current], backend);
+ monoTriangulationRecFunBackend(dec_array[i-1], botVertex,
+ inc_chain, inc_current,
+ dec_chain, i,
+ compFun,
+ backend);
+ }
+ else /*compFun(inc_array[inc_current], dec_array[dec_current]) > 0*/
+ {
+
+ reflexChain rChain(20, 1);
+ rChain.processNewVertex(topVertex, backend);
+ for(i=inc_current; i<inc_nVertices; i++)
+ {
+ if(compFun(inc_array[i], dec_array[dec_current]) >0)
+ rChain.processNewVertex(inc_array[i], backend);
+ else
+ break;
+ }
+ rChain.outputFan(dec_array[dec_current], backend);
+ monoTriangulationRecFunBackend(inc_array[i-1], botVertex,
+ inc_chain, i,
+ dec_chain, dec_current,
+ compFun,
+ backend);
+ }
+ }/*end case neither is empty*/
+}
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/monotonizer.cc b/mesalib/src/glu/sgi/libnurbs/internals/monotonizer.cc
new file mode 100644
index 000000000..5845d310b
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/monotonizer.cc
@@ -0,0 +1,260 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * monotonizer.c++
+ *
+ */
+
+#include "glimports.h"
+#include "mystdio.h"
+#include "myassert.h"
+#include "arc.h"
+#include "arctess.h"
+#include "bezierarc.h"
+#include "bin.h"
+#include "mapdesc.h"
+#include "nurbsconsts.h"
+#include "subdivider.h"
+
+/*-----------------------------------------------------------------------------
+ * Subdivider::decompose - break all curves into monotone arcs
+ *-----------------------------------------------------------------------------
+ */
+int
+Subdivider::decompose( Bin& bin, REAL geo_stepsize )
+{
+ Arc_ptr jarc;
+ for( jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) {
+ if( ! jarc->isTessellated() ) {
+ /* points have not been transformed, therefore they may be either
+ homogeneous or inhomogeneous */
+ tessellate( jarc, geo_stepsize );
+ if( jarc->isDisconnected() || jarc->next->isDisconnected() )
+ return 1;
+ }
+ }
+
+ for( jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) {
+ monotonize( jarc, bin );
+ }
+
+#ifndef NDEBUG
+ for( jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) {
+ assert( isMonotone( jarc ) != 0 );
+ }
+#endif
+
+ return 0;
+}
+
+void
+Subdivider::tessellate( Arc_ptr jarc, REAL geo_stepsize )
+{
+ BezierArc *b = jarc->bezierArc;
+ Mapdesc *mapdesc = b->mapdesc;
+
+ if( mapdesc->isRational() ) {
+ REAL max = mapdesc->calcVelocityRational( b->cpts, b->stride, b->order );
+ REAL arc_stepsize = (max > 1.0) ? (1.0/max) : 1.0;
+ if( jarc->bezierArc->order != 2 )
+ arctessellator.tessellateNonlinear( jarc, geo_stepsize, arc_stepsize, 1 );
+ else {
+ arctessellator.tessellateLinear( jarc, geo_stepsize, arc_stepsize, 1 );
+ }
+ } else {
+ REAL max = mapdesc->calcVelocityNonrational( b->cpts, b->stride, b->order );
+ REAL arc_stepsize = (max > 1.0) ? (1.0/max) : 1.0;
+ if( jarc->bezierArc->order != 2 )
+ arctessellator.tessellateNonlinear( jarc, geo_stepsize, arc_stepsize, 0 );
+ else {
+ arctessellator.tessellateLinear( jarc, geo_stepsize, arc_stepsize, 0 );
+ }
+ }
+}
+
+/*-------------------------------------------------------------------------
+ * Subdivider::monotonize - break up a jordan arc into s,t-monotone
+ * components. This code will remove degenerate segments, including
+ * arcs of only a single point.
+ *-------------------------------------------------------------------------
+ */
+void
+Subdivider::monotonize( Arc_ptr jarc, Bin& bin )
+{
+ TrimVertex *firstvert = jarc->pwlArc->pts;
+ TrimVertex *lastvert = firstvert + (jarc->pwlArc->npts - 1);
+ long uid = jarc->nuid;
+ arc_side side = jarc->getside();
+ dir sdir = none;
+ dir tdir = none;
+ int degenerate = 1;
+
+ int nudegenerate;
+ int change;
+
+ TrimVertex *vert;
+ for( vert = firstvert; vert != lastvert; vert++ ) {
+
+ nudegenerate = 1;
+ change = 0;
+
+ /* check change relative to s axis, clear degenerate bit if needed */
+ REAL sdiff = vert[1].param[0] - vert[0].param[0];
+ if( sdiff == 0 ) {
+ if( sdir != same ) {
+ sdir = same;
+ change = 1;
+ }
+ } else if( sdiff < 0.0 ) {
+ if( sdir != down ) {
+ sdir = down;
+ change = 1;
+ }
+ nudegenerate = 0;
+ } else {
+ if( sdir != up ) {
+ sdir = up;
+ change = 1;
+ }
+ nudegenerate = 0;
+ }
+
+ /* check change relative to t axis, clear degenerate bit if needed */
+ REAL tdiff = vert[1].param[1] - vert[0].param[1];
+ if( tdiff == 0 ) {
+ if( tdir != same ) {
+ tdir = same;
+ change = 1;
+ }
+ } else if( tdiff < 0.0 ) {
+ if( tdir != down ) {
+ tdir = down;
+ change = 1;
+ }
+ nudegenerate = 0;
+ } else {
+ if( tdir != up ) {
+ tdir = up;
+ change = 1;
+ }
+ nudegenerate = 0;
+ }
+
+ if( change ) {
+ if( ! degenerate ) {
+ /* make last segment into separate pwl curve */
+ jarc->pwlArc->npts = vert - firstvert + 1;
+ jarc = (new(arcpool) Arc( side, uid ))->append( jarc );
+ jarc->pwlArc = new(pwlarcpool) PwlArc();
+ bin.addarc( jarc );
+ }
+ firstvert = jarc->pwlArc->pts = vert;
+ degenerate = nudegenerate;
+ }
+ }
+ jarc->pwlArc->npts = vert - firstvert + 1;
+
+ if( degenerate ) {
+ /* remove jarc from circularly linked list */
+ jarc->prev->next = jarc->next;
+ jarc->next->prev = jarc->prev;
+
+ assert( jarc->prev->check( ) != 0 );
+ assert( jarc->next->check( ) != 0 );
+
+ /* remove jarc from bin */
+ bin.remove_this_arc( jarc );
+
+ jarc->pwlArc->deleteMe( pwlarcpool ); jarc->pwlArc = 0;
+ jarc->deleteMe( arcpool );
+ }
+}
+
+/*-------------------------------------------------------------------------
+ * Subdivider::isMonotone - return true if arc is monotone AND non-degenerate
+ *-------------------------------------------------------------------------
+ */
+int
+Subdivider::isMonotone( Arc_ptr jarc )
+{
+ TrimVertex *firstvert = jarc->pwlArc->pts;
+ TrimVertex *lastvert = firstvert + (jarc->pwlArc->npts - 1);
+
+ if( firstvert == lastvert ) return 1;
+
+ TrimVertex *vert = firstvert;
+ enum dir sdir;
+ enum dir tdir;
+
+ REAL diff = vert[1].param[0] - vert[0].param[0];
+ if( diff == 0.0 )
+ sdir = same;
+ else if( diff < 0.0 )
+ sdir = down;
+ else
+ sdir = up;
+
+ diff = vert[1].param[1] - vert[0].param[1];
+ if( diff == 0.0 )
+ tdir = same;
+ else if( diff < 0.0 )
+ tdir = down;
+ else
+ tdir = up;
+
+ if( (sdir == same) && (tdir == same) ) return 0;
+
+ for( ++vert ; vert != lastvert; vert++ ) {
+ diff = vert[1].param[0] - vert[0].param[0];
+ if( diff == 0.0 ) {
+ if( sdir != same ) return 0;
+ } else if( diff < 0.0 ) {
+ if( sdir != down ) return 0;
+ } else {
+ if( sdir != up ) return 0;
+ }
+
+ diff = vert[1].param[1] - vert[0].param[1];
+ if( diff == 0.0 ) {
+ if( tdir != same ) return 0;
+ } else if( diff < 0.0 ) {
+ if( tdir != down ) return 0;
+ } else {
+ if( tdir != up ) return 0;
+ }
+ }
+ return 1;
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/monotonizer.h b/mesalib/src/glu/sgi/libnurbs/internals/monotonizer.h
new file mode 100644
index 000000000..e951084ff
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/monotonizer.h
@@ -0,0 +1,64 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * monotonizer.h
+ *
+ */
+
+#ifndef __glumonotonizer_h_
+#define __glumonotonizer_h_
+
+#include "mysetjmp.h"
+#include "types.h"
+
+class Arc;
+class ArcTessellator;
+class Pool;
+class Bin;
+class PwlArcPool;
+class Mapdesc;
+
+class Monotonizer {
+ ArcTessellator& arctessellator;
+ Pool& arcpool;
+ Pool& pwlarcpool;
+ jmp_buf& nurbsJmpBuf;
+
+ enum dir { down, same, up, none };
+ void tessellate( Arc *, REAL );
+ void monotonize( Arc *, Bin & );
+ int isMonotone( Arc * );
+public:
+ Monotonizer( ArcTessellator& at, Pool& ap, Pool& p, jmp_buf& j )
+ : arctessellator(at), arcpool(ap), pwlarcpool(p), nurbsJmpBuf(j) {}
+ int decompose( Bin &, REAL );
+};
+#endif /* __glumonotonizer_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/myassert.h b/mesalib/src/glu/sgi/libnurbs/internals/myassert.h
new file mode 100644
index 000000000..cbd6006f5
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/myassert.h
@@ -0,0 +1,51 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * myassert.h
+ *
+ */
+
+#ifndef __glumyassert_h_
+#define __glumyassert_h_
+
+#ifdef STANDALONE
+#define assert(EX) ((void)0)
+#endif
+
+#ifdef LIBRARYBUILD
+#include <assert.h>
+#endif
+
+#ifdef GLBUILD
+#define assert(EX) ((void)0)
+#endif
+
+#endif /* __glumyassert_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/mycode.cc b/mesalib/src/glu/sgi/libnurbs/internals/mycode.cc
new file mode 100644
index 000000000..3625cacd7
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/mycode.cc
@@ -0,0 +1,67 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+**
+*/
+/*
+*/
+
+#include "mymath.h"
+
+#ifdef NEEDCEILF
+
+float ceilf( float x )
+{
+ if( x < 0 ) {
+ float nx = -x;
+ int ix = (int) nx;
+ return (float) -ix;
+ } else {
+ int ix = (int) x;
+ if( x == (float) ix ) return x;
+ return (float) (ix+1);
+ }
+}
+
+float floorf( float x )
+{
+ if( x < 0 ) {
+ float nx = -x;
+ int ix = (int) nx;
+ if( nx == (float) ix ) return x;
+ return (float) -(ix+1);
+ } else {
+ int ix = (int) x;
+ return (float) ix;
+ }
+}
+#endif
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/mymath.h b/mesalib/src/glu/sgi/libnurbs/internals/mymath.h
new file mode 100644
index 000000000..17ef7237f
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/mymath.h
@@ -0,0 +1,68 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * mymath.h
+ *
+ */
+
+#ifndef __glumymath_h_
+#define __glumymath_h_
+
+#ifdef GLBUILD
+#define sqrtf gl_fsqrt
+#endif
+
+#if defined(GLBUILD) || defined(STANDALONE)
+#define M_SQRT2 1.41421356237309504880
+#define ceilf myceilf
+#define floorf myfloorf
+#define sqrtf sqrt
+extern "C" double sqrt(double);
+extern "C" float ceilf(float);
+extern "C" float floorf(float);
+#define NEEDCEILF
+#endif
+
+#ifdef LIBRARYBUILD
+#include <math.h>
+#endif
+
+#if !defined sqrtf
+# define sqrtf(x) ((float)sqrt(x))
+#endif
+#if !defined ceilf
+# define ceilf(x) ((float)ceil(x))
+#endif
+#if !defined floorf
+# define floorf(x) ((float)floor(x))
+#endif
+
+#endif /* __glumymath_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/mysetjmp.h b/mesalib/src/glu/sgi/libnurbs/internals/mysetjmp.h
new file mode 100644
index 000000000..2a3f6a87b
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/mysetjmp.h
@@ -0,0 +1,85 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * mysetjmp.h
+ *
+ */
+
+#ifndef __glumysetjmp_h_
+#define __glumysetjmp_h_
+
+#ifdef STANDALONE
+struct JumpBuffer;
+extern "C" JumpBuffer *newJumpbuffer( void );
+extern "C" void deleteJumpbuffer(JumpBuffer *);
+extern "C" void mylongjmp( JumpBuffer *, int );
+extern "C" int mysetjmp( JumpBuffer * );
+#endif
+
+#ifdef GLBUILD
+#define setjmp gl_setjmp
+#define longjmp gl_longjmp
+#endif
+
+#if defined(LIBRARYBUILD) || defined(GLBUILD)
+#include <setjmp.h>
+#include <stdlib.h>
+
+struct JumpBuffer {
+ jmp_buf buf;
+};
+
+inline JumpBuffer *
+newJumpbuffer( void )
+{
+ return (JumpBuffer *) malloc( sizeof( JumpBuffer ) );
+}
+
+inline void
+deleteJumpbuffer(JumpBuffer *jb)
+{
+ free( (void *) jb);
+}
+
+inline void
+mylongjmp( JumpBuffer *j, int code )
+{
+ ::longjmp( j->buf, code );
+}
+
+inline int
+mysetjmp( JumpBuffer *j )
+{
+ return setjmp( j->buf );
+}
+#endif
+
+#endif /* __glumysetjmp_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/mystring.h b/mesalib/src/glu/sgi/libnurbs/internals/mystring.h
new file mode 100644
index 000000000..d2952da89
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/mystring.h
@@ -0,0 +1,56 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * mystring.h
+ *
+ */
+
+#ifndef __glumystring_h_
+#define __glumystring_h_
+
+#ifdef STANDALONE
+typedef unsigned int size_t;
+extern "C" void * memcpy(void *, const void *, size_t);
+extern "C" void * memset(void *, int, size_t);
+#endif
+
+#ifdef GLBUILD
+#define memcpy(a,b,c) bcopy(b,a,c)
+#define memset(a,b,c) bzero(a,c)
+extern "C" void bcopy(const void *, void *, int);
+extern "C" void bzero(void *, int);
+#endif
+
+#ifdef LIBRARYBUILD
+#include <string.h>
+#endif
+
+#endif /* __glumystring_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/nurbsconsts.h b/mesalib/src/glu/sgi/libnurbs/internals/nurbsconsts.h
new file mode 100644
index 000000000..acc5d7f31
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/nurbsconsts.h
@@ -0,0 +1,120 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * nurbsconsts.h
+ *
+ */
+
+#ifndef __glunurbsconsts_h_
+#define __glunurbsconsts_h_
+
+/* NURBS Properties - one set per map,
+ each takes a single INREAL arg */
+#define N_SAMPLING_TOLERANCE 1
+#define N_S_RATE 6
+#define N_T_RATE 7
+#define N_CLAMPFACTOR 13
+#define N_NOCLAMPING 0.0
+#define N_MINSAVINGS 14
+#define N_NOSAVINGSSUBDIVISION 0.0
+
+/* NURBS Properties - one set per map,
+ each takes an enumerated value */
+#define N_CULLING 2
+#define N_NOCULLING 0.0
+#define N_CULLINGON 1.0
+#define N_SAMPLINGMETHOD 10
+#define N_NOSAMPLING 0.0
+#define N_FIXEDRATE 3.0
+#define N_DOMAINDISTANCE 2.0
+#define N_PARAMETRICDISTANCE 5.0
+#define N_PATHLENGTH 6.0
+#define N_SURFACEAREA 7.0
+#define N_OBJECTSPACE_PARA 8.0
+#define N_OBJECTSPACE_PATH 9.0
+#define N_BBOX_SUBDIVIDING 17
+#define N_NOBBOXSUBDIVISION 0.0
+#define N_BBOXTIGHT 1.0
+#define N_BBOXROUND 2.0
+
+/* NURBS Rendering Properties - one set per renderer
+ each takes an enumerated value */
+#define N_DISPLAY 3
+#define N_FILL 1.0
+#define N_OUTLINE_POLY 2.0
+#define N_OUTLINE_TRI 3.0
+#define N_OUTLINE_QUAD 4.0
+#define N_OUTLINE_PATCH 5.0
+#define N_OUTLINE_PARAM 6.0
+#define N_OUTLINE_PARAM_S 7.0
+#define N_OUTLINE_PARAM_ST 8.0
+#define N_OUTLINE_SUBDIV 9.0
+#define N_OUTLINE_SUBDIV_S 10.0
+#define N_OUTLINE_SUBDIV_ST 11.0
+#define N_ISOLINE_S 12.0
+#define N_ERRORCHECKING 4
+#define N_NOMSG 0.0
+#define N_MSG 1.0
+
+/* GL 4.0 propeties not defined above */
+#ifndef N_PIXEL_TOLERANCE
+#define N_PIXEL_TOLERANCE N_SAMPLING_TOLERANCE
+#define N_ERROR_TOLERANCE 20
+#define N_SUBDIVISIONS 5
+#define N_TILES 8
+#define N_TMP1 9
+#define N_TMP2 N_SAMPLINGMETHOD
+#define N_TMP3 11
+#define N_TMP4 12
+#define N_TMP5 N_CLAMPFACTOR
+#define N_TMP6 N_MINSAVINGS
+#define N_S_STEPS N_S_RATE
+#define N_T_STEPS N_T_RATE
+#endif
+
+/* NURBS Rendering Properties - one set per map,
+ each takes an INREAL matrix argument */
+#define N_CULLINGMATRIX 1
+#define N_SAMPLINGMATRIX 2
+#define N_BBOXMATRIX 3
+
+
+/* NURBS Rendering Properties - one set per map,
+ each takes an INREAL vector argument */
+#define N_BBOXSIZE 4
+
+/* type argument for trimming curves */
+#ifndef N_P2D
+#define N_P2D 0x8
+#define N_P2DR 0xd
+#endif
+
+#endif /* __glunurbsconsts_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/nurbsinterfac.cc b/mesalib/src/glu/sgi/libnurbs/internals/nurbsinterfac.cc
new file mode 100644
index 000000000..520bd419e
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/nurbsinterfac.cc
@@ -0,0 +1,537 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * nurbsinterfac.c++
+ *
+ */
+
+#include "glimports.h"
+#include "mystdio.h"
+#include "nurbsconsts.h"
+#include "nurbstess.h"
+#include "bufpool.h"
+#include "quilt.h"
+#include "displaylist.h"
+#include "knotvector.h"
+#include "mapdesc.h"
+
+#define THREAD( work, arg, cleanup ) \
+ if( dl ) {\
+ arg->save = 1;\
+ dl->append( (PFVS)&NurbsTessellator::work, (void *) arg, (PFVS)&NurbsTessellator::cleanup );\
+ } else {\
+ arg->save = 0;\
+ work( arg );\
+ }
+
+#define THREAD2( work ) \
+ if( dl ) {\
+ dl->append( (PFVS)&NurbsTessellator::work, 0, 0 );\
+ } else {\
+ work( );\
+ }
+
+NurbsTessellator::NurbsTessellator( BasicCurveEvaluator &c, BasicSurfaceEvaluator& e)
+ : maplist( backend ),
+ backend( c, e ),
+ subdivider( renderhints, backend ),
+ o_pwlcurvePool( sizeof( O_pwlcurve ), 32, "o_pwlcurvePool" ),
+ o_nurbscurvePool( sizeof( O_nurbscurve ), 32, "o_nurbscurvePool"),
+ o_curvePool( sizeof( O_curve ), 32, "o_curvePool" ),
+ o_trimPool( sizeof( O_trim ), 32, "o_trimPool" ),
+ o_surfacePool( sizeof( O_surface ), 1, "o_surfacePool" ),
+ o_nurbssurfacePool( sizeof( O_nurbssurface ), 4, "o_nurbssurfacePool" ),
+ propertyPool( sizeof( Property ), 32, "propertyPool" ),
+ quiltPool( sizeof( Quilt ), 32, "quiltPool" )
+{
+ dl = 0;
+ inSurface = 0;
+ inCurve = 0;
+ inTrim = 0;
+ playBack = 0;
+ jumpbuffer = newJumpbuffer();
+ subdivider.setJumpbuffer( jumpbuffer );
+}
+
+NurbsTessellator::~NurbsTessellator( void )
+{
+ if( inTrim ) {
+ do_nurbserror( 12 );
+ endtrim();
+ }
+
+ if( inSurface ) {
+ *nextNurbssurface = 0;
+ do_freeall();
+ }
+
+ if (jumpbuffer) {
+ deleteJumpbuffer(jumpbuffer);
+ jumpbuffer= 0;
+ }
+}
+
+/*-----------------------------------------------------------------------------
+ * bgnsurface - allocate and initialize an o_surface structure
+ *
+ * Client: GL user
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::bgnsurface( long nuid )
+{
+ O_surface *o_surface = new(o_surfacePool) O_surface;
+ o_surface->nuid = nuid;
+ THREAD( do_bgnsurface, o_surface, do_freebgnsurface );
+}
+
+/*-----------------------------------------------------------------------------
+ * bgncurve - allocate an initialize an o_curve structure
+ *
+ * Client: GL user
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::bgncurve( long nuid )
+{
+ O_curve *o_curve = new(o_curvePool) O_curve;
+ o_curve->nuid = nuid;
+ THREAD( do_bgncurve, o_curve, do_freebgncurve );
+}
+/*-----------------------------------------------------------------------------
+ * endcurve -
+ *
+ * Client:
+ *-----------------------------------------------------------------------------
+ */
+
+void
+NurbsTessellator::endcurve( void )
+{
+ THREAD2( do_endcurve );
+}
+
+/*-----------------------------------------------------------------------------
+ * endsurface - user level end of surface call
+ *
+ * Client: GL user
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::endsurface( void )
+{
+ THREAD2( do_endsurface );
+}
+
+
+/*-----------------------------------------------------------------------------
+ * bgntrim - allocate and initialize a new trim loop structure (o_trim )
+ *
+ * Client: GL user
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::bgntrim( void )
+{
+ O_trim *o_trim = new(o_trimPool) O_trim;
+ THREAD( do_bgntrim, o_trim, do_freebgntrim );
+}
+
+/*-----------------------------------------------------------------------------
+ * endtrim -
+ *
+ * Client: GL user
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::endtrim( void )
+{
+ THREAD2( do_endtrim );
+}
+
+
+/*-----------------------------------------------------------------------------
+ * pwlcurve -
+ *
+ * count - number of points on curve
+ * array - array of points on curve
+ * byte_stride - distance between points in bytes
+ * type - valid data flag
+ *
+ * Client: Gl user
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::pwlcurve( long count, INREAL array[], long byte_stride, long type )
+{
+ Mapdesc *mapdesc = maplist.locate( type );
+
+ if( mapdesc == 0 ) {
+ do_nurbserror( 35 );
+ isDataValid = 0;
+ return;
+ }
+
+ if ( (type != N_P2D) && (type != N_P2DR) ) {
+ do_nurbserror( 22 );
+ isDataValid = 0;
+ return;
+ }
+ if( count < 0 ) {
+ do_nurbserror( 33 );
+ isDataValid = 0;
+ return;
+ }
+ if( byte_stride < 0 ) {
+ do_nurbserror( 34 );
+ isDataValid = 0;
+ return;
+ }
+
+#ifdef NOTDEF
+ if( mapdesc->isRational() ) {
+ INREAL *p = array;
+ INREAL x = p[0]; INREAL y = p[1]; INREAL w = p[2];
+ p = (INREAL *) (((char *) p) + byte_stride);
+ for( long i = 1; i != count; i++ ) {
+ if( p[0] == x && p[1] == y && p[2] == w ) break;
+ x = p[0]; y = p[1]; w = p[2];
+ p = (INREAL *) (((char *) p) + byte_stride);
+ }
+ if( i != count ) {
+ do_nurbserror( 37 );
+ _glu_dprintf( "point %d (%f,%f)\n", i, x, y );
+ isDataValid = 0;
+ return;
+ }
+ } else {
+ INREAL *p = array;
+ INREAL x = p[0]; INREAL y = p[1];
+ p = (INREAL *) (((char *) p) + byte_stride);
+ for( long i = 1; i != count; i++ ) {
+ if( p[0] == x && p[1] == y ) break;
+ x = p[0]; y = p[1];
+ p = (INREAL *) (((char *) p) + byte_stride);
+ }
+ if( i != count ) {
+ do_nurbserror( 37 );
+ _glu_dprintf( "point %d (%f,%f)\n", i, x, y );
+ isDataValid = 0;
+ return;
+ }
+ }
+#endif
+
+ O_pwlcurve *o_pwlcurve = new(o_pwlcurvePool) O_pwlcurve( type, count, array, byte_stride, extTrimVertexPool.get((int)count) );
+ THREAD( do_pwlcurve, o_pwlcurve, do_freepwlcurve );
+}
+
+
+/*-----------------------------------------------------------------------------
+ * nurbscurve -
+ *
+ * Client: GL user
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::nurbscurve(
+ long nknots, /* number of p knots */
+ INREAL knot[], /* nondecreasing knot values in p */
+ long byte_stride, /* distance in bytes between control points */
+ INREAL ctlarray[], /* pointer to first control point */
+ long order, /* order of spline */
+ long type ) /* description of range space */
+{
+
+ Mapdesc *mapdesc = maplist.locate( type );
+
+ if( mapdesc == 0 ) {
+ do_nurbserror( 35 );
+ isDataValid = 0;
+ return;
+ }
+
+ if( ctlarray == 0 ) {
+ do_nurbserror( 36 );
+ isDataValid = 0;
+ return;
+ }
+
+ if( byte_stride < 0 ) {
+ do_nurbserror( 34 );
+ isDataValid = 0;
+ return;
+ }
+
+ Knotvector knots;
+
+ knots.init( nknots, byte_stride, order, knot );
+ if( do_check_knots( &knots, "curve" ) ) return;
+
+ O_nurbscurve *o_nurbscurve = new(o_nurbscurvePool) O_nurbscurve(type);
+ o_nurbscurve->bezier_curves = new(quiltPool) Quilt(mapdesc);
+ o_nurbscurve->bezier_curves->toBezier( knots,ctlarray, mapdesc->getNcoords() );
+
+ THREAD( do_nurbscurve, o_nurbscurve, do_freenurbscurve );
+}
+
+
+/*-----------------------------------------------------------------------------
+ * nurbssurface -
+ *
+ * Client: User routine
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::nurbssurface(
+ long sknot_count, /* number of s knots */
+ INREAL sknot[], /* nondecreasing knot values in s */
+ long tknot_count, /* number of t knots */
+ INREAL tknot[], /* nondecreasing knot values in t */
+ long s_byte_stride, /* s step size in memory bytes */
+ long t_byte_stride, /* t step size in memory bytes */
+ INREAL ctlarray[], /* pointer to first control point */
+ long sorder, /* order of the spline in s parameter */
+ long torder, /* order of the spline in t parameter */
+ long type) /* description of range space */
+{
+ Mapdesc *mapdesc = maplist.locate( type );
+
+ if( mapdesc == 0 ) {
+ do_nurbserror( 35 );
+ isDataValid = 0;
+ return;
+ }
+
+ if( s_byte_stride < 0 ) {
+ do_nurbserror( 34 );
+ isDataValid = 0;
+ return;
+ }
+
+ if( t_byte_stride < 0 ) {
+ do_nurbserror( 34 );
+ isDataValid = 0;
+ return;
+ }
+
+ Knotvector sknotvector, tknotvector;
+
+ sknotvector.init( sknot_count, s_byte_stride, sorder, sknot );
+ if( do_check_knots( &sknotvector, "surface" ) ) return;
+
+ tknotvector.init( tknot_count, t_byte_stride, torder, tknot );
+ if( do_check_knots( &tknotvector, "surface" ) ) return;
+
+ O_nurbssurface *o_nurbssurface = new(o_nurbssurfacePool) O_nurbssurface(type);
+ o_nurbssurface->bezier_patches = new(quiltPool) Quilt(mapdesc);
+
+ o_nurbssurface->bezier_patches->toBezier( sknotvector, tknotvector,
+ ctlarray, mapdesc->getNcoords() );
+ THREAD( do_nurbssurface, o_nurbssurface, do_freenurbssurface );
+}
+
+
+/*-----------------------------------------------------------------------------
+ * setnurbsproperty -
+ *
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::setnurbsproperty( long tag, INREAL value )
+{
+ if( ! renderhints.isProperty( tag ) ) {
+ do_nurbserror( 26 );
+ } else {
+ Property *prop = new(propertyPool) Property( tag, value );
+ THREAD( do_setnurbsproperty, prop, do_freenurbsproperty );
+ }
+}
+
+/*-----------------------------------------------------------------------------
+ * setnurbsproperty -
+ *
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::setnurbsproperty( long type, long tag, INREAL value )
+{
+ Mapdesc *mapdesc = maplist.locate( type );
+
+ if( mapdesc == 0 ) {
+ do_nurbserror( 35 );
+ return;
+ }
+
+ if( ! mapdesc->isProperty( tag ) ) {
+ do_nurbserror( 26 );
+ return;
+ }
+
+ Property *prop = new(propertyPool) Property( type, tag, value );
+ THREAD( do_setnurbsproperty2, prop, do_freenurbsproperty );
+}
+
+
+/*-----------------------------------------------------------------------------
+ * getnurbsproperty -
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+NurbsTessellator::getnurbsproperty( long tag, INREAL *value )
+{
+ if( renderhints.isProperty( tag ) ) {
+ *value = renderhints.getProperty( tag );
+ } else {
+ do_nurbserror( 26 );
+ }
+}
+
+/*-----------------------------------------------------------------------------
+ * getnurbsproperty -
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+NurbsTessellator::getnurbsproperty( long type, long tag, INREAL *value )
+{
+ Mapdesc *mapdesc = maplist.locate( type );
+
+ if( mapdesc == 0 )
+ do_nurbserror( 35 );
+
+ if( mapdesc->isProperty( tag ) ) {
+ *value = mapdesc->getProperty( tag );
+ } else {
+ do_nurbserror( 26 );
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * setnurbsproperty - accept a user supplied matrix as culling or sampling mat
+ *--------------------------------------------------------------------------
+ */
+
+void
+NurbsTessellator::setnurbsproperty( long type, long purpose, INREAL *mat )
+{
+ // XXX - cannot be put in display list
+ Mapdesc *mapdesc = maplist.locate( type );
+
+ if( mapdesc == 0 ) {
+ do_nurbserror( 35 );
+ isDataValid = 0;
+ } else if( purpose == N_BBOXSIZE ) {
+ mapdesc->setBboxsize( mat );
+ } else {
+#ifndef NDEBUG
+ _glu_dprintf( "ERRORRORRORR!!!\n");
+#endif
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * setnurbsproperty - accept a user supplied matrix as culling or sampling mat
+ *--------------------------------------------------------------------------
+ */
+
+void
+NurbsTessellator::setnurbsproperty( long type, long purpose, INREAL *mat,
+ long rstride, long cstride )
+{
+ // XXX - cannot be put in display list
+ Mapdesc *mapdesc = maplist.locate( type );
+
+ if( mapdesc == 0 ) {
+ do_nurbserror( 35 );
+ isDataValid = 0;
+ } else if( purpose == N_CULLINGMATRIX ) {
+ mapdesc->setCmat( mat, rstride, cstride );
+ } else if( purpose == N_SAMPLINGMATRIX ) {
+ mapdesc->setSmat( mat, rstride, cstride );
+ } else if( purpose == N_BBOXMATRIX ) {
+ mapdesc->setBmat( mat, rstride, cstride );
+ } else {
+#ifndef NDEBUG
+ _glu_dprintf( "ERRORRORRORR!!!\n");
+#endif
+ }
+}
+
+void
+NurbsTessellator::redefineMaps( void )
+{
+ maplist.initialize();
+}
+
+void
+NurbsTessellator::defineMap( long type, long rational, long ncoords )
+{
+ maplist.define( type, (int) rational, (int) ncoords );
+}
+
+void
+NurbsTessellator::discardRecording( void *_dl )
+{
+ delete (DisplayList *) _dl;
+}
+
+void *
+NurbsTessellator::beginRecording( void )
+{
+ dl = new DisplayList( this );
+ return (void *) dl;
+}
+
+void
+NurbsTessellator::endRecording( void )
+{
+ dl->endList();
+ dl = 0;
+}
+
+void
+NurbsTessellator::playRecording( void *_dl )
+{
+ playBack = 1;
+ bgnrender();
+ ((DisplayList *)_dl)->play();
+ endrender();
+ playBack = 0;
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/nurbstess.cc b/mesalib/src/glu/sgi/libnurbs/internals/nurbstess.cc
new file mode 100644
index 000000000..68dfd95f3
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/nurbstess.cc
@@ -0,0 +1,691 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * nurbstess.c++
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "mysetjmp.h"
+#include "mystdio.h"
+#include "nurbsconsts.h"
+#include "nurbstess.h"
+#include "bufpool.h"
+#include "quilt.h"
+#include "knotvector.h"
+#include "mapdesc.h"
+#include "maplist.h"
+
+void
+NurbsTessellator::set_domain_distance_u_rate(REAL u_rate)
+{
+ subdivider.set_domain_distance_u_rate(u_rate);
+}
+
+void
+NurbsTessellator::set_domain_distance_v_rate(REAL v_rate)
+{
+ subdivider.set_domain_distance_v_rate(v_rate);
+}
+
+void
+NurbsTessellator::set_is_domain_distance_sampling(int flag)
+{
+ subdivider.set_is_domain_distance_sampling(flag);
+}
+
+void
+NurbsTessellator::resetObjects( void )
+{
+ subdivider.clear();
+}
+
+void
+NurbsTessellator::makeobj( int )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "makeobj\n" );
+#endif
+}
+
+void
+NurbsTessellator::closeobj( void )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "closeobj\n" );
+#endif
+}
+
+void
+NurbsTessellator::bgnrender( void )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "bgnrender\n" );
+#endif
+}
+
+void
+NurbsTessellator::endrender( void )
+{
+#ifndef NDEBUG
+ _glu_dprintf( "endrender\n" );
+#endif
+}
+
+/*-----------------------------------------------------------------------------
+ * do_freebgnsurface - free o_surface structure
+ *
+ * Client: do_freeall(), bgnsurface()
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::do_freebgnsurface( O_surface *o_surface )
+{
+ o_surface->deleteMe( o_surfacePool );
+}
+
+
+/*-----------------------------------------------------------------------------
+ * do_bgnsurface - begin the display of a surface
+ *
+ * Client: bgnsurface()
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::do_bgnsurface( O_surface *o_surface )
+{
+ if( inSurface ) {
+ do_nurbserror( 27 );
+ endsurface();
+ }
+ inSurface = 1;
+
+ if( ! playBack ) bgnrender();
+
+ isTrimModified = 0;
+ isSurfaceModified = 0;
+ isDataValid = 1;
+ numTrims = 0;
+ currentSurface = o_surface;
+ nextTrim = &( currentSurface->o_trim );
+ nextNurbssurface = &( currentSurface->o_nurbssurface );
+}
+
+/*-----------------------------------------------------------------------------
+ * do_bgncurve - begin the display of a curve
+ *
+ * Client: bgncurve()
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::do_bgncurve( O_curve *o_curve )
+{
+ if ( inCurve ) {
+ do_nurbserror( 6 );
+ endcurve();
+ }
+
+ inCurve = 1;
+ currentCurve = o_curve;
+ currentCurve->curvetype = ct_none;
+
+ if( inTrim ) {
+ if( *nextCurve != o_curve ) {
+ isCurveModified = 1;
+ *nextCurve = o_curve;
+ }
+ } else {
+ if( ! playBack ) bgnrender();
+ isDataValid = 1;
+ }
+ nextCurve = &(o_curve->next);
+ nextPwlcurve = &(o_curve->curve.o_pwlcurve);
+ nextNurbscurve = &(o_curve->curve.o_nurbscurve);
+}
+
+/*-----------------------------------------------------------------------------
+ * do_endcurve -
+ *
+ * Client: endcurve()
+ *-----------------------------------------------------------------------------
+ */
+
+void
+NurbsTessellator::do_endcurve( void )
+{
+ if( ! inCurve ) {
+ do_nurbserror( 7 );
+ return;
+ }
+ inCurve = 0;
+
+ *nextCurve = 0;
+ if (currentCurve->curvetype == ct_nurbscurve)
+ *nextNurbscurve = 0;
+ else
+ *nextPwlcurve = 0;
+
+ if ( ! inTrim ) {
+ if( ! isDataValid ) {
+ do_freecurveall( currentCurve );
+ return;
+ }
+
+ int errval;
+ errval = ::mysetjmp( jumpbuffer );
+ if( errval == 0 ) {
+ if( currentCurve->curvetype == ct_nurbscurve ) {
+ subdivider.beginQuilts();
+ for( O_nurbscurve *n = currentCurve->curve.o_nurbscurve; n != 0; n = n->next )
+ subdivider.addQuilt( n->bezier_curves );
+ subdivider.endQuilts();
+ subdivider.drawCurves();
+ if( ! playBack ) endrender();
+ } else {
+ /* XXX */
+ if( ! playBack ) endrender();
+ /*do_draw_pwlcurve( currentCurve->curve.o_pwlcurve ) */;
+ do_nurbserror( 9 );
+ }
+ } else {
+ if( ! playBack ) endrender();
+ do_nurbserror( errval );
+ }
+ do_freecurveall( currentCurve );
+ resetObjects();
+ }
+}
+
+/*-----------------------------------------------------------------------------
+ * do_endsurface - mark end of surface, display surface, free immediate data
+ *
+ * Client:
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::do_endsurface( void )
+{
+ if( inTrim ) {
+ do_nurbserror( 12 );
+ endtrim();
+ }
+
+ if( ! inSurface ) {
+ do_nurbserror( 13 );
+ return;
+ }
+ inSurface = 0;
+
+ *nextNurbssurface = 0;
+
+ if( ! isDataValid ) {
+ do_freeall( );
+ return;
+ }
+
+ if( *nextTrim != 0 ) {
+ isTrimModified = 1;
+ *nextTrim = 0;
+ }
+
+ int errval;
+
+ errval = ::mysetjmp( jumpbuffer );
+ if( errval == 0 ) {
+ if( numTrims > 0 ) {
+
+ subdivider.beginTrims();
+ for( O_trim *trim = currentSurface->o_trim; trim; trim = trim->next ) {
+ subdivider.beginLoop();
+ for( O_curve *curve = trim->o_curve; curve; curve = curve->next ) {
+ curve->used = 0;
+ assert( curve->curvetype != ct_none );
+ if (curve->curvetype == ct_pwlcurve) {
+ O_pwlcurve *c = curve->curve.o_pwlcurve;
+ subdivider.addArc( c->npts, c->pts, curve->nuid );
+ } else {
+ Quilt *quilt = curve->curve.o_nurbscurve->bezier_curves;
+ Quiltspec *qspec = quilt->qspec;
+ REAL *cpts = quilt->cpts + qspec->offset;
+ REAL *cptsend = cpts + (qspec->width * qspec->order * qspec->stride);
+ for( ; cpts != cptsend; cpts += qspec->order*qspec->stride )
+ subdivider.addArc( cpts, quilt, curve->nuid );
+ }
+ }
+ subdivider.endLoop();
+ }
+ subdivider.endTrims();
+ }
+
+ subdivider.beginQuilts();
+ for( O_nurbssurface *n = currentSurface->o_nurbssurface; n; n = n->next )
+ subdivider.addQuilt( n->bezier_patches );
+ subdivider.endQuilts();
+ subdivider.drawSurfaces( currentSurface->nuid );
+ if( ! playBack ) endrender();
+ } else {
+ if( ! playBack ) endrender();
+ do_nurbserror( errval );
+ }
+
+ do_freeall( );
+ resetObjects();
+}
+
+/*-----------------------------------------------------------------------------
+ * do_freeall - free all data allocated in immediate mode
+ *
+ * Client:
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::do_freeall( void )
+{
+ for( O_trim *o_trim = currentSurface->o_trim; o_trim; ) {
+ O_trim *next_o_trim = o_trim->next;
+ for( O_curve *curve = o_trim->o_curve; curve; ) {
+ O_curve *next_o_curve = curve->next;
+ do_freecurveall( curve );
+ curve = next_o_curve;
+ }
+ if( o_trim->save == 0 ) do_freebgntrim( o_trim );
+ o_trim = next_o_trim;
+ }
+
+ O_nurbssurface *nurbss, *next_nurbss;
+ for( nurbss= currentSurface->o_nurbssurface; nurbss; nurbss = next_nurbss) {
+ next_nurbss = nurbss->next;
+ if( nurbss->save == 0 )
+ do_freenurbssurface( nurbss );
+ else
+ nurbss->used = 0;
+ }
+
+ if( currentSurface->save == 0 ) do_freebgnsurface( currentSurface );
+}
+
+void
+NurbsTessellator::do_freecurveall( O_curve *curve )
+{
+ assert( curve->curvetype != ct_none );
+
+ if( curve->curvetype == ct_nurbscurve ) {
+ O_nurbscurve *ncurve, *next_ncurve;
+ for( ncurve=curve->curve.o_nurbscurve; ncurve; ncurve=next_ncurve ) {
+ next_ncurve = ncurve->next;
+ if( ncurve->save == 0 )
+ do_freenurbscurve( ncurve );
+ else
+ ncurve->used = 0;
+ }
+ } else {
+ O_pwlcurve *pcurve, *next_pcurve;
+ for( pcurve=curve->curve.o_pwlcurve; pcurve; pcurve=next_pcurve ) {
+ next_pcurve = pcurve->next;
+ if( pcurve->save == 0 )
+ do_freepwlcurve( pcurve );
+ else
+ pcurve->used = 0;
+ }
+ }
+ if( curve->save == 0 )
+ do_freebgncurve( curve );
+}
+
+
+/*-----------------------------------------------------------------------------
+ * do_freebgntrim - free the space allocated for a trim loop
+ *
+ * Client:
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::do_freebgntrim( O_trim *o_trim )
+{
+ o_trim->deleteMe( o_trimPool );
+}
+
+
+/*-----------------------------------------------------------------------------
+ * do_bgntrim - link in a trim loop to the current trimmed surface description
+ *
+ * Client: bgntrim()
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::do_bgntrim( O_trim *o_trim )
+{
+
+ if( ! inSurface ) {
+ do_nurbserror( 15 );
+ bgnsurface( 0 );
+ inSurface = 2;
+ }
+
+ if( inTrim ) {
+ do_nurbserror( 16 );
+ endtrim();
+ }
+ inTrim = 1;
+
+ if( *nextTrim != o_trim ) {
+ isTrimModified = 1;
+ *nextTrim = o_trim;
+ }
+
+ currentTrim = o_trim;
+ nextTrim = &(o_trim->next);
+ nextCurve = &(o_trim->o_curve);
+}
+
+
+/*-----------------------------------------------------------------------------
+ * do_endtrim - mark the end of the current trim loop
+ *
+ * Client: endtrim()
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::do_endtrim( void )
+{
+ if( ! inTrim ) {
+ do_nurbserror( 17 );
+ return;
+ }
+ inTrim = 0;
+
+ if( currentTrim->o_curve == 0 ) {
+ do_nurbserror( 18 );
+ isDataValid = 0;
+ }
+
+ numTrims++;
+
+ if( *nextCurve != 0 ) {
+ isTrimModified = 1;
+ *nextCurve = 0;
+ }
+}
+
+/*-----------------------------------------------------------------------------
+ * do_freepwlcurve -
+ *
+ * Client:
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::do_freepwlcurve( O_pwlcurve *o_pwlcurve )
+{
+ o_pwlcurve->deleteMe( o_pwlcurvePool );
+}
+
+void
+NurbsTessellator::do_freebgncurve( O_curve *o_curve )
+{
+ o_curve->deleteMe( o_curvePool );
+}
+
+/*-----------------------------------------------------------------------------
+ * do_pwlcurve - link in pwl trim loop to the current surface description
+ *
+ * Client: pwlcurve()
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::do_pwlcurve( O_pwlcurve *o_pwlcurve )
+{
+ if( ! inTrim ) {
+ do_nurbserror( 19 );
+ if( o_pwlcurve->save == 0 )
+ do_freepwlcurve(o_pwlcurve );
+ return;
+ }
+
+ if( ! inCurve ) {
+ bgncurve( 0 );
+ inCurve = 2;
+ }
+
+ if( o_pwlcurve->used ) {
+ do_nurbserror( 20 );
+ isDataValid = 0;
+ return;
+ } else
+ o_pwlcurve->used = 1;
+
+ if( currentCurve->curvetype == ct_none ) {
+ currentCurve->curvetype = ct_pwlcurve;
+ } else if( currentCurve->curvetype != ct_pwlcurve ) {
+ do_nurbserror( 21 );
+ isDataValid = 0;
+ return;
+ }
+
+ if( *nextPwlcurve != o_pwlcurve ) {
+ isCurveModified = 1;
+ *nextPwlcurve = o_pwlcurve;
+ }
+ nextPwlcurve = &(o_pwlcurve->next);
+
+ if( o_pwlcurve->owner != currentCurve ) {
+ isCurveModified = 1;
+ o_pwlcurve->owner = currentCurve;
+ }
+
+ if( (inCurve == 2) )
+ endcurve();
+}
+
+
+/*-----------------------------------------------------------------------------
+ * do_freenurbscurve -
+ *
+ * Client:
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::do_freenurbscurve( O_nurbscurve *o_nurbscurve )
+{
+ o_nurbscurve->bezier_curves->deleteMe( quiltPool );
+ o_nurbscurve->deleteMe( o_nurbscurvePool );
+}
+
+
+/*-----------------------------------------------------------------------------
+ * do_nurbscurve -
+ *
+ * Client: nurbscurve()
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::do_nurbscurve( O_nurbscurve *o_nurbscurve )
+{
+ if ( ! inCurve ) {
+ bgncurve( 0 );
+ inCurve = 2;
+ }
+
+ if( o_nurbscurve->used ) {
+ /* error - curve was already called in current surface */
+ do_nurbserror( 23 );
+ isDataValid = 0;
+ return;
+ } else
+ o_nurbscurve->used = 1;
+
+ if( currentCurve->curvetype == ct_none ) {
+ currentCurve->curvetype = ct_nurbscurve;
+ } else if( currentCurve->curvetype != ct_nurbscurve ) {
+ do_nurbserror( 24 );
+ isDataValid = 0;
+ return;
+ }
+
+ if( *nextNurbscurve != o_nurbscurve ) {
+ isCurveModified = 1;
+ *nextNurbscurve = o_nurbscurve;
+ }
+
+ nextNurbscurve = &(o_nurbscurve->next);
+
+ if( o_nurbscurve->owner != currentCurve ) {
+ isCurveModified = 1;
+ o_nurbscurve->owner = currentCurve;
+ }
+
+ if( o_nurbscurve->owner == 0 )
+ isCurveModified = 1;
+
+ if( inCurve == 2 )
+ endcurve();
+}
+
+
+/*-----------------------------------------------------------------------------
+ * do_freenurbssurface -
+ *
+ * Client:
+ *-----------------------------------------------------------------------------
+ */
+
+void
+NurbsTessellator::do_freenurbssurface( O_nurbssurface *o_nurbssurface )
+{
+ o_nurbssurface->bezier_patches->deleteMe( quiltPool );
+ o_nurbssurface->deleteMe( o_nurbssurfacePool );
+}
+
+/*-----------------------------------------------------------------------------
+ * do_nurbssurface -
+ *
+ * Client: nurbssurface()
+ *-----------------------------------------------------------------------------
+ */
+void
+NurbsTessellator::do_nurbssurface( O_nurbssurface *o_nurbssurface )
+{
+ if( ! inSurface ) {
+ bgnsurface( 0 );
+ inSurface = 2;
+ }
+
+ if( o_nurbssurface->used ) {
+ /* error - surface was already called in current block */
+ do_nurbserror( 25 );
+ isDataValid = 0;
+ return;
+ } else
+ o_nurbssurface->used = 1;
+
+ if( *nextNurbssurface != o_nurbssurface ) {
+ isSurfaceModified = 1;
+ *nextNurbssurface = o_nurbssurface;
+ }
+
+ if( o_nurbssurface->owner != currentSurface ) {
+ isSurfaceModified = 1;
+ o_nurbssurface->owner = currentSurface;
+ }
+ nextNurbssurface = &(o_nurbssurface->next);
+
+ if( inSurface == 2 )
+ endsurface();
+}
+
+
+/*-----------------------------------------------------------------------------
+ * do_freenurbsproperty
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+NurbsTessellator::do_freenurbsproperty( Property *prop )
+{
+ prop->deleteMe( propertyPool );
+}
+
+
+/*-----------------------------------------------------------------------------
+ * do_setnurbsproperty -
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+NurbsTessellator::do_setnurbsproperty( Property *prop )
+{
+ renderhints.setProperty( prop->tag, prop->value );
+ if( prop->save == 0 )
+ do_freenurbsproperty( prop );
+}
+
+void
+NurbsTessellator::do_setnurbsproperty2( Property *prop )
+{
+ Mapdesc *mapdesc = maplist.find( prop->type );
+
+ mapdesc->setProperty( prop->tag, prop->value );
+ if( prop->save == 0 )
+ do_freenurbsproperty( prop );
+}
+
+void
+NurbsTessellator::errorHandler( int )
+{
+}
+
+void
+NurbsTessellator::do_nurbserror( int msg )
+{
+ errorHandler( msg );
+}
+
+int
+NurbsTessellator::do_check_knots( Knotvector *knots, const char *msg )
+{
+ int status = knots->validate();
+ if( status ) {
+ do_nurbserror( status );
+ if( renderhints.errorchecking != N_NOMSG ) knots->show( msg );
+ }
+ return status;
+}
+
+
+
+
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/nurbstess.h b/mesalib/src/glu/sgi/libnurbs/internals/nurbstess.h
new file mode 100644
index 000000000..a6869002f
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/nurbstess.h
@@ -0,0 +1,172 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * nurbstess.h
+ *
+ */
+
+#ifndef __glunurbstess_h_
+#define __glunurbstess_h_
+
+#include "mysetjmp.h"
+#include "subdivider.h"
+#include "renderhints.h"
+#include "backend.h"
+#include "maplist.h"
+#include "reader.h"
+#include "nurbsconsts.h"
+
+struct Knotvector;
+class Quilt;
+class DisplayList;
+class BasicCurveEvaluator;
+class BasicSurfaceEvaluator;
+
+class NurbsTessellator {
+public:
+ NurbsTessellator( BasicCurveEvaluator &c,
+ BasicSurfaceEvaluator &e );
+ virtual ~NurbsTessellator( void );
+
+ void getnurbsproperty( long, INREAL * );
+ void getnurbsproperty( long, long, INREAL * );
+ void setnurbsproperty( long, INREAL );
+ void setnurbsproperty( long, long, INREAL );
+ void setnurbsproperty( long, long, INREAL * );
+ void setnurbsproperty( long, long, INREAL *, long, long );
+
+ // called before a tessellation begins/ends
+ virtual void bgnrender( void );
+ virtual void endrender( void );
+
+ // called to make a display list of the output vertices
+ virtual void makeobj( int n );
+ virtual void closeobj( void );
+
+ // called when a error occurs
+ virtual void errorHandler( int );
+
+ void bgnsurface( long );
+ void endsurface( void );
+ void bgntrim( void );
+ void endtrim( void );
+ void bgncurve( long );
+ void endcurve( void );
+ void pwlcurve( long, INREAL[], long, long );
+ void nurbscurve( long, INREAL[], long, INREAL[], long, long );
+ void nurbssurface( long, INREAL[], long, INREAL[], long, long,
+ INREAL[], long, long, long );
+
+ void defineMap( long, long, long );
+ void redefineMaps( void );
+
+ // recording of input description
+ void discardRecording( void * );
+ void * beginRecording( void );
+ void endRecording( void );
+ void playRecording( void * );
+
+ //for optimizing untrimmed nurbs in the case of domain distance sampling
+ void set_domain_distance_u_rate(REAL u_rate);
+ void set_domain_distance_v_rate(REAL v_rate);
+ void set_is_domain_distance_sampling(int flag);
+
+
+protected:
+ Renderhints renderhints;
+ Maplist maplist;
+ Backend backend;
+
+private:
+
+ void resetObjects( void );
+ int do_check_knots( Knotvector *, const char * );
+ void do_nurbserror( int );
+ void do_bgncurve( O_curve * );
+ void do_endcurve( void );
+ void do_freeall( void );
+ void do_freecurveall( O_curve * );
+ void do_freebgntrim( O_trim * );
+ void do_freebgncurve( O_curve * );
+ void do_freepwlcurve( O_pwlcurve * );
+ void do_freenurbscurve( O_nurbscurve * );
+ void do_freenurbssurface( O_nurbssurface * );
+ void do_freebgnsurface( O_surface * );
+ void do_bgnsurface( O_surface * );
+ void do_endsurface( void );
+ void do_bgntrim( O_trim * );
+ void do_endtrim( void );
+ void do_pwlcurve( O_pwlcurve * );
+ void do_nurbscurve( O_nurbscurve * );
+ void do_nurbssurface( O_nurbssurface * );
+ void do_freenurbsproperty( Property * );
+ void do_setnurbsproperty( Property * );
+ void do_setnurbsproperty2( Property * );
+
+ Subdivider subdivider;
+ JumpBuffer* jumpbuffer;
+ Pool o_pwlcurvePool;
+ Pool o_nurbscurvePool;
+ Pool o_curvePool;
+ Pool o_trimPool;
+ Pool o_surfacePool;
+ Pool o_nurbssurfacePool;
+ Pool propertyPool;
+public:
+ Pool quiltPool;
+private:
+ TrimVertexPool extTrimVertexPool;
+
+ int inSurface; /* bgnsurface seen */
+ int inCurve; /* bgncurve seen */
+ int inTrim; /* bgntrim seen */
+ int isCurveModified; /* curve changed */
+ int isTrimModified; /* trim curves changed */
+ int isSurfaceModified; /* surface changed */
+ int isDataValid; /* all data is good */
+ int numTrims; /* valid trim regions */
+ int playBack;
+
+ O_trim** nextTrim; /* place to link o_trim */
+ O_curve** nextCurve; /* place to link o_curve */
+ O_nurbscurve** nextNurbscurve; /* place to link o_nurbscurve */
+ O_pwlcurve** nextPwlcurve; /* place to link o_pwlcurve */
+ O_nurbssurface** nextNurbssurface; /* place to link o_nurbssurface */
+
+ O_surface* currentSurface;
+ O_trim* currentTrim;
+ O_curve* currentCurve;
+
+ DisplayList *dl;
+
+};
+
+#endif /* __glunurbstess_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/patch.cc b/mesalib/src/glu/sgi/libnurbs/internals/patch.cc
new file mode 100644
index 000000000..808baa69e
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/patch.cc
@@ -0,0 +1,504 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * patch.c++
+ *
+ */
+
+#include <stdio.h>
+#include "glimports.h"
+#include "mystdio.h"
+#include "myassert.h"
+#include "mymath.h"
+#include "mystring.h"
+#include "patch.h"
+#include "mapdesc.h"
+#include "quilt.h"
+#include "nurbsconsts.h"
+#include "simplemath.h" //for glu_abs function in ::singleStep();
+
+
+/*--------------------------------------------------------------------------
+ * Patch - copy patch from quilt and transform control points
+ *--------------------------------------------------------------------------
+ */
+
+Patch::Patch( Quilt_ptr geo, REAL *pta, REAL *ptb, Patch *n )
+{
+/* pspec[i].range is uninit here */
+ mapdesc = geo->mapdesc;
+ cullval = mapdesc->isCulling() ? CULL_ACCEPT : CULL_TRIVIAL_ACCEPT;
+ notInBbox = mapdesc->isBboxSubdividing() ? 1 : 0;
+ needsSampling = mapdesc->isRangeSampling() ? 1 : 0;
+ pspec[0].order = geo->qspec[0].order;
+ pspec[1].order = geo->qspec[1].order;
+ pspec[0].stride = pspec[1].order * MAXCOORDS;
+ pspec[1].stride = MAXCOORDS;
+
+ /* transform control points to sampling and culling spaces */
+ REAL *ps = geo->cpts;
+ geo->select( pta, ptb );
+ ps += geo->qspec[0].offset;
+ ps += geo->qspec[1].offset;
+ ps += geo->qspec[0].index * geo->qspec[0].order * geo->qspec[0].stride;
+ ps += geo->qspec[1].index * geo->qspec[1].order * geo->qspec[1].stride;
+
+ if( needsSampling ) {
+ mapdesc->xformSampling( ps, geo->qspec[0].order, geo->qspec[0].stride,
+ geo->qspec[1].order, geo->qspec[1].stride,
+ spts, pspec[0].stride, pspec[1].stride );
+ }
+
+ if( cullval == CULL_ACCEPT ) {
+ mapdesc->xformCulling( ps, geo->qspec[0].order, geo->qspec[0].stride,
+ geo->qspec[1].order, geo->qspec[1].stride,
+ cpts, pspec[0].stride, pspec[1].stride );
+ }
+
+ if( notInBbox ) {
+ mapdesc->xformBounding( ps, geo->qspec[0].order, geo->qspec[0].stride,
+ geo->qspec[1].order, geo->qspec[1].stride,
+ bpts, pspec[0].stride, pspec[1].stride );
+ }
+
+ /* set scale range */
+ pspec[0].range[0] = geo->qspec[0].breakpoints[geo->qspec[0].index];
+ pspec[0].range[1] = geo->qspec[0].breakpoints[geo->qspec[0].index+1];
+ pspec[0].range[2] = pspec[0].range[1] - pspec[0].range[0];
+
+ pspec[1].range[0] = geo->qspec[1].breakpoints[geo->qspec[1].index];
+ pspec[1].range[1] = geo->qspec[1].breakpoints[geo->qspec[1].index+1];
+ pspec[1].range[2] = pspec[1].range[1] - pspec[1].range[0];
+
+ // may need to subdivide to match range of sub-patch
+ if( pspec[0].range[0] != pta[0] ) {
+ assert( pspec[0].range[0] < pta[0] );
+ Patch lower( *this, 0, pta[0], 0 );
+ *this = lower;
+ }
+
+ if( pspec[0].range[1] != ptb[0] ) {
+ assert( pspec[0].range[1] > ptb[0] );
+ Patch upper( *this, 0, ptb[0], 0 );
+ }
+
+ if( pspec[1].range[0] != pta[1] ) {
+ assert( pspec[1].range[0] < pta[1] );
+ Patch lower( *this, 1, pta[1], 0 );
+ *this = lower;
+ }
+
+ if( pspec[1].range[1] != ptb[1] ) {
+ assert( pspec[1].range[1] > ptb[1] );
+ Patch upper( *this, 1, ptb[1], 0 );
+ }
+ checkBboxConstraint();
+ next = n;
+}
+
+/*--------------------------------------------------------------------------
+ * Patch - subdivide a patch along an isoparametric line
+ *--------------------------------------------------------------------------
+ */
+
+Patch::Patch( Patch& upper, int param, REAL value, Patch *n )
+{
+ Patch& lower = *this;
+
+ lower.cullval = upper.cullval;
+ lower.mapdesc = upper.mapdesc;
+ lower.notInBbox = upper.notInBbox;
+ lower.needsSampling = upper.needsSampling;
+ lower.pspec[0].order = upper.pspec[0].order;
+ lower.pspec[1].order = upper.pspec[1].order;
+ lower.pspec[0].stride = upper.pspec[0].stride;
+ lower.pspec[1].stride = upper.pspec[1].stride;
+ lower.next = n;
+
+ /* reset scale range */
+ switch( param ) {
+ case 0: {
+ REAL d = (value-upper.pspec[0].range[0]) / upper.pspec[0].range[2];
+ if( needsSampling )
+ mapdesc->subdivide( upper.spts, lower.spts, d, pspec[1].order,
+ pspec[1].stride, pspec[0].order, pspec[0].stride );
+
+ if( cullval == CULL_ACCEPT )
+ mapdesc->subdivide( upper.cpts, lower.cpts, d, pspec[1].order,
+ pspec[1].stride, pspec[0].order, pspec[0].stride );
+
+ if( notInBbox )
+ mapdesc->subdivide( upper.bpts, lower.bpts, d, pspec[1].order,
+ pspec[1].stride, pspec[0].order, pspec[0].stride );
+
+ lower.pspec[0].range[0] = upper.pspec[0].range[0];
+ lower.pspec[0].range[1] = value;
+ lower.pspec[0].range[2] = value - upper.pspec[0].range[0];
+ upper.pspec[0].range[0] = value;
+ upper.pspec[0].range[2] = upper.pspec[0].range[1] - value;
+
+ lower.pspec[1].range[0] = upper.pspec[1].range[0];
+ lower.pspec[1].range[1] = upper.pspec[1].range[1];
+ lower.pspec[1].range[2] = upper.pspec[1].range[2];
+ break;
+ }
+ case 1: {
+ REAL d = (value-upper.pspec[1].range[0]) / upper.pspec[1].range[2];
+ if( needsSampling )
+ mapdesc->subdivide( upper.spts, lower.spts, d, pspec[0].order,
+ pspec[0].stride, pspec[1].order, pspec[1].stride );
+ if( cullval == CULL_ACCEPT )
+ mapdesc->subdivide( upper.cpts, lower.cpts, d, pspec[0].order,
+ pspec[0].stride, pspec[1].order, pspec[1].stride );
+ if( notInBbox )
+ mapdesc->subdivide( upper.bpts, lower.bpts, d, pspec[0].order,
+ pspec[0].stride, pspec[1].order, pspec[1].stride );
+ lower.pspec[0].range[0] = upper.pspec[0].range[0];
+ lower.pspec[0].range[1] = upper.pspec[0].range[1];
+ lower.pspec[0].range[2] = upper.pspec[0].range[2];
+
+ lower.pspec[1].range[0] = upper.pspec[1].range[0];
+ lower.pspec[1].range[1] = value;
+ lower.pspec[1].range[2] = value - upper.pspec[1].range[0];
+ upper.pspec[1].range[0] = value;
+ upper.pspec[1].range[2] = upper.pspec[1].range[1] - value;
+ break;
+ }
+ }
+
+ // inherit bounding box
+ if( mapdesc->isBboxSubdividing() && ! notInBbox )
+ memcpy( lower.bb, upper.bb, sizeof( bb ) );
+
+ lower.checkBboxConstraint();
+ upper.checkBboxConstraint();
+}
+
+/*--------------------------------------------------------------------------
+ * clamp - clamp the sampling rate to a given maximum
+ *--------------------------------------------------------------------------
+ */
+
+void
+Patch::clamp( void )
+{
+ if( mapdesc->clampfactor != N_NOCLAMPING ) {
+ pspec[0].clamp( mapdesc->clampfactor );
+ pspec[1].clamp( mapdesc->clampfactor );
+ }
+}
+
+void
+Patchspec::clamp( REAL clampfactor )
+{
+ if( sidestep[0] < minstepsize )
+ sidestep[0] = clampfactor * minstepsize;
+ if( sidestep[1] < minstepsize )
+ sidestep[1] = clampfactor * minstepsize;
+ if( stepsize < minstepsize )
+ stepsize = clampfactor * minstepsize;
+}
+
+void
+Patch::checkBboxConstraint( void )
+{
+ if( notInBbox &&
+ mapdesc->bboxTooBig( bpts, pspec[0].stride, pspec[1].stride,
+ pspec[0].order, pspec[1].order, bb ) != 1 ) {
+ notInBbox = 0;
+ }
+}
+
+void
+Patch::bbox( void )
+{
+ if( mapdesc->isBboxSubdividing() )
+ mapdesc->surfbbox( bb );
+}
+
+/*--------------------------------------------------------------------------
+ * getstepsize - compute the sampling density across the patch
+ * and determine if patch needs to be subdivided
+ *--------------------------------------------------------------------------
+ */
+
+void
+Patch::getstepsize( void )
+{
+ pspec[0].minstepsize = pspec[1].minstepsize = 0;
+ pspec[0].needsSubdivision = pspec[1].needsSubdivision = 0;
+
+ if( mapdesc->isConstantSampling() ) {
+ // fixed number of samples per patch in each direction
+ // maxsrate is number of s samples per patch
+ // maxtrate is number of t samples per patch
+ pspec[0].getstepsize( mapdesc->maxsrate );
+ pspec[1].getstepsize( mapdesc->maxtrate );
+
+ } else if( mapdesc->isDomainSampling() ) {
+ // maxsrate is number of s samples per unit s length of domain
+ // maxtrate is number of t samples per unit t length of domain
+ pspec[0].getstepsize( mapdesc->maxsrate * pspec[0].range[2] );
+ pspec[1].getstepsize( mapdesc->maxtrate * pspec[1].range[2] );
+
+ } else if( ! needsSampling ) {
+ pspec[0].singleStep();
+ pspec[1].singleStep();
+ } else {
+ // upper bound on path length between sample points
+ REAL tmp[MAXORDER][MAXORDER][MAXCOORDS];
+ const int trstride = sizeof(tmp[0]) / sizeof(REAL);
+ const int tcstride = sizeof(tmp[0][0]) / sizeof(REAL);
+
+ assert( pspec[0].order <= MAXORDER );
+
+ /* points have been transformed, therefore they are homogeneous */
+
+ int val = mapdesc->project( spts, pspec[0].stride, pspec[1].stride,
+ &tmp[0][0][0], trstride, tcstride,
+ pspec[0].order, pspec[1].order );
+ if( val == 0 ) {
+ // control points cross infinity, therefore partials are undefined
+ pspec[0].getstepsize( mapdesc->maxsrate );
+ pspec[1].getstepsize( mapdesc->maxtrate );
+ } else {
+ REAL t1 = mapdesc->getProperty( N_PIXEL_TOLERANCE );
+// REAL t2 = mapdesc->getProperty( N_ERROR_TOLERANCE );
+ pspec[0].minstepsize = ( mapdesc->maxsrate > 0.0 ) ?
+ (pspec[0].range[2] / mapdesc->maxsrate) : 0.0;
+ pspec[1].minstepsize = ( mapdesc->maxtrate > 0.0 ) ?
+ (pspec[1].range[2] / mapdesc->maxtrate) : 0.0;
+ if( mapdesc->isParametricDistanceSampling() ||
+ mapdesc->isObjectSpaceParaSampling() ) {
+
+ REAL t2;
+ t2 = mapdesc->getProperty( N_ERROR_TOLERANCE );
+
+ // t2 is upper bound on the distance between surface and tessellant
+ REAL ssv[2], ttv[2];
+ REAL ss = mapdesc->calcPartialVelocity( ssv, &tmp[0][0][0], trstride, tcstride, pspec[0].order, pspec[1].order, 2, 0, pspec[0].range[2], pspec[1].range[2], 0 );
+ REAL st = mapdesc->calcPartialVelocity( 0, &tmp[0][0][0], trstride, tcstride, pspec[0].order, pspec[1].order, 1, 1, pspec[0].range[2], pspec[1].range[2], -1 );
+ REAL tt = mapdesc->calcPartialVelocity( ttv, &tmp[0][0][0], trstride, tcstride, pspec[0].order, pspec[1].order, 0, 2, pspec[0].range[2], pspec[1].range[2], 1 );
+ //make sure that ss st and tt are nonnegative:
+ if(ss <0) ss = -ss;
+ if(st <0) st = -st;
+ if(tt <0) tt = -tt;
+
+ if( ss != 0.0 && tt != 0.0 ) {
+ /* printf( "ssv[0] %g ssv[1] %g ttv[0] %g ttv[1] %g\n",
+ ssv[0], ssv[1], ttv[0], ttv[1] ); */
+ REAL ttq = sqrtf( (float) ss );
+ REAL ssq = sqrtf( (float) tt );
+ REAL ds = sqrtf( 4 * t2 * ttq / ( ss * ttq + st * ssq ) );
+ REAL dt = sqrtf( 4 * t2 * ssq / ( tt * ssq + st * ttq ) );
+ pspec[0].stepsize = ( ds < pspec[0].range[2] ) ? ds : pspec[0].range[2];
+ REAL scutoff = 2.0 * t2 / ( pspec[0].range[2] * pspec[0].range[2]);
+ pspec[0].sidestep[0] = (ssv[0] > scutoff) ? sqrtf( 2.0 * t2 / ssv[0] ) : pspec[0].range[2];
+ pspec[0].sidestep[1] = (ssv[1] > scutoff) ? sqrtf( 2.0 * t2 / ssv[1] ) : pspec[0].range[2];
+
+ pspec[1].stepsize = ( dt < pspec[1].range[2] ) ? dt : pspec[1].range[2];
+ REAL tcutoff = 2.0 * t2 / ( pspec[1].range[2] * pspec[1].range[2]);
+ pspec[1].sidestep[0] = (ttv[0] > tcutoff) ? sqrtf( 2.0 * t2 / ttv[0] ) : pspec[1].range[2];
+ pspec[1].sidestep[1] = (ttv[1] > tcutoff) ? sqrtf( 2.0 * t2 / ttv[1] ) : pspec[1].range[2];
+ } else if( ss != 0.0 ) {
+ REAL x = pspec[1].range[2] * st;
+ REAL ds = ( sqrtf( x * x + 8.0 * t2 * ss ) - x ) / ss;
+ pspec[0].stepsize = ( ds < pspec[0].range[2] ) ? ds : pspec[0].range[2];
+ REAL scutoff = 2.0 * t2 / ( pspec[0].range[2] * pspec[0].range[2]);
+ pspec[0].sidestep[0] = (ssv[0] > scutoff) ? sqrtf( 2.0 * t2 / ssv[0] ) : pspec[0].range[2];
+ pspec[0].sidestep[1] = (ssv[1] > scutoff) ? sqrtf( 2.0 * t2 / ssv[1] ) : pspec[0].range[2];
+ pspec[1].singleStep();
+ } else if( tt != 0.0 ) {
+ REAL x = pspec[0].range[2] * st;
+ REAL dt = ( sqrtf( x * x + 8.0 * t2 * tt ) - x ) / tt;
+ pspec[0].singleStep();
+ REAL tcutoff = 2.0 * t2 / ( pspec[1].range[2] * pspec[1].range[2]);
+ pspec[1].stepsize = ( dt < pspec[1].range[2] ) ? dt : pspec[1].range[2];
+ pspec[1].sidestep[0] = (ttv[0] > tcutoff) ? sqrtf( 2.0 * t2 / ttv[0] ) : pspec[1].range[2];
+ pspec[1].sidestep[1] = (ttv[1] > tcutoff) ? sqrtf( 2.0 * t2 / ttv[1] ) : pspec[1].range[2];
+ } else {
+ if( 4.0 * t2 > st * pspec[0].range[2] * pspec[1].range[2] ) {
+ pspec[0].singleStep();
+ pspec[1].singleStep();
+ } else {
+ REAL area = 4.0 * t2 / st;
+ REAL ds = sqrtf( area * pspec[0].range[2] / pspec[1].range[2] );
+ REAL dt = sqrtf( area * pspec[1].range[2] / pspec[0].range[2] );
+ pspec[0].stepsize = ( ds < pspec[0].range[2] ) ? ds : pspec[0].range[2];
+ pspec[0].sidestep[0] = pspec[0].range[2];
+ pspec[0].sidestep[1] = pspec[0].range[2];
+
+ pspec[1].stepsize = ( dt < pspec[1].range[2] ) ? dt : pspec[1].range[2];
+ pspec[1].sidestep[0] = pspec[1].range[2];
+ pspec[1].sidestep[1] = pspec[1].range[2];
+ }
+ }
+ } else if( mapdesc->isPathLengthSampling() ||
+ mapdesc->isObjectSpacePathSampling()) {
+ // t1 is upper bound on path length
+ REAL msv[2], mtv[2];
+ REAL ms = mapdesc->calcPartialVelocity( msv, &tmp[0][0][0], trstride, tcstride, pspec[0].order, pspec[1].order, 1, 0, pspec[0].range[2], pspec[1].range[2], 0 );
+ REAL mt = mapdesc->calcPartialVelocity( mtv, &tmp[0][0][0], trstride, tcstride, pspec[0].order, pspec[1].order, 0, 1, pspec[0].range[2], pspec[1].range[2], 1 );
+ REAL side_scale = 1.0;
+
+ if( ms != 0.0 ) {
+ if( mt != 0.0 ) {
+/* REAL d = t1 / ( ms * ms + mt * mt );*/
+/* REAL ds = mt * d;*/
+ REAL ds = t1 / (2.0*ms);
+/* REAL dt = ms * d;*/
+ REAL dt = t1 / (2.0*mt);
+ pspec[0].stepsize = ( ds < pspec[0].range[2] ) ? ds : pspec[0].range[2];
+ pspec[0].sidestep[0] = ( msv[0] * pspec[0].range[2] > t1 ) ? (side_scale* t1 / msv[0]) : pspec[0].range[2];
+ pspec[0].sidestep[1] = ( msv[1] * pspec[0].range[2] > t1 ) ? (side_scale* t1 / msv[1]) : pspec[0].range[2];
+
+ pspec[1].stepsize = ( dt < pspec[1].range[2] ) ? dt : pspec[1].range[2];
+ pspec[1].sidestep[0] = ( mtv[0] * pspec[1].range[2] > t1 ) ? (side_scale*t1 / mtv[0]) : pspec[1].range[2];
+ pspec[1].sidestep[1] = ( mtv[1] * pspec[1].range[2] > t1 ) ? (side_scale*t1 / mtv[1]) : pspec[1].range[2];
+ } else {
+ pspec[0].stepsize = ( t1 < ms * pspec[0].range[2] ) ? (t1 / ms) : pspec[0].range[2];
+ pspec[0].sidestep[0] = ( msv[0] * pspec[0].range[2] > t1 ) ? (t1 / msv[0]) : pspec[0].range[2];
+ pspec[0].sidestep[1] = ( msv[1] * pspec[0].range[2] > t1 ) ? (t1 / msv[1]) : pspec[0].range[2];
+
+ pspec[1].singleStep();
+ }
+ } else {
+ if( mt != 0.0 ) {
+ pspec[0].singleStep();
+
+ pspec[1].stepsize = ( t1 < mt * pspec[1].range[2] ) ? (t1 / mt) : pspec[1].range[2];
+ pspec[1].sidestep[0] = ( mtv[0] * pspec[1].range[2] > t1 ) ? (t1 / mtv[0]) : pspec[1].range[2];
+ pspec[1].sidestep[1] = ( mtv[1] * pspec[1].range[2] > t1 ) ? (t1 / mtv[1]) : pspec[1].range[2];
+ } else {
+ pspec[0].singleStep();
+ pspec[1].singleStep();
+ }
+ }
+ } else if( mapdesc->isSurfaceAreaSampling() ) {
+ // t is the square root of area
+/*
+ REAL msv[2], mtv[2];
+ REAL ms = mapdesc->calcPartialVelocity( msv, &tmp[0][0][0], trstride, tcstride, pspec[0].order, pspec[1].order, 1, 0, pspec[0].range[2], pspec[1].range[2], 0 );
+ REAL mt = mapdesc->calcPartialVelocity( mtv, &tmp[0][0][0], trstride, tcstride, pspec[0].order, pspec[1].order, 0, 1, pspec[0].range[2], pspec[1].range[2], 1 );
+ if( ms != 0.0 && mt != 0.0 ) {
+ REAL d = 1.0 / (ms * mt);
+ t *= M_SQRT2;
+ REAL ds = t * sqrtf( d * pspec[0].range[2] / pspec[1].range[2] );
+ REAL dt = t * sqrtf( d * pspec[1].range[2] / pspec[0].range[2] );
+ pspec[0].stepsize = ( ds < pspec[0].range[2] ) ? ds : pspec[0].range[2];
+ pspec[0].sidestep[0] = ( msv[0] * pspec[0].range[2] > t ) ? (t / msv[0]) : pspec[0].range[2];
+ pspec[0].sidestep[1] = ( msv[1] * pspec[0].range[2] > t ) ? (t / msv[1]) : pspec[0].range[2];
+
+ pspec[1].stepsize = ( dt < pspec[1].range[2] ) ? dt : pspec[1].range[2];
+ pspec[1].sidestep[0] = ( mtv[0] * pspec[1].range[2] > t ) ? (t / mtv[0]) : pspec[1].range[2];
+ pspec[1].sidestep[1] = ( mtv[1] * pspec[1].range[2] > t ) ? (t / mtv[1]) : pspec[1].range[2];
+ } else {
+ pspec[0].singleStep();
+ pspec[1].singleStep();
+ }
+*/
+ } else {
+ pspec[0].singleStep();
+ pspec[1].singleStep();
+ }
+ }
+ }
+
+#ifdef DEBUG
+ _glu_dprintf( "sidesteps %g %g %g %g, stepsize %g %g\n",
+ pspec[0].sidestep[0], pspec[0].sidestep[1],
+ pspec[1].sidestep[0], pspec[1].sidestep[1],
+ pspec[0].stepsize, pspec[1].stepsize );
+#endif
+
+ if( mapdesc->minsavings != N_NOSAVINGSSUBDIVISION ) {
+ REAL savings = 1./(pspec[0].stepsize * pspec[1].stepsize) ;
+ savings-= (2./( pspec[0].sidestep[0] + pspec[0].sidestep[1] )) *
+ (2./( pspec[1].sidestep[0] + pspec[1].sidestep[1] ));
+
+ savings *= pspec[0].range[2] * pspec[1].range[2];
+ if( savings > mapdesc->minsavings ) {
+ pspec[0].needsSubdivision = pspec[1].needsSubdivision = 1;
+ }
+ }
+
+ if( pspec[0].stepsize < pspec[0].minstepsize ) pspec[0].needsSubdivision = 1;
+ if( pspec[1].stepsize < pspec[1].minstepsize ) pspec[1].needsSubdivision = 1;
+ needsSampling = (needsSampling ? needsSamplingSubdivision() : 0);
+}
+
+void
+Patchspec::singleStep()
+{
+ stepsize = sidestep[0] = sidestep[1] = glu_abs(range[2]);
+}
+
+void
+Patchspec::getstepsize( REAL max ) // max is number of samples for entire patch
+{
+ stepsize = ( max >= 1.0 ) ? range[2] / max : range[2];
+ if (stepsize < 0.0) {
+ stepsize = -stepsize;
+ }
+ sidestep[0] = sidestep[1] = minstepsize = stepsize;
+}
+
+int
+Patch::needsSamplingSubdivision( void )
+{
+ return (pspec[0].needsSubdivision || pspec[1].needsSubdivision) ? 1 : 0;
+}
+
+int
+Patch::needsNonSamplingSubdivision( void )
+{
+ return notInBbox;
+}
+
+int
+Patch::needsSubdivision( int param )
+{
+ return pspec[param].needsSubdivision;
+}
+
+int
+Patch::cullCheck( void )
+{
+ if( cullval == CULL_ACCEPT )
+ cullval = mapdesc->cullCheck( cpts, pspec[0].order, pspec[0].stride,
+ pspec[1].order, pspec[1].stride );
+ return cullval;
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/patch.h b/mesalib/src/glu/sgi/libnurbs/internals/patch.h
new file mode 100644
index 000000000..324a25938
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/patch.h
@@ -0,0 +1,94 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * patch.h
+ *
+ */
+
+#ifndef __glupatch_h_
+#define __glupatch_h_
+
+#include "types.h"
+#include "defines.h"
+
+class Quilt;
+class Mapdesc;
+
+
+struct Pspec {
+ REAL range[3];
+ REAL sidestep[2];
+ REAL stepsize;
+ REAL minstepsize;
+ int needsSubdivision;
+};
+
+struct Patchspec : public Pspec {
+ int order;
+ int stride;
+ void clamp( REAL );
+ void getstepsize( REAL );
+ void singleStep( void );
+};
+
+class Patch {
+public:
+friend class Subdivider;
+friend class Quilt;
+friend class Patchlist;
+ Patch( Quilt *, REAL*, REAL *, Patch * );
+ Patch( Patch &, int, REAL, Patch * );
+ void bbox( void );
+ void clamp( void );
+ void getstepsize( void );
+ int cullCheck( void );
+ int needsSubdivision( int );
+ int needsSamplingSubdivision( void );
+ int needsNonSamplingSubdivision( void );
+
+ int get_uorder() {return pspec[0].order;}
+ int get_vorder() {return pspec[1].order;}
+
+private:
+
+ Mapdesc* mapdesc;
+ Patch* next;
+ int cullval;
+ int notInBbox;
+ int needsSampling;
+ REAL cpts[MAXORDER*MAXORDER*MAXCOORDS]; //culling pts
+ REAL spts[MAXORDER*MAXORDER*MAXCOORDS]; //sampling pts
+ REAL bpts[MAXORDER*MAXORDER*MAXCOORDS]; //bbox pts
+ Patchspec pspec[2];
+ void checkBboxConstraint( void );
+ REAL bb[2][MAXCOORDS];
+};
+#endif /* __glupatch_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/patchlist.cc b/mesalib/src/glu/sgi/libnurbs/internals/patchlist.cc
new file mode 100644
index 000000000..989d2dd00
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/patchlist.cc
@@ -0,0 +1,170 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * patchlist.c++
+ *
+ */
+
+#include <stdio.h>
+#include "glimports.h"
+#include "myassert.h"
+#include "mystdio.h"
+#include "quilt.h"
+#include "patchlist.h"
+#include "patch.h"
+#include "nurbsconsts.h"
+
+Patchlist::Patchlist( Quilt *quilts, REAL *pta, REAL *ptb )
+{
+ patch = 0;
+ for( Quilt *q = quilts; q; q = q->next )
+ patch = new Patch( q, pta, ptb, patch );
+ pspec[0].range[0] = pta[0];
+ pspec[0].range[1] = ptb[0];
+ pspec[0].range[2] = ptb[0] - pta[0];
+
+ pspec[1].range[0] = pta[1];
+ pspec[1].range[1] = ptb[1];
+ pspec[1].range[2] = ptb[1] - pta[1];
+}
+
+Patchlist::Patchlist( Patchlist &upper, int param, REAL value)
+{
+ Patchlist &lower = *this;
+ patch = 0;
+ for( Patch *p = upper.patch; p; p = p->next )
+ patch = new Patch( *p, param, value, patch );
+
+ if( param == 0 ) {
+ lower.pspec[0].range[0] = upper.pspec[0].range[0];
+ lower.pspec[0].range[1] = value;
+ lower.pspec[0].range[2] = value - upper.pspec[0].range[0];
+ upper.pspec[0].range[0] = value;
+ upper.pspec[0].range[2] = upper.pspec[0].range[1] - value;
+ lower.pspec[1] = upper.pspec[1];
+ } else {
+ lower.pspec[0] = upper.pspec[0];
+ lower.pspec[1].range[0] = upper.pspec[1].range[0];
+ lower.pspec[1].range[1] = value;
+ lower.pspec[1].range[2] = value - upper.pspec[1].range[0];
+ upper.pspec[1].range[0] = value;
+ upper.pspec[1].range[2] = upper.pspec[1].range[1] - value;
+ }
+}
+
+Patchlist::~Patchlist()
+{
+ while( patch ) {
+ Patch *p = patch;
+ patch = patch->next;
+ delete p;
+ }
+}
+
+int
+Patchlist::cullCheck( void )
+{
+ for( Patch *p = patch; p; p = p->next )
+ if( p->cullCheck() == CULL_TRIVIAL_REJECT )
+ return CULL_TRIVIAL_REJECT;
+ return CULL_ACCEPT;
+}
+
+void
+Patchlist::getRanges(REAL ranges[4])
+{
+ ranges[0] = pspec[0].range[0];
+ ranges[1] = pspec[0].range[1];
+ ranges[2] = pspec[1].range[0];
+ ranges[3] = pspec[1].range[1];
+}
+
+void
+Patchlist::getstepsize( void )
+{
+ pspec[0].stepsize = pspec[0].range[2];
+ pspec[0].sidestep[0] = pspec[0].range[2];
+ pspec[0].sidestep[1] = pspec[0].range[2];
+
+ pspec[1].stepsize = pspec[1].range[2];
+ pspec[1].sidestep[0] = pspec[1].range[2];
+ pspec[1].sidestep[1] = pspec[1].range[2];
+
+ for( Patch *p = patch; p; p = p->next ) {
+ p->getstepsize();
+ p->clamp();
+ pspec[0].stepsize = ((p->pspec[0].stepsize < pspec[0].stepsize) ? p->pspec[0].stepsize : pspec[0].stepsize);
+ pspec[0].sidestep[0] = ((p->pspec[0].sidestep[0] < pspec[0].sidestep[0]) ? p->pspec[0].sidestep[0] : pspec[0].sidestep[0]);
+ pspec[0].sidestep[1] = ((p->pspec[0].sidestep[1] < pspec[0].sidestep[1]) ? p->pspec[0].sidestep[1] : pspec[0].sidestep[1]);
+ pspec[1].stepsize = ((p->pspec[1].stepsize < pspec[1].stepsize) ? p->pspec[1].stepsize : pspec[1].stepsize);
+ pspec[1].sidestep[0] = ((p->pspec[1].sidestep[0] < pspec[1].sidestep[0]) ? p->pspec[1].sidestep[0] : pspec[1].sidestep[0]);
+ pspec[1].sidestep[1] = ((p->pspec[1].sidestep[1] < pspec[1].sidestep[1]) ? p->pspec[1].sidestep[1] : pspec[1].sidestep[1]);
+ }
+}
+
+void
+Patchlist::bbox( void )
+{
+ for( Patch *p = patch; p; p = p->next )
+ p->bbox();
+}
+
+int
+Patchlist::needsNonSamplingSubdivision( void )
+{
+ notInBbox = 0;
+ for( Patch *p = patch; p; p = p->next )
+ notInBbox |= p->needsNonSamplingSubdivision();
+ return notInBbox;
+}
+
+int
+Patchlist::needsSamplingSubdivision( void )
+{
+ pspec[0].needsSubdivision = 0;
+ pspec[1].needsSubdivision = 0;
+
+ for( Patch *p = patch; p; p = p->next ) {
+ pspec[0].needsSubdivision |= p->pspec[0].needsSubdivision;
+ pspec[1].needsSubdivision |= p->pspec[0].needsSubdivision;
+ }
+ return (pspec[0].needsSubdivision || pspec[1].needsSubdivision) ? 1 : 0;
+}
+
+int
+Patchlist::needsSubdivision( int param )
+{
+ return pspec[param].needsSubdivision;
+}
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/patchlist.h b/mesalib/src/glu/sgi/libnurbs/internals/patchlist.h
new file mode 100644
index 000000000..9bfc5b47a
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/patchlist.h
@@ -0,0 +1,92 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * patchlist.h
+ *
+ */
+
+#ifndef __glupatchlist_h_
+#define __glupatchlist_h_
+
+#include "types.h"
+#include "defines.h"
+#include "patch.h"
+
+class Quilt;
+
+class Patchlist {
+friend class Subdivider;
+public:
+ Patchlist( Quilt *, REAL *, REAL * );
+ Patchlist( Patchlist &, int , REAL );
+ ~Patchlist();
+ void bbox();
+ int cullCheck( void );
+ void getstepsize( void );
+ int needsNonSamplingSubdivision( void );
+ int needsSamplingSubdivision( void );
+ int needsSubdivision( int );
+ REAL getStepsize( int );
+ void getRanges(REAL ranges[4]);
+
+ int get_uorder();
+ int get_vorder();
+private:
+ Patch *patch;
+ int notInBbox;
+ int needsSampling;
+ Pspec pspec[2];
+};
+
+inline REAL
+Patchlist::getStepsize( int param )
+{
+ return pspec[param].stepsize;
+}
+
+inline int
+Patchlist::get_uorder()
+{
+ return patch->get_uorder();
+
+}
+
+inline int
+ Patchlist::get_vorder()
+{
+ return patch->get_vorder();
+}
+
+
+
+
+
+#endif /* __glupatchlist_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/pwlarc.h b/mesalib/src/glu/sgi/libnurbs/internals/pwlarc.h
new file mode 100644
index 000000000..2e5175a6f
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/pwlarc.h
@@ -0,0 +1,78 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * pwlarc.h
+ *
+ */
+
+#ifndef __glupwlarc_h_
+#define __glupwlarc_h_
+
+#include "myassert.h"
+#include "nurbsconsts.h"
+
+class TrimVertex;
+
+class PwlArc : public PooledObj { /* a piecewise-linear arc */
+public:
+ TrimVertex * pts; /* sample points */
+ int npts; /* number of sample points */
+ long type; /* curve type */
+ inline PwlArc( void );
+ inline PwlArc( int, TrimVertex * );
+ inline PwlArc( int, TrimVertex *, long );
+};
+
+inline
+PwlArc::PwlArc( void )
+{
+ type = N_P2D;
+ pts = 0;
+ npts = -1;
+}
+
+inline
+PwlArc::PwlArc( int _npts, TrimVertex *_pts )
+{
+ pts = _pts;
+ npts = _npts;
+ type = N_P2D;
+}
+
+inline
+PwlArc::PwlArc( int _npts, TrimVertex *_pts, long _type )
+{
+ pts = _pts;
+ npts = _npts;
+ type = _type;
+}
+
+#endif /* __glupwlarc_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/quilt.cc b/mesalib/src/glu/sgi/libnurbs/internals/quilt.cc
new file mode 100644
index 000000000..4fc58b747
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/quilt.cc
@@ -0,0 +1,276 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * quilt.c++
+ *
+ */
+
+#include "glimports.h"
+#include "mystdio.h"
+#include "myassert.h"
+#include "quilt.h"
+#include "backend.h"
+#include "mapdesc.h"
+#include "flist.h"
+#include "knotvector.h"
+#include "patchlist.h"
+#include "math.h" //fglu_abs()
+#include "simplemath.h" //min()
+
+/* local preprocessor definitions */
+#define DEF_PATCH_STEPSIZE .4
+#define fsizeof(x) (sizeof(x)/sizeof(REAL))
+
+
+Quilt::Quilt( Mapdesc *_mapdesc )
+{
+ mapdesc = _mapdesc;
+}
+
+void
+Quilt::deleteMe( Pool& p )
+{
+ for( Quiltspec *q=qspec; q != eqspec; q++ ) {
+#if 1
+ if( q->breakpoints) delete[] q->breakpoints; q->breakpoints = 0;
+#else
+ if( q->breakpoints) {
+ delete[] q->breakpoints;
+ q->breakpoints = 0;
+printf("in here\n");
+ }
+#endif
+ }
+ if( cpts ) delete[] cpts;
+ cpts = 0;
+ PooledObj::deleteMe( p );
+}
+
+void
+Quilt::show( void )
+{
+#ifndef NDEBUG
+ int nc = mapdesc->getNcoords();
+ REAL *ps = cpts;
+ ps += qspec[0].offset;
+ ps += qspec[1].offset;
+ for( int i=0; i!= qspec[0].order * qspec[0].width; i++ ) {
+ for( int j = 0; j!= qspec[1].order * qspec[1].width; j++ ) {
+ for( int k=0; k < nc; k++ )
+ _glu_dprintf( "%g ", ps[i*qspec[0].stride + j*qspec[1].stride + k] );
+ _glu_dprintf( "\n" );
+ }
+ _glu_dprintf( "\n" );
+ }
+ _glu_dprintf( "\n" );
+#endif
+}
+
+/*--------------------------------------------------------------------------
+ * Quilt::select - find which map in each quilt contains the points
+ * pta and ptb with pta[i] < ptb[i]
+ *--------------------------------------------------------------------------
+ */
+
+void
+Quilt::select( REAL *pta, REAL *ptb )
+{
+ int dim = eqspec - qspec;
+ int i, j;
+ for( i=0; i<dim; i++) {
+ for( j=qspec[i].width-1; j>=0; j-- )
+ if( (qspec[i].breakpoints[j] <= pta[i] ) &&
+ (ptb[i] <= qspec[i].breakpoints[j+1] ) )
+ break;
+ assert( j != -1 );
+ qspec[i].index = j;
+ }
+}
+
+void
+Quilt::download( Backend &backend )
+{
+ if( getDimension() == 2 ) {
+ REAL *ps = cpts;
+ ps += qspec[0].offset;
+ ps += qspec[1].offset;
+ ps += qspec[0].index * qspec[0].order * qspec[0].stride;
+ ps += qspec[1].index * qspec[1].order * qspec[1].stride;
+ backend.surfpts( mapdesc->getType(), ps,
+ qspec[0].stride,
+ qspec[1].stride,
+ qspec[0].order,
+ qspec[1].order,
+ qspec[0].breakpoints[qspec[0].index],
+ qspec[0].breakpoints[qspec[0].index+1],
+ qspec[1].breakpoints[qspec[1].index],
+ qspec[1].breakpoints[qspec[1].index+1] );
+ } else {
+ REAL *ps = cpts;
+ ps += qspec[0].offset;
+ ps += qspec[0].index * qspec[0].order * qspec[0].stride;
+ backend.curvpts( mapdesc->getType(), ps,
+ qspec[0].stride,
+ qspec[0].order,
+ qspec[0].breakpoints[qspec[0].index],
+ qspec[0].breakpoints[qspec[0].index+1] );
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * Quilt::downloadAll - download each map that contains the current patch
+ *--------------------------------------------------------------------------
+ */
+
+void
+Quilt::downloadAll( REAL *pta, REAL *ptb, Backend &backend )
+{
+ for( Quilt *m = this; m; m=m->next ) {
+ m->select( pta, ptb );
+ m->download( backend );
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * Quilt::isCulled - determine if an entire quilt is trivially rejected.
+ *--------------------------------------------------------------------------
+ */
+
+int
+Quilt::isCulled( void )
+{
+ if( mapdesc->isCulling() )
+ return mapdesc->xformAndCullCheck( cpts + qspec[0].offset + qspec[1].offset,
+ qspec[0].order * qspec[0].width, qspec[0].stride,
+ qspec[1].order * qspec[1].width, qspec[1].stride );
+ else
+ return CULL_ACCEPT;
+}
+
+/*---------------------------------------------------------------------------
+ * Quilt::getRange - retrieve the valid paramater range of a set of quilts
+ *---------------------------------------------------------------------------
+ */
+void
+Quilt::getRange( REAL *from, REAL *to, Flist& slist, Flist &tlist )
+{
+ getRange( from, to, 0, slist );
+ getRange( from, to, 1, tlist );
+}
+
+/*---------------------------------------------------------------------------
+ * Quilt::getRange - retrieve the valid paramater range of a set of quilts
+ *---------------------------------------------------------------------------
+ */
+void
+Quilt::getRange( REAL *from, REAL *to, int i, Flist &list )
+{
+ Quilt *maps = this;
+ from[i] = maps->qspec[i].breakpoints[0];
+ to[i] = maps->qspec[i].breakpoints[maps->qspec[i].width];
+ int maxpts = 0;
+ Quilt_ptr m;
+ for( m=maps; m; m=m->next ) {
+ if( m->qspec[i].breakpoints[0] > from[i] )
+ from[i] = m->qspec[i].breakpoints[0];
+ if( m->qspec[i].breakpoints[m->qspec[i].width] < to[i] )
+ to[i] = m->qspec[i].breakpoints[m->qspec[i].width];
+ maxpts += m->qspec[i].width + 1;
+ }
+
+ list.grow( maxpts );
+
+ for( m=maps; m; m=m->next )
+ for( int j=0; j<=m->qspec[i].width; j++ ) {
+ list.add( m->qspec[i].breakpoints[j] );
+ }
+
+ list.filter( );
+ list.taper( from[i], to[i] );
+}
+
+void
+Quilt::getRange( REAL *from, REAL *to, Flist& slist )
+{
+ getRange( from, to, 0, slist );
+}
+
+void
+Quilt::findRates( Flist& slist, Flist& tlist, REAL rate[2] )
+{
+ findSampleRates( slist, tlist );
+ rate[0] = qspec[0].step_size;
+ rate[1] = qspec[1].step_size;
+
+ for( Quilt *q = next; q; q = q->next ) {
+ q->findSampleRates( slist, tlist );
+ if( q->qspec[0].step_size < rate[0] )
+ rate[0] = q->qspec[0].step_size;
+ if( q->qspec[1].step_size < rate[1] )
+ rate[1] = q->qspec[1].step_size;
+ }
+}
+
+void
+Quilt::findSampleRates( Flist& slist, Flist& tlist )
+{
+ qspec[0].step_size = DEF_PATCH_STEPSIZE *
+ (qspec[0].breakpoints[qspec[0].width] - qspec[0].breakpoints[0]);
+ qspec[1].step_size = DEF_PATCH_STEPSIZE *
+ (qspec[1].breakpoints[qspec[1].width] - qspec[1].breakpoints[0]);
+
+ for( int i = slist.start; i < slist.end-1; i++ ) {
+ for( int j = tlist.start; j < tlist.end-1; j++ ) {
+
+ REAL pta[2], ptb[2];
+ pta[0] = slist.pts[i];
+ ptb[0] = slist.pts[i+1];
+ pta[1] = tlist.pts[j];
+ ptb[1] = tlist.pts[j+1];
+ Patchlist patchlist( this, pta, ptb );
+ patchlist.getstepsize();
+
+ {
+ float edge_len_s = min(glu_abs(ptb[0]-pta[0]),1.0);
+ float edge_len_t = min(glu_abs(ptb[1]-pta[1]),1.0);
+
+ if( patchlist.getStepsize(0)/edge_len_s < qspec[0].step_size )
+ qspec[0].step_size = patchlist.getStepsize(0)/edge_len_s;
+ if( patchlist.getStepsize(1)/edge_len_t < qspec[1].step_size )
+ qspec[1].step_size = patchlist.getStepsize(1)/edge_len_t;
+ }
+ }
+ }
+}
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/quilt.h b/mesalib/src/glu/sgi/libnurbs/internals/quilt.h
new file mode 100644
index 000000000..fe1e3309e
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/quilt.h
@@ -0,0 +1,92 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * quilt.h
+ *
+ */
+
+#ifndef __gluquilt_h_
+#define __gluquilt_h_
+
+#include "defines.h"
+#include "bufpool.h"
+#include "types.h"
+
+class Backend;
+class Mapdesc;
+class Flist;
+struct Knotvector;
+
+/* constants for memory allocation of NURBS to Bezier conversion */
+#define MAXDIM 2
+
+struct Quiltspec { /* a specification for a dimension of a quilt */
+ int stride; /* words between points */
+ int width; /* number of segments */
+ int offset; /* words to first point */
+ int order; /* order */
+ int index; /* current segment number */
+ int bdry[2]; /* boundary edge flag */
+ REAL step_size;
+ Knot * breakpoints;
+};
+
+typedef Quiltspec *Quiltspec_ptr;
+
+class Quilt : public PooledObj { /* an array of bezier patches */
+public:
+ Quilt( Mapdesc * );
+ Mapdesc * mapdesc; /* map descriptor */
+ REAL * cpts; /* control points */
+ Quiltspec qspec[MAXDIM]; /* the dimensional data */
+ Quiltspec_ptr eqspec; /* qspec trailer */
+ Quilt *next; /* next quilt in linked list */
+
+public:
+ void deleteMe( Pool& );
+ void toBezier( Knotvector &, INREAL *, long );
+ void toBezier( Knotvector &, Knotvector &, INREAL *, long );
+ void select( REAL *, REAL * );
+ int getDimension( void ) { return eqspec - qspec; }
+ void download( Backend & );
+ void downloadAll( REAL *, REAL *, Backend & );
+ int isCulled( void );
+ void getRange( REAL *, REAL *, Flist&, Flist & );
+ void getRange( REAL *, REAL *, int, Flist & );
+ void getRange( REAL *, REAL *, Flist& );
+ void findRates( Flist& slist, Flist& tlist, REAL[2] );
+ void findSampleRates( Flist& slist, Flist& tlist );
+ void show();
+};
+
+typedef class Quilt *Quilt_ptr;
+
+#endif /* __gluquilt_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/reader.cc b/mesalib/src/glu/sgi/libnurbs/internals/reader.cc
new file mode 100644
index 000000000..6135eef60
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/reader.cc
@@ -0,0 +1,146 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * reader.c++
+ *
+ */
+
+#include <stdio.h>
+#include "glimports.h"
+#include "nurbsconsts.h"
+#include "reader.h"
+#include "trimvertex.h"
+#include "simplemath.h"
+
+//when read a pwlCurve, if two consecutive points are the same, then
+//eliminate one of them. This makes the tessellator more robust. The spec
+//assumes the application makes sure there are no redundant points.
+//but in Inspector, the trim curves seem to have redundant points a lot.
+//I guess other similar users may have the same problem.
+
+#define ELIMINATE_REDUNDANT_POINTS
+
+#ifdef ELIMINATE_REDUNDANT_POINTS
+#define equal(x,y) ( glu_abs(x-y) <= 0.00001)
+#endif
+
+#ifdef ELIMINATE_REDUNDANT_POINTS
+O_pwlcurve::O_pwlcurve( long _type, long count, INREAL *array, long byte_stride, TrimVertex *trimpts )
+{
+ next = 0;
+ used = 0;
+ owner = 0;
+ pts = trimpts;
+ npts = (int) count;
+ int i;
+
+ /* copy user data into internal trimming data structures */
+ switch( _type ) {
+ case N_P2D: {
+ TrimVertex *v = pts;
+ TrimVertex *prev = NULL;
+ int num = 0;
+ int doit;
+ for(i=0; i<count; i++) {
+ doit = 1;
+ if(prev != NULL)
+ {
+ if(equal(prev->param[0], array[0]) && equal(prev->param[1], array[1]))
+ {
+ doit = 0;
+ }
+ }
+
+ if(doit)
+ {
+ v->param[0] = (REAL) array[0];
+ v->param[1] = (REAL) array[1];
+ prev = v;
+ v++;
+ num++;
+ }
+ array = (INREAL *) (((char *) array) + byte_stride);
+ }
+ npts = num;
+ break;
+ }
+ case N_P2DR: {
+ TrimVertex *v = pts;
+ for( TrimVertex *lastv = v + count; v != lastv; v++ ) {
+ v->param[0] = (REAL) array[0] / (REAL) array[2];
+ v->param[1] = (REAL) array[1] / (REAL) array[2];
+ array = (INREAL *) (((char *) array) + byte_stride);
+ }
+ break;
+ }
+ }
+}
+#else
+O_pwlcurve::O_pwlcurve( long _type, long count, INREAL *array, long byte_stride, TrimVertex *trimpts )
+{
+ next = 0;
+ used = 0;
+ owner = 0;
+ pts = trimpts;
+ npts = (int) count;
+
+ /* copy user data into internal trimming data structures */
+ switch( _type ) {
+ case N_P2D: {
+ TrimVertex *v = pts;
+ for( TrimVertex *lastv = v + count; v != lastv; v++ ) {
+ v->param[0] = (REAL) array[0];
+ v->param[1] = (REAL) array[1];
+ array = (INREAL *) (((char *) array) + byte_stride);
+ }
+ break;
+ }
+ case N_P2DR: {
+ TrimVertex *v = pts;
+ for( TrimVertex *lastv = v + count; v != lastv; v++ ) {
+ v->param[0] = (REAL) array[0] / (REAL) array[2];
+ v->param[1] = (REAL) array[1] / (REAL) array[2];
+ array = (INREAL *) (((char *) array) + byte_stride);
+ }
+ break;
+ }
+ }
+}
+#endif
+
+
+
+
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/reader.h b/mesalib/src/glu/sgi/libnurbs/internals/reader.h
new file mode 100644
index 000000000..8a8dcebb5
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/reader.h
@@ -0,0 +1,132 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * reader.h
+ *
+ */
+
+#ifndef __glureader_h_
+#define __glureader_h_
+
+#include "bufpool.h"
+#include "types.h"
+
+enum Curvetype { ct_nurbscurve, ct_pwlcurve, ct_none };
+
+struct Property;
+struct O_surface;
+struct O_nurbssurface;
+struct O_trim;
+class O_pwlcurve;
+struct O_nurbscurve;
+struct O_curve;
+class Quilt;
+class TrimVertex;
+
+
+struct O_curve : public PooledObj {
+ union {
+ O_nurbscurve *o_nurbscurve;
+ O_pwlcurve *o_pwlcurve;
+ } curve;
+ Curvetype curvetype; /* arc type: pwl or nurbs */
+ O_curve * next; /* next arc in loop */
+ O_surface * owner; /* owning surface */
+ int used; /* curve called in cur surf */
+ int save; /* 1 if in display list */
+ long nuid;
+ O_curve() { next = 0; used = 0; owner = 0;
+ curve.o_pwlcurve = 0; }
+ };
+
+struct O_nurbscurve : public PooledObj {
+ Quilt *bezier_curves; /* array of bezier curves */
+ long type; /* range descriptor */
+ REAL tesselation; /* tesselation tolerance */
+ int method; /* tesselation method */
+ O_nurbscurve * next; /* next curve in list */
+ int used; /* curve called in cur surf */
+ int save; /* 1 if in display list */
+ O_curve * owner; /* owning curve */
+ O_nurbscurve( long _type )
+ { type = _type; owner = 0; next = 0; used = 0; }
+ };
+
+class O_pwlcurve : public PooledObj {
+public:
+ TrimVertex *pts; /* array of trim vertices */
+ int npts; /* number of trim vertices */
+ O_pwlcurve * next; /* next curve in list */
+ int used; /* curve called in cur surf */
+ int save; /* 1 if in display list */
+ O_curve * owner; /* owning curve */
+ O_pwlcurve( long, long, INREAL *, long, TrimVertex * );
+ };
+
+struct O_trim : public PooledObj {
+ O_curve *o_curve; /* closed trim loop */
+ O_trim * next; /* next loop along trim */
+ int save; /* 1 if in display list */
+ O_trim() { next = 0; o_curve = 0; }
+ };
+
+struct O_nurbssurface : public PooledObj {
+ Quilt * bezier_patches;/* array of bezier patches */
+ long type; /* range descriptor */
+ O_surface * owner; /* owning surface */
+ O_nurbssurface * next; /* next surface in chain */
+ int save; /* 1 if in display list */
+ int used; /* 1 if prev called in block */
+ O_nurbssurface( long _type )
+ { type = _type; owner = 0; next = 0; used = 0; }
+ };
+
+struct O_surface : public PooledObj {
+ O_nurbssurface * o_nurbssurface; /* linked list of surfaces */
+ O_trim * o_trim; /* list of trim loops */
+ int save; /* 1 if in display list */
+ long nuid;
+ O_surface() { o_trim = 0; o_nurbssurface = 0; }
+ };
+
+struct Property : public PooledObj {
+ long type;
+ long tag;
+ REAL value;
+ int save; /* 1 if in display list */
+ Property( long _type, long _tag, INREAL _value )
+ { type = _type; tag = _tag; value = (REAL) _value; }
+ Property( long _tag, INREAL _value )
+ { type = 0; tag = _tag; value = (REAL) _value; }
+ };
+
+class NurbsTessellator;
+#endif /* __glureader_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/renderhints.cc b/mesalib/src/glu/sgi/libnurbs/internals/renderhints.cc
new file mode 100644
index 000000000..a3aa62d42
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/renderhints.cc
@@ -0,0 +1,133 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * renderhints.c++
+ *
+ */
+
+#include "glimports.h"
+#include "mystdio.h"
+#include "renderhints.h"
+#include "defines.h"
+#include "nurbsconsts.h"
+
+
+/*--------------------------------------------------------------------------
+ * Renderhints::Renderhints - set all window specific options
+ *--------------------------------------------------------------------------
+ */
+Renderhints::Renderhints()
+{
+ display_method = N_FILL;
+ errorchecking = N_MSG;
+ subdivisions = 6.0;
+ tmp1 = 0.0;
+}
+
+void
+Renderhints::init( void )
+{
+ maxsubdivisions = (int) subdivisions;
+ if( maxsubdivisions < 0 ) maxsubdivisions = 0;
+
+
+ if( display_method == N_FILL ) {
+ wiretris = 0;
+ wirequads = 0;
+ } else if( display_method == N_OUTLINE_TRI ) {
+ wiretris = 1;
+ wirequads = 0;
+ } else if( display_method == N_OUTLINE_QUAD ) {
+ wiretris = 0;
+ wirequads = 1;
+ } else {
+ wiretris = 1;
+ wirequads = 1;
+ }
+}
+
+int
+Renderhints::isProperty( long property )
+{
+ switch ( property ) {
+ case N_DISPLAY:
+ case N_ERRORCHECKING:
+ case N_SUBDIVISIONS:
+ case N_TMP1:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+REAL
+Renderhints::getProperty( long property )
+{
+ switch ( property ) {
+ case N_DISPLAY:
+ return display_method;
+ case N_ERRORCHECKING:
+ return errorchecking;
+ case N_SUBDIVISIONS:
+ return subdivisions;
+ case N_TMP1:
+ return tmp1;
+ default:
+ abort();
+ return -1; //not necessary, needed to shut up compiler
+ }
+}
+
+void
+Renderhints::setProperty( long property, REAL value )
+{
+ switch ( property ) {
+ case N_DISPLAY:
+ display_method = value;
+ break;
+ case N_ERRORCHECKING:
+ errorchecking = value;
+ break;
+ case N_SUBDIVISIONS:
+ subdivisions = value;
+ break;
+ case N_TMP1: /* unused */
+ tmp1 = value;
+ break;
+ default:
+ abort();
+ break;
+ }
+}
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/renderhints.h b/mesalib/src/glu/sgi/libnurbs/internals/renderhints.h
new file mode 100644
index 000000000..444f649be
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/renderhints.h
@@ -0,0 +1,60 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * renderhints.h
+ *
+ */
+
+#ifndef __glurenderhints_h_
+#define __glurenderhints_h_
+
+#include "types.h"
+
+class Renderhints {
+public:
+ Renderhints( void );
+ void init( void );
+ int isProperty( long );
+ REAL getProperty( long );
+ void setProperty( long, REAL );
+
+ REAL display_method; /* display mode */
+ REAL errorchecking; /* activate error checking */
+ REAL subdivisions; /* maximum number of subdivisions per patch */
+ REAL tmp1; /* unused */
+
+ int displaydomain;
+ int maxsubdivisions;
+ int wiretris;
+ int wirequads;
+};
+
+#endif /* __glurenderhints_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/simplemath.h b/mesalib/src/glu/sgi/libnurbs/internals/simplemath.h
new file mode 100644
index 000000000..0a060c57e
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/simplemath.h
@@ -0,0 +1,50 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * simplemath.h
+ *
+ */
+
+#ifndef __glusimplemath_h_
+#define __glusimplemath_h_
+
+/* simple inline routines */
+
+inline int
+max( int x, int y ) { return ( x < y ) ? y : x; }
+
+inline REAL
+min( REAL x, REAL y ) { return ( x > y ) ? y : x; }
+
+inline REAL
+glu_abs( REAL x ) { return ( x < 0.0 ) ? -x : x; }
+
+#endif /* __glusimplemath_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/slicer.cc b/mesalib/src/glu/sgi/libnurbs/internals/slicer.cc
new file mode 100644
index 000000000..27d2a650d
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/slicer.cc
@@ -0,0 +1,1300 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * slicer.c++
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include "glimports.h"
+#include "mystdio.h"
+#include "myassert.h"
+#include "bufpool.h"
+#include "slicer.h"
+#include "backend.h"
+#include "arc.h"
+#include "gridtrimvertex.h"
+#include "simplemath.h"
+#include "trimvertex.h"
+#include "varray.h"
+
+#include "polyUtil.h" //for area()
+
+//static int count=0;
+
+/*USE_OPTTT is initiated in trimvertex.h*/
+
+#ifdef USE_OPTTT
+ #include <GL/gl.h>
+#endif
+
+//#define USE_READ_FLAG //whether to use new or old tesselator
+ //if defined, it reads "flagFile",
+ // if the number is 1, then use new tess
+ // otherwise, use the old tess.
+ //if not defined, then use new tess.
+#ifdef USE_READ_FLAG
+static Int read_flag(char* name);
+Int newtess_flag = read_flag("flagFile");
+#endif
+
+//#define COUNT_TRIANGLES
+#ifdef COUNT_TRIANGLES
+Int num_triangles = 0;
+Int num_quads = 0;
+#endif
+
+#define max(a,b) ((a>b)? a:b)
+#define ZERO 0.00001 /*determing whether a loop is a rectngle or not*/
+#define equalRect(a,b) ((glu_abs(a-b) <= ZERO)? 1:0) //only used in tessellating a rectangle
+
+#if 0 // UNUSED
+static Int is_Convex(Arc_ptr loop)
+{
+ if(area(loop->tail(), loop->head(), loop->next->head()) <0 )
+ return 0;
+ for(Arc_ptr jarc = loop->next; jarc != loop; jarc = jarc->next)
+ {
+ if(area(jarc->tail(), jarc->head(), jarc->next->head()) < 0)
+ return 0;
+ }
+ return 1;
+}
+#endif
+
+/******triangulate a monotone polygon**************/
+#include "monoTriangulation.h"
+#if 0 // UNUSED
+static int is_U_monotone(Arc_ptr loop)
+{
+ int n_changes=0;
+ int prev_sign;
+ int cur_sign;
+ Arc_ptr temp;
+
+ cur_sign = compV2InX(loop->head(), loop->tail());
+
+ n_changes = (compV2InX(loop->prev->head(), loop->prev->tail())
+ != cur_sign);
+
+ for(temp=loop->next; temp != loop; temp = temp->next)
+ {
+ prev_sign = cur_sign;
+ cur_sign = compV2InX(temp->head(), temp->tail());
+ if(cur_sign != prev_sign)
+ {
+#ifdef DEBUG
+ printf("***change signe\n");
+#endif
+ n_changes++;
+ }
+ }
+ if(n_changes == 2) return 1;
+ else
+ return 0;
+}
+#endif
+
+inline int compInY(REAL a[2], REAL b[2])
+{
+ if(a[1] < b[1])
+ return -1;
+ else if (a[1] > b[1])
+ return 1;
+ else if(a[0] > b[0])
+ return 1;
+ else return -1;
+}
+
+void monoTriangulationLoop(Arc_ptr loop, Backend& backend, primStream* pStream)
+{
+ int i;
+ //find the top, bottom, increasing and decreasing chain
+ //then call monoTrianulation
+ Arc_ptr jarc, temp;
+ Arc_ptr top;
+ Arc_ptr bot;
+ top = bot = loop;
+ if(compInY(loop->tail(), loop->prev->tail()) < 0)
+ {
+ //first find bot
+ for(temp = loop->next; temp != loop; temp = temp->next)
+ {
+ if(compInY(temp->tail(), temp->prev->tail()) > 0)
+ break;
+ }
+ bot = temp->prev;
+ //then find top
+ for(temp=loop->prev; temp != loop; temp = temp->prev)
+ {
+ if(compInY(temp->tail(), temp->prev->tail()) > 0)
+ break;
+ }
+ top = temp;
+ }
+ else //loop > loop->prev
+ {
+ for(temp=loop->next; temp != loop; temp = temp->next)
+ {
+ if(compInY(temp->tail(), temp->prev->tail()) < 0)
+ break;
+ }
+ top = temp->prev;
+ for(temp=loop->prev; temp != loop; temp = temp->prev)
+ {
+ if(compInY(temp->tail(), temp->prev->tail()) < 0)
+ break;
+ }
+ bot = temp;
+ }
+ //creat increase and decrease chains
+ vertexArray inc_chain(50); //this is a dynamci array
+ for(i=1; i<=top->pwlArc->npts-2; i++)
+ {
+ //the first vertex is the top which doesn't below to inc_chain
+ inc_chain.appendVertex(top->pwlArc->pts[i].param);
+ }
+ for(jarc=top->next; jarc != bot; jarc = jarc->next)
+ {
+ for(i=0; i<=jarc->pwlArc->npts-2; i++)
+ {
+ inc_chain.appendVertex(jarc->pwlArc->pts[i].param);
+ }
+
+ }
+ vertexArray dec_chain(50);
+ for(jarc = top->prev; jarc != bot; jarc = jarc->prev)
+ {
+ for(i=jarc->pwlArc->npts-2; i>=0; i--)
+ {
+ dec_chain.appendVertex(jarc->pwlArc->pts[i].param);
+ }
+ }
+ for(i=bot->pwlArc->npts-2; i>=1; i--)
+ {
+ dec_chain.appendVertex(jarc->pwlArc->pts[i].param);
+ }
+
+ monoTriangulationRec(top->tail(), bot->tail(), &inc_chain, 0,
+ &dec_chain, 0, &backend);
+
+}
+
+/********tesselate a rectanlge (OPTIMIZATION**************/
+static void triangulateRectGen(Arc_ptr loop, int n_ulines, int n_vlines, Backend& backend);
+
+static Int is_rect(Arc_ptr loop)
+{
+ Int nlines =1;
+ for(Arc_ptr jarc = loop->next; jarc != loop; jarc = jarc->next)
+ {
+ nlines++;
+ if(nlines == 5)
+ break;
+ }
+ if(nlines != 4)
+ return 0;
+
+
+/*
+printf("here1\n");
+printf("loop->tail=(%f,%f)\n", loop->tail()[0], loop->tail()[1]);
+printf("loop->head=(%f,%f)\n", loop->head()[0], loop->head()[1]);
+printf("loop->next->tail=(%f,%f)\n", loop->next->tail()[0], loop->next->tail()[1]);
+printf("loop->next->head=(%f,%f)\n", loop->next->head()[0], loop->next->head()[1]);
+if(fglu_abs(loop->tail()[0] - loop->head()[0])<0.000001)
+ printf("equal 1\n");
+if(loop->next->tail()[1] == loop->next->head()[1])
+ printf("equal 2\n");
+*/
+
+ if( (glu_abs(loop->tail()[0] - loop->head()[0])<=ZERO) &&
+ (glu_abs(loop->next->tail()[1] - loop->next->head()[1])<=ZERO) &&
+ (glu_abs(loop->prev->tail()[1] - loop->prev->head()[1])<=ZERO) &&
+ (glu_abs(loop->prev->prev->tail()[0] - loop->prev->prev->head()[0])<=ZERO)
+ )
+ return 1;
+ else if
+ ( (glu_abs(loop->tail()[1] - loop->head()[1]) <= ZERO) &&
+ (glu_abs(loop->next->tail()[0] - loop->next->head()[0]) <= ZERO) &&
+ (glu_abs(loop->prev->tail()[0] - loop->prev->head()[0]) <= ZERO) &&
+ (glu_abs(loop->prev->prev->tail()[1] - loop->prev->prev->head()[1]) <= ZERO)
+ )
+ return 1;
+ else
+ return 0;
+}
+
+
+//a line with the same u for opt
+#ifdef USE_OPTTT
+static void evalLineNOGE_BU(TrimVertex *verts, int n, Backend& backend)
+{
+ int i;
+ backend.preEvaluateBU(verts[0].param[0]);
+ for(i=0; i<n; i++)
+ backend.tmeshvertNOGE_BU(&verts[i]);
+}
+#endif
+
+//a line with the same v for opt
+#ifdef USE_OPTTT
+static void evalLineNOGE_BV(TrimVertex *verts, int n, Backend& backend)
+{
+ int i;
+ backend.preEvaluateBV(verts[0].param[1]);
+
+ for(i=0; i<n; i++)
+ backend.tmeshvertNOGE_BV(&verts[i]);
+}
+#endif
+
+#ifdef USE_OPTTT
+static void evalLineNOGE(TrimVertex *verts, int n, Backend& backend)
+{
+
+ if(verts[0].param[0] == verts[n-1].param[0]) //all u;s are equal
+ evalLineNOGE_BU(verts, n, backend);
+ else if(verts[0].param[1] == verts[n-1].param[1]) //all v's are equal
+ evalLineNOGE_BV(verts, n, backend);
+ else
+ {
+ int i;
+ for(i=0; i<n; i++)
+ backend.tmeshvertNOGE(&verts[i]);
+ }
+}
+#endif
+
+inline void OPT_OUTVERT(TrimVertex& vv, Backend& backend)
+{
+
+#ifdef USE_OPTTT
+ glNormal3fv(vv.cache_normal);
+ glVertex3fv(vv.cache_point);
+#else
+
+ backend.tmeshvert(&vv);
+
+#endif
+
+}
+
+static void triangulateRectAux(PwlArc* top, PwlArc* bot, PwlArc* left, PwlArc* right, Backend& backend);
+
+static void triangulateRect(Arc_ptr loop, Backend& backend, int TB_or_LR, int ulinear, int vlinear)
+{
+ //we know the loop is a rectangle, but not sure which is top
+ Arc_ptr top, bot, left, right;
+ if(loop->tail()[1] == loop->head()[1])
+ {
+ if(loop->tail()[1] > loop->prev->prev->tail()[1])
+ {
+
+ top = loop;
+ }
+ else{
+
+ top = loop->prev->prev;
+ }
+ }
+ else
+ {
+ if(loop->tail()[0] > loop->prev->prev->tail()[0])
+ {
+ //loop is the right arc
+
+ top = loop->next;
+ }
+ else
+ {
+
+ top = loop->prev;
+ }
+ }
+ left = top->next;
+ bot = left->next;
+ right= bot->next;
+
+ //if u, v are both nonlinear, then if the
+ //boundary is tessellated dense, we also
+ //sample the inside to get a better tesslletant.
+ if( (!ulinear) && (!vlinear))
+ {
+ int nu = top->pwlArc->npts;
+ if(nu < bot->pwlArc->npts)
+ nu = bot->pwlArc->npts;
+ int nv = left->pwlArc->npts;
+ if(nv < right->pwlArc->npts)
+ nv = right->pwlArc->npts;
+/*
+ if(nu > 2 && nv > 2)
+ {
+ triangulateRectGen(top, nu-2, nv-2, backend);
+ return;
+ }
+*/
+ }
+
+ if(TB_or_LR == 1)
+ triangulateRectAux(top->pwlArc, bot->pwlArc, left->pwlArc, right->pwlArc, backend);
+ else if(TB_or_LR == -1)
+ triangulateRectAux(left->pwlArc, right->pwlArc, bot->pwlArc, top->pwlArc, backend);
+ else
+ {
+ Int maxPointsTB = top->pwlArc->npts + bot->pwlArc->npts;
+ Int maxPointsLR = left->pwlArc->npts + right->pwlArc->npts;
+
+ if(maxPointsTB < maxPointsLR)
+ triangulateRectAux(left->pwlArc, right->pwlArc, bot->pwlArc, top->pwlArc, backend);
+ else
+ triangulateRectAux(top->pwlArc, bot->pwlArc, left->pwlArc, right->pwlArc, backend);
+ }
+}
+
+static void triangulateRectAux(PwlArc* top, PwlArc* bot, PwlArc* left, PwlArc* right, Backend& backend)
+{ //if(maxPointsTB >= maxPointsLR)
+ {
+
+ Int d, topd_left, topd_right, botd_left, botd_right, i,j;
+ d = left->npts /2;
+
+#ifdef USE_OPTTT
+ evalLineNOGE(top->pts, top->npts, backend);
+ evalLineNOGE(bot->pts, bot->npts, backend);
+ evalLineNOGE(left->pts, left->npts, backend);
+ evalLineNOGE(right->pts, right->npts, backend);
+#endif
+
+ if(top->npts == 2) {
+ backend.bgntfan();
+ OPT_OUTVERT(top->pts[0], backend);//the root
+ for(i=0; i<left->npts; i++){
+ OPT_OUTVERT(left->pts[i], backend);
+ }
+ for(i=1; i<= bot->npts-2; i++){
+ OPT_OUTVERT(bot->pts[i], backend);
+ }
+ backend.endtfan();
+
+ backend.bgntfan();
+ OPT_OUTVERT(bot->pts[bot->npts-2], backend);
+ for(i=0; i<right->npts; i++){
+ OPT_OUTVERT(right->pts[i], backend);
+ }
+ backend.endtfan();
+ }
+ else if(bot->npts == 2) {
+ backend.bgntfan();
+ OPT_OUTVERT(bot->pts[0], backend);//the root
+ for(i=0; i<right->npts; i++){
+ OPT_OUTVERT(right->pts[i], backend);
+ }
+ for(i=1; i<= top->npts-2; i++){
+ OPT_OUTVERT(top->pts[i], backend);
+ }
+ backend.endtfan();
+
+ backend.bgntfan();
+ OPT_OUTVERT(top->pts[top->npts-2], backend);
+ for(i=0; i<left->npts; i++){
+ OPT_OUTVERT(left->pts[i], backend);
+ }
+ backend.endtfan();
+ }
+ else { //both top and bot have >=3 points
+
+ backend.bgntfan();
+
+ OPT_OUTVERT(top->pts[top->npts-2], backend);
+
+ for(i=0; i<=d; i++)
+ {
+ OPT_OUTVERT(left->pts[i], backend);
+ }
+ backend.endtfan();
+
+ backend.bgntfan();
+
+ OPT_OUTVERT(bot->pts[1], backend);
+
+ OPT_OUTVERT(top->pts[top->npts-2], backend);
+
+ for(i=d; i< left->npts; i++)
+ {
+ OPT_OUTVERT(left->pts[i], backend);
+ }
+ backend.endtfan();
+
+ d = right->npts/2;
+ //output only when d<right->npts-1 and
+ //
+ if(d<right->npts-1)
+ {
+ backend.bgntfan();
+ // backend.tmeshvert(& top->pts[1]);
+ OPT_OUTVERT(top->pts[1], backend);
+ for(i=d; i< right->npts; i++)
+ {
+ // backend.tmeshvert(& right->pts[i]);
+
+ OPT_OUTVERT(right->pts[i], backend);
+
+ }
+ backend.endtfan();
+ }
+
+ backend.bgntfan();
+ // backend.tmeshvert(& bot->pts[bot->npts-2]);
+ OPT_OUTVERT( bot->pts[bot->npts-2], backend);
+ for(i=0; i<=d; i++)
+ {
+ // backend.tmeshvert(& right->pts[i]);
+ OPT_OUTVERT(right->pts[i], backend);
+
+ }
+
+ // backend.tmeshvert(& top->pts[1]);
+ OPT_OUTVERT(top->pts[1], backend);
+
+ backend.endtfan();
+
+
+ topd_left = top->npts-2;
+ topd_right = 1; //topd_left>= topd_right
+
+ botd_left = 1;
+ botd_right = bot->npts-2; //botd_left<= bot_dright
+
+
+ if(top->npts < bot->npts)
+ {
+ int delta=bot->npts - top->npts;
+ int u = delta/2;
+ botd_left = 1+ u;
+ botd_right = bot->npts-2-( delta-u);
+
+ if(botd_left >1)
+ {
+ backend.bgntfan();
+ // backend.tmeshvert(& top->pts[top->npts-2]);
+ OPT_OUTVERT(top->pts[top->npts-2], backend);
+ for(i=1; i<= botd_left; i++)
+ {
+ // backend.tmeshvert(& bot->pts[i]);
+ OPT_OUTVERT(bot->pts[i] , backend);
+ }
+ backend.endtfan();
+ }
+ if(botd_right < bot->npts-2)
+ {
+ backend.bgntfan();
+ OPT_OUTVERT(top->pts[1], backend);
+ for(i=botd_right; i<= bot->npts-2; i++)
+ OPT_OUTVERT(bot->pts[i], backend);
+ backend.endtfan();
+ }
+ }
+ else if(top->npts> bot->npts)
+ {
+ int delta=top->npts-bot->npts;
+ int u = delta/2;
+ topd_left = top->npts-2 - u;
+ topd_right = 1+delta-u;
+
+ if(topd_left < top->npts-2)
+ {
+ backend.bgntfan();
+ // backend.tmeshvert(& bot->pts[1]);
+ OPT_OUTVERT(bot->pts[1], backend);
+ for(i=topd_left; i<= top->npts-2; i++)
+ {
+ // backend.tmeshvert(& top->pts[i]);
+ OPT_OUTVERT(top->pts[i], backend);
+ }
+ backend.endtfan();
+ }
+ if(topd_right > 1)
+ {
+ backend.bgntfan();
+ OPT_OUTVERT(bot->pts[bot->npts-2], backend);
+ for(i=1; i<= topd_right; i++)
+ OPT_OUTVERT(top->pts[i], backend);
+ backend.endtfan();
+ }
+ }
+
+ if(topd_left <= topd_right)
+ return;
+
+ backend.bgnqstrip();
+ for(j=botd_left, i=topd_left; i>=topd_right; i--,j++)
+ {
+ // backend.tmeshvert(& top->pts[i]);
+ // backend.tmeshvert(& bot->pts[j]);
+ OPT_OUTVERT(top->pts[i], backend);
+ OPT_OUTVERT(bot->pts[j], backend);
+ }
+ backend.endqstrip();
+
+ }
+ }
+}
+
+
+static void triangulateRectCenter(int n_ulines, REAL* u_val,
+ int n_vlines, REAL* v_val,
+ Backend& backend)
+{
+
+ // XXX this code was patched by Diego Santa Cruz <Diego.SantaCruz@epfl.ch>
+ // to fix a problem in which glMapGrid2f() was called with bad parameters.
+ // This has beens submitted to SGI but not integrated as of May 1, 2001.
+ if(n_ulines>1 && n_vlines>1) {
+ backend.surfgrid(u_val[0], u_val[n_ulines-1], n_ulines-1,
+ v_val[n_vlines-1], v_val[0], n_vlines-1);
+ backend.surfmesh(0,0,n_ulines-1,n_vlines-1);
+ }
+
+ return;
+
+ /*
+ for(i=0; i<n_vlines-1; i++)
+ {
+
+ backend.bgnqstrip();
+ for(j=0; j<n_ulines; j++)
+ {
+ trimVert.param[0] = u_val[j];
+ trimVert.param[1] = v_val[i+1];
+ backend.tmeshvert(& trimVert);
+
+ trimVert.param[1] = v_val[i];
+ backend.tmeshvert(& trimVert);
+ }
+ backend.endqstrip();
+
+ }
+ */
+}
+
+//it works for top, bot, left ad right, you need ot select correct arguments
+static void triangulateRectTopGen(Arc_ptr arc, int n_ulines, REAL* u_val, Real v, int dir, int is_u, Backend& backend)
+{
+
+ if(is_u)
+ {
+ int i,k;
+ REAL* upper_val = (REAL*) malloc(sizeof(REAL) * arc->pwlArc->npts);
+ assert(upper_val);
+ if(dir)
+ {
+ for(k=0,i=arc->pwlArc->npts-1; i>=0; i--,k++)
+ {
+ upper_val[k] = arc->pwlArc->pts[i].param[0];
+ }
+ backend.evalUStrip(arc->pwlArc->npts, arc->pwlArc->pts[0].param[1],
+ upper_val,
+ n_ulines, v, u_val);
+ }
+ else
+ {
+ for(k=0,i=0; i<arc->pwlArc->npts; i++,k++)
+ {
+ upper_val[k] = arc->pwlArc->pts[i].param[0];
+
+ }
+
+ backend.evalUStrip(
+ n_ulines, v, u_val,
+ arc->pwlArc->npts, arc->pwlArc->pts[0].param[1], upper_val
+ );
+ }
+
+ free(upper_val);
+ return;
+ }
+ else //is_v
+ {
+ int i,k;
+ REAL* left_val = (REAL*) malloc(sizeof(REAL) * arc->pwlArc->npts);
+ assert(left_val);
+ if(dir)
+ {
+ for(k=0,i=arc->pwlArc->npts-1; i>=0; i--,k++)
+ {
+ left_val[k] = arc->pwlArc->pts[i].param[1];
+ }
+ backend.evalVStrip(arc->pwlArc->npts, arc->pwlArc->pts[0].param[0],
+ left_val,
+ n_ulines, v, u_val);
+ }
+ else
+ {
+ for(k=0,i=0; i<arc->pwlArc->npts; i++,k++)
+ {
+ left_val[k] = arc->pwlArc->pts[i].param[1];
+ }
+ backend.evalVStrip(
+ n_ulines, v, u_val,
+ arc->pwlArc->npts, arc->pwlArc->pts[0].param[0], left_val
+ );
+ }
+ free(left_val);
+ return;
+ }
+
+ //the following is a different version of the above code. If you comment
+ //the above code, the following code will still work. The reason to leave
+ //the folliwng code here is purely for testing purpose.
+ /*
+ int i,j;
+ PwlArc* parc = arc->pwlArc;
+ int d1 = parc->npts-1;
+ int d2 = 0;
+ TrimVertex trimVert;
+ trimVert.nuid = 0;//????
+ REAL* temp_u_val = u_val;
+ if(dir ==0) //have to reverse u_val
+ {
+ temp_u_val = (REAL*) malloc(sizeof(REAL) * n_ulines);
+ assert(temp_u_val);
+ for(i=0; i<n_ulines; i++)
+ temp_u_val[i] = u_val[n_ulines-1-i];
+ }
+ u_val = temp_u_val;
+
+ if(parc->npts > n_ulines)
+ {
+ d1 = n_ulines-1;
+
+ backend.bgntfan();
+ if(is_u){
+ trimVert.param[0] = u_val[0];
+ trimVert.param[1] = v;
+ }
+ else
+ {
+ trimVert.param[1] = u_val[0];
+ trimVert.param[0] = v;
+ }
+
+ backend.tmeshvert(& trimVert);
+ for(i=d1; i< parc->npts; i++)
+ backend.tmeshvert(& parc->pts[i]);
+ backend.endtfan();
+
+
+ }
+ else if(parc->npts < n_ulines)
+ {
+ d2 = n_ulines-parc->npts;
+
+
+ backend.bgntfan();
+ backend.tmeshvert(& parc->pts[parc->npts-1]);
+ for(i=0; i<= d2; i++)
+ {
+ if(is_u){
+ trimVert.param[0] = u_val[i];
+ trimVert.param[1] = v;
+ }
+ else
+ {
+ trimVert.param[1] = u_val[i];
+ trimVert.param[0] = v;
+ }
+ backend.tmeshvert(&trimVert);
+ }
+ backend.endtfan();
+
+ }
+ if(d1>0){
+
+
+ backend.bgnqstrip();
+ for(i=d1, j=d2; i>=0; i--, j++)
+ {
+ backend.tmeshvert(& parc->pts[i]);
+
+ if(is_u){
+ trimVert.param[0] = u_val[j];
+ trimVert.param[1] = v;
+ }
+ else{
+ trimVert.param[1] = u_val[j];
+ trimVert.param[0] = v;
+ }
+ backend.tmeshvert(&trimVert);
+
+
+
+ }
+ backend.endqstrip();
+
+
+ }
+ if(dir == 0) //temp_u_val was mallocated
+ free(temp_u_val);
+ */
+}
+
+//n_ulines is the number of ulines inside, and n_vlines is the number of vlines
+//inside, different from meanings elsewhere!!!
+static void triangulateRectGen(Arc_ptr loop, int n_ulines, int n_vlines, Backend& backend)
+{
+
+ int i;
+ //we know the loop is a rectangle, but not sure which is top
+ Arc_ptr top, bot, left, right;
+
+ if(equalRect(loop->tail()[1] , loop->head()[1]))
+ {
+
+ if(loop->tail()[1] > loop->prev->prev->tail()[1])
+ {
+
+ top = loop;
+ }
+ else{
+
+ top = loop->prev->prev;
+ }
+ }
+ else
+ {
+ if(loop->tail()[0] > loop->prev->prev->tail()[0])
+ {
+ //loop is the right arc
+
+ top = loop->next;
+ }
+ else
+ {
+
+ top = loop->prev;
+ }
+ }
+
+ left = top->next;
+ bot = left->next;
+ right= bot->next;
+
+#ifdef COUNT_TRIANGLES
+ num_triangles += loop->pwlArc->npts +
+ left->pwlArc->npts +
+ bot->pwlArc->npts +
+ right->pwlArc->npts
+ + 2*n_ulines + 2*n_vlines
+ -8;
+ num_quads += (n_ulines-1)*(n_vlines-1);
+#endif
+/*
+ backend.surfgrid(left->tail()[0], right->tail()[0], n_ulines+1,
+ top->tail()[1], bot->tail()[1], n_vlines+1);
+// if(n_ulines>1 && n_vlines>1)
+ backend.surfmesh(0,0,n_ulines+1,n_vlines+1);
+return;
+*/
+ REAL* u_val=(REAL*) malloc(sizeof(REAL)*n_ulines);
+ assert(u_val);
+ REAL* v_val=(REAL*)malloc(sizeof(REAL) * n_vlines);
+ assert(v_val);
+ REAL u_stepsize = (right->tail()[0] - left->tail()[0])/( (REAL) n_ulines+1);
+ REAL v_stepsize = (top->tail()[1] - bot->tail()[1])/( (REAL) n_vlines+1);
+ Real temp=left->tail()[0]+u_stepsize;
+ for(i=0; i<n_ulines; i++)
+ {
+ u_val[i] = temp;
+ temp += u_stepsize;
+ }
+ temp = bot->tail()[1] + v_stepsize;
+ for(i=0; i<n_vlines; i++)
+ {
+ v_val[i] = temp;
+ temp += v_stepsize;
+ }
+
+ triangulateRectTopGen(top, n_ulines, u_val, v_val[n_vlines-1], 1,1, backend);
+ triangulateRectTopGen(bot, n_ulines, u_val, v_val[0], 0, 1, backend);
+ triangulateRectTopGen(left, n_vlines, v_val, u_val[0], 1, 0, backend);
+ triangulateRectTopGen(right, n_vlines, v_val, u_val[n_ulines-1], 0,0, backend);
+
+
+
+
+ //triangulate the center
+ triangulateRectCenter(n_ulines, u_val, n_vlines, v_val, backend);
+
+ free(u_val);
+ free(v_val);
+
+}
+
+
+
+
+/**********for reading newtess_flag from a file**********/
+#ifdef USE_READ_FLAG
+static Int read_flag(char* name)
+{
+ Int ret;
+ FILE* fp = fopen(name, "r");
+ if(fp == NULL)
+ {
+ fprintf(stderr, "can't open file %s\n", name);
+ exit(1);
+ }
+ fscanf(fp, "%i", &ret);
+ fclose(fp);
+ return ret;
+}
+#endif
+
+/***********nextgen tess****************/
+#include "sampleMonoPoly.h"
+directedLine* arcToDLine(Arc_ptr arc)
+{
+ int i;
+ Real vert[2];
+ directedLine* ret;
+ sampledLine* sline = new sampledLine(arc->pwlArc->npts);
+ for(i=0; i<arc->pwlArc->npts; i++)
+ {
+ vert[0] = arc->pwlArc->pts[i].param[0];
+ vert[1] = arc->pwlArc->pts[i].param[1];
+ sline->setPoint(i, vert);
+ }
+ ret = new directedLine(INCREASING, sline);
+ return ret;
+}
+
+/*an pwlArc may not be a straight line*/
+directedLine* arcToMultDLines(directedLine* original, Arc_ptr arc)
+{
+ directedLine* ret = original;
+ int is_linear = 0;
+ if(arc->pwlArc->npts == 2 )
+ is_linear = 1;
+ else if(area(arc->pwlArc->pts[0].param, arc->pwlArc->pts[1].param, arc->pwlArc->pts[arc->pwlArc->npts-1].param) == 0.0)
+ is_linear = 1;
+
+ if(is_linear)
+ {
+ directedLine *dline = arcToDLine(arc);
+ if(ret == NULL)
+ ret = dline;
+ else
+ ret->insert(dline);
+ return ret;
+ }
+ else /*not linear*/
+ {
+ for(Int i=0; i<arc->pwlArc->npts-1; i++)
+ {
+ Real vert[2][2];
+ vert[0][0] = arc->pwlArc->pts[i].param[0];
+ vert[0][1] = arc->pwlArc->pts[i].param[1];
+ vert[1][0] = arc->pwlArc->pts[i+1].param[0];
+ vert[1][1] = arc->pwlArc->pts[i+1].param[1];
+
+ sampledLine *sline = new sampledLine(2, vert);
+ directedLine *dline = new directedLine(INCREASING, sline);
+ if(ret == NULL)
+ ret = dline;
+ else
+ ret->insert(dline);
+ }
+ return ret;
+ }
+}
+
+
+
+directedLine* arcLoopToDLineLoop(Arc_ptr loop)
+{
+ directedLine* ret;
+
+ if(loop == NULL)
+ return NULL;
+ ret = arcToMultDLines(NULL, loop);
+//ret->printSingle();
+ for(Arc_ptr temp = loop->next; temp != loop; temp = temp->next){
+ ret = arcToMultDLines(ret, temp);
+//ret->printSingle();
+ }
+
+ return ret;
+}
+
+/*
+void Slicer::evalRBArray(rectBlockArray* rbArray, gridWrap* grid)
+{
+ TrimVertex *trimVert = (TrimVertex*)malloc(sizeof(TrimVertex));
+ trimVert -> nuid = 0;//????
+
+ Real* u_values = grid->get_u_values();
+ Real* v_values = grid->get_v_values();
+
+ Int i,j,k,l;
+
+ for(l=0; l<rbArray->get_n_elements(); l++)
+ {
+ rectBlock* block = rbArray->get_element(l);
+ for(k=0, i=block->get_upGridLineIndex(); i>block->get_lowGridLineIndex(); i--, k++)
+ {
+
+ backend.bgnqstrip();
+ for(j=block->get_leftIndices()[k+1]; j<= block->get_rightIndices()[k+1]; j++)
+ {
+ trimVert->param[0] = u_values[j];
+ trimVert->param[1] = v_values[i];
+ backend.tmeshvert(trimVert);
+
+ trimVert->param[1] = v_values[i-1];
+ backend.tmeshvert(trimVert);
+
+ }
+ backend.endqstrip();
+
+ }
+ }
+
+ free(trimVert);
+}
+*/
+
+void Slicer::evalRBArray(rectBlockArray* rbArray, gridWrap* grid)
+{
+ Int i,j,k;
+
+ Int n_vlines=grid->get_n_vlines();
+ //the reason to switch the position of v_max and v_min is because of the
+ //the orientation problem. glEvalMesh generates quad_strip clockwise, but
+ //we need counter-clockwise.
+ backend.surfgrid(grid->get_u_min(), grid->get_u_max(), grid->get_n_ulines()-1,
+ grid->get_v_max(), grid->get_v_min(), n_vlines-1);
+
+
+ for(j=0; j<rbArray->get_n_elements(); j++)
+ {
+ rectBlock* block = rbArray->get_element(j);
+ Int low = block->get_lowGridLineIndex();
+ Int high = block->get_upGridLineIndex();
+
+ for(k=0, i=high; i>low; i--, k++)
+ {
+ backend.surfmesh(block->get_leftIndices()[k+1], n_vlines-1-i, block->get_rightIndices()[k+1]-block->get_leftIndices()[k+1], 1);
+ }
+ }
+}
+
+
+void Slicer::evalStream(primStream* pStream)
+{
+ Int i,j,k;
+ k=0;
+/* TrimVertex X;*/
+ TrimVertex *trimVert =/*&X*/ (TrimVertex*)malloc(sizeof(TrimVertex));
+ trimVert -> nuid = 0;//???
+ Real* vertices = pStream->get_vertices(); //for efficiency
+ for(i=0; i<pStream->get_n_prims(); i++)
+ {
+
+ //ith primitive has #vertices = lengths[i], type=types[i]
+ switch(pStream->get_type(i)){
+ case PRIMITIVE_STREAM_FAN:
+
+ backend.bgntfan();
+
+ for(j=0; j<pStream->get_length(i); j++)
+ {
+ trimVert->param[0] = vertices[k];
+ trimVert->param[1] = vertices[k+1];
+ backend.tmeshvert(trimVert);
+
+// backend.tmeshvert(vertices[k], vertices[k+1]);
+ k += 2;
+ }
+ backend.endtfan();
+ break;
+
+ default:
+ fprintf(stderr, "evalStream: not implemented yet\n");
+ exit(1);
+
+ }
+ }
+ free(trimVert);
+}
+
+
+
+
+void Slicer::slice_new(Arc_ptr loop)
+{
+//count++;
+//if(count == 78) count=1;
+//printf("count=%i\n", count);
+//if( ! (4<= count && count <=4)) return;
+
+
+ Int num_ulines;
+ Int num_vlines;
+ Real uMin, uMax, vMin, vMax;
+ Real mydu, mydv;
+ uMin = uMax = loop->tail()[0];
+ vMin = vMax = loop->tail()[1];
+ mydu = (du>0)? du: -du;
+ mydv = (dv>0)? dv: -dv;
+
+ for(Arc_ptr jarc=loop->next; jarc != loop; jarc = jarc->next)
+ {
+
+ if(jarc->tail()[0] < uMin)
+ uMin = jarc->tail()[0];
+ if(jarc->tail()[0] > uMax)
+ uMax = jarc->tail()[0];
+ if(jarc->tail()[1] < vMin)
+ vMin = jarc->tail()[1];
+ if(jarc->tail()[1] > vMax)
+ vMax = jarc->tail()[1];
+ }
+
+ if (uMax == uMin)
+ return; // prevent divide-by-zero. Jon Perry. 17 June 2002
+
+ if(mydu > uMax - uMin)
+ num_ulines = 2;
+ else
+ {
+ num_ulines = 3 + (Int) ((uMax-uMin)/mydu);
+ }
+ if(mydv>=vMax-vMin)
+ num_vlines = 2;
+ else
+ {
+ num_vlines = 2+(Int)((vMax-vMin)/mydv);
+ }
+
+ Int isRect = is_rect(loop);
+
+ if(isRect && (num_ulines<=2 || num_vlines<=2))
+ {
+ if(vlinear)
+ triangulateRect(loop, backend, 1, ulinear, vlinear);
+ else if(ulinear)
+ triangulateRect(loop, backend, -1, ulinear, vlinear);
+ else
+ triangulateRect(loop, backend, 0, ulinear, vlinear);
+ }
+
+ else if(isRect)
+ {
+ triangulateRectGen(loop, num_ulines-2, num_vlines-2, backend);
+ }
+ else if( (num_ulines<=2 || num_vlines <=2) && ulinear)
+ {
+ monoTriangulationFunBackend(loop, compV2InY, &backend);
+ }
+ else if( (!ulinear) && (!vlinear) && (num_ulines == 2) && (num_vlines > 2))
+ {
+ monoTriangulationFunBackend(loop, compV2InY, &backend);
+ }
+ else
+ {
+ directedLine* poly = arcLoopToDLineLoop(loop);
+
+ gridWrap grid(num_ulines, num_vlines, uMin, uMax, vMin, vMax);
+ primStream pStream(20, 20);
+ rectBlockArray rbArray(20);
+
+ sampleMonoPoly(poly, &grid, ulinear, vlinear, &pStream, &rbArray);
+
+ evalStream(&pStream);
+
+ evalRBArray(&rbArray, &grid);
+
+#ifdef COUNT_TRIANGLES
+ num_triangles += pStream.num_triangles();
+ num_quads += rbArray.num_quads();
+#endif
+ poly->deleteSinglePolygonWithSline();
+ }
+
+#ifdef COUNT_TRIANGLES
+ printf("num_triangles=%i\n", num_triangles);
+ printf("num_quads = %i\n", num_quads);
+#endif
+}
+
+void Slicer::slice(Arc_ptr loop)
+{
+#ifdef USE_READ_FLAG
+ if(read_flag("flagFile"))
+ slice_new(loop);
+ else
+ slice_old(loop);
+
+#else
+ slice_new(loop);
+#endif
+
+}
+
+
+
+Slicer::Slicer( Backend &b )
+ : CoveAndTiler( b ), Mesher( b ), backend( b )
+{
+ ulinear = 0;
+ vlinear = 0;
+}
+
+Slicer::~Slicer()
+{
+}
+
+void
+Slicer::setisolines( int x )
+{
+ isolines = x;
+}
+
+void
+Slicer::setstriptessellation( REAL x, REAL y )
+{
+ assert(x > 0 && y > 0);
+ du = x;
+ dv = y;
+ setDu( du );
+}
+
+void
+Slicer::slice_old( Arc_ptr loop )
+{
+ loop->markverts();
+
+ Arc_ptr extrema[4];
+ loop->getextrema( extrema );
+
+ unsigned int npts = loop->numpts();
+ TrimRegion::init( npts, extrema[0] );
+
+ Mesher::init( npts );
+
+ long ulines = uarray.init( du, extrema[1], extrema[3] );
+//printf("ulines = %i\n", ulines);
+ Varray varray;
+ long vlines = varray.init( dv, extrema[0], extrema[2] );
+//printf("vlines = %i\n", vlines);
+ long botv = 0;
+ long topv;
+ TrimRegion::init( varray.varray[botv] );
+ getGridExtent( &extrema[0]->pwlArc->pts[0], &extrema[0]->pwlArc->pts[0] );
+
+ for( long quad=0; quad<varray.numquads; quad++ ) {
+ backend.surfgrid( uarray.uarray[0],
+ uarray.uarray[ulines-1],
+ ulines-1,
+ varray.vval[quad],
+ varray.vval[quad+1],
+ varray.voffset[quad+1] - varray.voffset[quad] );
+
+ for( long i=varray.voffset[quad]+1; i <= varray.voffset[quad+1]; i++ ) {
+ topv = botv++;
+ advance( topv - varray.voffset[quad],
+ botv - varray.voffset[quad],
+ varray.varray[botv] );
+ if( i == vlines )
+ getPts( extrema[2] );
+ else
+ getPts( backend );
+ getGridExtent();
+ if( isolines ) {
+ outline();
+ } else {
+ if( canTile() )
+ coveAndTile();
+ else
+ mesh();
+ }
+ }
+ }
+}
+
+
+void
+Slicer::outline( void )
+{
+ GridTrimVertex upper, lower;
+ Hull::init( );
+
+ backend.bgnoutline();
+ while( (nextupper( &upper )) ) {
+ if( upper.isGridVert() )
+ backend.linevert( upper.g );
+ else
+ backend.linevert( upper.t );
+ }
+ backend.endoutline();
+
+ backend.bgnoutline();
+ while( (nextlower( &lower )) ) {
+ if( lower.isGridVert() )
+ backend.linevert( lower.g );
+ else
+ backend.linevert( lower.t );
+ }
+ backend.endoutline();
+}
+
+
+void
+Slicer::outline( Arc_ptr jarc )
+{
+ jarc->markverts();
+
+ if( jarc->pwlArc->npts >= 2 ) {
+ backend.bgnoutline();
+ for( int j = jarc->pwlArc->npts-1; j >= 0; j-- )
+ backend.linevert( &(jarc->pwlArc->pts[j]) );
+ backend.endoutline();
+ }
+}
+
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/slicer.h b/mesalib/src/glu/sgi/libnurbs/internals/slicer.h
new file mode 100644
index 000000000..e1f5d22ff
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/slicer.h
@@ -0,0 +1,84 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * slicer.h
+ *
+ */
+
+#ifndef __gluslicer_h_
+#define __gluslicer_h_
+
+#include "trimregion.h"
+#include "mesher.h"
+#include "coveandtiler.h"
+#include "primitiveStream.h"
+#include "rectBlock.h"
+
+class Backend;
+class Arc;
+class TrimVertex;
+
+class Slicer : public CoveAndTiler, public Mesher {
+public:
+ Slicer( Backend & );
+ ~Slicer( void );
+ void slice( Arc_ptr );
+ void slice_old( Arc_ptr);
+ void slice_new( Arc_ptr );
+ void evalStream(primStream* );
+ void evalRBArray(rectBlockArray* rbArray, gridWrap* grid);
+
+ void outline( Arc_ptr );
+ void setstriptessellation( REAL, REAL );
+ void setisolines( int );
+
+ void set_ulinear(int ulinear_flag)
+ {
+ ulinear = ulinear_flag;
+ }
+ void set_vlinear(int vlinear_flag)
+ {
+ vlinear = vlinear_flag;
+ }
+private:
+ Backend& backend;
+ REAL oneOverDu;
+ REAL du, dv;
+ int isolines;
+
+ void outline( void );
+ void initGridlines( void );
+ void advanceGridlines( long );
+
+ int ulinear; //indicate whether uorder is 2 or not
+ int vlinear; //indicate whether vorder is 2 or not
+};
+#endif /* __gluslicer_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/sorter.cc b/mesalib/src/glu/sgi/libnurbs/internals/sorter.cc
new file mode 100644
index 000000000..7a7994149
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/sorter.cc
@@ -0,0 +1,139 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * sorter.c++
+ *
+ */
+
+#include "glimports.h"
+#include "sorter.h"
+#include "mystdio.h"
+
+Sorter::Sorter( int _es )
+{
+ es = _es;
+}
+
+void
+Sorter::qsort( void *a, int n )
+{
+ qs1( (char *)a, ((char *)a)+n*es);
+}
+
+int
+Sorter::qscmp( char *, char * )
+{
+ _glu_dprintf( "Sorter::qscmp: pure virtual called\n" );
+ return 0;
+}
+
+
+void
+Sorter::qsexc( char *, char * )
+{
+ _glu_dprintf( "Sorter::qsexc: pure virtual called\n" );
+}
+
+
+void
+Sorter::qstexc( char *, char *, char * )
+{
+ _glu_dprintf( "Sorter::qstexc: pure virtual called\n" );
+}
+
+void
+Sorter::qs1( char *a, char *l )
+{
+ char *i, *j;
+ char *lp, *hp;
+ int c;
+ unsigned int n;
+
+start:
+ if((n=l-a) <= (unsigned int)es)
+ return;
+ n = es * (n / (2*es));
+ hp = lp = a+n;
+ i = a;
+ j = l-es;
+ while(1) {
+ if(i < lp) {
+ if((c = qscmp(i, lp)) == 0) {
+ qsexc(i, lp -= es);
+ continue;
+ }
+ if(c < 0) {
+ i += es;
+ continue;
+ }
+ }
+
+loop:
+ if(j > hp) {
+ if((c = qscmp(hp, j)) == 0) {
+ qsexc(hp += es, j);
+ goto loop;
+ }
+ if(c > 0) {
+ if(i == lp) {
+ qstexc(i, hp += es, j);
+ i = lp += es;
+ goto loop;
+ }
+ qsexc(i, j);
+ j -= es;
+ i += es;
+ continue;
+ }
+ j -= es;
+ goto loop;
+ }
+
+ if(i == lp) {
+ if(lp-a >= l-hp) {
+ qs1(hp+es, l);
+ l = lp;
+ } else {
+ qs1(a, lp);
+ a = hp+es;
+ }
+ goto start;
+ }
+
+ qstexc(j, lp -= es, i);
+ j = hp -= es;
+ }
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/sorter.h b/mesalib/src/glu/sgi/libnurbs/internals/sorter.h
new file mode 100644
index 000000000..57ea12129
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/sorter.h
@@ -0,0 +1,51 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+/*
+*/
+
+#ifndef __glusorter_h_
+#define __glusorter_h_
+
+class Sorter {
+public:
+ Sorter( int es );
+ virtual ~Sorter() { /* silence warning*/ }
+ void qsort( void *a, int n );
+
+protected:
+ virtual int qscmp( char *, char * );
+ virtual void qsexc( char *i, char *j ); // i<-j, j<-i
+ virtual void qstexc( char *i, char *j, char *k ); // i<-k, k<-j, j<-i
+
+private:
+ void qs1( char *, char * );
+ int es;
+};
+#endif /* __glusorter_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/splitarcs.cc b/mesalib/src/glu/sgi/libnurbs/internals/splitarcs.cc
new file mode 100644
index 000000000..1f79d543f
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/splitarcs.cc
@@ -0,0 +1,293 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * splitarcs.c++
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "mysetjmp.h"
+#include "mystdio.h"
+#include "subdivider.h"
+#include "arcsorter.h"
+#include "arc.h"
+#include "bin.h"
+
+/* local preprocessor definitions */
+#define MAXARCS 10
+
+/*----------------------------------------------------------------------------
+ * Subdivider::split - split trim regions in source bin by line (param == value).
+ *----------------------------------------------------------------------------
+ */
+
+void
+Subdivider::split( Bin& bin, Bin& left, Bin& right, int param, REAL value )
+{
+ Bin intersections, unknown;
+
+ partition( bin, left, intersections, right, unknown, param, value );
+
+ int count = intersections.numarcs();
+ if( count % 2 ) {
+#ifndef NDEBUG
+ left.show( "left" );
+ intersections.show( "intersections" );
+ right.show( "right" );
+#endif
+ ::mylongjmp( jumpbuffer, 29 );
+ }
+
+ Arc_ptr arclist[MAXARCS], *list;
+ if( count >= MAXARCS ) {
+ list = new Arc_ptr[count];
+ } else {
+ list = arclist;
+ }
+
+ Arc_ptr jarc, *last, *lptr;
+ for( last = list; (jarc=intersections.removearc()) != NULL; last++ )
+ *last = jarc;
+
+ if( param == 0 ) { /* sort into increasing t order */
+ ArcSdirSorter sorter(*this);
+ sorter.qsort( list, count );
+
+ //::qsort ((void *)list, count, sizeof(Arc_ptr), (cmpfunc)compare_s);
+ for( lptr=list; lptr<last; lptr+=2 )
+ check_s ( lptr[0], lptr[1] );
+ for( lptr=list; lptr<last; lptr+=2 )
+ join_s ( left, right, lptr[0], lptr[1] );
+ for( lptr=list; lptr != last; lptr++ ) {
+ if( ((*lptr)->head()[0] <= value) && ((*lptr)->tail()[0] <= value) )
+ left.addarc( *lptr );
+ else
+ right.addarc( *lptr );
+ }
+ } else { /* sort into decreasing s order */
+ ArcTdirSorter sorter(*this);
+ sorter.qsort( list, count );
+ //::qsort ((void *)list, count, sizeof(Arc_ptr), (cmpfunc)compare_t);
+ for( lptr=list; lptr<last; lptr+=2 )
+ check_t ( lptr[0], lptr[1] );
+ for( lptr=list; lptr<last; lptr+=2 )
+ join_t ( left, right, lptr[0], lptr[1] );
+ for( lptr=list; lptr != last; lptr++ ) {
+ if( ((*lptr)->head()[1] <= value) && ((*lptr)->tail()[1] <= value) )
+ left.addarc( *lptr );
+ else
+ right.addarc( *lptr );
+ }
+ }
+
+ if( list != arclist ) delete[] list;
+ unknown.adopt();
+}
+
+
+void
+Subdivider::check_s( Arc_ptr jarc1, Arc_ptr jarc2 )
+{
+ assert( jarc1->check( ) != 0 );
+ assert( jarc2->check( ) != 0 );
+ assert( jarc1->next->check( ) != 0 );
+ assert( jarc2->next->check( ) != 0 );
+ assert( jarc1 != jarc2 );
+
+ /* XXX - if these assertions fail, it is due to user error or
+ undersampling */
+ if( ! ( jarc1->tail()[0] < (jarc1)->head()[0] ) ) {
+#ifndef NDEBUG
+ _glu_dprintf( "s difference %f\n", (jarc1)->tail()[0] - (jarc1)->head()[0] );
+#endif
+ ::mylongjmp( jumpbuffer, 28 );
+ }
+
+ if( ! ( jarc2->tail()[0] > (jarc2)->head()[0] ) ) {
+#ifndef NDEBUG
+ _glu_dprintf( "s difference %f\n", (jarc2)->tail()[0] - (jarc2)->head()[0] );
+#endif
+ ::mylongjmp( jumpbuffer, 28 );
+ }
+}
+
+inline void
+Subdivider::link( Arc_ptr jarc1, Arc_ptr jarc2, Arc_ptr up, Arc_ptr down )
+{
+ up->nuid = down->nuid = 0; // XXX
+
+ up->next = jarc2;
+ down->next = jarc1;
+ up->prev = jarc1->prev;
+ down->prev = jarc2->prev;
+
+ down->next->prev = down;
+ up->next->prev = up;
+ down->prev->next = down;
+ up->prev->next = up;
+}
+
+inline void
+Subdivider::simple_link( Arc_ptr jarc1, Arc_ptr jarc2 )
+{
+ Arc_ptr tmp = jarc2->prev;
+ jarc2->prev = jarc1->prev;
+ jarc1->prev = tmp;
+ jarc2->prev->next = jarc2;
+ jarc1->prev->next = jarc1;
+}
+
+
+/*----------------------------------------------------------------------------
+ * join - add a pair of oppositely directed jordan arcs between two arcs
+ *----------------------------------------------------------------------------
+ */
+
+void
+Subdivider::join_s( Bin& left, Bin& right, Arc_ptr jarc1, Arc_ptr jarc2 )
+{
+ assert( jarc1->check( ) != 0);
+ assert( jarc2->check( ) != 0);
+ assert( jarc1 != jarc2 );
+
+ if( ! jarc1->getitail() )
+ jarc1 = jarc1->next;
+
+ if( ! jarc2->getitail() )
+ jarc2 = jarc2->next;
+
+ REAL s = jarc1->tail()[0];
+ REAL t1 = jarc1->tail()[1];
+ REAL t2 = jarc2->tail()[1];
+
+ if( t1 == t2 ) {
+ simple_link( jarc1, jarc2 );
+ } else {
+ Arc_ptr newright = new(arcpool) Arc( arc_right, 0 );
+ Arc_ptr newleft = new(arcpool) Arc( arc_left, 0 );
+ assert( t1 < t2 );
+ if( isBezierArcType() ) {
+ arctessellator.bezier( newright, s, s, t1, t2 );
+ arctessellator.bezier( newleft, s, s, t2, t1 );
+ } else {
+ arctessellator.pwl_right( newright, s, t1, t2, stepsizes[0] );
+ arctessellator.pwl_left( newleft, s, t2, t1, stepsizes[2] );
+ }
+ link( jarc1, jarc2, newright, newleft );
+ left.addarc( newright );
+ right.addarc( newleft );
+ }
+
+ assert( jarc1->check( ) != 0 );
+ assert( jarc2->check( ) != 0 );
+ assert( jarc1->next->check( ) != 0);
+ assert( jarc2->next->check( ) != 0);
+}
+
+void
+Subdivider::check_t( Arc_ptr jarc1, Arc_ptr jarc2 )
+{
+ assert( jarc1->check( ) != 0 );
+ assert( jarc2->check( ) != 0 );
+ assert( jarc1->next->check( ) != 0 );
+ assert( jarc2->next->check( ) != 0 );
+ assert( jarc1 != jarc2 );
+
+ /* XXX - if these assertions fail, it is due to user error or
+ undersampling */
+ if( ! ( jarc1->tail()[1] < (jarc1)->head()[1] ) ) {
+#ifndef NDEBUG
+ _glu_dprintf( "t difference %f\n", jarc1->tail()[1] - (jarc1)->head()[1] );
+#endif
+ ::mylongjmp( jumpbuffer, 28 );
+ }
+
+ if( ! ( jarc2->tail()[1] > (jarc2)->head()[1] ) ) {
+#ifndef NDEBUG
+ _glu_dprintf( "t difference %f\n", jarc2->tail()[1] - (jarc2)->head()[1] );
+#endif
+ ::mylongjmp( jumpbuffer, 28 );
+ }
+}
+
+/*----------------------------------------------------------------------------
+ * join_t - add a pair of oppositely directed jordan arcs between two arcs
+ *----------------------------------------------------------------------------
+ */
+
+void
+Subdivider::join_t( Bin& bottom, Bin& top, Arc_ptr jarc1, Arc_ptr jarc2 )
+{
+ assert( jarc1->check( ) != 0 );
+ assert( jarc2->check( ) != 0 );
+ assert( jarc1->next->check( ) != 0 );
+ assert( jarc2->next->check( ) != 0 );
+ assert( jarc1 != jarc2 );
+
+ if( ! jarc1->getitail() )
+ jarc1 = jarc1->next;
+
+ if( ! jarc2->getitail() )
+ jarc2 = jarc2->next;
+
+ REAL s1 = jarc1->tail()[0];
+ REAL s2 = jarc2->tail()[0];
+ REAL t = jarc1->tail()[1];
+
+ if( s1 == s2 ) {
+ simple_link( jarc1, jarc2 );
+ } else {
+ Arc_ptr newtop = new(arcpool) Arc( arc_top, 0 );
+ Arc_ptr newbot = new(arcpool) Arc( arc_bottom, 0 );
+ assert( s1 > s2 );
+ if( isBezierArcType() ) {
+ arctessellator.bezier( newtop, s1, s2, t, t );
+ arctessellator.bezier( newbot, s2, s1, t, t );
+ } else {
+ arctessellator.pwl_top( newtop, t, s1, s2, stepsizes[1] );
+ arctessellator.pwl_bottom( newbot, t, s2, s1, stepsizes[3] );
+ }
+ link( jarc1, jarc2, newtop, newbot );
+ bottom.addarc( newtop );
+ top.addarc( newbot );
+ }
+
+ assert( jarc1->check( ) != 0 );
+ assert( jarc2->check( ) != 0 );
+ assert( jarc1->next->check( ) != 0 );
+ assert( jarc2->next->check( ) != 0 );
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/subdivider.cc b/mesalib/src/glu/sgi/libnurbs/internals/subdivider.cc
new file mode 100644
index 000000000..cc0b51470
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/subdivider.cc
@@ -0,0 +1,910 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * subdivider.cxx
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "mystdio.h"
+#include "subdivider.h"
+#include "arc.h"
+#include "bezierarc.h"
+#include "bin.h"
+#include "renderhints.h"
+#include "backend.h"
+#include "mapdesc.h"
+#include "quilt.h"
+#include "patchlist.h"
+#include "patch.h"
+#include "nurbsconsts.h"
+#include "trimvertpool.h"
+#include "simplemath.h"
+
+#include "polyUtil.h" //for function area()
+
+//#define PARTITION_TEST
+#ifdef PARTITION_TEST
+#include "partitionY.h"
+#include "monoTriangulation.h"
+#include "dataTransform.h"
+#include "monoChain.h"
+
+#endif
+
+
+#define OPTIMIZE_UNTRIMED_CASE
+
+
+Bin*
+Subdivider::makePatchBoundary( const REAL *from, const REAL *to )
+{
+ Bin* ret = new Bin();
+ REAL smin = from[0];
+ REAL smax = to[0];
+ REAL tmin = from[1];
+ REAL tmax = to[1];
+
+ pjarc = 0;
+
+ Arc_ptr jarc = new(arcpool) Arc( arc_bottom, 0 );
+ arctessellator.bezier( jarc, smin, smax, tmin, tmin );
+ ret->addarc( jarc );
+ pjarc = jarc->append( pjarc );
+
+ jarc = new(arcpool) Arc( arc_right, 0 );
+ arctessellator.bezier( jarc, smax, smax, tmin, tmax );
+ ret->addarc( jarc );
+ pjarc = jarc->append( pjarc );
+
+ jarc = new(arcpool) Arc( arc_top, 0 );
+ arctessellator.bezier( jarc, smax, smin, tmax, tmax );
+ ret->addarc( jarc );
+ pjarc = jarc->append( pjarc );
+
+ jarc = new(arcpool) Arc( arc_left, 0 );
+ arctessellator.bezier( jarc, smin, smin, tmax, tmin );
+ ret->addarc( jarc );
+ jarc->append( pjarc );
+
+ assert( jarc->check() != 0 );
+ return ret;
+}
+
+/*---------------------------------------------------------------------------
+ * Subdivider - construct a subdivider
+ *---------------------------------------------------------------------------
+ */
+
+Subdivider::Subdivider( Renderhints& r, Backend& b )
+ : slicer( b ),
+ arctessellator( trimvertexpool, pwlarcpool ),
+ arcpool( sizeof( Arc), 1, "arcpool" ),
+ bezierarcpool( sizeof( BezierArc ), 1, "Bezarcpool" ),
+ pwlarcpool( sizeof( PwlArc ), 1, "Pwlarcpool" ),
+ renderhints( r ),
+ backend( b )
+{
+}
+
+void
+Subdivider::setJumpbuffer( JumpBuffer *j )
+{
+ jumpbuffer = j;
+}
+
+/*---------------------------------------------------------------------------
+ * clear - reset all state after possible error condition
+ *---------------------------------------------------------------------------
+ */
+
+void
+Subdivider::clear( void )
+{
+ trimvertexpool.clear();
+ arcpool.clear();
+ pwlarcpool.clear();
+ bezierarcpool.clear();
+}
+
+/*---------------------------------------------------------------------------
+ * ~Subdivider - destroy a subdivider
+ *---------------------------------------------------------------------------
+ */
+
+Subdivider::~Subdivider( void )
+{
+}
+
+/*---------------------------------------------------------------------------
+ * addArc - add a bezier arc to a trim loop and to a bin
+ *---------------------------------------------------------------------------
+ */
+void
+Subdivider::addArc( REAL *cpts, Quilt *quilt, long _nuid )
+{
+ BezierArc *bezierArc = new(bezierarcpool) BezierArc;
+ Arc *jarc = new(arcpool) Arc( arc_none, _nuid );
+ jarc->pwlArc = 0;
+ jarc->bezierArc = bezierArc;
+ bezierArc->order = quilt->qspec->order;
+ bezierArc->stride = quilt->qspec->stride;
+ bezierArc->mapdesc = quilt->mapdesc;
+ bezierArc->cpts = cpts;
+ initialbin.addarc( jarc );
+ pjarc = jarc->append( pjarc );
+}
+
+/*---------------------------------------------------------------------------
+ * addArc - add a pwl arc to a trim loop and to a bin
+ *---------------------------------------------------------------------------
+ */
+
+void
+Subdivider::addArc( int npts, TrimVertex *pts, long _nuid )
+{
+ Arc *jarc = new(arcpool) Arc( arc_none, _nuid );
+ jarc->pwlArc = new(pwlarcpool) PwlArc( npts, pts );
+ initialbin.addarc( jarc );
+ pjarc = jarc->append( pjarc );
+}
+
+void
+Subdivider::beginQuilts( void )
+{
+ qlist = 0;
+}
+
+void
+Subdivider::addQuilt( Quilt *quilt )
+{
+ quilt->next = qlist;
+ qlist = quilt;
+}
+
+/*---------------------------------------------------------------------------
+ * drawSurfaces - main entry point for surface tessellation
+ *---------------------------------------------------------------------------
+ */
+
+void
+Subdivider::drawSurfaces( long nuid )
+{
+ renderhints.init( );
+
+ if (qlist == NULL)
+ {
+ //initialbin could be nonempty due to some errors
+ freejarcs(initialbin);
+ return;
+ }
+
+ for( Quilt *q = qlist; q; q = q->next ) {
+ if( q->isCulled( ) == CULL_TRIVIAL_REJECT ) {
+ freejarcs( initialbin );
+ return;
+ }
+ }
+
+
+ REAL from[2], to[2];
+ qlist->getRange( from, to, spbrkpts, tpbrkpts );
+#ifdef OPTIMIZE_UNTRIMED_CASE
+ //perform optimization only when the samplng method is
+ //DOMAIN_DISTANCE and the display methdo is either
+ //fill or outline_polygon.
+ int optimize = (is_domain_distance_sampling && (renderhints.display_method != N_OUTLINE_PATCH));
+#endif
+
+ if( ! initialbin.isnonempty() ) {
+#ifdef OPTIMIZE_UNTRIMED_CASE
+ if(! optimize )
+ {
+
+ makeBorderTrim( from, to );
+ }
+#else
+ makeBorderTrim( from, to );
+#endif
+ } else {
+ REAL rate[2];
+ qlist->findRates( spbrkpts, tpbrkpts, rate );
+
+ if( decompose( initialbin, min(rate[0], rate[1]) ) )
+ mylongjmp( jumpbuffer, 31 );
+ }
+
+ backend.bgnsurf( renderhints.wiretris, renderhints.wirequads, nuid );
+
+#ifdef PARTITION_TEST
+ if( initialbin.isnonempty() && spbrkpts.end-2 == spbrkpts.start &&
+ tpbrkpts.end-2 == tpbrkpts.start)
+{
+ for(int i=spbrkpts.start; i<spbrkpts.end-1; i++){
+ for(int j=tpbrkpts.start; j<tpbrkpts.end-1; j++){
+ Real pta[2], ptb[2];
+ pta[0] = spbrkpts.pts[i];
+ ptb[0] = spbrkpts.pts[i+1];
+ pta[1] = tpbrkpts.pts[j];
+ ptb[1] = tpbrkpts.pts[j+1];
+ qlist->downloadAll(pta, ptb, backend);
+
+ directedLine *poly;
+
+ {
+
+ poly = bin_to_DLineLoops(initialbin);
+
+ poly=poly->deleteDegenerateLinesAllPolygons();
+
+ sampledLine* retSampledLines;
+//printf("before MC_partition\n");
+ poly = MC_partitionY(poly, &retSampledLines);
+//printf("after MC_partition\n");
+
+ }
+
+
+ {
+ primStream pStream(5000,5000);
+ directedLine* temp;
+
+ for(temp=poly; temp != NULL; temp=temp->getNextPolygon())
+
+ monoTriangulation(temp, &pStream);
+
+ slicer.evalStream(&pStream);
+
+ }
+ //need to clean up space
+ }
+ }
+ freejarcs( initialbin );
+ backend.endsurf();
+ return;
+
+ /*
+ printf("num_polygons=%i\n", poly->numPolygons());
+ printf("num_edges=%i\n", poly->numEdgesAllPolygons());
+ poly->writeAllPolygons("zloutputFile");
+ return;
+ {
+ primStream pStream(20,20);
+ for(directedLine* tempD = poly; tempD != NULL; tempD = tempD->getNextPolygon())
+ monoTriangulation(tempD, &pStream);
+ }
+ return;
+ */
+}
+#endif //PARTITION_TEST
+
+
+#ifdef OPTIMIZE_UNTRIMED_CASE
+ if( (!initialbin.isnonempty()) && optimize )
+ {
+ int i,j;
+ int num_u_steps;
+ int num_v_steps;
+ for(i=spbrkpts.start; i<spbrkpts.end-1; i++){
+ for(j=tpbrkpts.start; j<tpbrkpts.end-1; j++){
+ Real pta[2], ptb[2];
+ pta[0] = spbrkpts.pts[i];
+ ptb[0] = spbrkpts.pts[i+1];
+ pta[1] = tpbrkpts.pts[j];
+ ptb[1] = tpbrkpts.pts[j+1];
+ qlist->downloadAll(pta, ptb, backend);
+
+ num_u_steps = (int) (domain_distance_u_rate * (ptb[0]-pta[0]));
+ num_v_steps = (int) (domain_distance_v_rate * (ptb[1]-pta[1]));
+
+ if(num_u_steps <= 0) num_u_steps = 1;
+ if(num_v_steps <= 0) num_v_steps = 1;
+
+ backend.surfgrid(pta[0], ptb[0], num_u_steps,
+ ptb[1], pta[1], num_v_steps);
+ backend.surfmesh(0,0,num_u_steps,num_v_steps);
+
+
+
+ continue;
+ /* the following is left for reference purpose, don't delete
+ {
+ Bin* tempSource;
+ Patchlist patchlist(qlist, pta, ptb);
+ patchlist.getstepsize();
+
+ tempSource=makePatchBoundary(pta, ptb);
+
+ tessellation(*tempSource, patchlist);
+
+ render(*tempSource);
+ delete tempSource;
+ }
+ */
+ }
+ }
+ }
+ else
+ subdivideInS( initialbin );
+#else
+
+ subdivideInS( initialbin );
+#endif
+
+ backend.endsurf();
+
+}
+
+void
+Subdivider::subdivideInS( Bin& source )
+{
+ if( renderhints.display_method == N_OUTLINE_PARAM ) {
+ outline( source );
+ freejarcs( source );
+ } else {
+ setArcTypeBezier();
+ setNonDegenerate();
+ splitInS( source, spbrkpts.start, spbrkpts.end );
+ }
+}
+
+
+/*---------------------------------------------------------------------------
+ * splitInS - split a patch and a bin by an isoparametric line
+ *---------------------------------------------------------------------------
+ */
+
+void
+Subdivider::splitInS( Bin& source, int start, int end )
+{
+ if( source.isnonempty() ) {
+ if( start != end ) {
+ int i = start + (end - start) / 2;
+ Bin left, right;
+ split( source, left, right, 0, spbrkpts.pts[i] );
+ splitInS( left, start, i );
+ splitInS( right, i+1, end );
+ } else {
+ if( start == spbrkpts.start || start == spbrkpts.end ) {
+ freejarcs( source );
+ } else if( renderhints.display_method == N_OUTLINE_PARAM_S ) {
+ outline( source );
+ freejarcs( source );
+ } else {
+ setArcTypeBezier();
+ setNonDegenerate();
+ s_index = start;
+ splitInT( source, tpbrkpts.start, tpbrkpts.end );
+ }
+ }
+ }
+}
+
+/*---------------------------------------------------------------------------
+ * splitInT - split a patch and a bin by an isoparametric line
+ *---------------------------------------------------------------------------
+ */
+
+void
+Subdivider::splitInT( Bin& source, int start, int end )
+{
+ if( source.isnonempty() ) {
+ if( start != end ) {
+ int i = start + (end - start) / 2;
+ Bin left, right;
+ split( source, left, right, 1, tpbrkpts.pts[i] );
+ splitInT( left, start, i );
+ splitInT( right, i+1, end );
+ } else {
+ if( start == tpbrkpts.start || start == tpbrkpts.end ) {
+ freejarcs( source );
+ } else if( renderhints.display_method == N_OUTLINE_PARAM_ST ) {
+ outline( source );
+ freejarcs( source );
+ } else {
+ t_index = start;
+ setArcTypeBezier();
+ setDegenerate();
+
+ REAL pta[2], ptb[2];
+ pta[0] = spbrkpts.pts[s_index-1];
+ pta[1] = tpbrkpts.pts[t_index-1];
+
+ ptb[0] = spbrkpts.pts[s_index];
+ ptb[1] = tpbrkpts.pts[t_index];
+ qlist->downloadAll( pta, ptb, backend );
+
+ Patchlist patchlist( qlist, pta, ptb );
+/*
+printf("-------samplingSplit-----\n");
+source.show("samplingSplit source");
+*/
+ samplingSplit( source, patchlist, renderhints.maxsubdivisions, 0 );
+ setNonDegenerate();
+ setArcTypeBezier();
+ }
+ }
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * samplingSplit - recursively subdivide patch, cull check each subpatch
+ *--------------------------------------------------------------------------
+ */
+
+void
+Subdivider::samplingSplit(
+ Bin& source,
+ Patchlist& patchlist,
+ int subdivisions,
+ int param )
+{
+ if( ! source.isnonempty() ) return;
+
+ if( patchlist.cullCheck() == CULL_TRIVIAL_REJECT ) {
+ freejarcs( source );
+ return;
+ }
+
+ patchlist.getstepsize();
+
+ if( renderhints.display_method == N_OUTLINE_PATCH ) {
+ tessellation( source, patchlist );
+ outline( source );
+ freejarcs( source );
+ return;
+ }
+
+ //patchlist.clamp();
+
+ tessellation( source, patchlist );
+
+ if( patchlist.needsSamplingSubdivision() && (subdivisions > 0) ) {
+ if( ! patchlist.needsSubdivision( 0 ) )
+ param = 1;
+ else if( ! patchlist.needsSubdivision( 1 ) )
+ param = 0;
+ else
+ param = 1 - param;
+
+ Bin left, right;
+ REAL mid = ( patchlist.pspec[param].range[0] +
+ patchlist.pspec[param].range[1] ) * 0.5;
+ split( source, left, right, param, mid );
+ Patchlist subpatchlist( patchlist, param, mid );
+ samplingSplit( left, subpatchlist, subdivisions-1, param );
+ samplingSplit( right, patchlist, subdivisions-1, param );
+ } else {
+ setArcTypePwl();
+ setDegenerate();
+ nonSamplingSplit( source, patchlist, subdivisions, param );
+ setDegenerate();
+ setArcTypeBezier();
+ }
+}
+
+void
+Subdivider::nonSamplingSplit(
+ Bin& source,
+ Patchlist& patchlist,
+ int subdivisions,
+ int param )
+{
+ if( patchlist.needsNonSamplingSubdivision() && (subdivisions > 0) ) {
+ param = 1 - param;
+
+ Bin left, right;
+ REAL mid = ( patchlist.pspec[param].range[0] +
+ patchlist.pspec[param].range[1] ) * 0.5;
+ split( source, left, right, param, mid );
+ Patchlist subpatchlist( patchlist, param, mid );
+ if( left.isnonempty() )
+ if( subpatchlist.cullCheck() == CULL_TRIVIAL_REJECT )
+ freejarcs( left );
+ else
+ nonSamplingSplit( left, subpatchlist, subdivisions-1, param );
+ if( right.isnonempty() )
+ if( patchlist.cullCheck() == CULL_TRIVIAL_REJECT )
+ freejarcs( right );
+ else
+ nonSamplingSplit( right, patchlist, subdivisions-1, param );
+
+ } else {
+ // make bbox calls
+ patchlist.bbox();
+ backend.patch( patchlist.pspec[0].range[0], patchlist.pspec[0].range[1],
+ patchlist.pspec[1].range[0], patchlist.pspec[1].range[1] );
+
+ if( renderhints.display_method == N_OUTLINE_SUBDIV ) {
+ outline( source );
+ freejarcs( source );
+ } else {
+ setArcTypePwl();
+ setDegenerate();
+ findIrregularS( source );
+ monosplitInS( source, smbrkpts.start, smbrkpts.end );
+ }
+ }
+}
+
+/*--------------------------------------------------------------------------
+ * tessellation - set tessellation of interior and boundary of patch
+ *--------------------------------------------------------------------------
+ */
+
+void
+Subdivider::tessellation( Bin& bin, Patchlist &patchlist )
+{
+ // tessellate unsampled trim curves
+ tessellate( bin, patchlist.pspec[1].sidestep[1], patchlist.pspec[0].sidestep[1],
+ patchlist.pspec[1].sidestep[0], patchlist.pspec[0].sidestep[0] );
+
+ // set interior sampling rates
+ slicer.setstriptessellation( patchlist.pspec[0].stepsize, patchlist.pspec[1].stepsize );
+
+ //added by zl: set the order which will be used in slicer.c++
+ slicer.set_ulinear( (patchlist.get_uorder() == 2));
+ slicer.set_vlinear( (patchlist.get_vorder() == 2));
+
+ // set boundary sampling rates
+ stepsizes[0] = patchlist.pspec[1].stepsize;
+ stepsizes[1] = patchlist.pspec[0].stepsize;
+ stepsizes[2] = patchlist.pspec[1].stepsize;
+ stepsizes[3] = patchlist.pspec[0].stepsize;
+}
+
+/*---------------------------------------------------------------------------
+ * monosplitInS - split a patch and a bin by an isoparametric line
+ *---------------------------------------------------------------------------
+ */
+
+void
+Subdivider::monosplitInS( Bin& source, int start, int end )
+{
+ if( source.isnonempty() ) {
+ if( start != end ) {
+ int i = start + (end - start) / 2;
+ Bin left, right;
+ split( source, left, right, 0, smbrkpts.pts[i] );
+ monosplitInS( left, start, i );
+ monosplitInS( right, i+1, end );
+ } else {
+ if( renderhints.display_method == N_OUTLINE_SUBDIV_S ) {
+ outline( source );
+ freejarcs( source );
+ } else {
+ setArcTypePwl();
+ setDegenerate();
+ findIrregularT( source );
+ monosplitInT( source, tmbrkpts.start, tmbrkpts.end );
+ }
+ }
+ }
+}
+
+/*---------------------------------------------------------------------------
+ * monosplitInT - split a patch and a bin by an isoparametric line
+ *---------------------------------------------------------------------------
+ */
+
+void
+Subdivider::monosplitInT( Bin& source, int start, int end )
+{
+ if( source.isnonempty() ) {
+ if( start != end ) {
+ int i = start + (end - start) / 2;
+ Bin left, right;
+ split( source, left, right, 1, tmbrkpts.pts[i] );
+ monosplitInT( left, start, i );
+ monosplitInT( right, i+1, end );
+ } else {
+ if( renderhints.display_method == N_OUTLINE_SUBDIV_ST ) {
+ outline( source );
+ freejarcs( source );
+ } else {
+/*
+printf("*******render\n");
+source.show("source\n");
+*/
+ render( source );
+ freejarcs( source );
+ }
+ }
+ }
+}
+
+
+/*----------------------------------------------------------------------------
+ * findIrregularS - determine points of non-monotonicity is s direction
+ *----------------------------------------------------------------------------
+ */
+
+void
+Subdivider::findIrregularS( Bin& bin )
+{
+ assert( bin.firstarc()->check() != 0 );
+
+ smbrkpts.grow( bin.numarcs() );
+
+ for( Arc_ptr jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) {
+ REAL *a = jarc->prev->tail();
+ REAL *b = jarc->tail();
+ REAL *c = jarc->head();
+
+ if( b[1] == a[1] && b[1] == c[1] ) continue;
+
+ //corrected code
+ if((b[1]<=a[1] && b[1] <= c[1]) ||
+ (b[1]>=a[1] && b[1] >= c[1]))
+ {
+ //each arc (jarc, jarc->prev, jarc->next) is a
+ //monotone arc consisting of multiple line segements.
+ //it may happen that jarc->prev and jarc->next are the same,
+ //that is, jarc->prev and jarc form a closed loop.
+ //In such case, a and c will be the same.
+ if(a[0]==c[0] && a[1] == c[1])
+ {
+ if(jarc->pwlArc->npts >2)
+ {
+ c = jarc->pwlArc->pts[jarc->pwlArc->npts-2].param;
+ }
+ else
+ {
+ assert(jarc->prev->pwlArc->npts>2);
+ a = jarc->prev->pwlArc->pts[jarc->prev->pwlArc->npts-2].param;
+ }
+
+ }
+ if(area(a,b,c) < 0)
+ {
+ smbrkpts.add(b[0]);
+ }
+
+ }
+
+ /* old code,
+ if( b[1] <= a[1] && b[1] <= c[1] ) {
+ if( ! ccwTurn_tr( jarc->prev, jarc ) )
+ smbrkpts.add( b[0] );
+ } else if( b[1] >= a[1] && b[1] >= c[1] ) {
+ if( ! ccwTurn_tl( jarc->prev, jarc ) )
+ smbrkpts.add( b[0] );
+ }
+ */
+
+ }
+
+ smbrkpts.filter();
+}
+
+/*----------------------------------------------------------------------------
+ * findIrregularT - determine points of non-monotonicity in t direction
+ * where one arc is parallel to the s axis.
+ *----------------------------------------------------------------------------
+ */
+
+void
+Subdivider::findIrregularT( Bin& bin )
+{
+ assert( bin.firstarc()->check() != 0 );
+
+ tmbrkpts.grow( bin.numarcs() );
+
+ for( Arc_ptr jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) {
+ REAL *a = jarc->prev->tail();
+ REAL *b = jarc->tail();
+ REAL *c = jarc->head();
+
+ if( b[0] == a[0] && b[0] == c[0] ) continue;
+
+ if( b[0] <= a[0] && b[0] <= c[0] ) {
+ if( a[1] != b[1] && b[1] != c[1] ) continue;
+ if( ! ccwTurn_sr( jarc->prev, jarc ) )
+ tmbrkpts.add( b[1] );
+ } else if ( b[0] >= a[0] && b[0] >= c[0] ) {
+ if( a[1] != b[1] && b[1] != c[1] ) continue;
+ if( ! ccwTurn_sl( jarc->prev, jarc ) )
+ tmbrkpts.add( b[1] );
+ }
+ }
+ tmbrkpts.filter( );
+}
+
+/*-----------------------------------------------------------------------------
+ * makeBorderTrim - if no user input trimming data then create
+ * a trimming curve around the boundaries of the Quilt. The curve consists of
+ * four Jordan arcs, one for each side of the Quilt, connected, of course,
+ * head to tail.
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Subdivider::makeBorderTrim( const REAL *from, const REAL *to )
+{
+ REAL smin = from[0];
+ REAL smax = to[0];
+ REAL tmin = from[1];
+ REAL tmax = to[1];
+
+ pjarc = 0;
+
+ Arc_ptr jarc = new(arcpool) Arc( arc_bottom, 0 );
+ arctessellator.bezier( jarc, smin, smax, tmin, tmin );
+ initialbin.addarc( jarc );
+ pjarc = jarc->append( pjarc );
+
+ jarc = new(arcpool) Arc( arc_right, 0 );
+ arctessellator.bezier( jarc, smax, smax, tmin, tmax );
+ initialbin.addarc( jarc );
+ pjarc = jarc->append( pjarc );
+
+ jarc = new(arcpool) Arc( arc_top, 0 );
+ arctessellator.bezier( jarc, smax, smin, tmax, tmax );
+ initialbin.addarc( jarc );
+ pjarc = jarc->append( pjarc );
+
+ jarc = new(arcpool) Arc( arc_left, 0 );
+ arctessellator.bezier( jarc, smin, smin, tmax, tmin );
+ initialbin.addarc( jarc );
+ jarc->append( pjarc );
+
+ assert( jarc->check() != 0 );
+}
+
+/*----------------------------------------------------------------------------
+ * render - renders all monotone regions in a bin and frees the bin
+ *----------------------------------------------------------------------------
+ */
+
+void
+Subdivider::render( Bin& bin )
+{
+ bin.markall();
+
+#ifdef N_ISOLINE_S
+ slicer.setisolines( ( renderhints.display_method == N_ISOLINE_S ) ? 1 : 0 );
+#else
+ slicer.setisolines( 0 );
+#endif
+
+ for( Arc_ptr jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) {
+ if( jarc->ismarked() ) {
+ assert( jarc->check( ) != 0 );
+ Arc_ptr jarchead = jarc;
+ do {
+ jarc->clearmark();
+ jarc = jarc->next;
+ } while (jarc != jarchead);
+ slicer.slice( jarc );
+ }
+ }
+}
+
+/*---------------------------------------------------------------------------
+ * outline - render the trimmed patch by outlining the boundary
+ *---------------------------------------------------------------------------
+ */
+
+void
+Subdivider::outline( Bin& bin )
+{
+ bin.markall();
+ for( Arc_ptr jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) {
+ if( jarc->ismarked() ) {
+ assert( jarc->check( ) != 0 );
+ Arc_ptr jarchead = jarc;
+ do {
+ slicer.outline( jarc );
+ jarc->clearmark();
+ jarc = jarc->prev;
+ } while (jarc != jarchead);
+ }
+ }
+}
+
+/*---------------------------------------------------------------------------
+ * freejarcs - free all arcs in a bin
+ *---------------------------------------------------------------------------
+ */
+
+void
+Subdivider::freejarcs( Bin& bin )
+{
+ bin.adopt(); /* XXX - should not be necessary */
+
+ Arc_ptr jarc;
+ while( (jarc = bin.removearc()) != NULL ) {
+ if( jarc->pwlArc ) jarc->pwlArc->deleteMe( pwlarcpool ); jarc->pwlArc = 0;
+ if( jarc->bezierArc) jarc->bezierArc->deleteMe( bezierarcpool ); jarc->bezierArc = 0;
+ jarc->deleteMe( arcpool );
+ }
+}
+
+/*----------------------------------------------------------------------------
+ * tessellate - tessellate all Bezier arcs in a bin
+ * 1) only accepts linear Bezier arcs as input
+ * 2) the Bezier arcs are stored in the pwlArc structure
+ * 3) only vertical or horizontal lines work
+ * -- should
+ * 1) represent Bezier arcs in BezierArc structure
+ * (this requires a multitude of changes to the code)
+ * 2) accept high degree Bezier arcs (hard)
+ * 3) map the curve onto the surface to determine tessellation
+ * 4) work for curves of arbitrary geometry
+ *----------------------------------------------------------------------------
+ */
+
+
+void
+Subdivider::tessellate( Bin& bin, REAL rrate, REAL trate, REAL lrate, REAL brate )
+{
+ for( Arc_ptr jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) {
+ if( jarc->isbezier( ) ) {
+ assert( jarc->pwlArc->npts == 2 );
+ TrimVertex *pts = jarc->pwlArc->pts;
+ REAL s1 = pts[0].param[0];
+ REAL t1 = pts[0].param[1];
+ REAL s2 = pts[1].param[0];
+ REAL t2 = pts[1].param[1];
+
+ jarc->pwlArc->deleteMe( pwlarcpool ); jarc->pwlArc = 0;
+
+ switch( jarc->getside() ) {
+ case arc_left:
+ assert( s1 == s2 );
+ arctessellator.pwl_left( jarc, s1, t1, t2, lrate );
+ break;
+ case arc_right:
+ assert( s1 == s2 );
+ arctessellator.pwl_right( jarc, s1, t1, t2, rrate );
+ break;
+ case arc_top:
+ assert( t1 == t2 );
+ arctessellator.pwl_top( jarc, t1, s1, s2, trate );
+ break;
+ case arc_bottom:
+ assert( t1 == t2 );
+ arctessellator.pwl_bottom( jarc, t1, s1, s2, brate );
+ break;
+ case arc_none:
+ (void) abort();
+ break;
+ }
+ assert( ! jarc->isbezier() );
+ assert( jarc->check() != 0 );
+ }
+ }
+}
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/subdivider.h b/mesalib/src/glu/sgi/libnurbs/internals/subdivider.h
new file mode 100644
index 000000000..4d5395181
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/subdivider.h
@@ -0,0 +1,200 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * subdivider.h
+ *
+ */
+
+#ifndef __glusubdivider_h_
+#define __glusubdivider_h_
+
+#include "mysetjmp.h"
+#include "bin.h"
+#include "flist.h"
+#include "slicer.h"
+#include "arctess.h"
+#include "trimvertex.h"
+#include "trimvertpool.h"
+
+class Arc;
+class Pool;
+class Renderhints;
+class Quilt;
+class Patchlist;
+class Curvelist;
+struct JumpBuffer;
+
+class Subdivider {
+public:
+ Subdivider( Renderhints&, Backend& );
+ ~Subdivider( void );
+ void clear( void );
+
+ void beginTrims( void ) {}
+ void beginLoop( void );
+ void addArc( REAL *, Quilt *, long );
+ void addArc( int, TrimVertex *, long );
+ void endLoop( void ) {}
+ void endTrims( void ) {}
+
+ void beginQuilts( void );
+ void addQuilt( Quilt * );
+ void endQuilts( void ) {}
+
+ void drawCurves( void );
+ void drawSurfaces( long );
+
+ int ccwTurn_sl( Arc_ptr, Arc_ptr );
+ int ccwTurn_sr( Arc_ptr , Arc_ptr );
+ int ccwTurn_tl( Arc_ptr , Arc_ptr );
+ int ccwTurn_tr( Arc_ptr , Arc_ptr );
+
+ void setJumpbuffer( JumpBuffer * );
+
+ void set_domain_distance_u_rate(REAL u_rate)
+ {
+ domain_distance_u_rate = u_rate;
+ }
+ void set_domain_distance_v_rate(REAL v_rate)
+ {
+ domain_distance_v_rate = v_rate;
+ }
+ void set_is_domain_distance_sampling(int flag)
+ {
+ is_domain_distance_sampling = flag;
+ }
+
+private:
+ void classify_headonleft_s( Bin &, Bin &, Bin &, REAL );
+ void classify_tailonleft_s( Bin &, Bin &, Bin &, REAL );
+ void classify_headonright_s( Bin &, Bin &, Bin &, REAL );
+ void classify_tailonright_s( Bin &, Bin &, Bin &, REAL );
+ void classify_headonleft_t( Bin &, Bin &, Bin &, REAL );
+ void classify_tailonleft_t( Bin &, Bin &, Bin &, REAL );
+ void classify_headonright_t( Bin &, Bin &, Bin &, REAL );
+ void classify_tailonright_t( Bin &, Bin &, Bin &, REAL );
+
+ enum dir { down, same, up, none };
+ void tessellate( Arc_ptr, REAL );
+ void monotonize( Arc_ptr , Bin & );
+ int isMonotone( Arc_ptr );
+ int decompose( Bin &, REAL );
+
+
+ Slicer slicer;
+ ArcTessellator arctessellator;
+ Pool arcpool;
+ Pool bezierarcpool;
+ Pool pwlarcpool;
+ TrimVertexPool trimvertexpool;
+
+ JumpBuffer* jumpbuffer;
+ Renderhints& renderhints;
+ Backend& backend;
+
+ Bin initialbin;
+ Arc_ptr pjarc;
+ int s_index;
+ int t_index;
+ Quilt * qlist;
+ Flist spbrkpts;
+ Flist tpbrkpts;
+ Flist smbrkpts;
+ Flist tmbrkpts;
+ REAL stepsizes[4];
+ int showDegenerate;
+ int isArcTypeBezier;
+
+ void samplingSplit( Curvelist&, int );
+
+ void subdivideInS( Bin& );
+ void splitInS( Bin&, int, int );
+ void splitInT( Bin&, int, int );
+ void samplingSplit( Bin&, Patchlist&, int, int );
+ void nonSamplingSplit( Bin&, Patchlist&, int, int );
+ void tessellation( Bin&, Patchlist& );
+ void monosplitInS( Bin&, int, int );
+ void monosplitInT( Bin&, int, int );
+
+ void outline( Bin & );
+ void freejarcs( Bin & );
+ void render( Bin & );
+ void split( Bin &, Bin &, Bin &, int, REAL );
+ void tessellate( Bin &, REAL, REAL, REAL, REAL );
+
+ inline void setDegenerate( void ) { showDegenerate = 1; }
+ inline void setNonDegenerate( void ) { showDegenerate = 0; }
+ inline int showingDegenerate( void ) { return showDegenerate; }
+ inline void setArcTypeBezier( void ) { isArcTypeBezier = 1; }
+ inline void setArcTypePwl( void ) { isArcTypeBezier = 0; }
+ inline int isBezierArcType( void ) { return isArcTypeBezier; }
+
+ void makeBorderTrim( const REAL *, const REAL * );
+ void split( Bin &, int, const REAL *, int, int );
+ void partition( Bin &, Bin &, Bin &, Bin &, Bin &, int, REAL );
+ void findIrregularS( Bin & );
+ void findIrregularT( Bin & );
+
+
+ inline int bbox( TrimVertex *, TrimVertex *, TrimVertex *, int );
+ static int bbox( REAL, REAL, REAL, REAL, REAL, REAL );
+ static int ccw( TrimVertex *, TrimVertex *, TrimVertex * );
+ void join_s( Bin &, Bin &, Arc_ptr, Arc_ptr );
+ void join_t( Bin &, Bin &, Arc_ptr , Arc_ptr );
+ int arc_split( Arc_ptr , int, REAL, int );
+ void check_s( Arc_ptr , Arc_ptr );
+ void check_t( Arc_ptr , Arc_ptr );
+ inline void link( Arc_ptr , Arc_ptr , Arc_ptr , Arc_ptr );
+ inline void simple_link( Arc_ptr , Arc_ptr );
+
+ Bin* makePatchBoundary( const REAL *from, const REAL *to );
+
+ /*in domain distance method, the tessellation is controled by two numbers:
+ *GLU_U_STEP: number of u-segments per unit u length of domain
+ *GLU_V_STEP: number of v-segments per unit v length of domain
+ *These two numbers are normally stored in mapdesc->maxs(t)rate.
+ *I (ZL) put these two numbers here so that I can optimize the untrimmed
+ *case in the case of domain distance sampling.
+ *These two numbers are set by set_domain_distance_u_rate() and ..._v_..().
+ */
+ REAL domain_distance_u_rate;
+ REAL domain_distance_v_rate;
+ int is_domain_distance_sampling;
+};
+
+inline void
+Subdivider::beginLoop( void )
+{
+ pjarc = 0;
+}
+
+
+#endif /* __glusubdivider_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/tobezier.cc b/mesalib/src/glu/sgi/libnurbs/internals/tobezier.cc
new file mode 100644
index 000000000..531f26bc7
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/tobezier.cc
@@ -0,0 +1,687 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * tobezier.c++
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "mystdio.h"
+#include "mystring.h"
+#include "quilt.h"
+#include "knotvector.h"
+
+/* local type definitions */
+struct Breakpt { /* breakpoints */
+ Knot value; /* value */
+ int multi; /* multiplicity */
+ int def; /* deficit */
+};
+
+struct Knotspec { /* knotvector format */
+ long order; /* order of spline */
+ Knot_ptr inkbegin; /* input knot sequence */
+ Knot_ptr inkend; /* location after last knot */
+ Knot_ptr outkbegin; /* in-process knot subsequence */
+ Knot_ptr outkend; /* location after last knot */
+ Knot_ptr kleft; /* */
+ Knot_ptr kright; /* */
+ Knot_ptr kfirst; /* */
+ Knot_ptr klast; /* */
+ Knot_ptr sbegin; /* conversion factor values */
+ Breakpt * bbegin; /* in-process breakpoints */
+ Breakpt * bend; /* last breakpoint */
+ int ncoords; /* coordinates per control point */
+ int prestride; /* stride between input points */
+ int poststride; /* stride between output points */
+ int preoffset; /* scaled point offset */
+ int postoffset; /* scaled point offset */
+ int prewidth; /* width of dimension */
+ int postwidth; /* width of dimension */
+ int istransformed; /* was dimension transformed */
+ Knotspec * next; /* next knotspec */
+ Knotspec * kspectotrans; /* knotspec in transformation direction */
+
+ Knotspec( void );
+ ~Knotspec( void );
+ void factors( void );
+ void insert( REAL * );
+ void preselect();
+ void select( void );
+ void copy( INREAL *, REAL * );
+ void breakpoints( void );
+ void knots( void );
+ void transform( REAL * );
+ void showpts( REAL * );
+
+ void pt_io_copy( REAL *, INREAL * );
+ void pt_oo_copy( REAL *, REAL * );
+ void pt_oo_sum( REAL*, REAL*, REAL*, Knot, Knot );
+};
+
+struct Splinespec { /* a non-uniform tensor element */
+ Splinespec( int );
+ ~Splinespec(void);
+ Knotspec *kspec; /* format of each param. dir. */
+ int dim; /* domain dimension */
+ REAL * outcpts; /* Bezier control points */
+
+ void kspecinit( Knotvector & );
+ void kspecinit( Knotvector &, Knotvector & );
+ void select( void );
+ void layout( long );
+ void setupquilt( Quilt_ptr );
+ void copy( INREAL * );
+ void transform( void );
+};
+
+/*-----------------------------------------------------------------------------
+ * Quilt::toBezier - convert from NURBS to rational Bezier
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Quilt::toBezier(
+ Knotvector& knotvector, /* a knot vector */
+ INREAL *ctlpts, /* input contol points */
+ long ncoords ) /* number of coordinates per control point */
+{
+ Splinespec spline( 1 );
+ spline.kspecinit( knotvector );
+ spline.select();
+ spline.layout( ncoords );
+ spline.setupquilt( this );
+ spline.copy( ctlpts );
+ spline.transform();
+}
+
+void
+Quilt::toBezier(
+ Knotvector& sknotvector, /* a knot vector */
+ Knotvector& tknotvector, /* a knot vector */
+ INREAL *ctlpts, /* input contol points */
+ long ncoords ) /* number of coordinates per control point */
+{
+ Splinespec spline( 2 );
+ spline.kspecinit( sknotvector, tknotvector );
+ spline.select();
+ spline.layout( ncoords );
+ spline.setupquilt( this );
+ spline.copy( ctlpts );
+ spline.transform();
+}
+Splinespec::Splinespec( int dimen )
+{
+ dim = dimen;
+}
+
+Splinespec::~Splinespec( void )
+{
+ /* Note: do NOT delete 'outcpts' here since its address (not contents)
+ * is copied in 'cpts' in this file in function Splinespec::setupquilt().
+ * This block of memory will eventually be deleted in file quilt.c++ in
+ * function Quilt::deleteMe() through 'cpts' so do NOT delete it here!
+ */
+ Knotspec *ktrav= kspec; //start at beginning of list
+ while (ktrav != 0) { //any items to delete?
+ Knotspec *deleteThis= ktrav; //remember to delete this
+ ktrav= ktrav->next; //go to next item if any
+ delete deleteThis; //delete it
+ }
+} /* ~Splinespec() */
+
+/*-----------------------------------------------------------------------------
+ * Splinespec::kspecinit - initialize Splinespec structure
+ *
+ * Client: Quilt::toBezier
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Splinespec::kspecinit( Knotvector& knotvector )
+{
+ kspec = new Knotspec;
+ kspec->inkbegin = knotvector.knotlist;
+ kspec->inkend = knotvector.knotlist + knotvector.knotcount;
+ kspec->prestride = (int) knotvector.stride;
+ kspec->order = knotvector.order;
+ kspec->next = NULL;
+}
+
+void
+Splinespec::kspecinit( Knotvector& sknotvector, Knotvector& tknotvector )
+{
+ kspec = new Knotspec;
+ Knotspec *tkspec = new Knotspec;
+
+ kspec->inkbegin = sknotvector.knotlist;
+ kspec->inkend = sknotvector.knotlist + sknotvector.knotcount;
+ kspec->prestride = (int) sknotvector.stride;
+ kspec->order = sknotvector.order;
+ kspec->next = tkspec;
+
+ tkspec->inkbegin = tknotvector.knotlist;
+ tkspec->inkend = tknotvector.knotlist + tknotvector.knotcount;
+ tkspec->prestride = (int) tknotvector.stride;
+ tkspec->order = tknotvector.order;
+ tkspec->next = NULL;
+}
+
+
+/*-----------------------------------------------------------------------------
+ * Splinespec::select - select the subsegments to copy
+ *
+ * Client: gl_quilt_to_bezier
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Splinespec::select( )
+{
+ for( Knotspec *knotspec = kspec; knotspec; knotspec = knotspec->next ) {
+ knotspec->preselect();
+ knotspec->select();
+ }
+}
+
+/*-----------------------------------------------------------------------------
+ * Splinespec::layout -
+ *
+ * Client: gl_quilt_to_bezier
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Splinespec::layout( long ncoords )
+{
+
+ long stride = ncoords;
+ for( Knotspec *knotspec = kspec; knotspec; knotspec=knotspec->next ) {
+ knotspec->poststride = (int) stride;
+ stride *= ((knotspec->bend-knotspec->bbegin)*knotspec->order + knotspec->postoffset);
+ knotspec->preoffset *= knotspec->prestride;
+ knotspec->prewidth *= knotspec->poststride;
+ knotspec->postwidth *= knotspec->poststride;
+ knotspec->postoffset *= knotspec->poststride;
+ knotspec->ncoords = (int) ncoords;
+ }
+ outcpts = new REAL[stride];
+ assert( outcpts != 0 );
+}
+
+/*-----------------------------------------------------------------------------
+ * Splinespec::copy - copy the control points of current subobject
+ *
+ * Client: gl_quilt_to_bezier
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Splinespec::copy( INREAL *incpts )
+{
+ kspec->copy( incpts, outcpts );
+}
+
+/*-----------------------------------------------------------------------------
+ * Splinespec::setupquilt - assign all quilt variables from knotspec
+ *
+ * Client: gl_quilt_to_bezier
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Splinespec::setupquilt( Quilt_ptr quilt )
+{
+ Quiltspec_ptr qspec = quilt->qspec;
+ quilt->eqspec = qspec + dim;
+ for( Knotspec *knotspec = kspec; knotspec; knotspec=knotspec->next, qspec++ ) {
+ qspec->stride = knotspec->poststride;
+ qspec->width = knotspec->bend - knotspec->bbegin;
+ qspec->order = (int) knotspec->order;
+ qspec->offset = knotspec->postoffset;
+ qspec->index = 0;
+ qspec->bdry[0] = (knotspec->kleft == knotspec->kfirst) ? 1 : 0;
+ qspec->bdry[1] = (knotspec->kright == knotspec->klast) ? 1 : 0;
+ qspec->breakpoints = new Knot[qspec->width+1];
+ Knot_ptr k = qspec->breakpoints;
+ for( Breakpt *bk = knotspec->bbegin; bk <= knotspec->bend; bk++ )
+ *(k++) = bk->value;
+ }
+ quilt->cpts = outcpts;
+ quilt->next = 0;
+}
+
+/*-----------------------------------------------------------------------------
+ * Splinespec::transform - convert a spline to Bezier format
+ *
+ * Client: gl_quilt_to_bezier
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Splinespec::transform( void )
+{
+ Knotspec *knotspec;
+ for( knotspec = kspec; knotspec; knotspec=knotspec->next )
+ knotspec->istransformed = 0;
+
+ for( knotspec = kspec; knotspec; knotspec=knotspec->next ) {
+ for( Knotspec *kspec2 = kspec; kspec2; kspec2=kspec2->next )
+ kspec2->kspectotrans = knotspec;
+ kspec->transform( outcpts );
+ knotspec->istransformed = 1;
+ }
+}
+
+
+/*-----------------------------------------------------------------------------
+ * Knotspec::Knotspec - constuct a knot spec
+ *-----------------------------------------------------------------------------
+ */
+
+Knotspec::Knotspec( void )
+{
+ bbegin = 0;
+ sbegin = 0;
+ outkbegin = 0;
+}
+
+/*-----------------------------------------------------------------------------
+ * Knotspec::copy - copy the control points along minor direction
+ *
+ * Client: Splinespec::copy
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Knotspec::copy( INREAL *inpt, REAL *outpt )
+{
+ inpt = (INREAL *) (((char *) inpt) + preoffset);
+
+ if( next ) {
+ for( REAL *lpt=outpt+prewidth; outpt != lpt; outpt += poststride ) {
+ next->copy( inpt, outpt );
+ inpt = (INREAL *) (((char *) inpt) + prestride);
+ }
+ } else {
+ for( REAL *lpt=outpt+prewidth; outpt != lpt; outpt += poststride ) {
+ pt_io_copy( outpt, inpt );
+ inpt = (INREAL *) (((char *) inpt) + prestride);
+ }
+ }
+}
+
+/*-----------------------------------------------------------------------------
+ * Knotspec::showpts - print out points before transformation
+ *
+ * Client: Knotspec::select
+ *-----------------------------------------------------------------------------
+ */
+void
+Knotspec::showpts( REAL *outpt )
+{
+ if( next ) {
+ for( REAL *lpt=outpt+prewidth; outpt != lpt; outpt += poststride )
+ next->showpts( outpt );
+ } else {
+ for( REAL *lpt=outpt+prewidth; outpt != lpt; outpt += poststride )
+ _glu_dprintf( "show %g %g %g\n", outpt[0], outpt[1], outpt[2] );
+ }
+}
+
+/*-----------------------------------------------------------------------------
+ * Knotspec::factors - precompute scale factors
+ * - overwrites knot vector, actual new knot vector is NOT produced
+ *
+ * Client: Knotspec::select
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Knotspec::factors( void )
+{
+ Knot *mid = (outkend - 1) - order + bend->multi;
+ Knot_ptr fptr = sbegin;
+
+ for( Breakpt *bpt = bend; bpt >= bbegin; bpt-- ) {
+ mid -= bpt->multi; // last knot less than knot to insert
+ int def = bpt->def - 1; // number of knots to insert
+ if( def <= 0 ) continue;
+ Knot kv = bpt->value; // knot to insert
+
+ Knot *kf = (mid-def) + (order-1);
+ for( Knot *kl = kf + def; kl != kf; kl-- ) {
+ Knot *kh, *kt;
+ for( kt=kl, kh=mid; kt != kf; kh--, kt-- )
+ *(fptr++) = (kv - *kh) / (*kt - *kh);
+ *kl = kv;
+ }
+ }
+}
+
+/*-----------------------------------------------------------------------------
+ * Knotspec::insert - convert subobject in direction of kspec into Bezier
+ *
+ * Client: Knotspec::transform
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Knotspec::insert( REAL *p )
+{
+ Knot_ptr fptr = sbegin;
+ REAL *srcpt = p + prewidth - poststride;
+ REAL *dstpt = p + postwidth + postoffset - poststride;
+ Breakpt *bpt = bend;
+
+ for( REAL *pend = srcpt - poststride*bpt->def; srcpt != pend; pend +=poststride ) {
+ REAL *p1 = srcpt;
+ for( REAL *p2 = srcpt-poststride; p2 != pend; p1 = p2, p2 -= poststride ) {
+ pt_oo_sum( p1, p1, p2, *fptr, 1.0-*fptr );
+ fptr++;
+ }
+ }
+
+ for( --bpt; bpt >= bbegin; bpt-- ) {
+
+ for( int multi = bpt->multi; multi > 0; multi-- ) {
+ pt_oo_copy( dstpt, srcpt );
+ dstpt -= poststride;
+ srcpt -= poststride;
+ }
+
+ for( REAL *pend = srcpt - poststride*bpt->def; srcpt != pend; pend +=poststride, dstpt-=poststride ) {
+ pt_oo_copy( dstpt, srcpt );
+ REAL *p1 = srcpt;
+
+ for( REAL *p2 = srcpt-poststride; p2 != pend; p1=p2, p2 -= poststride ) {
+ pt_oo_sum( p1, p1, p2, *fptr, 1.0-*fptr );
+ fptr++;
+ }
+ }
+ }
+}
+
+/*-----------------------------------------------------------------------------
+ * Knotspec::preselect - initialize kspec for processing
+ *
+ * Client: Splinespec::select
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Knotspec::preselect( void )
+{
+ Knot kval;
+
+ /* position klast after last knot of "last" breakpoint */
+ for( klast = inkend - order, kval = *klast; klast != inkend; klast++ )
+ if( ! identical( *klast, kval ) ) break;
+
+ /* position kfirst after last knot of "first" breakpoint */
+ for( kfirst = inkbegin+order-1, kval= *kfirst; kfirst != inkend; kfirst++ )
+ if( ! identical( *kfirst, kval ) ) break;
+
+ /* compute multiplicity of first breakpoint */
+ Knot_ptr k;
+ for( k = kfirst - 1; k >= inkbegin; k-- )
+ if( ! identical( kval, *k ) ) break;
+ k++;
+
+ /* allocate space for breakpoints -
+ use worst case estimate on number of breakpoints */
+
+ bbegin = new Breakpt[(klast - kfirst)+1];
+ /* record multiplicity and value of first breakpoint */
+ bbegin->multi = kfirst - k;
+ bbegin->value = kval;
+ bend = bbegin;
+
+ kleft = kright = kfirst;
+}
+
+
+/*-----------------------------------------------------------------------------
+ * Knotspec::select - Knotspec::select segments and precompute scale factors
+ *
+ * Client: Splinespec::select
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Knotspec::select( void )
+{
+ breakpoints();
+ knots();
+ factors();
+
+ preoffset = kleft - (inkbegin + order);
+ postwidth = (int)((bend - bbegin) * order);
+ prewidth = (int)((outkend - outkbegin) - order);
+ postoffset = (bbegin->def > 1) ? (bbegin->def-1) : 0;
+}
+
+/*-----------------------------------------------------------------------------
+ * Knotspec::breakpoints - compute breakpoints for knotspec
+ *
+ * Client: Knotspec::select
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Knotspec::breakpoints( void )
+{
+ Breakpt *ubpt = bbegin;
+ Breakpt *ubend = bend;
+ long nfactors = 0;
+
+ ubpt->value = ubend->value;
+ ubpt->multi = ubend->multi;
+
+ kleft = kright;
+
+ for( ; kright != klast; kright++ ) {
+ if ( identical(*kright,ubpt->value) ) {
+ (ubpt->multi)++;
+ } else {
+ ubpt->def = (int) (order - ubpt->multi);
+ nfactors += (ubpt->def * (ubpt->def - 1)) / 2;
+ (++ubpt)->value = *kright;
+ ubpt->multi = 1;
+ }
+ }
+ ubpt->def = (int) (order - ubpt->multi);
+ nfactors += (ubpt->def * (ubpt->def - 1)) / 2;
+
+ bend = ubpt;
+
+ if( nfactors ) {
+ sbegin = new Knot[nfactors];
+ } else {
+ sbegin = NULL;
+ }
+}
+
+
+/*-----------------------------------------------------------------------------
+ * Knotspec::knots - copy relevant subsequence of knots into temporary area
+ *
+ * Client: Knotspec::select
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Knotspec::knots( void )
+{
+ Knot_ptr inkpt = kleft - order;
+ Knot_ptr inkend = kright + bend->def;
+
+ /* allocate space for knots and factors */
+ outkbegin = new Knot[inkend-inkpt];
+ Knot_ptr outkpt;
+ for( outkpt = outkbegin; inkpt != inkend; inkpt++, outkpt++ )
+ *outkpt = *inkpt;
+
+ outkend = outkpt;
+}
+
+
+/*-----------------------------------------------------------------------------
+ * Knotspec::transform - convert a spline along a given direction
+ *
+ * Client: Splienspec::transform
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Knotspec::transform( REAL *p )
+{
+ if( next ) {
+ if( this == kspectotrans ) {
+ next->transform( p );
+ } else {
+ if( istransformed ) {
+ p += postoffset;
+ for( REAL *pend = p + postwidth; p != pend; p += poststride )
+ next->transform( p );
+ } else {
+ REAL *pend = p + prewidth;
+ for( ; p != pend; p += poststride )
+ next->transform( p );
+ }
+ }
+ } else {
+ if( this == kspectotrans ) {
+ insert( p );
+ } else {
+ if( istransformed ) {
+ p += postoffset;
+ for( REAL *pend = p + postwidth; p != pend; p += poststride )
+ kspectotrans->insert( p );
+ } else {
+ REAL *pend = p + prewidth;
+ for( ; p != pend; p += poststride )
+ kspectotrans->insert( p );
+ }
+ }
+ }
+}
+
+/*-----------------------------------------------------------------------------
+ * Knotspec::~Knotspec - free space alocated for knotspec
+ *-----------------------------------------------------------------------------
+ */
+
+Knotspec::~Knotspec( void )
+{
+ if( bbegin ) delete[] bbegin;
+ if( sbegin ) delete[] sbegin;
+ if( outkbegin ) delete[] outkbegin;
+}
+
+
+/*-----------------------------------------------------------------------------
+ * pt_io_copy - make internal copy of input cntrl pt. of x coords
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Knotspec::pt_io_copy( REAL *topt, INREAL *frompt )
+{
+ switch( ncoords ) {
+ case 4:
+ topt[3] = (REAL) frompt[3];
+ case 3:
+ topt[2] = (REAL) frompt[2];
+ case 2:
+ topt[1] = (REAL) frompt[1];
+ case 1:
+ topt[0] = (REAL) frompt[0];
+ break;
+ default: {
+ for( int i = 0; i < ncoords; i++ )
+ *topt++ = (REAL) *frompt++;
+ }
+ }
+}
+
+/*-----------------------------------------------------------------------------
+ * pt_oo_copy - make internal copy of internal cntrl pt. of x coords
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Knotspec::pt_oo_copy( REAL *topt, REAL *frompt )
+{
+ switch( ncoords ) {
+ case 4:
+ topt[3] = frompt[3];
+ case 3:
+ topt[2] = frompt[2];
+ case 2:
+ topt[1] = frompt[1];
+ case 1:
+ topt[0] = frompt[0];
+ break;
+ default:
+ memcpy( topt, frompt, ncoords * sizeof( REAL ) );
+ }
+}
+
+/*-----------------------------------------------------------------------------
+ * pt_oo_sum - compute affine combination of internal cntrl pts
+ *-----------------------------------------------------------------------------
+ */
+
+void
+Knotspec::pt_oo_sum( REAL *x, REAL *y, REAL *z, Knot a, Knot b )
+{
+ switch( ncoords ) {
+ case 4:
+ x[3] = a * y[3] + b * z[3];
+ case 3:
+ x[2] = a * y[2] + b * z[2];
+ case 2:
+ x[1] = a * y[1] + b * z[1];
+ case 1:
+ x[0] = a * y[0] + b * z[0];
+ break;
+ default: {
+ for( int i = 0; i < ncoords; i++ )
+ *x++ = a * *y++ + b * *z++;
+ }
+ }
+}
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/trimline.cc b/mesalib/src/glu/sgi/libnurbs/internals/trimline.cc
new file mode 100644
index 000000000..61f34cd38
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/trimline.cc
@@ -0,0 +1,223 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * trimline.c++
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "mystdio.h"
+#include "trimline.h"
+#include "backend.h"
+
+Trimline::Trimline()
+{
+ size = 0; pts = 0; numverts = 0;
+ tinterp = &t; binterp = &b;
+}
+
+Trimline::~Trimline()
+{
+ if( pts ) delete[] pts;
+}
+
+void
+Trimline::init( TrimVertex *v )
+{
+ reset();
+ grow(1);
+ append(v);
+}
+
+inline void
+Trimline::grow( long npts )
+{
+ if( size < npts ) {
+ size = 2 * npts;
+ if( pts ) delete[] pts;
+ pts = new TrimVertex_p[size];
+ }
+}
+
+inline void
+Trimline::append( TrimVertex *v )
+{
+ assert( numverts != size );
+ pts[numverts++] = v;
+}
+
+void
+Trimline::init( long npts, Arc_ptr jarc, long last )
+{
+ jarcl.init( jarc, 0, last );
+ grow( npts + 2 );
+}
+
+inline void
+Trimline::swap()
+{
+ TrimVertex *tmp=tinterp;
+ tinterp=binterp;
+ binterp=tmp;
+}
+
+void
+Trimline::getNextPt()
+{
+ *binterp = *jarcl.getnextpt();
+}
+
+void
+Trimline::getPrevPt()
+{
+ *binterp = *jarcl.getprevpt();
+}
+
+/*----------------------------------------------------------------------
+ * getNextPts - make arrays of pointers to trim points on left and right
+ * hulls of trim strip.
+ *----------------------------------------------------------------------
+ */
+void
+Trimline::getNextPts( REAL vval, Backend& backend )
+{
+ reset(); swap(); append( tinterp );
+ assert( tinterp->param[1] >= vval );
+
+ register TrimVertex *p;
+ for( p=jarcl.getnextpt() ; p->param[1] >= vval; p=jarcl.getnextpt() ) {
+ append( p );
+ }
+
+ /* compute and copy pointer to final point on left hull */
+ if( interpvert( last(), p, binterp, vval ) ) {
+ binterp->nuid = p->nuid;
+ backend.triangle( p, binterp, last() );
+ append( binterp );
+ }
+ jarcl.reverse();
+ (void) jarcl.getprevpt(); /* reset jarcl to proper position */
+ jarcl.reverse();
+}
+
+void
+Trimline::getPrevPts( REAL vval, Backend& backend )
+{
+ reset(); swap(); append( tinterp );
+ assert( tinterp->param[1] >= vval );
+
+ register TrimVertex *q;
+ for( q=jarcl.getprevpt(); q->param[1] >= vval; q=jarcl.getprevpt() ) {
+ append( q );
+ }
+
+ /* compute and copy pointer to final point on right hull */
+ if( interpvert( q, last(), binterp, vval ) ) {
+ binterp->nuid = q->nuid;
+ backend.triangle( last(), binterp, q );
+ append( binterp );
+ }
+ jarcl.reverse();
+ (void) jarcl.getnextpt(); /* reset jarcl to proper position */
+ jarcl.reverse();
+}
+
+void
+Trimline::getNextPts( Arc_ptr botarc )
+{
+ reset(); swap(); append( tinterp );
+
+#ifndef NDEBUG
+ PwlArc *lastpwl = botarc->prev->pwlArc;
+ TrimVertex *lastpt1 = &lastpwl->pts[lastpwl->npts-1];
+#endif
+ TrimVertex *lastpt2 = botarc->pwlArc->pts;
+ register TrimVertex *p = jarcl.getnextpt();
+ for( append( p ); p != lastpt2; append( p ) ) {
+ assert( p != lastpt1 );
+ p = jarcl.getnextpt();
+ }
+}
+
+void
+Trimline::getPrevPts( Arc_ptr botarc )
+{
+ reset(); swap(); append( tinterp );
+
+ PwlArc *lastpwl = botarc->prev->pwlArc;
+ TrimVertex *lastpt1 = &lastpwl->pts[lastpwl->npts-1];
+#ifndef NDEBUG
+ TrimVertex *lastpt2 = botarc->pwlArc->pts;
+#endif
+
+ register TrimVertex *q = jarcl.getprevpt();
+ for( append( q ); q != lastpt1; append( q ) ) {
+ assert( q != lastpt2 );
+ q = jarcl.getprevpt();
+ }
+}
+
+
+long
+Trimline::interpvert( TrimVertex *a, TrimVertex *b, TrimVertex *c, REAL vval )
+{
+ REAL denom = a->param[1] - b->param[1];
+
+ if(denom != 0) {
+ if( vval == a->param[1] ) {
+ c->param[0] = a->param[0];
+ c->param[1] = a->param[1];
+ c->nuid = a->nuid;
+ return 0;
+ } else if( vval == b->param[1] ) {
+ c->param[0] = b->param[0];
+ c->param[1] = b->param[1];
+ c->nuid = b->nuid;
+ return 0;
+ } else {
+ REAL r = (a->param[1] - vval)/denom;
+ c->param[0] = a->param[0] - r * (a->param[0] - b->param[0]);
+ c->param[1] = vval;
+ return 1;
+ }
+ } else {
+ c->param[0] = a->param[0];
+ c->param[1] = a->param[1];
+ c->nuid = a->nuid;
+ return 0;
+ }
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/trimline.h b/mesalib/src/glu/sgi/libnurbs/internals/trimline.h
new file mode 100644
index 000000000..ecc884284
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/trimline.h
@@ -0,0 +1,103 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * trimline.h
+ *
+ */
+
+#ifndef __glutrimline_h_
+#define __glutrimline_h_
+
+class Arc;
+class Backend;
+
+#include "trimvertex.h"
+#include "jarcloc.h"
+
+
+class Trimline {
+private:
+ TrimVertex** pts;
+ long numverts;
+ long i;
+ long size;
+ Jarcloc jarcl;
+ TrimVertex t, b;
+ TrimVertex *tinterp, *binterp;
+ void reset( void ) { numverts = 0; }
+ inline void grow( long );
+ inline void swap( void );
+ inline void append( TrimVertex * );
+ static long interpvert( TrimVertex *, TrimVertex *, TrimVertex *, REAL );
+
+
+
+public:
+ Trimline();
+ ~Trimline();
+ void init( TrimVertex * );
+ void init( long, Arc_ptr, long );
+ void getNextPt( void );
+ void getPrevPt( void );
+ void getNextPts( REAL, Backend & );
+ void getPrevPts( REAL, Backend & );
+ void getNextPts( Arc_ptr );
+ void getPrevPts( Arc_ptr );
+ inline TrimVertex * next( void );
+ inline TrimVertex * prev( void );
+ inline TrimVertex * first( void );
+ inline TrimVertex * last( void );
+};
+
+inline TrimVertex *
+Trimline::next( void )
+{
+ if( i < numverts) return pts[i++]; else return 0;
+}
+
+inline TrimVertex *
+Trimline::prev( void )
+{
+ if( i >= 0 ) return pts[i--]; else return 0;
+}
+
+inline TrimVertex *
+Trimline::first( void )
+{
+ i = 0; return pts[i];
+}
+
+inline TrimVertex *
+Trimline::last( void )
+{
+ i = numverts; return pts[--i];
+}
+#endif /* __glutrimline_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/trimregion.cc b/mesalib/src/glu/sgi/libnurbs/internals/trimregion.cc
new file mode 100644
index 000000000..efe789356
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/trimregion.cc
@@ -0,0 +1,114 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * trimregion.c++
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "mystdio.h"
+#include "trimregion.h"
+#include "backend.h"
+
+TrimRegion::TrimRegion( void )
+{
+}
+
+void
+TrimRegion::setDu( REAL du )
+{
+ oneOverDu = 1.0/du;
+}
+
+void
+TrimRegion::init( long npts, Arc_ptr extrema )
+{
+ left.init( npts, extrema, extrema->pwlArc->npts - 1 );
+ left.getNextPt();
+
+ right.init( npts, extrema, 0 );
+ right.getPrevPt();
+}
+
+void
+TrimRegion::getPts( Arc_ptr extrema )
+{
+ left.getNextPts( extrema );
+ right.getPrevPts( extrema );
+}
+
+void
+TrimRegion::getPts( Backend &backend )
+{
+ left.getNextPts( bot.vval, backend );
+ right.getPrevPts( bot.vval, backend );
+}
+
+void
+TrimRegion::getGridExtent( void )
+{
+ getGridExtent( left.last(), right.last() );
+}
+
+void
+TrimRegion::getGridExtent( TrimVertex *l, TrimVertex *r )
+{
+ bot.ustart = (long) ((l->param[0] - uarray.uarray[0])*oneOverDu);
+ if( l->param[0] >= uarray.uarray[bot.ustart] ) bot.ustart++;
+// if( l->param[0] > uarray.uarray[bot.ustart] ) bot.ustart++;
+ assert( l->param[0] <= uarray.uarray[bot.ustart] );
+ assert( l->param[0] >= uarray.uarray[bot.ustart-1] );
+
+ bot.uend = (long) ((r->param[0] - uarray.uarray[0])*oneOverDu);
+ if( uarray.uarray[bot.uend] >= r->param[0] ) bot.uend--;
+// if( uarray.uarray[bot.uend] > r->param[0] ) bot.uend--;
+ assert( r->param[0] >= uarray.uarray[bot.uend] );
+ assert( r->param[0] <= uarray.uarray[bot.uend+1] );
+}
+
+int
+TrimRegion::canTile( void )
+{
+ TrimVertex *lf = left.first();
+ TrimVertex *ll = left.last();
+ TrimVertex *l = ( ll->param[0] > lf->param[0] ) ? ll : lf;
+
+ TrimVertex *rf = right.first();
+ TrimVertex *rl = right.last();
+ TrimVertex *r = ( rl->param[0] < rf->param[0] ) ? rl : rf;
+ return (l->param[0] <= r->param[0]) ? 1 : 0;
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/trimregion.h b/mesalib/src/glu/sgi/libnurbs/internals/trimregion.h
new file mode 100644
index 000000000..ee15d7b98
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/trimregion.h
@@ -0,0 +1,84 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * trimregion.h
+ *
+ */
+
+#ifndef __glutrimregion_h_
+#define __glutrimregion_h_
+
+#include "trimline.h"
+#include "gridline.h"
+#include "uarray.h"
+
+class Arc;
+class Backend;
+
+class TrimRegion {
+public:
+ TrimRegion();
+ Trimline left;
+ Trimline right;
+ Gridline top;
+ Gridline bot;
+ Uarray uarray;
+
+ void init( REAL );
+ void advance( REAL, REAL, REAL );
+ void setDu( REAL );
+ void init( long, Arc_ptr );
+ void getPts( Arc_ptr );
+ void getPts( Backend & );
+ void getGridExtent( TrimVertex *, TrimVertex * );
+ void getGridExtent( void );
+ int canTile( void );
+private:
+ REAL oneOverDu;
+};
+
+inline void
+TrimRegion::init( REAL vval )
+{
+ bot.vval = vval;
+}
+
+inline void
+TrimRegion::advance( REAL topVindex, REAL botVindex, REAL botVval )
+{
+ top.vindex = (long) topVindex;
+ bot.vindex = (long) botVindex;
+ top.vval = bot.vval;
+ bot.vval = botVval;
+ top.ustart = bot.ustart;
+ top.uend = bot.uend;
+}
+#endif /* __glutrimregion_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/trimvertex.h b/mesalib/src/glu/sgi/libnurbs/internals/trimvertex.h
new file mode 100644
index 000000000..2780b764a
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/trimvertex.h
@@ -0,0 +1,63 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * trimvertex.h
+ *
+ */
+
+#ifndef __glutrimvertex_h_
+#define __glutrimvertex_h_
+
+#include "types.h"
+
+/*#define USE_OPTTT*/
+
+class TrimVertex { /* a vertex on a trim curve */
+public:
+ REAL param[2]; /* parametric space coords */
+#ifdef USE_OPTTT
+ REAL cache_point[4]; //only when USE_OPTTT is on in slicer.c++
+ REAL cache_normal[3];
+#endif
+ long nuid;
+};
+
+typedef class TrimVertex *TrimVertex_p;
+
+inline REAL
+det3( TrimVertex *a, TrimVertex *b, TrimVertex *c )
+{
+ return a->param[0] * (b->param[1]-c->param[1]) +
+ b->param[0] * (c->param[1]-a->param[1]) +
+ c->param[0] * (a->param[1]-b->param[1]);
+}
+
+#endif /* __glutrimvertex_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/trimvertpool.cc b/mesalib/src/glu/sgi/libnurbs/internals/trimvertpool.cc
new file mode 100644
index 000000000..3e5bd7038
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/trimvertpool.cc
@@ -0,0 +1,119 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * trimvertexpool.c++
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "mystdio.h"
+#include "mystring.h"
+#include "trimvertex.h"
+#include "trimvertpool.h"
+#include "bufpool.h"
+
+/*----------------------------------------------------------------------------
+ * TrimVertexPool::TrimVertexPool
+ *----------------------------------------------------------------------------
+ */
+TrimVertexPool::TrimVertexPool( void )
+ : pool( sizeof(TrimVertex)*3, 32, "Threevertspool" )
+{
+ // initialize array of pointers to vertex lists
+ nextvlistslot = 0;
+ vlistsize = INIT_VERTLISTSIZE;
+ vlist = new TrimVertex_p[vlistsize];
+}
+
+/*----------------------------------------------------------------------------
+ * TrimVertexPool::~TrimVertexPool
+ *----------------------------------------------------------------------------
+ */
+TrimVertexPool::~TrimVertexPool( void )
+{
+ // free all arrays of TrimVertices vertices
+ while( nextvlistslot ) {
+ delete [] vlist[--nextvlistslot];
+ }
+
+ // reallocate space for array of pointers to vertex lists
+ if( vlist ) delete[] vlist;
+}
+
+/*----------------------------------------------------------------------------
+ * TrimVertexPool::clear
+ *----------------------------------------------------------------------------
+ */
+void
+TrimVertexPool::clear( void )
+{
+ // reinitialize pool of 3 vertex arrays
+ pool.clear();
+
+ // free all arrays of TrimVertices vertices
+ while( nextvlistslot ) {
+ delete [] vlist[--nextvlistslot];
+ vlist[nextvlistslot] = 0;
+ }
+
+ // reallocate space for array of pointers to vertex lists
+ if( vlist ) delete[] vlist;
+ vlist = new TrimVertex_p[vlistsize];
+}
+
+
+/*----------------------------------------------------------------------------
+ * TrimVertexPool::get - allocate a vertex list
+ *----------------------------------------------------------------------------
+ */
+TrimVertex *
+TrimVertexPool::get( int n )
+{
+ TrimVertex *v;
+ if( n == 3 ) {
+ v = (TrimVertex *) pool.new_buffer();
+ } else {
+ if( nextvlistslot == vlistsize ) {
+ vlistsize *= 2;
+ TrimVertex_p *nvlist = new TrimVertex_p[vlistsize];
+ memcpy( nvlist, vlist, nextvlistslot * sizeof(TrimVertex_p) );
+ if( vlist ) delete[] vlist;
+ vlist = nvlist;
+ }
+ v = vlist[nextvlistslot++] = new TrimVertex[n];
+ }
+ return v;
+}
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/trimvertpool.h b/mesalib/src/glu/sgi/libnurbs/internals/trimvertpool.h
new file mode 100644
index 000000000..ebd3c04b1
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/trimvertpool.h
@@ -0,0 +1,57 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * trimvertexpool.h
+ *
+ */
+
+#ifndef __glutrimvertpool_h_
+#define __glutrimvertpool_h_
+
+#include "bufpool.h"
+
+class TrimVertex;
+
+#define INIT_VERTLISTSIZE 200
+
+class TrimVertexPool {
+public:
+ TrimVertexPool( void );
+ ~TrimVertexPool( void );
+ void clear( void );
+ TrimVertex * get( int );
+private:
+ Pool pool;
+ TrimVertex ** vlist;
+ int nextvlistslot;
+ int vlistsize;
+};
+#endif /* __glutrimvertpool_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/types.h b/mesalib/src/glu/sgi/libnurbs/internals/types.h
new file mode 100644
index 000000000..8b59625cf
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/types.h
@@ -0,0 +1,47 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * types.h
+ *
+ */
+
+#ifndef __glutypes_h_
+#define __glutypes_h_
+
+//typedef double INREAL;
+#define INREAL float
+typedef float REAL;
+typedef void (*Pfvv)( void );
+typedef void (*Pfvf)( float * );
+typedef int (*cmpfunc)(const void *, const void *);
+typedef REAL Knot, *Knot_ptr;/* knot values */
+
+#endif /* __glutypes_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/uarray.cc b/mesalib/src/glu/sgi/libnurbs/internals/uarray.cc
new file mode 100644
index 000000000..f0e236437
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/uarray.cc
@@ -0,0 +1,72 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * uarray.c++
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "mystdio.h"
+#include "uarray.h"
+#include "arc.h"
+
+Uarray::Uarray( void )
+{
+ uarray = 0;
+ size = 0;
+}
+
+Uarray::~Uarray( void )
+{
+ if( uarray ) delete[] uarray;
+}
+
+long
+Uarray::init( REAL delta, Arc_ptr lo, Arc_ptr hi )
+{
+ ulines = (long) ((hi->tail()[0] - lo->tail()[0])/delta) + 3;
+ if( size < ulines ) {
+ size = ulines * 2;
+ if( uarray ) delete[] uarray;
+ uarray = new REAL[size];
+ assert( uarray != 0);
+ }
+ uarray[0] = lo->tail()[0] - delta/2.0;
+ for( long i = 1 ; i != ulines; i++ )
+ uarray[i] = uarray[0] + i*delta;
+ return ulines;
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/uarray.h b/mesalib/src/glu/sgi/libnurbs/internals/uarray.h
new file mode 100644
index 000000000..cc6fae1b7
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/uarray.h
@@ -0,0 +1,55 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * uarray.h
+ *
+ */
+
+#ifndef __gluuarray_h_
+#define __gluuarray_h_
+
+#include "types.h"
+
+class Arc;
+typedef class Arc *Arc_ptr;
+
+class Uarray {
+private:
+ long size;
+ long ulines;
+public:
+ Uarray();
+ ~Uarray();
+ long init( REAL, Arc_ptr, Arc_ptr );
+ REAL * uarray;
+};
+
+#endif /* __gluuarray_h_ */
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/varray.cc b/mesalib/src/glu/sgi/libnurbs/internals/varray.cc
new file mode 100644
index 000000000..31cc73a9d
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/varray.cc
@@ -0,0 +1,144 @@
+/*
+** License Applicability. Except to the extent portions of this file are
+** made subject to an alternative license as permitted in the SGI Free
+** Software License B, Version 1.1 (the "License"), the contents of this
+** file are subject only to the provisions of the License. You may not use
+** this file except in compliance with the License. You may obtain a copy
+** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
+** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
+**
+** http://oss.sgi.com/projects/FreeB
+**
+** Note that, as provided in the License, the Software is distributed on an
+** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
+** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
+** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
+** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
+**
+** Original Code. The Original Code is: OpenGL Sample Implementation,
+** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
+** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
+** Copyright in any portions created by third parties is as indicated
+** elsewhere herein. All Rights Reserved.
+**
+** Additional Notice Provisions: The application programming interfaces
+** established by SGI in conjunction with the Original Code are The
+** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
+** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
+** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
+** Window System(R) (Version 1.3), released October 19, 1998. This software
+** was created using the OpenGL(R) version 1.2.1 Sample Implementation
+** published by SGI, but has not been independently verified as being
+** compliant with the OpenGL(R) version 1.2.1 Specification.
+*/
+
+/*
+ * varray.c++
+ *
+ */
+
+#include "glimports.h"
+#include "myassert.h"
+#include "mystdio.h"
+#include "varray.h"
+#include "arc.h"
+#include "simplemath.h" // glu_abs()
+
+#define TINY 0.0001
+inline long sgn( REAL x )
+{
+ return (x < -TINY) ? -1 : ((x > TINY) ? 1 : 0 );
+}
+
+
+Varray::Varray( void )
+{
+ varray = 0;
+ size = 0;
+}
+
+Varray::~Varray( void )
+{
+ if( varray ) delete[] varray;
+}
+
+inline void
+Varray::update( Arc_ptr arc, long dir[2], REAL val )
+{
+ register long ds = sgn(arc->tail()[0] - arc->prev->tail()[0]);
+ register long dt = sgn(arc->tail()[1] - arc->prev->tail()[1]);
+
+ if( dir[0] != ds || dir[1] != dt ) {
+ dir[0] = ds;
+ dir[1] = dt;
+ append( val );
+ }
+}
+
+void
+Varray::grow( long guess )
+{
+ if( size < guess ) {
+ size = guess * 2;
+ if( varray ) delete[] varray;
+ varray = new REAL[size];
+ assert( varray != 0 );
+ }
+}
+
+long
+Varray::init( REAL delta, Arc_ptr toparc, Arc_ptr botarc )
+{
+ Arc_ptr left = toparc->next;
+ Arc_ptr right = toparc;
+ long ldir[2], rdir[2];
+
+ ldir[0] = sgn( left->tail()[0] - left->prev->tail()[0] );
+ ldir[1] = sgn( left->tail()[1] - left->prev->tail()[1] );
+ rdir[0] = sgn( right->tail()[0] - right->prev->tail()[0] );
+ rdir[1] = sgn( right->tail()[1] - right->prev->tail()[1] );
+
+ vval[0] = toparc->tail()[1];
+ numquads = 0;
+
+ while( 1 ) {
+ switch( sgn( left->tail()[1] - right->prev->tail()[1] ) ) {
+ case 1:
+ left = left->next;
+ update( left, ldir, left->prev->tail()[1] );
+ break;
+ case -1:
+ right = right->prev;
+ update( right, rdir, right->tail()[1] );
+ break;
+ case 0:
+ if( glu_abs(left->tail()[1] - botarc->tail()[1]) < TINY) goto end;
+ if( glu_abs(left->tail()[0]-right->prev->tail()[0]) < TINY &&
+ glu_abs(left->tail()[1]-right->prev->tail()[1]) < TINY) goto end;
+ left = left->next;
+ break;
+ }
+ }
+
+end:
+ append( botarc->tail()[1] );
+
+ grow( ((long) ((vval[0] - vval[numquads])/delta)) + numquads + 2 );
+
+ long i, index = 0;
+ for( i=0; i<numquads; i++ ) {
+ voffset[i] = index;
+ varray[index++] = vval[i];
+ REAL dist = vval[i] - vval[i+1];
+ if( dist > delta ) {
+ long steps = ((long) (dist/delta)) +1;
+ float deltav = - dist / (REAL) steps;
+ for( long j=1; j<steps; j++ )
+ varray[index++] = vval[i] + j * deltav;
+ }
+ }
+ voffset[i] = index;
+ varray[index] = vval[i];
+ return index;
+}
+
diff --git a/mesalib/src/glu/sgi/libnurbs/internals/varray.h b/mesalib/src/glu/sgi/libnurbs/internals/varray.h
new file mode 100644
index 000000000..b12ff837c
--- /dev/null
+++ b/mesalib/src/glu/sgi/libnurbs/internals/varray.h
@@ -0,0 +1,68 @@
+/*
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+/*
+ * varray.h
+ *
+ */
+
+#ifndef __gluvarray_h_
+#define __gluvarray_h_
+
+#include "types.h"
+
+class Arc;
+
+class Varray {
+public:
+ Varray();
+ ~Varray();
+ long init( REAL, Arc *, Arc * );
+ REAL * varray;
+ REAL vval[1000];
+ long voffset[1000];
+ long numquads;
+
+private:
+ long size;
+ inline void update( Arc *, long[2], REAL );
+ void grow( long );
+ inline void append( REAL );
+};
+
+inline void
+Varray::append( REAL v )
+{
+ if( v != vval[numquads] )
+ vval[++numquads] = v;
+}
+
+
+#endif /* __gluvarray_h_ */