Updates to SGI GLU code to get it to compile clean with the Open Watcom compiler.
[mesa.git] / src / glu / sgi / libnurbs / internals / coveandtiler.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 * coveandtiler.c++
37 *
38 * $Date: 2003/10/14 23:48:57 $ $Revision: 1.2 $
39 * $Header: /home/krh/git/sync/mesa-cvs-repo/Mesa/src/glu/sgi/libnurbs/internals/coveandtiler.cc,v 1.2 2003/10/14 23:48:57 kendallb Exp $
40 */
41
42 #include "glimports.h"
43 #include "myassert.h"
44 #include "mystdio.h"
45 #include "coveandtiler.h"
46 #include "gridvertex.h"
47 #include "gridtrimvertex.h"
48 #include "uarray.h"
49 #include "backend.h"
50
51
52 const int CoveAndTiler::MAXSTRIPSIZE = 1000;
53
54 CoveAndTiler::CoveAndTiler( Backend& b )
55 : backend( b )
56 { }
57
58 CoveAndTiler::~CoveAndTiler( void )
59 { }
60
61 inline void
62 CoveAndTiler::output( GridVertex &gv )
63 {
64 backend.tmeshvert( &gv );
65 }
66
67 inline void
68 CoveAndTiler::output( TrimVertex *tv )
69 {
70 backend.tmeshvert( tv );
71 }
72
73 inline void
74 CoveAndTiler::output( GridTrimVertex& g )
75 {
76 backend.tmeshvert( &g );
77 }
78
79 void
80 CoveAndTiler::coveAndTile( void )
81 {
82 long ustart = (top.ustart >= bot.ustart) ? top.ustart : bot.ustart;
83 long uend = (top.uend <= bot.uend) ? top.uend : bot.uend;
84 if( ustart <= uend ) {
85 tile( bot.vindex, ustart, uend );
86 if( top.ustart >= bot.ustart )
87 coveUpperLeft();
88 else
89 coveLowerLeft();
90
91 if( top.uend <= bot.uend )
92 coveUpperRight();
93 else
94 coveLowerRight();
95 } else {
96 TrimVertex blv, tlv, *bl, *tl;
97 GridTrimVertex bllv, tllv;
98 TrimVertex *lf = left.first();
99 TrimVertex *ll = left.last();
100 if( lf->param[0] >= ll->param[0] ) {
101 blv.param[0] = lf->param[0];
102 blv.param[1] = ll->param[1];
103 blv.nuid = 0; // XXX
104 assert( blv.param[1] == bot.vval );
105 bl = &blv;
106 tl = lf;
107 tllv.set( lf );
108 if( ll->param[0] > uarray.uarray[top.ustart-1] ) {
109 bllv.set( ll );
110 assert( ll->param[0] <= uarray.uarray[bot.ustart] );
111 } else {
112 bllv.set( top.ustart-1, bot.vindex );
113 }
114 coveUpperLeftNoGrid( bl );
115 } else {
116 tlv.param[0] = ll->param[0];
117 tlv.param[1] = lf->param[1];
118 tlv.nuid = 0; // XXX
119 assert( tlv.param[1] == top.vval );
120 tl = &tlv;
121 bl = ll;
122 bllv.set( ll );
123 if( lf->param[0] > uarray.uarray[bot.ustart-1] ) {
124 assert( lf->param[0] <= uarray.uarray[bot.ustart] );
125 tllv.set( lf );
126 } else {
127 tllv.set( bot.ustart-1, top.vindex );
128 }
129 coveLowerLeftNoGrid( tl );
130 }
131
132 TrimVertex brv, trv, *br, *tr;
133 GridTrimVertex brrv, trrv;
134 TrimVertex *rf = right.first();
135 TrimVertex *rl = right.last();
136
137 if( rf->param[0] <= rl->param[0] ) {
138 brv.param[0] = rf->param[0];
139 brv.param[1] = rl->param[1];
140 brv.nuid = 0; // XXX
141 assert( brv.param[1] == bot.vval );
142 br = &brv;
143 tr = rf;
144 trrv.set( rf );
145 if( rl->param[0] < uarray.uarray[top.uend+1] ) {
146 assert( rl->param[0] >= uarray.uarray[top.uend] );
147 brrv.set( rl );
148 } else {
149 brrv.set( top.uend+1, bot.vindex );
150 }
151 coveUpperRightNoGrid( br );
152 } else {
153 trv.param[0] = rl->param[0];
154 trv.param[1] = rf->param[1];
155 trv.nuid = 0; // XXX
156 assert( trv.param[1] == top.vval );
157 tr = &trv;
158 br = rl;
159 brrv.set( rl );
160 if( rf->param[0] < uarray.uarray[bot.uend+1] ) {
161 assert( rf->param[0] >= uarray.uarray[bot.uend] );
162 trrv.set( rf );
163 } else {
164 trrv.set( bot.uend+1, top.vindex );
165 }
166 coveLowerRightNoGrid( tr );
167 }
168
169 backend.bgntmesh( "doit" );
170 output(trrv);
171 output(tllv);
172 output( tr );
173 output( tl );
174 output( br );
175 output( bl );
176 output(brrv);
177 output(bllv);
178 backend.endtmesh();
179 }
180 }
181
182 void
183 CoveAndTiler::tile( long vindex, long ustart, long uend )
184 {
185 long numsteps = uend - ustart;
186
187 if( numsteps == 0 ) return;
188
189 if( numsteps > MAXSTRIPSIZE ) {
190 long umid = ustart + (uend - ustart) / 2;
191 tile( vindex, ustart, umid );
192 tile( vindex, umid, uend );
193 } else {
194 backend.surfmesh( ustart, vindex-1, numsteps, 1 );
195 }
196 }
197
198 void
199 CoveAndTiler::coveUpperRight( void )
200 {
201 GridVertex tgv( top.uend, top.vindex );
202 GridVertex gv( top.uend, bot.vindex );
203
204 right.first();
205 backend.bgntmesh( "coveUpperRight" );
206 output( right.next() );
207 output( tgv );
208 backend.swaptmesh();
209 output( gv );
210 coveUR();
211 backend.endtmesh();
212 }
213
214 void
215 CoveAndTiler::coveUpperRightNoGrid( TrimVertex* br )
216 {
217 backend.bgntmesh( "coveUpperRight" );
218 output( right.first() );
219 output( right.next() );
220 backend.swaptmesh();
221 output( br );
222 coveUR();
223 backend.endtmesh();
224 }
225
226 void
227 CoveAndTiler::coveUR( )
228 {
229 GridVertex gv( top.uend, bot.vindex );
230 TrimVertex *vert = right.next();
231 if( vert == NULL ) return;
232
233 assert( vert->param[0] >= uarray.uarray[gv.gparam[0]] );
234
235 if( gv.nextu() >= bot.uend ) {
236 for( ; vert; vert = right.next() ) {
237 output( vert );
238 backend.swaptmesh();
239 }
240 } else while( 1 ) {
241 if( vert->param[0] < uarray.uarray[gv.gparam[0]] ) {
242 output( vert );
243 backend.swaptmesh();
244 vert = right.next();
245 if( vert == NULL ) break;
246 } else {
247 backend.swaptmesh();
248 output( gv );
249 if( gv.nextu() == bot.uend ) {
250 for( ; vert; vert = right.next() ) {
251 output( vert );
252 backend.swaptmesh();
253 }
254 break;
255 }
256 }
257 }
258 }
259
260 void
261 CoveAndTiler::coveUpperLeft( void )
262 {
263 GridVertex tgv( top.ustart, top.vindex );
264 GridVertex gv( top.ustart, bot.vindex );
265
266 left.first();
267 backend.bgntmesh( "coveUpperLeft" );
268 output( tgv );
269 output( left.next() );
270 output( gv );
271 backend.swaptmesh();
272 coveUL();
273 backend.endtmesh();
274 }
275
276 void
277 CoveAndTiler::coveUpperLeftNoGrid( TrimVertex* bl )
278 {
279 backend.bgntmesh( "coveUpperLeftNoGrid" );
280 output( left.first() );
281 output( left.next() );
282 output( bl );
283 backend.swaptmesh();
284 coveUL();
285 backend.endtmesh();
286 }
287
288 void
289 CoveAndTiler::coveUL()
290 {
291 GridVertex gv( top.ustart, bot.vindex );
292 TrimVertex *vert = left.next();
293 if( vert == NULL ) return;
294 assert( vert->param[0] <= uarray.uarray[gv.gparam[0]] );
295
296 if( gv.prevu() <= bot.ustart ) {
297 for( ; vert; vert = left.next() ) {
298 backend.swaptmesh();
299 output( vert );
300 }
301 } else while( 1 ) {
302 if( vert->param[0] > uarray.uarray[gv.gparam[0]] ) {
303 backend.swaptmesh();
304 output( vert );
305 vert = left.next();
306 if( vert == NULL ) break;
307 } else {
308 output( gv );
309 backend.swaptmesh();
310 if( gv.prevu() == bot.ustart ) {
311 for( ; vert; vert = left.next() ) {
312 backend.swaptmesh();
313 output( vert );
314 }
315 break;
316 }
317 }
318 }
319 }
320
321 void
322 CoveAndTiler::coveLowerLeft( void )
323 {
324 GridVertex bgv( bot.ustart, bot.vindex );
325 GridVertex gv( bot.ustart, top.vindex );
326
327 left.last();
328 backend.bgntmesh( "coveLowerLeft" );
329 output( left.prev() );
330 output( bgv );
331 backend.swaptmesh();
332 output( gv );
333 coveLL();
334 backend.endtmesh();
335 }
336
337 void
338 CoveAndTiler::coveLowerLeftNoGrid( TrimVertex* tl )
339 {
340 backend.bgntmesh( "coveLowerLeft" );
341 output( left.last() );
342 output( left.prev() );
343 backend.swaptmesh();
344 output( tl );
345 coveLL( );
346 backend.endtmesh();
347 }
348
349 void
350 CoveAndTiler::coveLL()
351 {
352 GridVertex gv( bot.ustart, top.vindex );
353 TrimVertex *vert = left.prev();
354 if( vert == NULL ) return;
355 assert( vert->param[0] <= uarray.uarray[gv.gparam[0]] );
356
357 if( gv.prevu() <= top.ustart ) {
358 for( ; vert; vert = left.prev() ) {
359 output( vert );
360 backend.swaptmesh();
361 }
362 } else while( 1 ) {
363 if( vert->param[0] > uarray.uarray[gv.gparam[0]] ){
364 output( vert );
365 backend.swaptmesh();
366 vert = left.prev();
367 if( vert == NULL ) break;
368 } else {
369 backend.swaptmesh();
370 output( gv );
371 if( gv.prevu() == top.ustart ) {
372 for( ; vert; vert = left.prev() ) {
373 output( vert );
374 backend.swaptmesh();
375 }
376 break;
377 }
378 }
379 }
380 }
381
382 void
383 CoveAndTiler::coveLowerRight( void )
384 {
385 GridVertex bgv( bot.uend, bot.vindex );
386 GridVertex gv( bot.uend, top.vindex );
387
388 right.last();
389 backend.bgntmesh( "coveLowerRight" );
390 output( bgv );
391 output( right.prev() );
392 output( gv );
393 backend.swaptmesh();
394 coveLR();
395 backend.endtmesh( );
396 }
397
398 void
399 CoveAndTiler::coveLowerRightNoGrid( TrimVertex* tr )
400 {
401 backend.bgntmesh( "coveLowerRIght" );
402 output( right.last() );
403 output( right.prev() );
404 output( tr );
405 backend.swaptmesh();
406 coveLR();
407 backend.endtmesh();
408 }
409
410 void
411 CoveAndTiler::coveLR( )
412 {
413 GridVertex gv( bot.uend, top.vindex );
414 TrimVertex *vert = right.prev();
415 if( vert == NULL ) return;
416 assert( vert->param[0] >= uarray.uarray[gv.gparam[0]] );
417
418 if( gv.nextu() >= top.uend ) {
419 for( ; vert; vert = right.prev() ) {
420 backend.swaptmesh();
421 output( vert );
422 }
423 } else while( 1 ) {
424 if( vert->param[0] < uarray.uarray[gv.gparam[0]] ) {
425 backend.swaptmesh();
426 output( vert );
427 vert = right.prev();
428 if( vert == NULL ) break;
429 } else {
430 output( gv );
431 backend.swaptmesh();
432 if( gv.nextu() == top.uend ) {
433 for( ; vert; vert = right.prev() ) {
434 backend.swaptmesh();
435 output( vert );
436 }
437 break;
438 }
439 }
440 }
441 }
442