Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int GetMemRequired( int width, int height, ImageFormat imageFormat, bool mipmap )
- {
- if( !mipmap )
- {
- if( imageFormat == IMAGE_FORMAT_DXT1 ||
- imageFormat == IMAGE_FORMAT_DXT3 ||
- imageFormat == IMAGE_FORMAT_DXT5 )
- {
- /*
- DDSURFACEDESC desc;
- memset( &desc, 0, sizeof(desc) );
- DWORD dwEncodeType;
- dwEncodeType = GetDXTCEncodeType( imageFormat );
- desc.dwSize = sizeof( desc );
- desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
- desc.dwWidth = width;
- desc.dwHeight = height;
- return S3TCgetEncodeSize( &desc, dwEncodeType );
- */
- Assert( ( width < 4 ) || !( width % 4 ) );
- Assert( ( height < 4 ) || !( height % 4 ) );
- if( width < 4 && width > 0 )
- {
- width = 4;
- }
- if( height < 4 && height > 0 )
- {
- height = 4;
- }
- int numBlocks = ( width * height ) >> 4;
- switch( imageFormat )
- {
- case IMAGE_FORMAT_DXT1:
- return numBlocks * 8;
- break;
- case IMAGE_FORMAT_DXT3:
- case IMAGE_FORMAT_DXT5:
- return numBlocks * 16;
- break;
- default:
- Assert( 0 );
- return 0;
- break;
- }
- }
- else
- {
- return width * height * SizeInBytes(imageFormat);
- }
- }
- else
- {
- int memSize = 0;
- while( 1 )
- {
- memSize += GetMemRequired( width, height, imageFormat, false );
- if( width == 1 && height == 1 )
- {
- break;
- }
- width >>= 1;
- height >>= 1;
- if( width < 1 )
- {
- width = 1;
- }
- if( height < 1 )
- {
- height = 1;
- }
- }
- return memSize;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement