source: trunk/src/opengl/glu/nurbs/internals/coveandtiler.cpp

Last change on this file was 2689, checked in by jeroen, 26 years ago

* empty log message *

File size: 10.7 KB
Line 
1/* $Id: coveandtiler.cpp,v 1.1 2000-02-09 08:50:21 jeroen Exp $ */
2/*
3** License Applicability. Except to the extent portions of this file are
4** made subject to an alternative license as permitted in the SGI Free
5** Software License B, Version 1.0 (the "License"), the contents of this
6** file are subject only to the provisions of the License. You may not use
7** this file except in compliance with the License. You may obtain a copy
8** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10**
11** http://oss.sgi.com/projects/FreeB
12**
13** Note that, as provided in the License, the Software is distributed on an
14** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18**
19** Original Code. The Original Code is: OpenGL Sample Implementation,
20** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22** Copyright in any portions created by third parties is as indicated
23** elsewhere herein. All Rights Reserved.
24**
25** Additional Notice Provisions: The application programming interfaces
26** established by SGI in conjunction with the Original Code are The
27** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30** Window System(R) (Version 1.3), released October 19, 1998. This software
31** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32** published by SGI, but has not been independently verified as being
33** compliant with the OpenGL(R) version 1.2.1 Specification.
34*/
35
36/*
37 * coveandtiler.c++
38 *
39 * $Date: 2000-02-09 08:50:21 $ $Revision: 1.1 $
40 * $Header: /home/ktk/tmp/odin/2007/netlabs.cvs/odin32/src/opengl/glu/nurbs/internals/coveandtiler.cpp,v 1.1 2000-02-09 08:50:21 jeroen Exp $
41 */
42
43#include "glimports.h"
44#include "myassert.h"
45#include "mystdio.h"
46#include "coveandtiler.h"
47#include "gridvertex.h"
48#include "gridtrimvertex.h"
49#include "uarray.h"
50#include "backend.h"
51
52
53const int CoveAndTiler::MAXSTRIPSIZE = 1000;
54
55CoveAndTiler::CoveAndTiler( Backend& b )
56 : backend( b )
57{ }
58
59CoveAndTiler::~CoveAndTiler( void )
60{ }
61
62inline void
63CoveAndTiler::output( GridVertex &gv )
64{
65 backend.tmeshvert( &gv );
66}
67
68inline void
69CoveAndTiler::output( TrimVertex *tv )
70{
71 backend.tmeshvert( tv );
72}
73
74inline void
75CoveAndTiler::output( GridTrimVertex& g )
76{
77 backend.tmeshvert( &g );
78}
79
80void
81CoveAndTiler::coveAndTile( void )
82{
83 long ustart = (top.ustart >= bot.ustart) ? top.ustart : bot.ustart;
84 long uend = (top.uend <= bot.uend) ? top.uend : bot.uend;
85 if( ustart <= uend ) {
86 tile( bot.vindex, ustart, uend );
87 if( top.ustart >= bot.ustart )
88 coveUpperLeft();
89 else
90 coveLowerLeft();
91
92 if( top.uend <= bot.uend )
93 coveUpperRight();
94 else
95 coveLowerRight();
96 } else {
97 TrimVertex blv, tlv, *bl, *tl;
98 GridTrimVertex bllv, tllv;
99 TrimVertex *lf = left.first();
100 TrimVertex *ll = left.last();
101 if( lf->param[0] >= ll->param[0] ) {
102 blv.param[0] = lf->param[0];
103 blv.param[1] = ll->param[1];
104 blv.nuid = 0; // XXX
105 assert( blv.param[1] == bot.vval );
106 bl = &blv;
107 tl = lf;
108 tllv.set( lf );
109 if( ll->param[0] > uarray.uarray[top.ustart-1] ) {
110 bllv.set( ll );
111 assert( ll->param[0] <= uarray.uarray[bot.ustart] );
112 } else {
113 bllv.set( top.ustart-1, bot.vindex );
114 }
115 coveUpperLeftNoGrid( bl );
116 } else {
117 tlv.param[0] = ll->param[0];
118 tlv.param[1] = lf->param[1];
119 tlv.nuid = 0; // XXX
120 assert( tlv.param[1] == top.vval );
121 tl = &tlv;
122 bl = ll;
123 bllv.set( ll );
124 if( lf->param[0] > uarray.uarray[bot.ustart-1] ) {
125 assert( lf->param[0] <= uarray.uarray[bot.ustart] );
126 tllv.set( lf );
127 } else {
128 tllv.set( bot.ustart-1, top.vindex );
129 }
130 coveLowerLeftNoGrid( tl );
131 }
132
133 TrimVertex brv, trv, *br, *tr;
134 GridTrimVertex brrv, trrv;
135 TrimVertex *rf = right.first();
136 TrimVertex *rl = right.last();
137
138 if( rf->param[0] <= rl->param[0] ) {
139 brv.param[0] = rf->param[0];
140 brv.param[1] = rl->param[1];
141 brv.nuid = 0; // XXX
142 assert( brv.param[1] == bot.vval );
143 br = &brv;
144 tr = rf;
145 trrv.set( rf );
146 if( rl->param[0] < uarray.uarray[top.uend+1] ) {
147 assert( rl->param[0] >= uarray.uarray[top.uend] );
148 brrv.set( rl );
149 } else {
150 brrv.set( top.uend+1, bot.vindex );
151 }
152 coveUpperRightNoGrid( br );
153 } else {
154 trv.param[0] = rl->param[0];
155 trv.param[1] = rf->param[1];
156 trv.nuid = 0; // XXX
157 assert( trv.param[1] == top.vval );
158 tr = &trv;
159 br = rl;
160 brrv.set( rl );
161 if( rf->param[0] < uarray.uarray[bot.uend+1] ) {
162 assert( rf->param[0] >= uarray.uarray[bot.uend] );
163 trrv.set( rf );
164 } else {
165 trrv.set( bot.uend+1, top.vindex );
166 }
167 coveLowerRightNoGrid( tr );
168 }
169
170 backend.bgntmesh( "doit" );
171 output(trrv);
172 output(tllv);
173 output( tr );
174 output( tl );
175 output( br );
176 output( bl );
177 output(brrv);
178 output(bllv);
179 backend.endtmesh();
180 }
181}
182
183void
184CoveAndTiler::tile( long vindex, long ustart, long uend )
185{
186 long numsteps = uend - ustart;
187
188 if( numsteps == 0 ) return;
189
190 if( numsteps > MAXSTRIPSIZE ) {
191 long umid = ustart + (uend - ustart) / 2;
192 tile( vindex, ustart, umid );
193 tile( vindex, umid, uend );
194 } else {
195 backend.surfmesh( ustart, vindex-1, numsteps, 1 );
196 }
197}
198
199void
200CoveAndTiler::coveUpperRight( void )
201{
202 GridVertex tgv( top.uend, top.vindex );
203 GridVertex gv( top.uend, bot.vindex );
204
205 right.first();
206 backend.bgntmesh( "coveUpperRight" );
207 output( right.next() );
208 output( tgv );
209 backend.swaptmesh();
210 output( gv );
211 coveUR();
212 backend.endtmesh();
213}
214
215void
216CoveAndTiler::coveUpperRightNoGrid( TrimVertex* br )
217{
218 backend.bgntmesh( "coveUpperRight" );
219 output( right.first() );
220 output( right.next() );
221 backend.swaptmesh();
222 output( br );
223 coveUR();
224 backend.endtmesh();
225}
226
227void
228CoveAndTiler::coveUR( )
229{
230 GridVertex gv( top.uend, bot.vindex );
231 TrimVertex *vert = right.next();
232 if( vert == NULL ) return;
233
234 assert( vert->param[0] >= uarray.uarray[gv.gparam[0]] );
235
236 if( gv.nextu() >= bot.uend ) {
237 for( ; vert; vert = right.next() ) {
238 output( vert );
239 backend.swaptmesh();
240 }
241 } else while( 1 ) {
242 if( vert->param[0] < uarray.uarray[gv.gparam[0]] ) {
243 output( vert );
244 backend.swaptmesh();
245 vert = right.next();
246 if( vert == NULL ) break;
247 } else {
248 backend.swaptmesh();
249 output( gv );
250 if( gv.nextu() == bot.uend ) {
251 for( ; vert; vert = right.next() ) {
252 output( vert );
253 backend.swaptmesh();
254 }
255 break;
256 }
257 }
258 }
259}
260
261void
262CoveAndTiler::coveUpperLeft( void )
263{
264 GridVertex tgv( top.ustart, top.vindex );
265 GridVertex gv( top.ustart, bot.vindex );
266
267 left.first();
268 backend.bgntmesh( "coveUpperLeft" );
269 output( tgv );
270 output( left.next() );
271 output( gv );
272 backend.swaptmesh();
273 coveUL();
274 backend.endtmesh();
275}
276
277void
278CoveAndTiler::coveUpperLeftNoGrid( TrimVertex* bl )
279{
280 backend.bgntmesh( "coveUpperLeftNoGrid" );
281 output( left.first() );
282 output( left.next() );
283 output( bl );
284 backend.swaptmesh();
285 coveUL();
286 backend.endtmesh();
287}
288
289void
290CoveAndTiler::coveUL()
291{
292 GridVertex gv( top.ustart, bot.vindex );
293 TrimVertex *vert = left.next();
294 if( vert == NULL ) return;
295 assert( vert->param[0] <= uarray.uarray[gv.gparam[0]] );
296
297 if( gv.prevu() <= bot.ustart ) {
298 for( ; vert; vert = left.next() ) {
299 backend.swaptmesh();
300 output( vert );
301 }
302 } else while( 1 ) {
303 if( vert->param[0] > uarray.uarray[gv.gparam[0]] ) {
304 backend.swaptmesh();
305 output( vert );
306 vert = left.next();
307 if( vert == NULL ) break;
308 } else {
309 output( gv );
310 backend.swaptmesh();
311 if( gv.prevu() == bot.ustart ) {
312 for( ; vert; vert = left.next() ) {
313 backend.swaptmesh();
314 output( vert );
315 }
316 break;
317 }
318 }
319 }
320}
321
322void
323CoveAndTiler::coveLowerLeft( void )
324{
325 GridVertex bgv( bot.ustart, bot.vindex );
326 GridVertex gv( bot.ustart, top.vindex );
327
328 left.last();
329 backend.bgntmesh( "coveLowerLeft" );
330 output( left.prev() );
331 output( bgv );
332 backend.swaptmesh();
333 output( gv );
334 coveLL();
335 backend.endtmesh();
336}
337
338void
339CoveAndTiler::coveLowerLeftNoGrid( TrimVertex* tl )
340{
341 backend.bgntmesh( "coveLowerLeft" );
342 output( left.last() );
343 output( left.prev() );
344 backend.swaptmesh();
345 output( tl );
346 coveLL( );
347 backend.endtmesh();
348}
349
350void
351CoveAndTiler::coveLL()
352{
353 GridVertex gv( bot.ustart, top.vindex );
354 TrimVertex *vert = left.prev();
355 if( vert == NULL ) return;
356 assert( vert->param[0] <= uarray.uarray[gv.gparam[0]] );
357
358 if( gv.prevu() <= top.ustart ) {
359 for( ; vert; vert = left.prev() ) {
360 output( vert );
361 backend.swaptmesh();
362 }
363 } else while( 1 ) {
364 if( vert->param[0] > uarray.uarray[gv.gparam[0]] ){
365 output( vert );
366 backend.swaptmesh();
367 vert = left.prev();
368 if( vert == NULL ) break;
369 } else {
370 backend.swaptmesh();
371 output( gv );
372 if( gv.prevu() == top.ustart ) {
373 for( ; vert; vert = left.prev() ) {
374 output( vert );
375 backend.swaptmesh();
376 }
377 break;
378 }
379 }
380 }
381}
382
383void
384CoveAndTiler::coveLowerRight( void )
385{
386 GridVertex bgv( bot.uend, bot.vindex );
387 GridVertex gv( bot.uend, top.vindex );
388
389 right.last();
390 backend.bgntmesh( "coveLowerRight" );
391 output( bgv );
392 output( right.prev() );
393 output( gv );
394 backend.swaptmesh();
395 coveLR();
396 backend.endtmesh( );
397}
398
399void
400CoveAndTiler::coveLowerRightNoGrid( TrimVertex* tr )
401{
402 backend.bgntmesh( "coveLowerRIght" );
403 output( right.last() );
404 output( right.prev() );
405 output( tr );
406 backend.swaptmesh();
407 coveLR();
408 backend.endtmesh();
409}
410
411void
412CoveAndTiler::coveLR( )
413{
414 GridVertex gv( bot.uend, top.vindex );
415 TrimVertex *vert = right.prev();
416 if( vert == NULL ) return;
417 assert( vert->param[0] >= uarray.uarray[gv.gparam[0]] );
418
419 if( gv.nextu() >= top.uend ) {
420 for( ; vert; vert = right.prev() ) {
421 backend.swaptmesh();
422 output( vert );
423 }
424 } else while( 1 ) {
425 if( vert->param[0] < uarray.uarray[gv.gparam[0]] ) {
426 backend.swaptmesh();
427 output( vert );
428 vert = right.prev();
429 if( vert == NULL ) break;
430 } else {
431 output( gv );
432 backend.swaptmesh();
433 if( gv.nextu() == top.uend ) {
434 for( ; vert; vert = right.prev() ) {
435 backend.swaptmesh();
436 output( vert );
437 }
438 break;
439 }
440 }
441 }
442}
443
Note: See TracBrowser for help on using the repository browser.