public static void CreateTexture(
            DdsFile dds,
            D3D11Device device,
            D3D11DeviceContext context,
            int maxSize,
            D3D11Usage usage,
            D3D11BindOptions bindOptions,
            D3D11CpuAccessOptions cpuAccessOptions,
            D3D11ResourceMiscOptions miscOptions,
            bool forceSRGB,
            out D3D11Resource texture,
            out D3D11ShaderResourceView textureView,
            out DdsAlphaMode alphaMode)
        {
            if (dds == null)
            {
                throw new ArgumentNullException(nameof(dds));
            }

            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            CreateTextureFromDDS(
                device,
                context,
                dds,
                dds.Data,
                maxSize,
                usage,
                bindOptions,
                cpuAccessOptions,
                miscOptions,
                forceSRGB,
                out texture,
                out textureView);

            alphaMode = dds.AlphaMode;
        }
 public static void CreateTexture(
     DdsFile dds,
     D3D11Device device,
     D3D11DeviceContext context,
     int maxSize,
     out D3D11Resource texture,
     out D3D11ShaderResourceView textureView,
     out DdsAlphaMode alphaMode)
 {
     CreateTexture(
         dds,
         device,
         context,
         maxSize,
         D3D11Usage.Default,
         D3D11BindOptions.ShaderResource,
         D3D11CpuAccessOptions.None,
         D3D11ResourceMiscOptions.None,
         false,
         out texture,
         out textureView,
         out alphaMode);
 }
Beispiel #3
0
        public static DdsFile FromStream(Stream stream)
        {
            DdsFile dds = new DdsFile();

            BinaryReader file = new BinaryReader(stream);

            int magic = file.ReadInt32();

            if (magic != DdsFile.DdsMagic)
            {
                throw new InvalidDataException();
            }

            if (file.ReadInt32() != 124)
            {
                throw new InvalidDataException();
            }

            dds.Options     = (DdsOptions)file.ReadInt32();
            dds.Height      = file.ReadInt32();
            dds.Width       = file.ReadInt32();
            dds.LinearSize  = file.ReadInt32();
            dds.Depth       = file.ReadInt32();
            dds.MipmapCount = file.ReadInt32();

            file.BaseStream.Position += 44;

            if (file.ReadInt32() != 32)
            {
                throw new InvalidDataException();
            }

            dds.PixelFormat.Options      = (DdsPixelFormatOptions)file.ReadInt32();
            dds.PixelFormat.FourCC       = (DdsFourCC)file.ReadInt32();
            dds.PixelFormat.RgbBitCount  = file.ReadInt32();
            dds.PixelFormat.RedBitMask   = file.ReadUInt32();
            dds.PixelFormat.GreenBitMask = file.ReadUInt32();
            dds.PixelFormat.BlueBitMask  = file.ReadUInt32();
            dds.PixelFormat.AlphaBitMask = file.ReadUInt32();

            dds.Caps  = (DdsCaps)file.ReadInt32();
            dds.Caps2 = (DdsAdditionalCaps)file.ReadInt32();

            file.BaseStream.Position += 12;

            if ((dds.PixelFormat.Options & DdsPixelFormatOptions.FourCC) != 0 && dds.PixelFormat.FourCC == DdsFourCC.DX10)
            {
                dds.Format              = (DdsFormat)file.ReadInt32();
                dds.ResourceDimension   = (DdsResourceDimension)file.ReadInt32();
                dds.ResourceMiscOptions = (DdsResourceMiscOptions)file.ReadInt32();
                dds.ArraySize           = file.ReadInt32();

                DdsAlphaMode mode = (DdsAlphaMode)(file.ReadInt32() & 0x7);
                switch (mode)
                {
                case DdsAlphaMode.Straight:
                case DdsAlphaMode.Premultiplied:
                case DdsAlphaMode.Opaque:
                case DdsAlphaMode.Custom:
                    dds.AlphaMode = mode;
                    break;
                }
            }
            else
            {
                dds.Format = DdsHelpers.GetDdsFormat(dds.PixelFormat);

                if ((dds.PixelFormat.Options & DdsPixelFormatOptions.FourCC) != 0)
                {
                    switch (dds.PixelFormat.FourCC)
                    {
                    case DdsFourCC.DXT2:
                    case DdsFourCC.DXT4:
                        dds.AlphaMode = DdsAlphaMode.Premultiplied;
                        break;
                    }
                }
            }

            dds.DataOffset = (int)file.BaseStream.Position;
            dds.Data       = file.ReadBytes((int)file.BaseStream.Length - (int)file.BaseStream.Position);

            return(dds);
        }