Beispiel #1
0
        private void ReadHeader(Ibasa.IO.BinaryReader reader)
        {
            HeaderFlags = (HeaderFlagsEnum)reader.ReadInt32();
            Height      = reader.ReadInt32();
            Width       = reader.ReadInt32();
            Pitch       = reader.ReadInt32();
            Depth       = reader.ReadInt32();
            MipmapCount = reader.ReadInt32();
            reader.ReadBytes(44); //skip padding

            int pixelSize = reader.ReadInt32();

            if (pixelSize != 32)
            {
                throw new InvalidDataException(string.Format("Pixel format size {0} does not match 32.", pixelSize));
            }

            PixelFlags  = (PixelFlagsEnum)reader.ReadInt32();
            FourCC      = new FourCC(reader.ReadInt32());
            RGBBitCount = reader.ReadInt32();
            RBitMask    = reader.ReadInt32();
            GBitMask    = reader.ReadInt32();
            BBitMask    = reader.ReadInt32();
            ABitMask    = reader.ReadInt32();

            SurfaceFlags = (SurfaceFlagsEnum)reader.ReadInt32();
            CubemapFlags = (CubemapFlagsEnum)reader.ReadInt32();

            reader.ReadBytes(12); //skip padding
        }
Beispiel #2
0
        private void SetInternalState()
        {
            HeaderFlags  = HeaderFlagsEnum.Caps | HeaderFlagsEnum.Width | HeaderFlagsEnum.Height | HeaderFlagsEnum.PixelFormat;
            SurfaceFlags = SurfaceFlagsEnum.Texture;
            CubemapFlags = Cubemap ? (CubemapFlagsEnum.Cubemap | CubemapFlagsEnum.AllFaces) : 0;
            MiscFlags    = 0;

            if (Image.MipLevels > 1)
            {
                HeaderFlags  |= HeaderFlagsEnum.MipmapCount;
                SurfaceFlags |= SurfaceFlagsEnum.Complex;
            }
            if (Image.Size.Depth > 1)
            {
                HeaderFlags |= HeaderFlagsEnum.Depth;
            }

            if (Image.Format.IsCompressed)
            {
                int unused;
                Pitch        = Image.Format.GetByteCount(Image.Size, out unused, out unused);
                HeaderFlags |= HeaderFlagsEnum.LinearSize;
            }
            else
            {
                int unused;
                Image.Format.GetByteCount(Image.Size, out Pitch, out unused);
                HeaderFlags |= HeaderFlagsEnum.Pitch;
            }

            Height      = Image.Size.Height;
            Width       = Image.Size.Width;
            Depth       = Image.Size.Depth > 1 ? Image.Size.Depth : 0;
            MipmapCount = Image.MipLevels > 1 ? Image.MipLevels : 0;

            SelectSaveFormat();

            if (IsDX10Mode)
            {
                ArraySize         = Cubemap ? Image.ArraySize / 6 : Image.ArraySize;
                ResourceDimension = Image.Size.Depth > 1 ? ResourceDimensionEnum.Texture3D :
                                    (Image.Size.Height > 1 ? ResourceDimensionEnum.Texture2D : ResourceDimensionEnum.Texture1D);
                MiscFlags = Cubemap ? MiscFlagsEnum.TextureCube : 0;
            }
        }
Beispiel #3
0
        private void SetInternalState()
        {
            HeaderFlags = HeaderFlagsEnum.Caps | HeaderFlagsEnum.Width | HeaderFlagsEnum.Height | HeaderFlagsEnum.PixelFormat;
            SurfaceFlags = SurfaceFlagsEnum.Texture;
            CubemapFlags = Cubemap ? (CubemapFlagsEnum.Cubemap | CubemapFlagsEnum.AllFaces) : 0;
            MiscFlags = 0;

            if (Image.MipLevels > 1)
            {
                HeaderFlags |= HeaderFlagsEnum.MipmapCount;
                SurfaceFlags |= SurfaceFlagsEnum.Complex;
            }
            if (Image.Size.Depth > 1)
            {
                HeaderFlags |= HeaderFlagsEnum.Depth;
            }

            if (Image.Format.IsCompressed)
            {
                int unused;
                Pitch = Image.Format.GetByteCount(Image.Size, out unused, out unused);
                HeaderFlags |= HeaderFlagsEnum.LinearSize;
            }
            else
            {
                int unused;
                Image.Format.GetByteCount(Image.Size, out Pitch, out unused);
                HeaderFlags |= HeaderFlagsEnum.Pitch;
            }

            Height = Image.Size.Height;
            Width = Image.Size.Width;
            Depth = Image.Size.Depth > 1 ? Image.Size.Depth : 0;
            MipmapCount = Image.MipLevels > 1 ? Image.MipLevels : 0;

            SelectSaveFormat();

            if (IsDX10Mode)
            {
                ArraySize = Cubemap ? Image.ArraySize / 6 : Image.ArraySize;
                ResourceDimension = Image.Size.Depth > 1 ? ResourceDimensionEnum.Texture3D :
                    (Image.Size.Height > 1 ? ResourceDimensionEnum.Texture2D : ResourceDimensionEnum.Texture1D);
                MiscFlags = Cubemap ? MiscFlagsEnum.TextureCube : 0;
            }
        }
