| 365 | } |
| 366 | |
| 367 | void TerrCell::updateGrid( const RectI &gridRect, bool opacityOnly ) |
| 368 | { |
| 369 | PROFILE_SCOPE( TerrCell_UpdateGrid ); |
| 370 | |
| 371 | // If we have a VB... then update it. |
| 372 | if ( mVertexBuffer.isValid() && !opacityOnly ) |
| 373 | _updateVertexBuffer(); |
| 374 | |
| 375 | // Update our PB, if any |
| 376 | _updatePrimitiveBuffer(); |
| 377 | |
| 378 | // If we don't have children... then we're |
| 379 | // a leaf at the bottom of the cell quadtree |
| 380 | // and we should just update our bounds. |
| 381 | if ( !mChildren[0] ) |
| 382 | { |
| 383 | if ( !opacityOnly ) |
| 384 | _updateBounds(); |
| 385 | |
| 386 | _updateMaterials(); |
| 387 | return; |
| 388 | } |
| 389 | |
| 390 | // Otherwise, we must call updateGrid on our children |
| 391 | // and then update our bounds/materials AFTER to contain them. |
| 392 | |
| 393 | mMaterials = 0; |
| 394 | |
| 395 | for ( U32 i = 0; i < 4; i++ ) |
| 396 | { |
| 397 | TerrCell *cell = mChildren[i]; |
| 398 | |
| 399 | // The overlap test doesn't hit shared edges |
| 400 | // so grow it a bit when we create it. |
| 401 | const RectI cellRect( cell->mPoint.x - 1, |
| 402 | cell->mPoint.y - 1, |
| 403 | cell->mSize + 2, |
| 404 | cell->mSize + 2 ); |
| 405 | |
| 406 | // We do an overlap and containment test as it |
| 407 | // properly handles zero sized rects. |
| 408 | if ( cellRect.contains( gridRect ) || |
| 409 | cellRect.overlaps( gridRect ) ) |
| 410 | cell->updateGrid( gridRect, opacityOnly ); |
| 411 | |
| 412 | // Update the bounds from our children. |
| 413 | if ( !opacityOnly ) |
| 414 | { |
| 415 | if ( i == 0 ) |
| 416 | mBounds = mChildren[i]->getBounds(); |
| 417 | else |
| 418 | mBounds.intersect( mChildren[i]->getBounds() ); |
| 419 | |
| 420 | mRadius = mBounds.len() * 0.5f; |
| 421 | } |
| 422 | |
| 423 | // Update the material flags. |
| 424 | mMaterials |= mChildren[i]->getMaterials(); |