public static byte[] Generate( uint width, uint height, uint mipmaps, TextureFormat format )
{
if ( !IsDDSTextureFormat( format ) ) { throw new Exception( "Texture format must be compatible with the DDS file format!" ); }
byte[] data = new byte[0x80];
DDSHeader header = new DDSHeader();
header.Flags = DDSFlags.DDSD_CAPS | DDSFlags.DDSD_HEIGHT | DDSFlags.DDSD_WIDTH | DDSFlags.DDSD_PIXELFORMAT;
header.Width = width;
header.Height = height;
if ( mipmaps > 1 ) {
header.Flags |= DDSFlags.DDSD_MIPMAPCOUNT;
header.MipMapCount = mipmaps;
}
header.PixelFormat.Flags = DDSFlags.DDPF_FOURCC;
header.PixelFormat.FourCC = format;
BitConverter.GetBytes( header.Magic ).CopyTo( data, 0x00 );
BitConverter.GetBytes( header.Size ).CopyTo( data, 0x04 );
BitConverter.GetBytes( header.Flags ).CopyTo( data, 0x08 );
BitConverter.GetBytes( header.Height ).CopyTo( data, 0x0C );
BitConverter.GetBytes( header.Width ).CopyTo( data, 0x10 );
BitConverter.GetBytes( header.PitchOrLinearSize ).CopyTo( data, 0x14 );
BitConverter.GetBytes( header.Depth ).CopyTo( data, 0x18 );
BitConverter.GetBytes( header.MipMapCount ).CopyTo( data, 0x1C );
BitConverter.GetBytes( header.PixelFormat.Size ).CopyTo( data, 0x4C );
BitConverter.GetBytes( header.PixelFormat.Flags ).CopyTo( data, 0x50 );
BitConverter.GetBytes( (uint)header.PixelFormat.FourCC ).CopyTo( data, 0x54 );
BitConverter.GetBytes( header.PixelFormat.RGBBitCount ).CopyTo( data, 0x58 );
BitConverter.GetBytes( header.PixelFormat.RBitMask ).CopyTo( data, 0x5C );
BitConverter.GetBytes( header.PixelFormat.GBitMask ).CopyTo( data, 0x60 );
BitConverter.GetBytes( header.PixelFormat.BBitMask ).CopyTo( data, 0x64 );
BitConverter.GetBytes( header.PixelFormat.ABitMask ).CopyTo( data, 0x68 );
BitConverter.GetBytes( header.Caps ).CopyTo( data, 0x6C );
BitConverter.GetBytes( header.Caps2 ).CopyTo( data, 0x70 );
return data;
}