Beispiel #4
0
        private void ReadHeader(Ibasa.IO.BinaryReader reader)
        {
            HeaderFlags = (HeaderFlagsEnum)reader.ReadInt32();
            Height = reader.ReadInt32();
            Width = reader.ReadInt32();
            Pitch = reader.ReadInt32();
            Depth = reader.ReadInt32();
            MipmapCount = reader.ReadInt32();
            reader.ReadBytes(44); //skip padding

            int pixelSize = reader.ReadInt32();
            if (pixelSize != 32)
                throw new InvalidDataException(string.Format("Pixel format size {0} does not match 32.", pixelSize));

            PixelFlags = (PixelFlagsEnum)reader.ReadInt32();
            FourCC = new FourCC(reader.ReadInt32());
            RGBBitCount = reader.ReadInt32();
            RBitMask = reader.ReadInt32();
            GBitMask = reader.ReadInt32();
            BBitMask = reader.ReadInt32();
            ABitMask = reader.ReadInt32();

            SurfaceFlags = (SurfaceFlagsEnum)reader.ReadInt32();
            CubemapFlags = (CubemapFlagsEnum)reader.ReadInt32();

            reader.ReadBytes(12); //skip padding
        }
Beispiel #5
0
        private void FixupInternalState()
        {
            HeaderFlags |= (HeaderFlagsEnum.Caps | HeaderFlagsEnum.Height | HeaderFlagsEnum.Width | HeaderFlagsEnum.PixelFormat);
            SurfaceFlags |= SurfaceFlagsEnum.Texture;

            //cubemap
            if(CubemapFlags != CubemapFlagsEnum.Volume && CubemapFlags != 0)
            {
                CubemapFlags |= CubemapFlagsEnum.Cubemap;
                SurfaceFlags |= SurfaceFlagsEnum.Complex;
                if (IsDX10Mode)
                {
                    CubemapFlags |= CubemapFlagsEnum.AllFaces;
                    MiscFlags |= MiscFlagsEnum.TextureCube;
                }
            }
            if(IsDX10Mode && MiscFlags.HasFlag(MiscFlagsEnum.TextureCube))
            {
                
                CubemapFlags |= CubemapFlagsEnum.Cubemap| CubemapFlagsEnum.AllFaces;
                SurfaceFlags |= SurfaceFlagsEnum.Complex;
            }

            //volume textures
            if(HeaderFlags.HasFlag(HeaderFlagsEnum.Depth) || CubemapFlags.HasFlag(CubemapFlagsEnum.Volume))
            {
                HeaderFlags |= HeaderFlagsEnum.Depth;
                CubemapFlags |= CubemapFlagsEnum.Volume;
                SurfaceFlags |= SurfaceFlagsEnum.Complex;
            }

            //sanatize pixel flags
            if(PixelFlags.HasFlag(PixelFlagsEnum.Rgb) && PixelFlags.HasFlag(PixelFlagsEnum.AlphaPixels))
                PixelFlags = PixelFlagsEnum.Rgb | PixelFlagsEnum.AlphaPixels;
            else if(PixelFlags.HasFlag(PixelFlagsEnum.Rgb))
                PixelFlags = PixelFlagsEnum.Rgb;
            else if(PixelFlags.HasFlag(PixelFlagsEnum.Luminance) && PixelFlags.HasFlag(PixelFlagsEnum.AlphaPixels))
                PixelFlags = PixelFlagsEnum.Luminance | PixelFlagsEnum.AlphaPixels;
            else if(PixelFlags.HasFlag(PixelFlagsEnum.Luminance))
                PixelFlags = PixelFlagsEnum.Luminance;
            else if(PixelFlags.HasFlag(PixelFlagsEnum.FourCC))
                PixelFlags = PixelFlagsEnum.FourCC;
            else if(PixelFlags.HasFlag(PixelFlagsEnum.Yuv))
                PixelFlags = PixelFlagsEnum.Yuv;
            else if(PixelFlags.HasFlag(PixelFlagsEnum.Alpha))
                PixelFlags = PixelFlagsEnum.Alpha;

            if (!PixelFlags.HasFlag(PixelFlagsEnum.FourCC))
            { 
                //uncompressed
                HeaderFlags |= HeaderFlagsEnum.Pitch;
                HeaderFlags &= ~HeaderFlagsEnum.LinearSize;
            }
            else
            {
                //dont know
                //HeaderFlags |= HeaderFlagsEnum.LinearSize;
                //HeaderFlags &= ~HeaderFlagsEnum.Pitch;
            }

            if (IsDX10Mode)
            {
                if(ResourceDimension == ResourceDimensionEnum.Texture3D || HeaderFlags.HasFlag(HeaderFlagsEnum.Depth))
                {
                    ResourceDimension = ResourceDimensionEnum.Texture3D;
                    HeaderFlags |= HeaderFlagsEnum.Depth;
                    CubemapFlags |= CubemapFlagsEnum.Volume;
                    SurfaceFlags |= SurfaceFlagsEnum.Complex;
                }
            }

            Width = Math.Max(Width, 1);
            Height = Math.Max(Height, 1);
            Depth = HeaderFlags.HasFlag(HeaderFlagsEnum.Depth) ? Math.Max(Depth, 1) : 0;
            MipmapCount = HeaderFlags.HasFlag(HeaderFlagsEnum.MipmapCount) ? Math.Max(MipmapCount, 1) : 0;
        }
