public UnhandledImageFormatException( TextureNativeSectionData.CompressionMode compression,
     TextureNativeSectionData.RasterFormat format )
     : base("Unhandled image format encountered: " +
         ( compression != TextureNativeSectionData.CompressionMode.None ?
             compression.ToString() + "-" : "" ) + format.ToString())
 {
 }
Exemple #2
0
        public Texture2D( TextureNativeSectionData tex )
            : base(TextureTarget.Texture2D)
        {
            Width = tex.Width;
            Height = tex.Height;

            WrapModeU = FindWrapMode( tex.WrapU );
            WrapModeV = FindWrapMode( tex.WrapV );

            InternalFormat = FindInternalFormat( tex.Compression, tex.Format );
            ExternalFormat = FindExternalFormat( tex.Compression, tex.Format );

            Compressed = tex.Compression != TextureNativeSectionData.CompressionMode.None;
            Alpha = tex.Alpha;

            MinFilter = FindMinFilter( tex.FilterFlags );

            MipMapCount = 1; // tex.MipMapCount;
            ContainsMipMaps = ( tex.Format & TextureNativeSectionData.RasterFormat.ExtMipMap ) != 0;
            GenerateMipMaps = true; // ( tex.Format & TextureNativeSectionData.RasterFormat.ExtAutoMipMap ) != 0;

            ImageLevelSizes = new int[ MipMapCount ];
            for ( int i = 0; i < MipMapCount; ++i )
                ImageLevelSizes[ i ] = FindImageDataSize( Width >> i, Height >> i, tex.Compression, tex.Format );

            ImageLevelData = new byte[ MipMapCount ][];
            for ( int i = 0; i < MipMapCount; ++i )
                ImageLevelData[ i ] = tex.ImageLevelData[ i ];
        }
Exemple #3
0
 private static TextureWrapMode FindWrapMode( TextureNativeSectionData.WrapMode mode )
 {
     switch ( mode )
     {
         case TextureNativeSectionData.WrapMode.Wrap:
             return TextureWrapMode.Repeat;
         case TextureNativeSectionData.WrapMode.Mirror:
             return TextureWrapMode.MirroredRepeat;
         case TextureNativeSectionData.WrapMode.Clamp:
             return TextureWrapMode.Clamp;
         default:
             return TextureWrapMode.Repeat;
     }
 }
Exemple #4
0
 private static TextureMinFilter FindMinFilter( TextureNativeSectionData.Filter filter )
 {
     switch ( filter )
     {
         case TextureNativeSectionData.Filter.Nearest:
             return TextureMinFilter.Nearest;
         case TextureNativeSectionData.Filter.MipNearest:
             return TextureMinFilter.NearestMipmapNearest;
         case TextureNativeSectionData.Filter.MipLinear:
             return TextureMinFilter.NearestMipmapLinear;
         case TextureNativeSectionData.Filter.LinearMipNearest:
             return TextureMinFilter.LinearMipmapNearest;
         case TextureNativeSectionData.Filter.LinearMipLinear:
             return TextureMinFilter.LinearMipmapLinear;
         default:
             return TextureMinFilter.Linear;
     }
 }
Exemple #5
0
 private static PixelInternalFormat FindInternalFormat(
     TextureNativeSectionData.CompressionMode compression,
     TextureNativeSectionData.RasterFormat format )
 {
     switch ( (TextureNativeSectionData.RasterFormat) ( (int) format & 0x0fff ) )
     {
         case TextureNativeSectionData.RasterFormat.R5G6B5:
             if ( compression == TextureNativeSectionData.CompressionMode.DXT1 )
                 return PixelInternalFormat.CompressedRgbS3tcDxt1Ext;
             goto default;
         case TextureNativeSectionData.RasterFormat.A1R5G5B5:
             if ( compression == TextureNativeSectionData.CompressionMode.DXT1 )
                 return PixelInternalFormat.CompressedRgbaS3tcDxt1Ext;
             goto default;
         case TextureNativeSectionData.RasterFormat.B8G8R8:
             if ( compression == TextureNativeSectionData.CompressionMode.None )
                 return PixelInternalFormat.Rgba;
             goto default;
         case TextureNativeSectionData.RasterFormat.B8G8R8A8:
             if ( compression == TextureNativeSectionData.CompressionMode.None )
                 return PixelInternalFormat.Rgba;
             goto default;
         case TextureNativeSectionData.RasterFormat.R4G4B4A4:
             if ( compression == TextureNativeSectionData.CompressionMode.DXT3 )
                 return PixelInternalFormat.CompressedRgbaS3tcDxt3Ext;
             goto default;
         default:
             throw new UnhandledImageFormatException( compression, format );
     }
 }
Exemple #6
0
 private static int FindImageDataSize( int width, int height,
     TextureNativeSectionData.CompressionMode compression,
     TextureNativeSectionData.RasterFormat format )
 {
     switch ( (TextureNativeSectionData.RasterFormat) ( (int) format & 0x0fff ) )
     {
         case TextureNativeSectionData.RasterFormat.R5G6B5:
             if ( compression == TextureNativeSectionData.CompressionMode.DXT1 )
                 return ( width * height ) >> 1;
             goto default;
         case TextureNativeSectionData.RasterFormat.A1R5G5B5:
             if ( compression == TextureNativeSectionData.CompressionMode.DXT1 )
                 return ( width * height ) >> 1;
             goto default;
         case TextureNativeSectionData.RasterFormat.B8G8R8:
             if ( compression == TextureNativeSectionData.CompressionMode.None )
                 return ( width * height ) << 2;
             goto default;
         case TextureNativeSectionData.RasterFormat.B8G8R8A8:
             if ( compression == TextureNativeSectionData.CompressionMode.None )
                 return ( width * height ) << 2;
             goto default;
         case TextureNativeSectionData.RasterFormat.R4G4B4A4:
             if ( compression == TextureNativeSectionData.CompressionMode.DXT3 )
                 return ( width * height );
             goto default;
         default:
             throw new UnhandledImageFormatException( compression, format );
     }
 }
Exemple #7
0
        private static PixelFormat FindExternalFormat(
            TextureNativeSectionData.CompressionMode compression,
            TextureNativeSectionData.RasterFormat format )
        {
            if ( compression != TextureNativeSectionData.CompressionMode.None )
                return PixelFormat.Alpha;

            switch ( (TextureNativeSectionData.RasterFormat) ( (int) format & 0x0fff ) )
            {
                case TextureNativeSectionData.RasterFormat.B8G8R8:
                    return PixelFormat.Bgra;
                case TextureNativeSectionData.RasterFormat.B8G8R8A8:
                    return PixelFormat.Bgra;
                default:
                    throw new UnhandledImageFormatException( compression, format );
            }
        }