Exemplo n.º 1
0
        /// <summary>
        /// Creates a DDS header from a set of information.
        /// </summary>
        /// <param name="Mips">Number of mipmaps.</param>
        /// <param name="Height">Height of top mipmap.</param>
        /// <param name="Width">Width of top mipmap.</param>
        /// <param name="surfaceformat">Format header represents.</param>
        public DDS_Header(int Mips, int Height, int Width, ImageEngineFormat surfaceformat, DXGI_FORMAT dx10Format = DXGI_FORMAT.DXGI_FORMAT_UNKNOWN)
        {
            dwSize        = 124;
            dwFlags       = DDSdwFlags.DDSD_CAPS | DDSdwFlags.DDSD_HEIGHT | DDSdwFlags.DDSD_WIDTH | DDSdwFlags.DDSD_PIXELFORMAT | (Mips != 1 ? DDSdwFlags.DDSD_MIPMAPCOUNT : 0);
            this.Width    = Width;
            this.Height   = Height;
            dwCaps        = DDSdwCaps.DDSCAPS_TEXTURE | (Mips == 1 ? 0 : DDSdwCaps.DDSCAPS_COMPLEX | DDSdwCaps.DDSCAPS_MIPMAP);
            dwMipMapCount = Mips == 1 ? 1 : Mips;
            ddspf         = new DDS_PIXELFORMAT(surfaceformat);

            if (surfaceformat == ImageEngineFormat.DDS_DX10 || surfaceformat == ImageEngineFormat.DDS_ARGB_32F)
            {
                if (surfaceformat == ImageEngineFormat.DDS_ARGB_32F)
                {
                    dx10Format = DXGI_FORMAT.DXGI_FORMAT_R32G32B32A32_FLOAT;
                }

                DX10_DXGI_AdditionalHeader = new DDS_DXGI_DX10_Additional
                {
                    dxgiFormat        = dx10Format,
                    resourceDimension = D3D10_RESOURCE_DIMENSION.DDS_DIMENSION_TEXTURE2D,
                    miscFlag          = DDS_DXGI_DX10_Additional.D3D10_RESOURCE_MISC_FLAGS.D3D10_RESOURCE_MISC_GENERATE_MIPS,
                    miscFlags2        = DXGI_MiscFlags.DDS_ALPHA_MODE_UNKNOWN,
                    arraySize         = 1
                };
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads DDS header from stream.
        /// </summary>
        /// <param name="stream">Fully formatted DDS image.</param>
        /// <returns>Header length.</returns>
        protected override long Load(Stream stream)
        {
            base.Load(stream);
            var temp = stream.ReadBytes(MaxHeaderSize);

            if (!CheckIdentifier(temp))
            {
                throw new FormatException("Stream is not a recognised DDS image.");
            }

            // Start header
            dwSize              = BitConverter.ToInt32(temp, 4);
            dwFlags             = (DDSdwFlags)BitConverter.ToInt32(temp, 8);
            Height              = BitConverter.ToInt32(temp, 12);
            Width               = BitConverter.ToInt32(temp, 16);
            dwPitchOrLinearSize = BitConverter.ToInt32(temp, 20);
            dwDepth             = BitConverter.ToInt32(temp, 24);
            dwMipMapCount       = BitConverter.ToInt32(temp, 28);
            for (int i = 0; i < 11; ++i)
            {
                dwReserved1[i] = BitConverter.ToInt32(temp, 32 + (i * 4));
            }

            // DDS PixelFormat
            ddspf = new DDS_PIXELFORMAT(temp);

            dwCaps      = (DDSdwCaps)BitConverter.ToInt32(temp, 108);
            dwCaps2     = BitConverter.ToInt32(temp, 112);
            dwCaps3     = BitConverter.ToInt32(temp, 116);
            dwCaps4     = BitConverter.ToInt32(temp, 120);
            dwReserved2 = BitConverter.ToInt32(temp, 124);

            // DX10 Additional header
            if (ddspf.dwFourCC == FourCC.DX10)
            {
                DX10_DXGI_AdditionalHeader = new DDS_DXGI_DX10_Additional(temp);
            }

            return(MaxHeaderSize);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reads DDS header from stream.
        /// </summary>
        /// <param name="stream">Fully formatted DDS image.</param>
        /// <returns>Header length.</returns>
        protected override long Load(Stream stream)
        {
            base.Load(stream);
            var temp = stream.ReadBytes(HeaderSize);

            if (!CheckIdentifier(temp))
                throw new FormatException("Stream is not a recognised DDS image.");

            // Start header
            dwSize = BitConverter.ToInt32(temp, 4);
            dwFlags = (DDSdwFlags)BitConverter.ToInt32(temp, 8);
            Height = BitConverter.ToInt32(temp, 12);
            Width = BitConverter.ToInt32(temp, 16);
            dwPitchOrLinearSize = BitConverter.ToInt32(temp, 20);
            dwDepth = BitConverter.ToInt32(temp, 24);
            dwMipMapCount = BitConverter.ToInt32(temp, 28);
            for (int i = 0; i < 11; ++i)
                dwReserved1[i] = BitConverter.ToInt32(temp, 32 + (i * 4));

            // DDS PixelFormat
            ddspf = new DDS_PIXELFORMAT(temp);

            dwCaps = (DDSdwCaps)BitConverter.ToInt32(temp, 108);
            dwCaps2 = BitConverter.ToInt32(temp, 112);
            dwCaps3 = BitConverter.ToInt32(temp, 116);
            dwCaps4 = BitConverter.ToInt32(temp, 120);
            dwReserved2 = BitConverter.ToInt32(temp, 124);

            // DX10 Additional header
            if (ddspf.dwFourCC == FourCC.DX10)
                DX10_DXGI_AdditionalHeader = new DDS_DXGI_DX10_Additional(temp);

            return HeaderSize;
        }