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

Method setFormat

Engine/source/gfx/bitmap/gBitmap.cpp:567–683  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

565
566//--------------------------------------------------------------------------
567bool GBitmap::setFormat(GFXFormat fmt)
568{
569 if (getFormat() == fmt)
570 return true;
571
572 PROFILE_SCOPE(GBitmap_setFormat);
573
574 // this is a nasty pointer math hack
575 // is there a quick way to calc pixels of a fully mipped bitmap?
576 U32 pixels = 0;
577 for (U32 i=0; i < mNumMipLevels; i++)
578 pixels += getHeight(i) * getWidth(i);
579
580 switch( getFormat() )
581 {
582 case GFXFormatR8G8B8:
583 switch ( fmt )
584 {
585 case GFXFormatR5G5B5A1:
586#ifdef _XBOX
587 bitmapConvertRGB_to_1555(mBits, pixels);
588#else
589 bitmapConvertRGB_to_5551(mBits, pixels);
590#endif
591 mInternalFormat = GFXFormatR5G5B5A1;
592 mBytesPerPixel = 2;
593 break;
594
595 case GFXFormatR8G8B8A8:
596 case GFXFormatR8G8B8X8:
597 // Took this out, it may crash -patw
598 //AssertFatal( mNumMipLevels == 1, "Do the mip-mapping in hardware." );
599
600 bitmapConvertRGB_to_RGBX( &mBits, pixels );
601 mInternalFormat = fmt;
602 mBytesPerPixel = 4;
603 mByteSize = pixels * 4;
604 break;
605
606 default:
607 AssertWarn(0, "GBitmap::setFormat: unable to convert bitmap to requested format.");
608 return false;
609 }
610 break;
611
612 case GFXFormatR8G8B8X8:
613 switch( fmt )
614 {
615 // No change needed for this
616 case GFXFormatR8G8B8A8:
617 mInternalFormat = GFXFormatR8G8B8A8;
618 break;
619
620 case GFXFormatR8G8B8:
621 bitmapConvertRGBX_to_RGB( &mBits, pixels );
622 mInternalFormat = GFXFormatR8G8B8;
623 mBytesPerPixel = 3;
624 mByteSize = pixels * 3;

Callers 4

_createTextureMethod · 0.45
setTextureMethod · 0.45
_loadTextureMethod · 0.45

Calls 2

getWidthFunction · 0.85
getHeightFunction · 0.50

Tested by

no test coverage detected