Ok, here's my story. So I'm working on the next version of
Scurvy Media. One of the things that I'd finally like to get in is the storage of texture/frame data as DXT compressed textures. Unfortunately, the math required to read those textures has escaped me thus far. I'm sure I'm missing something fundamental, so I figured I'd finally just ask those who know much more than I :-)
Here's what I have:
First, in my importer/processor, I load a Texture2DContent object that I then convert to a Dxt3BitmapContent pixel format
Texture2DContent c = new Texture2DContent();
BitmapContent b = new PixelBitmapContent<Microsoft.Xna.Framework.Graphics.PackedVector.Bgr565>(bitmap.Width, bitmap.Height);
c.Faces[0].Add(b);
GetData(bitmap);
b.SetPixelData(pixelBuffer);
c.ConvertBitmapType(typeof(Dxt3BitmapContent));
Then, in the content writer, I write each "frame" to the XNB file
byte[] pix = tex.Faces[0][0].GetPixelData();
output.Write(pix.Length);
output.Write(pix);
Then, at runtime in the content reader, I stream the pixel data out of the file stream and try to set it to the texture:
int frameSize = reader.ReadInt32();
if (Data == null)
{
Data = new byte[frameSize];
Pixels = new Bgr565[frameSize / 2];
}
_stream.Read(Data, 0, frameSize);
int currentPixel = 0;
for (int i = 0; i < Data.Length; i += 2)
{
Pixels[currentPixel].PackedValue = (ushort)((Data[i + 1] << 8) + Data
);
currentPixel++;
}
CurrentTexture.SetData<Bgr565>(Pixels);
Now at the risk of exposing my ignorance, I'm sure the problem lies in the way that I am reading the data from the stream. A good friend of mine helped me write that piece in the first place (for which I am deeply thankful :-P ). So the question is, what's the right way of reading out the dxt data and setting it to the texture?
Some stats:
- Video resolution: 160 x 120
- Size of the byte array that gets written to the XNB for one frame: 19200
- Size of the Bgr565[] Array that I'm using: 9600
- If I comment out the 'ConvertBitmapType' line, this all works without a hitch.
Again, I will reitorate, I'm 100% certain that I'm going about this the wrong way ... some guidance would be very much appreciated :-) Thanks in advance!!
Joel Martinez
Blog:
http://codecube.netPlay Videos on an XNA Texture:
Scurvy Media