Ejemplo n.º 1
0
        public static Texture Encode(Stream source)
        {
            var ddsHeader = new DDSHeader(source);

            int depth = 1;

            if (ddsHeader.Flags.HasFlag(DDSHeaderFlags.Depth))
            {
                depth = ddsHeader.Depth;
            }

            int mipMapCount = 1;

            if (ddsHeader.Flags.HasFlag(DDSHeaderFlags.MipMapCount))
            {
                mipMapCount = ddsHeader.MipMapCount;
            }

            var format = TextureUtilities.GetTextureFormat(ddsHeader.PixelFormat);

            var texture = new Texture(ddsHeader.Width, ddsHeader.Height, format, depth, mipMapCount);

            foreach (var level in texture.EnumerateLevels())
            {
                foreach (var mipMap in level)
                {
                    source.Read(mipMap.Data, 0, mipMap.Data.Length);
                }
            }

            return(texture);
        }