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

Method createDDSFileFromGBitmap

Engine/source/gfx/bitmap/ddsFile.cpp:660–726  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

658//------------------------------------------------------------------------------
659
660DDSFile *DDSFile::createDDSFileFromGBitmap( const GBitmap *gbmp )
661{
662 if( gbmp == NULL )
663 return NULL;
664
665 DDSFile *ret = new DDSFile;
666
667 // Set up the DDSFile properties that matter. Since this is a GBitmap, there
668 // are assumptions that can be made
669 ret->mHeight = gbmp->getHeight();
670 ret->mWidth = gbmp->getWidth();
671 ret->mDepth = 0;
672 ret->mFormat = gbmp->getFormat();
673 ret->mFlags.set(RGBData);
674 ret->mBytesPerPixel = gbmp->getBytesPerPixel();
675 ret->mMipMapCount = gbmp->getNumMipLevels();
676 ret->mHasTransparency = gbmp->getHasTransparency();
677
678 // ASSUMPTION!!!
679 // This _most likely_ does not belong here, but it is safe to assume that if
680 // a GBitmap is 24-bit, and it's being converted to a DDS, it is most likely
681 // going to be either:
682 // a) Uploaded as a 32-bit texture, and just needs to be padded to RGBX
683 // b) Uploaded as a compressed format, and needs to be padded to 32-bits anyway
684 if( ret->mFormat == GFXFormatR8G8B8 )
685 {
686 ret->mFormat = GFXFormatR8G8B8X8;
687 ret->mBytesPerPixel = 4;
688 }
689
690 if( ret->mMipMapCount > 1 )
691 ret->mFlags.set(MipMapsFlag);
692
693 // One surface per GBitmap
694 ret->mSurfaces.push_back( new SurfaceData() );
695
696 // Load the mips
697 for( S32 i = 0; i < ret->mMipMapCount; i++ )
698 {
699 const U32 mipSz = ret->getSurfaceSize(i);
700 ret->mSurfaces.last()->mMips.push_back( new U8[mipSz] );
701
702 U8 *mipMem = ret->mSurfaces.last()->mMips.last();
703
704 // If this is a straight copy, just do it, otherwise (ugh)
705 if( ret->mFormat == gbmp->getFormat() )
706 dMemcpy( mipMem, gbmp->getBits(i), mipSz );
707 else
708 {
709 // Assumption:
710 AssertFatal( gbmp->getBytesPerPixel() + 1 == ret->mBytesPerPixel, "Assumption failed, not 24->32 bit straight convert." );
711
712 for( S32 pxl = 0; pxl < gbmp->getWidth(i) * gbmp->getHeight(i); pxl++ )
713 {
714 U8 *dst = &mipMem[pxl * ret->mBytesPerPixel];
715 const U8 *src = &gbmp->getBits(i)[pxl * gbmp->getBytesPerPixel()];
716 dMemcpy( dst, src, gbmp->getBytesPerPixel() * sizeof(U8) );
717 dst[ret->mBytesPerPixel - 1] = 255;

Callers

nothing calls this directly

Calls 12

getNumMipLevelsMethod · 0.80
dMemcpyFunction · 0.50
getHeightMethod · 0.45
getWidthMethod · 0.45
getFormatMethod · 0.45
setMethod · 0.45
getBytesPerPixelMethod · 0.45
getHasTransparencyMethod · 0.45
push_backMethod · 0.45
getSurfaceSizeMethod · 0.45
lastMethod · 0.45
getBitsMethod · 0.45

Tested by

no test coverage detected