--------------------------------------------------------------------------
| 353 | |
| 354 | //-------------------------------------------------------------------------- |
| 355 | void GBitmap::allocateBitmapWithMips(const U32 in_width, const U32 in_height, const U32 in_numMips, const GFXFormat in_format) |
| 356 | { |
| 357 | //-------------------------------------- Some debug checks... |
| 358 | U32 svByteSize = mByteSize; |
| 359 | U8 *svBits = mBits; |
| 360 | |
| 361 | AssertFatal(in_width != 0 && in_height != 0, "GBitmap::allocateBitmap: width or height is 0"); |
| 362 | |
| 363 | mInternalFormat = in_format; |
| 364 | mWidth = in_width; |
| 365 | mHeight = in_height; |
| 366 | |
| 367 | mBytesPerPixel = 1; |
| 368 | switch (mInternalFormat) |
| 369 | { |
| 370 | case GFXFormatA8: |
| 371 | case GFXFormatL8: mBytesPerPixel = 1; |
| 372 | break; |
| 373 | case GFXFormatR8G8B8: mBytesPerPixel = 3; |
| 374 | break; |
| 375 | case GFXFormatR8G8B8X8: |
| 376 | case GFXFormatR8G8B8A8: mBytesPerPixel = 4; |
| 377 | break; |
| 378 | case GFXFormatL16: |
| 379 | case GFXFormatR5G6B5: |
| 380 | case GFXFormatR5G5B5A1: mBytesPerPixel = 2; |
| 381 | break; |
| 382 | case GFXFormatR16G16B16A16F: |
| 383 | case GFXFormatR16G16B16A16: mBytesPerPixel = 8; |
| 384 | break; |
| 385 | default: |
| 386 | AssertFatal(false, "GBitmap::GBitmap: misunderstood format specifier"); |
| 387 | break; |
| 388 | } |
| 389 | |
| 390 | // Set up the mip levels, if necessary... |
| 391 | mNumMipLevels = 1; |
| 392 | U32 allocPixels = in_width * in_height * mBytesPerPixel; |
| 393 | mMipLevelOffsets[0] = 0; |
| 394 | |
| 395 | |
| 396 | if (in_numMips != 0) |
| 397 | { |
| 398 | U32 currWidth = in_width; |
| 399 | U32 currHeight = in_height; |
| 400 | |
| 401 | do |
| 402 | { |
| 403 | mMipLevelOffsets[mNumMipLevels] = mMipLevelOffsets[mNumMipLevels - 1] + |
| 404 | (currWidth * currHeight * mBytesPerPixel); |
| 405 | currWidth >>= 1; |
| 406 | currHeight >>= 1; |
| 407 | if (currWidth == 0) currWidth = 1; |
| 408 | if (currHeight == 0) currHeight = 1; |
| 409 | |
| 410 | mNumMipLevels++; |
| 411 | allocPixels += currWidth * currHeight * mBytesPerPixel; |
| 412 | } while (currWidth != 1 || currHeight != 1 && mNumMipLevels != in_numMips); |
no test coverage detected