Beispiel #6
0
        private void FixupInternalState()
        {
            HeaderFlags  |= (HeaderFlagsEnum.Caps | HeaderFlagsEnum.Height | HeaderFlagsEnum.Width | HeaderFlagsEnum.PixelFormat);
            SurfaceFlags |= SurfaceFlagsEnum.Texture;

            //cubemap
            if (CubemapFlags != CubemapFlagsEnum.Volume && CubemapFlags != 0)
            {
                CubemapFlags |= CubemapFlagsEnum.Cubemap;
                SurfaceFlags |= SurfaceFlagsEnum.Complex;
                if (IsDX10Mode)
                {
                    CubemapFlags |= CubemapFlagsEnum.AllFaces;
                    MiscFlags    |= MiscFlagsEnum.TextureCube;
                }
            }
            if (IsDX10Mode && MiscFlags.HasFlag(MiscFlagsEnum.TextureCube))
            {
                CubemapFlags |= CubemapFlagsEnum.Cubemap | CubemapFlagsEnum.AllFaces;
                SurfaceFlags |= SurfaceFlagsEnum.Complex;
            }

            //volume textures
            if (HeaderFlags.HasFlag(HeaderFlagsEnum.Depth) || CubemapFlags.HasFlag(CubemapFlagsEnum.Volume))
            {
                HeaderFlags  |= HeaderFlagsEnum.Depth;
                CubemapFlags |= CubemapFlagsEnum.Volume;
                SurfaceFlags |= SurfaceFlagsEnum.Complex;
            }

            //sanatize pixel flags
            if (PixelFlags.HasFlag(PixelFlagsEnum.Rgb) && PixelFlags.HasFlag(PixelFlagsEnum.AlphaPixels))
            {
                PixelFlags = PixelFlagsEnum.Rgb | PixelFlagsEnum.AlphaPixels;
            }
            else if (PixelFlags.HasFlag(PixelFlagsEnum.Rgb))
            {
                PixelFlags = PixelFlagsEnum.Rgb;
            }
            else if (PixelFlags.HasFlag(PixelFlagsEnum.Luminance) && PixelFlags.HasFlag(PixelFlagsEnum.AlphaPixels))
            {
                PixelFlags = PixelFlagsEnum.Luminance | PixelFlagsEnum.AlphaPixels;
            }
            else if (PixelFlags.HasFlag(PixelFlagsEnum.Luminance))
            {
                PixelFlags = PixelFlagsEnum.Luminance;
            }
            else if (PixelFlags.HasFlag(PixelFlagsEnum.FourCC))
            {
                PixelFlags = PixelFlagsEnum.FourCC;
            }
            else if (PixelFlags.HasFlag(PixelFlagsEnum.Yuv))
            {
                PixelFlags = PixelFlagsEnum.Yuv;
            }
            else if (PixelFlags.HasFlag(PixelFlagsEnum.Alpha))
            {
                PixelFlags = PixelFlagsEnum.Alpha;
            }

            if (!PixelFlags.HasFlag(PixelFlagsEnum.FourCC))
            {
                //uncompressed
                HeaderFlags |= HeaderFlagsEnum.Pitch;
                HeaderFlags &= ~HeaderFlagsEnum.LinearSize;
            }
            else
            {
                //dont know
                //HeaderFlags |= HeaderFlagsEnum.LinearSize;
                //HeaderFlags &= ~HeaderFlagsEnum.Pitch;
            }

            if (IsDX10Mode)
            {
                if (ResourceDimension == ResourceDimensionEnum.Texture3D || HeaderFlags.HasFlag(HeaderFlagsEnum.Depth))
                {
                    ResourceDimension = ResourceDimensionEnum.Texture3D;
                    HeaderFlags      |= HeaderFlagsEnum.Depth;
                    CubemapFlags     |= CubemapFlagsEnum.Volume;
                    SurfaceFlags     |= SurfaceFlagsEnum.Complex;
                }
            }

            Width       = Math.Max(Width, 1);
            Height      = Math.Max(Height, 1);
            Depth       = HeaderFlags.HasFlag(HeaderFlagsEnum.Depth) ? Math.Max(Depth, 1) : 0;
            MipmapCount = HeaderFlags.HasFlag(HeaderFlagsEnum.MipmapCount) ? Math.Max(MipmapCount, 1) : 0;
        }