1*c2c66affSColin Finck /*
2*c2c66affSColin Finck ** License Applicability. Except to the extent portions of this file are
3*c2c66affSColin Finck ** made subject to an alternative license as permitted in the SGI Free
4*c2c66affSColin Finck ** Software License B, Version 1.1 (the "License"), the contents of this
5*c2c66affSColin Finck ** file are subject only to the provisions of the License. You may not use
6*c2c66affSColin Finck ** this file except in compliance with the License. You may obtain a copy
7*c2c66affSColin Finck ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8*c2c66affSColin Finck ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
9*c2c66affSColin Finck **
10*c2c66affSColin Finck ** http://oss.sgi.com/projects/FreeB
11*c2c66affSColin Finck **
12*c2c66affSColin Finck ** Note that, as provided in the License, the Software is distributed on an
13*c2c66affSColin Finck ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14*c2c66affSColin Finck ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15*c2c66affSColin Finck ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16*c2c66affSColin Finck ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
17*c2c66affSColin Finck **
18*c2c66affSColin Finck ** Original Code. The Original Code is: OpenGL Sample Implementation,
19*c2c66affSColin Finck ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20*c2c66affSColin Finck ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21*c2c66affSColin Finck ** Copyright in any portions created by third parties is as indicated
22*c2c66affSColin Finck ** elsewhere herein. All Rights Reserved.
23*c2c66affSColin Finck **
24*c2c66affSColin Finck ** Additional Notice Provisions: The application programming interfaces
25*c2c66affSColin Finck ** established by SGI in conjunction with the Original Code are The
26*c2c66affSColin Finck ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27*c2c66affSColin Finck ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28*c2c66affSColin Finck ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29*c2c66affSColin Finck ** Window System(R) (Version 1.3), released October 19, 1998. This software
30*c2c66affSColin Finck ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31*c2c66affSColin Finck ** published by SGI, but has not been independently verified as being
32*c2c66affSColin Finck ** compliant with the OpenGL(R) version 1.2.1 Specification.
33*c2c66affSColin Finck */
34*c2c66affSColin Finck 
35*c2c66affSColin Finck /*
36*c2c66affSColin Finck  * patchlist.c++
37*c2c66affSColin Finck  *
38*c2c66affSColin Finck  */
39*c2c66affSColin Finck 
40*c2c66affSColin Finck //#include <stdio.h>
41*c2c66affSColin Finck //#include "glimports.h"
42*c2c66affSColin Finck //#include "myassert.h"
43*c2c66affSColin Finck //#include "mystdio.h"
44*c2c66affSColin Finck #include "quilt.h"
45*c2c66affSColin Finck #include "patchlist.h"
46*c2c66affSColin Finck //#include "patch.h"
47*c2c66affSColin Finck 
Patchlist(Quilt * quilts,REAL * pta,REAL * ptb)48*c2c66affSColin Finck Patchlist::Patchlist( Quilt *quilts, REAL *pta, REAL *ptb )
49*c2c66affSColin Finck {
50*c2c66affSColin Finck     patch = 0;
51*c2c66affSColin Finck     for( Quilt *q = quilts; q; q = q->next )
52*c2c66affSColin Finck 	patch = new Patch( q, pta, ptb, patch );
53*c2c66affSColin Finck     pspec[0].range[0] = pta[0];
54*c2c66affSColin Finck     pspec[0].range[1] = ptb[0];
55*c2c66affSColin Finck     pspec[0].range[2] = ptb[0] - pta[0];
56*c2c66affSColin Finck 
57*c2c66affSColin Finck     pspec[1].range[0] = pta[1];
58*c2c66affSColin Finck     pspec[1].range[1] = ptb[1];
59*c2c66affSColin Finck     pspec[1].range[2] = ptb[1] - pta[1];
60*c2c66affSColin Finck }
61*c2c66affSColin Finck 
Patchlist(Patchlist & upper,int param,REAL value)62*c2c66affSColin Finck Patchlist::Patchlist( Patchlist &upper, int param,  REAL value)
63*c2c66affSColin Finck {
64*c2c66affSColin Finck     Patchlist &lower = *this;
65*c2c66affSColin Finck     patch = 0;
66*c2c66affSColin Finck     for( Patch *p = upper.patch; p; p = p->next )
67*c2c66affSColin Finck 	patch = new Patch( *p, param, value, patch );
68*c2c66affSColin Finck 
69*c2c66affSColin Finck     if( param == 0 ) {
70*c2c66affSColin Finck 	lower.pspec[0].range[0] = upper.pspec[0].range[0];
71*c2c66affSColin Finck 	lower.pspec[0].range[1] = value;
72*c2c66affSColin Finck 	lower.pspec[0].range[2] = value - upper.pspec[0].range[0];
73*c2c66affSColin Finck 	upper.pspec[0].range[0] = value;
74*c2c66affSColin Finck 	upper.pspec[0].range[2] = upper.pspec[0].range[1] - value;
75*c2c66affSColin Finck 	lower.pspec[1] = upper.pspec[1];
76*c2c66affSColin Finck     } else {
77*c2c66affSColin Finck 	lower.pspec[0] = upper.pspec[0];
78*c2c66affSColin Finck 	lower.pspec[1].range[0] = upper.pspec[1].range[0];
79*c2c66affSColin Finck 	lower.pspec[1].range[1] = value;
80*c2c66affSColin Finck 	lower.pspec[1].range[2] = value - upper.pspec[1].range[0];
81*c2c66affSColin Finck 	upper.pspec[1].range[0] = value;
82*c2c66affSColin Finck 	upper.pspec[1].range[2] = upper.pspec[1].range[1] - value;
83*c2c66affSColin Finck     }
84*c2c66affSColin Finck }
85*c2c66affSColin Finck 
~Patchlist()86*c2c66affSColin Finck Patchlist::~Patchlist()
87*c2c66affSColin Finck {
88*c2c66affSColin Finck     while( patch ) {
89*c2c66affSColin Finck 	Patch *p = patch;
90*c2c66affSColin Finck 	patch = patch->next;
91*c2c66affSColin Finck 	delete p;
92*c2c66affSColin Finck     }
93*c2c66affSColin Finck }
94*c2c66affSColin Finck 
95*c2c66affSColin Finck int
cullCheck(void)96*c2c66affSColin Finck Patchlist::cullCheck( void )
97*c2c66affSColin Finck {
98*c2c66affSColin Finck     for( Patch *p = patch; p; p = p->next )
99*c2c66affSColin Finck 	if( p->cullCheck() == CULL_TRIVIAL_REJECT )
100*c2c66affSColin Finck 	    return CULL_TRIVIAL_REJECT;
101*c2c66affSColin Finck     return CULL_ACCEPT;
102*c2c66affSColin Finck }
103*c2c66affSColin Finck 
104*c2c66affSColin Finck void
getRanges(REAL ranges[4])105*c2c66affSColin Finck Patchlist::getRanges(REAL ranges[4])
106*c2c66affSColin Finck {
107*c2c66affSColin Finck   ranges[0] = pspec[0].range[0];
108*c2c66affSColin Finck   ranges[1] = pspec[0].range[1];
109*c2c66affSColin Finck   ranges[2] = pspec[1].range[0];
110*c2c66affSColin Finck   ranges[3] = pspec[1].range[1];
111*c2c66affSColin Finck }
112*c2c66affSColin Finck 
113*c2c66affSColin Finck void
getstepsize(void)114*c2c66affSColin Finck Patchlist::getstepsize( void )
115*c2c66affSColin Finck {
116*c2c66affSColin Finck     pspec[0].stepsize    = pspec[0].range[2];
117*c2c66affSColin Finck     pspec[0].sidestep[0] = pspec[0].range[2];
118*c2c66affSColin Finck     pspec[0].sidestep[1] = pspec[0].range[2];
119*c2c66affSColin Finck 
120*c2c66affSColin Finck     pspec[1].stepsize    = pspec[1].range[2];
121*c2c66affSColin Finck     pspec[1].sidestep[0] = pspec[1].range[2];
122*c2c66affSColin Finck     pspec[1].sidestep[1] = pspec[1].range[2];
123*c2c66affSColin Finck 
124*c2c66affSColin Finck     for( Patch *p = patch; p; p = p->next ) {
125*c2c66affSColin Finck 	p->getstepsize();
126*c2c66affSColin Finck 	p->clamp();
127*c2c66affSColin Finck 	pspec[0].stepsize    =  ((p->pspec[0].stepsize < pspec[0].stepsize) ? p->pspec[0].stepsize : pspec[0].stepsize);
128*c2c66affSColin Finck 	pspec[0].sidestep[0] =  ((p->pspec[0].sidestep[0] < pspec[0].sidestep[0]) ? p->pspec[0].sidestep[0] : pspec[0].sidestep[0]);
129*c2c66affSColin Finck 	pspec[0].sidestep[1] =  ((p->pspec[0].sidestep[1] < pspec[0].sidestep[1]) ? p->pspec[0].sidestep[1] : pspec[0].sidestep[1]);
130*c2c66affSColin Finck 	pspec[1].stepsize    =  ((p->pspec[1].stepsize < pspec[1].stepsize) ? p->pspec[1].stepsize : pspec[1].stepsize);
131*c2c66affSColin Finck 	pspec[1].sidestep[0] =  ((p->pspec[1].sidestep[0] < pspec[1].sidestep[0]) ? p->pspec[1].sidestep[0] : pspec[1].sidestep[0]);
132*c2c66affSColin Finck 	pspec[1].sidestep[1] =  ((p->pspec[1].sidestep[1] < pspec[1].sidestep[1]) ? p->pspec[1].sidestep[1] : pspec[1].sidestep[1]);
133*c2c66affSColin Finck     }
134*c2c66affSColin Finck }
135*c2c66affSColin Finck 
136*c2c66affSColin Finck void
bbox(void)137*c2c66affSColin Finck Patchlist::bbox( void )
138*c2c66affSColin Finck {
139*c2c66affSColin Finck     for( Patch *p = patch; p; p = p->next )
140*c2c66affSColin Finck 	p->bbox();
141*c2c66affSColin Finck }
142*c2c66affSColin Finck 
143*c2c66affSColin Finck int
needsNonSamplingSubdivision(void)144*c2c66affSColin Finck Patchlist::needsNonSamplingSubdivision( void )
145*c2c66affSColin Finck {
146*c2c66affSColin Finck     notInBbox = 0;
147*c2c66affSColin Finck     for( Patch *p = patch; p; p = p->next )
148*c2c66affSColin Finck 	notInBbox |= p->needsNonSamplingSubdivision();
149*c2c66affSColin Finck     return notInBbox;
150*c2c66affSColin Finck }
151*c2c66affSColin Finck 
152*c2c66affSColin Finck int
needsSamplingSubdivision(void)153*c2c66affSColin Finck Patchlist::needsSamplingSubdivision( void )
154*c2c66affSColin Finck {
155*c2c66affSColin Finck     pspec[0].needsSubdivision = 0;
156*c2c66affSColin Finck     pspec[1].needsSubdivision = 0;
157*c2c66affSColin Finck 
158*c2c66affSColin Finck     for( Patch *p = patch; p; p = p->next ) {
159*c2c66affSColin Finck 	pspec[0].needsSubdivision |= p->pspec[0].needsSubdivision;
160*c2c66affSColin Finck 	pspec[1].needsSubdivision |= p->pspec[0].needsSubdivision;
161*c2c66affSColin Finck     }
162*c2c66affSColin Finck     return (pspec[0].needsSubdivision || pspec[1].needsSubdivision) ? 1 : 0;
163*c2c66affSColin Finck }
164*c2c66affSColin Finck 
165*c2c66affSColin Finck int
needsSubdivision(int param)166*c2c66affSColin Finck Patchlist::needsSubdivision( int param )
167*c2c66affSColin Finck {
168*c2c66affSColin Finck     return pspec[param].needsSubdivision;
169*c2c66affSColin Finck }
170