public Dds(System.IO.Stream fileStream)
{
using (System.IO.BinaryReader b = new System.IO.BinaryReader(fileStream))
{
b.BaseStream.Position = 12;
header.height = b.ReadUInt32();
header.width = b.ReadUInt32();
b.BaseStream.Position += 8;
header.mipMapCount = b.ReadUInt32();
b.BaseStream.Position += 52;
header.ddspf.fourCC = b.ReadUInt32();
header.ddspf.rGBBitCount = b.ReadUInt32();
b.BaseStream.Position += 20;
header.caps2 = (DDS_HEADER.Caps2)b.ReadUInt32();
b.BaseStream.Position += 12;
int count = 0;
if ((uint)header.caps2 != 0)
{
bdata2 = new Dictionary<int, byte[]>();
if ((header.caps2 & DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_POSITIVEX) == DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_POSITIVEX)
{
count++;
bdata2.Add(0, null);
}
else
{
bdata2.Add(-1, null);
}
if ((header.caps2 & DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_NEGATIVEX) == DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_NEGATIVEX)
{
count++;
bdata2.Add(1, null);
}
else
{
bdata2.Add(-2, null);
}
if ((header.caps2 & DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_POSITIVEY) == DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_POSITIVEY)
{
count++;
bdata2.Add(2, null);
}
else
{
bdata2.Add(-3, null);
}
if ((header.caps2 & DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_NEGATIVEY) == DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_NEGATIVEY)
{
count++;
bdata2.Add(3, null);
}
else
{
bdata2.Add(-4, null);
}
if ((header.caps2 & DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_POSITIVEZ) == DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_POSITIVEZ)
{
count++;
bdata2.Add(4, null);
}
else
{
bdata2.Add(-5, null);
}
if ((header.caps2 & DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_NEGATIVEZ) == DDS_HEADER.Caps2.DDSCAPS2_CUBEMAP_NEGATIVEZ)
{
count++;
bdata2.Add(5, null);
}
else
{
bdata2.Add(-6, null);
}
if (count > 0)
{
int length = (int)((b.BaseStream.Length - (long)128) / (long)count);
//System.Windows.Forms.MessageBox.Show(count.ToString() + " " + length.ToString());
for (int i = 0; i < bdata2.Count; i++)
{
if (bdata2.ContainsKey(i) == true)
{
bdata2[i] = b.ReadBytes(length);
}
}
}
else
{
throw new Exception("Loading cubemap failed because not all blocks were found. (Read)");
}
}
else
{
bdata = b.ReadBytes((int)(b.BaseStream.Length - (long)128));
}
}
}