MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / allocateBitmap

Method allocateBitmap

Engine/source/gfx/bitmap/gBitmap.cpp:271–352  ·  view source on GitHub ↗

--------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

269
270//--------------------------------------------------------------------------
271void 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;

Callers 7

sReadTGAFunction · 0.80
sReadPNGFunction · 0.80
sReadBMPFunction · 0.80
sReadJPGFunction · 0.80
_separateAlphaMethod · 0.80
beginMethod · 0.80

Calls 6

isPow2Function · 0.85
mFloorFunction · 0.85
mLog2Function · 0.85
mMaxFunction · 0.85
dMemsetFunction · 0.50
dMemcpyFunction · 0.50

Tested by

no test coverage detected