Hi, I'm trying to compress some PNG files to DDS with DXT5 then load them back into a Texture2D (XNA 4). I'm doing this because my game requires lots of tiled images that need to be loaded in and out constantly and PNG is turning out to be fairly slow. I'm running into a lot of problems though.
I tried using ManagedSquish, a .NET wrapper for libsquish, but it's crashing when I start the compression. I haven't even gotten to trying to set the compressed data into a Texture2D yet, even though I'm unsure if it will work. Any insight would be greatly appreciated. Here's my code thus far:
// Get texture pixels
Color[] _pixels = new Color[_texture.Width * _texture.Height];
_texture.GetData(_pixels);
// Format it as RBGA bytes
byte[] _rgbaData = new byte[_pixels.Length * 4];
for (int _pixelIndex = 0; _pixelIndex < _pixels.Length; _pixelIndex++)
{
_rgbaData[_pixelIndex + 0] = _pixels[_pixelIndex].R;
_rgbaData[_pixelIndex + 1] = _pixels[_pixelIndex].G;
_rgbaData[_pixelIndex + 2] = _pixels[_pixelIndex].B;
_rgbaData[_pixelIndex + 3] = _pixels[_pixelIndex].A;
}
// Compress using ManagedSquish [This is where it crashes]
var _compressedImage = ManagedSquish.Squish.CompressImage(
_rgbaData,
_texture.Width,
_texture.Height,
ManagedSquish.SquishFlags.Dxt5
);
// Assign data to Texture2D
Texture2D _newTex = new Texture2D(
Graphics.Device,
_texture.Width,
_texture.Height,
true,
SurfaceFormat.Dxt5
);
_newTex.SetData(_compressedImage);