Ejemplo n.º 1
0
        protected internal override Texture2D Read(ContentReader reader, Texture2D existingInstance)
        {
            Texture2D texture = null;

            SurfaceFormat  surfaceFormat   = (SurfaceFormat)reader.ReadInt32();
            int            width           = (reader.ReadInt32());
            int            height          = (reader.ReadInt32());
            int            levelCount      = (reader.ReadInt32());
            SetDataOptions compressionType = (SetDataOptions)reader.ReadInt32();
            int            imageLength     = width * height * 4;

            if (surfaceFormat == SurfaceFormat.Dxt3)
            {
                ESTexture2D temp = ESTexture2D.InitiFromDxt3File(reader, imageLength, width, height);
                texture = new Texture2D(new ESImage(temp));
            }
            else
            {
                byte[] imageBytes = reader.ReadBytes(imageLength);
                IntPtr ptr        = Marshal.AllocHGlobal(imageLength);
                try
                {
                    Marshal.Copy(imageBytes, 0, ptr, imageLength);
                    ESTexture2D temp = new ESTexture2D(ptr, SurfaceFormat.Rgba32, width, height, new Size(width, height), All.Linear);
                    texture = new Texture2D(new ESImage(temp));
                }
                finally
                {
                    Marshal.FreeHGlobal(ptr);
                }
            }

            return(texture);
        }