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