| 545 | } |
| 546 | |
| 547 | bool DDSFile::read(Stream &s, U32 dropMipCount) |
| 548 | { |
| 549 | if( !readHeader(s) || mMipMapCount == 0 ) |
| 550 | { |
| 551 | Con::errorf("DDSFile::read - error reading header!"); |
| 552 | return false; |
| 553 | } |
| 554 | |
| 555 | // If we're droping mips then make sure we have enough. |
| 556 | dropMipCount = getMin( dropMipCount, mMipMapCount - 1 ); |
| 557 | |
| 558 | // At this point we know what sort of image we contain. So we should |
| 559 | // allocate some buffers, and read it in. |
| 560 | |
| 561 | // How many surfaces are we talking about? |
| 562 | if(mFlags.test(CubeMapFlag)) |
| 563 | { |
| 564 | mSurfaces.setSize( Cubemap_Surface_Count ); |
| 565 | |
| 566 | for ( U32 i=0; i < Cubemap_Surface_Count; i++ ) |
| 567 | { |
| 568 | // Does the cubemap contain this surface? |
| 569 | if ( mFlags.test( CubeMap_PosX_Flag + ( i << 1 ) ) ) |
| 570 | mSurfaces[i] = new SurfaceData(); |
| 571 | else |
| 572 | { |
| 573 | mSurfaces[i] = NULL; |
| 574 | continue; |
| 575 | } |
| 576 | |
| 577 | // Load all the mips. |
| 578 | for(S32 l=0; l<mMipMapCount; l++) |
| 579 | mSurfaces[i]->readNextMip(this, s, mHeight, mWidth, l, l < dropMipCount ); |
| 580 | } |
| 581 | |
| 582 | } |
| 583 | else if (mFlags.test(VolumeFlag)) |
| 584 | { |
| 585 | // Do something with volume |
| 586 | } |
| 587 | else |
| 588 | { |
| 589 | // It's a plain old texture. |
| 590 | |
| 591 | // First allocate a SurfaceData to stick this in. |
| 592 | mSurfaces.push_back(new SurfaceData()); |
| 593 | |
| 594 | // Load however many mips there are. |
| 595 | for(S32 i=0; i<mMipMapCount; i++) |
| 596 | mSurfaces.last()->readNextMip(this, s, mHeight, mWidth, i, i < dropMipCount); |
| 597 | |
| 598 | // Ok, we're done. |
| 599 | } |
| 600 | |
| 601 | // If we're dropping mips then fix up the stats. |
| 602 | if ( dropMipCount > 0 ) |
| 603 | { |
| 604 | // Fix up the pitch and/or linear size. |