| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* Further, this software is distributed without any warranty that it is |
| 16 |
* free of the rightful claim of any third person regarding infringement |
| 17 |
* or the like. Any license provided herein, whether implied or |
| 18 |
* otherwise, applies only to this software file. Patent licenses, if |
| 19 |
* any, provided herein do not apply to combinations of this program with |
| 20 |
* other software, or any other product whatsoever. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU Lesser General Public |
| 23 |
* License along with this library; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
* |
| 26 |
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 |
* Mountain View, CA 94043, or: |
| 28 |
* |
| 29 |
* http://www.sgi.com |
| 30 |
* |
| 31 |
* For further information regarding this notice, see: |
| 32 |
* |
| 33 |
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 |
* |
| 35 |
*/ |
| 36 |
|
| 37 |
/* |
| 38 |
* coveandtiler.c++ - $Revision: 1.1.1.1 $ |
| 39 |
* Derrick Burns - 1991 |
| 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 |
|