--------------------------------------------------------------------------
| 447 | |
| 448 | //-------------------------------------------------------------------------- |
| 449 | bool GBitmap::setFormat(GFXFormat fmt) |
| 450 | { |
| 451 | if (getFormat() == fmt) |
| 452 | return true; |
| 453 | |
| 454 | PROFILE_SCOPE(GBitmap_setFormat); |
| 455 | |
| 456 | // this is a nasty pointer math hack |
| 457 | // is there a quick way to calc pixels of a fully mipped bitmap? |
| 458 | U32 pixels = 0; |
| 459 | for (U32 i=0; i < mNumMipLevels; i++) |
| 460 | pixels += getHeight(i) * getWidth(i); |
| 461 | |
| 462 | switch( getFormat() ) |
| 463 | { |
| 464 | case GFXFormatR8G8B8: |
| 465 | switch ( fmt ) |
| 466 | { |
| 467 | case GFXFormatR5G5B5A1: |
| 468 | #ifdef _XBOX |
| 469 | bitmapConvertRGB_to_1555(mBits, pixels); |
| 470 | #else |
| 471 | bitmapConvertRGB_to_5551(mBits, pixels); |
| 472 | #endif |
| 473 | mInternalFormat = GFXFormatR5G5B5A1; |
| 474 | mBytesPerPixel = 2; |
| 475 | break; |
| 476 | |
| 477 | case GFXFormatR8G8B8A8: |
| 478 | case GFXFormatR8G8B8X8: |
| 479 | // Took this out, it may crash -patw |
| 480 | //AssertFatal( mNumMipLevels == 1, "Do the mip-mapping in hardware." ); |
| 481 | |
| 482 | bitmapConvertRGB_to_RGBX( &mBits, pixels ); |
| 483 | mInternalFormat = fmt; |
| 484 | mBytesPerPixel = 4; |
| 485 | mByteSize = pixels * 4; |
| 486 | break; |
| 487 | |
| 488 | default: |
| 489 | AssertWarn(0, "GBitmap::setFormat: unable to convert bitmap to requested format."); |
| 490 | return false; |
| 491 | } |
| 492 | break; |
| 493 | |
| 494 | case GFXFormatR8G8B8X8: |
| 495 | switch( fmt ) |
| 496 | { |
| 497 | // No change needed for this |
| 498 | case GFXFormatR8G8B8A8: |
| 499 | mInternalFormat = GFXFormatR8G8B8A8; |
| 500 | break; |
| 501 | |
| 502 | case GFXFormatR8G8B8: |
| 503 | bitmapConvertRGBX_to_RGB( &mBits, pixels ); |
| 504 | mInternalFormat = GFXFormatR8G8B8; |
| 505 | mBytesPerPixel = 3; |
| 506 | mByteSize = pixels * 3; |
no test coverage detected