public void Load(Stream stream) { Name = FileInfo.FileName; using (var reader = new FileReader(stream)) { MainHeader = reader.ReadStruct <Header>(); PfHeader = reader.ReadStruct <DDSPFHeader>(); if (IsDX10) { Dx10Header = reader.ReadStruct <DX10Header>(); } byte[] Components = new byte[4] { 0, 1, 2, 3 }; bool Compressed = false; bool HasLuminance = false; bool HasAlpha = false; bool IsRGB = false; switch (PfHeader.Flags) { case 4: Compressed = true; break; case 2: case (uint)DDPF.LUMINANCE: HasLuminance = true; break; case (uint)DDPF.RGB: IsRGB = true; break; case 0x41: IsRGB = true; HasAlpha = true; break; } ToGenericFormat(); if (!IsDX10 && !this.IsBCNCompressed()) { Platform.OutputFormat = DDS_RGBA.GetUncompressedType(this, Components, IsRGB, HasAlpha, HasLuminance, PfHeader); } Depth = 1; Width = MainHeader.Width; Height = MainHeader.Height; MipCount = MainHeader.MipCount == 0 ? 1 : MainHeader.MipCount; ArrayCount = IsCubeMap ? (uint)6 : 1; } }
public void SetFlags(TexFormat format, bool isDX10, bool isCubemap) { var dxgiFormat = (DXGI_FORMAT)format; MainHeader.Flags = (uint)(DDSD.CAPS | DDSD.HEIGHT | DDSD.WIDTH | DDSD.PIXELFORMAT | DDSD.MIPMAPCOUNT | DDSD.LINEARSIZE); PfHeader.Caps1 = (uint)DDSCAPS.TEXTURE; if (MainHeader.MipCount > 1) { PfHeader.Caps1 |= (uint)(DDSCAPS.COMPLEX | DDSCAPS.MIPMAP); } if (isCubemap) { PfHeader.Caps2 |= (uint)(DDSCAPS2.CUBEMAP | DDSCAPS2.CUBEMAP_POSITIVEX | DDSCAPS2.CUBEMAP_NEGATIVEX | DDSCAPS2.CUBEMAP_POSITIVEY | DDSCAPS2.CUBEMAP_NEGATIVEY | DDSCAPS2.CUBEMAP_POSITIVEZ | DDSCAPS2.CUBEMAP_NEGATIVEZ); } if (isDX10) { PfHeader.Flags = (uint)DDPF.FOURCC; PfHeader.FourCC = FOURCC_DX10; Dx10Header.DxgiFormat = (uint)dxgiFormat; if (isCubemap) { Dx10Header.ArrayCount = (ArrayCount / 6); Dx10Header.MiscFlags1 = 0x4; } return; } var masks = DDS_RGBA.GetMasks(format); PfHeader.RBitMask = masks[0]; PfHeader.GBitMask = masks[1]; PfHeader.BBitMask = masks[2]; PfHeader.ABitMask = masks[3]; PfHeader.RgbBitCount = 0x8 * TextureFormatHelper.GetBytesPerPixel(format); PfHeader.Flags = (uint)(DDPF.RGB | DDPF.ALPHAPIXELS); switch (format) { case TexFormat.RGBA8_UNORM: case TexFormat.RGB8_SRGB: break; case TexFormat.RGB565_UNORM: PfHeader.Flags = (uint)(DDPF.RGB | DDPF.ALPHAPIXELS); break; case TexFormat.BC1_SRGB: case TexFormat.BC1_UNORM: PfHeader.Flags = (uint)DDPF.FOURCC; PfHeader.FourCC = FOURCC_DXT1; break; case TexFormat.BC2_SRGB: case TexFormat.BC2_UNORM: PfHeader.Flags = (uint)DDPF.FOURCC; PfHeader.FourCC = FOURCC_DXT3; break; case TexFormat.BC3_SRGB: case TexFormat.BC3_UNORM: PfHeader.Flags = (uint)DDPF.FOURCC; PfHeader.FourCC = FOURCC_DXT5; break; case TexFormat.BC4_UNORM: PfHeader.Flags = (uint)DDPF.FOURCC; PfHeader.FourCC = FOURCC_BC4U; break; case TexFormat.BC4_SNORM: PfHeader.Flags = (uint)DDPF.FOURCC; PfHeader.FourCC = FOURCC_BC4S; break; case TexFormat.BC5_UNORM: PfHeader.Flags = (uint)DDPF.FOURCC; PfHeader.FourCC = FOURCC_BC5U; break; case TexFormat.BC5_SNORM: PfHeader.Flags = (uint)DDPF.FOURCC; PfHeader.FourCC = FOURCC_BC5S; break; case TexFormat.BC6H_SF16: case TexFormat.BC6H_UF16: case TexFormat.BC7_UNORM: case TexFormat.BC7_SRGB: PfHeader.Flags = (uint)DDPF.FOURCC; PfHeader.FourCC = FOURCC_DX10; if (Dx10Header == null) { Dx10Header = new DX10Header(); } Dx10Header.DxgiFormat = (uint)dxgiFormat; break; } }