--------------------------------------------------------------------------
| 269 | |
| 270 | //-------------------------------------------------------------------------- |
| 271 | void GBitmap::allocateBitmap(const U32 in_width, const U32 in_height, const bool in_extrudeMipLevels, const GFXFormat in_format ) |
| 272 | { |
| 273 | //-------------------------------------- Some debug checks... |
| 274 | U32 svByteSize = mByteSize; |
| 275 | U8 *svBits = mBits; |
| 276 | |
| 277 | AssertFatal(in_width != 0 && in_height != 0, "GBitmap::allocateBitmap: width or height is 0"); |
| 278 | |
| 279 | if (in_extrudeMipLevels == true) |
| 280 | { |
| 281 | AssertFatal(isPow2(in_width) == true && isPow2(in_height) == true, "GBitmap::GBitmap: in order to extrude mip levels, bitmap w/h must be pow2"); |
| 282 | } |
| 283 | |
| 284 | mInternalFormat = in_format; |
| 285 | mWidth = in_width; |
| 286 | mHeight = in_height; |
| 287 | |
| 288 | mBytesPerPixel = 1; |
| 289 | switch (mInternalFormat) |
| 290 | { |
| 291 | case GFXFormatA8: |
| 292 | case GFXFormatL8: mBytesPerPixel = 1; |
| 293 | break; |
| 294 | case GFXFormatR8G8B8: mBytesPerPixel = 3; |
| 295 | break; |
| 296 | case GFXFormatR8G8B8A8_LINEAR_FORCE: |
| 297 | case GFXFormatR8G8B8X8: |
| 298 | case GFXFormatR8G8B8A8: mBytesPerPixel = 4; |
| 299 | break; |
| 300 | case GFXFormatL16: |
| 301 | case GFXFormatR5G6B5: |
| 302 | case GFXFormatR5G5B5A1: mBytesPerPixel = 2; |
| 303 | break; |
| 304 | case GFXFormatR16G16B16A16F: |
| 305 | case GFXFormatR16G16B16A16: mBytesPerPixel = 8; |
| 306 | break; |
| 307 | default: |
| 308 | AssertFatal(false, "GBitmap::GBitmap: misunderstood format specifier"); |
| 309 | break; |
| 310 | } |
| 311 | |
| 312 | // Set up the mip levels, if necessary... |
| 313 | mNumMipLevels = 1; |
| 314 | U32 allocPixels = in_width * in_height * mBytesPerPixel; |
| 315 | mMipLevelOffsets[0] = 0; |
| 316 | |
| 317 | |
| 318 | if (in_extrudeMipLevels == true) |
| 319 | { |
| 320 | U32 currWidth = in_width; |
| 321 | U32 currHeight = in_height; |
| 322 | |
| 323 | while (currWidth != 1 || currHeight != 1) |
| 324 | { |
| 325 | mMipLevelOffsets[mNumMipLevels] = mMipLevelOffsets[mNumMipLevels - 1] + |
| 326 | (currWidth * currHeight * mBytesPerPixel); |
| 327 | currWidth >>= 1; |
| 328 | currHeight >>= 1; |
no test coverage detected