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