Exemplo n.º 1
0
        internal static void ChangeTextureToRequestedFormat(TextureContent texture,
                                                            Type originalType,
                                                            TextureProcessorOutputFormat textureFormat)
        {
            switch (textureFormat)
            {
            case TextureProcessorOutputFormat.NoChange:
                if (originalType == null)
                {
                    break;
                }
                texture.ConvertBitmapType(originalType);
                return;

            case TextureProcessorOutputFormat.Color:
                texture.ConvertBitmapType(typeof(PixelBitmapContent <Color>));
                return;

            case TextureProcessorOutputFormat.DxtCompressed:
                BestGuessCompress(texture);
                break;

            default:
                return;
            }
        }
Exemplo n.º 2
0
        protected override void PlatformCompressTexture(
            ContentProcessorContext context, TextureContent content,
            TextureProcessorOutputFormat format, bool isSpriteFont)
        {
            format = GetTextureFormatForPlatform(format, context.TargetPlatform);

            // Make sure we're in a floating point format
            content.ConvertBitmapType(typeof(PixelBitmapContent <RgbaVector>));

            switch (format)
            {
            case TextureProcessorOutputFormat.AtcCompressed:
                GraphicsUtil.CompressAti(content, isSpriteFont);
                break;

            case TextureProcessorOutputFormat.Color16Bit:
                GraphicsUtil.CompressColor16Bit(content);
                break;

            case TextureProcessorOutputFormat.DxtCompressed:
                GraphicsUtil.CompressDxt(context, content, isSpriteFont);
                break;

            case TextureProcessorOutputFormat.Etc1Compressed:
                GraphicsUtil.CompressEtc1(context, content, isSpriteFont);
                break;

            case TextureProcessorOutputFormat.PvrCompressed:
                GraphicsUtil.CompressPvrtc(context, content, isSpriteFont);
                break;
            }
        }
Exemplo n.º 3
0
        internal static void ChangeTextureToRequestedFormat(TextureContent texture,
                                                            Type originalType,
                                                            TextureProcessorOutputFormat textureFormat)
        {
            switch (textureFormat)
            {
                case TextureProcessorOutputFormat.NoChange:
                    if (originalType == null)
                    {
                        break;
                    }
                    texture.ConvertBitmapType(originalType);
                    return;

                case TextureProcessorOutputFormat.Color:
                    texture.ConvertBitmapType(typeof (PixelBitmapContent<Color>));
                    return;

                case TextureProcessorOutputFormat.DxtCompressed:
                    BestGuessCompress(texture);
                    break;

                default:
                    return;
            }
        }
Exemplo n.º 4
0
        public override TextureContent Process(TextureContent input, ContentProcessorContext context)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (!this.ForceDXT5)
            {
                return(base.Process(input, context));
            }

            TextureContent ret = null;
            TextureProcessorOutputFormat fmt = this.TextureFormat;

            this.TextureFormat = TextureProcessorOutputFormat.NoChange;
            try
            {
                ret = base.Process(input, context);
                Type originalType = ret.Faces[0][0].GetType();
                if (originalType != typeof(Dxt5BitmapContent))
                {
                    ret.ConvertBitmapType(typeof(Dxt5BitmapContent));
                }
            }
            finally
            {
                this.TextureFormat = fmt;
            }
            return(ret);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the MaterialProcessor class.
 /// </summary>
 public MaterialProcessor()
 {
     colorKeyColor              = Color.Magenta;
     colorKeyEnabled            = true;
     defaultEffect              = MaterialProcessorDefaultEffect.BasicEffect;
     generateMipmaps            = false;
     premultiplyTextureAlpha    = true;
     resizeTexturesToPowerOfTwo = true;
     textureFormat              = TextureProcessorOutputFormat.Color;
 }
 private static bool IsCompressedTextureFormat(TextureProcessorOutputFormat format)
 {
     switch (format)
     {
     case TextureProcessorOutputFormat.AtcCompressed:
     case TextureProcessorOutputFormat.DxtCompressed:
     case TextureProcessorOutputFormat.Etc1Compressed:
     case TextureProcessorOutputFormat.PvrCompressed:
         return(true);
     }
     return(false);
 }
Exemplo n.º 7
0
        public TextureAtlasProcessor()
        {
            Pack        = true;
            RowCount    = 1;
            ColumnCount = 1;

            ColorKey           = new Color(255, 0, 255, 255);
            ColorKeyEnabled    = true;
            GenerateMipmaps    = false;
            PremultiplyAlpha   = true;
            ResizeToPowerOfTwo = false;
            TextureFormat      = TextureProcessorOutputFormat.Color;
        }
Exemplo n.º 8
0
        private static TextureProcessorOutputFormat GetTextureFormatForPlatform(
            TextureProcessorOutputFormat format, TargetPlatform platform)
        {
            // Select the default texture compression format for the target platform
            if (format == TextureProcessorOutputFormat.Compressed)
            {
                if (platform == TargetPlatform.iOS)
                {
                    format = TextureProcessorOutputFormat.PvrCompressed;
                }
                else if (platform == TargetPlatform.Android)
                {
                    format = TextureProcessorOutputFormat.Etc1Compressed;
                }
                else
                {
                    format = TextureProcessorOutputFormat.DxtCompressed;
                }
            }

            if (IsCompressedTextureFormat(format))
            {
                // Make sure the target platform supports the selected texture compression format
                if (platform == TargetPlatform.iOS)
                {
                    if (format != TextureProcessorOutputFormat.PvrCompressed)
                    {
                        throw new PlatformNotSupportedException(
                                  "iOS platform only supports PVR texture compression.");
                    }
                }
                else if (
                    platform == TargetPlatform.Windows ||
                    platform == TargetPlatform.WindowsPhone8 ||
                    platform == TargetPlatform.WindowsStoreApp ||
                    platform == TargetPlatform.DesktopGL ||
                    platform == TargetPlatform.MacOSX ||
                    platform == TargetPlatform.NativeClient ||
                    platform == TargetPlatform.Web)
                {
                    if (format != TextureProcessorOutputFormat.DxtCompressed)
                    {
                        throw new PlatformNotSupportedException(
                                  platform + " platform only supports DXT texture compression.");
                    }
                }
            }

            return(format);
        }
Exemplo n.º 9
0
        /// <summary>
        /// If format is TextureProcessorOutputFormat.Compressed, the appropriate compressed texture format for the target
        /// platform is returned. Otherwise the format is returned unchanged.
        /// </summary>
        /// <param name="format">The supplied texture format.</param>
        /// <param name="platform">The target platform.</param>
        /// <returns>The texture format.</returns>
        public static TextureProcessorOutputFormat GetTextureFormatForPlatform(TextureProcessorOutputFormat format, TargetPlatform platform)
        {
            // Select the default texture compression format for the target platform
            if (format == TextureProcessorOutputFormat.Compressed)
            {
                switch (platform)
                {
                case TargetPlatform.iOS:
                    format = TextureProcessorOutputFormat.PvrCompressed;
                    break;

                case TargetPlatform.Android:
                    format = TextureProcessorOutputFormat.Etc1Compressed;
                    break;

                default:
                    format = TextureProcessorOutputFormat.DxtCompressed;
                    break;
                }
            }

            if (IsCompressedTextureFormat(format))
            {
                // Make sure the target platform supports the selected texture compression format
                switch (platform)
                {
                case TargetPlatform.iOS:
                    if (format != TextureProcessorOutputFormat.PvrCompressed)
                    {
                        throw new PlatformNotSupportedException("iOS platform only supports PVR texture compression");
                    }
                    break;

                case TargetPlatform.Windows:
                case TargetPlatform.WindowsPhone8:
                case TargetPlatform.WindowsStoreApp:
                case TargetPlatform.DesktopGL:
                case TargetPlatform.MacOSX:
                case TargetPlatform.NativeClient:
                    if (format != TextureProcessorOutputFormat.DxtCompressed)
                    {
                        throw new PlatformNotSupportedException(platform.ToString() + " platform only supports DXT texture compression");
                    }
                    break;
                }
            }

            return(format);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Determines if the given texture format requires equal width and height on the target platform.
        /// </summary>
        /// <param name="format">The texture format.</param>
        /// <param name="platform">The target platform.</param>
        /// <returns>True if the texture format requires equal width and height on the target platform.</returns>
        public static bool RequiresSquare(TextureProcessorOutputFormat format, TargetPlatform platform)
        {
            if (format == TextureProcessorOutputFormat.Compressed)
            {
                format = GetTextureFormatForPlatform(format, platform);
            }

            switch (format)
            {
            case TextureProcessorOutputFormat.PvrCompressed:
                return(true);
            }

            return(false);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Performs conversion of the texture content to the correct format.
        /// </summary>
        /// <param name="context">The processor context.</param>
        /// <param name="content">The content to be compressed.</param>
        /// <param name="format">The user requested format for compression.</param>
        /// <param name="isSpriteFont">If the texture has represents a sprite font, i.e. is greyscale and has sharp black/white contrast.</param>
        public void ConvertTexture(
            ContentProcessorContext context, TextureContent content, TextureProcessorOutputFormat format, bool isSpriteFont)
        {
            // We do nothing in this case.
            if (format == TextureProcessorOutputFormat.NoChange)
            {
                return;
            }

            // If this is color just make sure the format is right and return it.
            if (format == TextureProcessorOutputFormat.Color)
            {
                content.ConvertBitmapType(typeof(PixelBitmapContent <Color>));
                return;
            }

            // Handle this common compression format.
            if (format == TextureProcessorOutputFormat.Color16Bit)
            {
                GraphicsUtil.CompressColor16Bit(content);
                return;
            }

            try
            {
                // All other formats require platform specific choices.
                PlatformCompressTexture(context, content, format, isSpriteFont);
            }
            catch (EntryPointNotFoundException ex)
            {
                context.Logger.LogImportantMessage("Could not find the entry point to compress the texture. " + ex.ToString());
                throw;
            }
            catch (DllNotFoundException ex)
            {
                context.Logger.LogImportantMessage("Could not compress texture. Required shared lib is missing. " + ex.ToString());
                throw;
            }
            catch (Exception ex)
            {
                context.Logger.LogImportantMessage("Could not convert texture. " + ex.ToString());
                throw;
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Determines if the texture format requires power-of-two dimensions on the target platform.
        /// </summary>
        /// <param name="format">The texture format.</param>
        /// <param name="platform">The target platform.</param>
        /// <param name="profile">The targeted graphics profile.</param>
        /// <returns>True if the texture format requires power-of-two dimensions on the target platform.</returns>
        public static bool RequiresPowerOfTwo(TextureProcessorOutputFormat format, TargetPlatform platform, GraphicsProfile profile)
        {
            if (format == TextureProcessorOutputFormat.Compressed)
            {
                format = GetTextureFormatForPlatform(format, platform);
            }

            switch (format)
            {
            case TextureProcessorOutputFormat.DxtCompressed:
                return(profile == GraphicsProfile.Reach);

            case TextureProcessorOutputFormat.PvrCompressed:
            case TextureProcessorOutputFormat.Etc1Compressed:
                return(true);
            }

            return(false);
        }
Exemplo n.º 13
0
        public override void Requirements(
            ContentProcessorContext context, TextureProcessorOutputFormat format,
            out bool requiresPowerOfTwo, out bool requiresSquare)
        {
            if (format == TextureProcessorOutputFormat.Compressed)
            {
                format = GetTextureFormatForPlatform(format, context.TargetPlatform);
            }

            // Does it require POT textures?
            switch (format)
            {
            default:
                requiresPowerOfTwo = false;
                break;

            case TextureProcessorOutputFormat.DxtCompressed:
                requiresPowerOfTwo = context.TargetProfile == GraphicsProfile.Reach;
                break;

            case TextureProcessorOutputFormat.PvrCompressed:
            case TextureProcessorOutputFormat.Etc1Compressed:
                requiresPowerOfTwo = true;
                break;
            }

            // Does it require square textures?
            switch (format)
            {
            default:
                requiresSquare = false;
                break;

            case TextureProcessorOutputFormat.PvrCompressed:
                requiresSquare = true;
                break;
            }
        }
Exemplo n.º 14
0
 /// <summary>
 /// Determines if the texture format will require power-of-two dimensions and/or equal width and height.
 /// </summary>
 /// <param name="context">The processor context.</param>
 /// <param name="format">The desired texture format.</param>
 /// <param name="requiresPowerOfTwo">True if the texture format requires power-of-two dimensions.</param>
 /// <param name="requiresSquare">True if the texture format requires equal width and height.</param>
 /// <returns>True if the texture format requires power-of-two dimensions.</returns>
 public abstract void Requirements(ContentProcessorContext context, TextureProcessorOutputFormat format, out bool requiresPowerOfTwo, out bool requiresSquare);
Exemplo n.º 15
0
 protected abstract void PlatformCompressTexture(ContentProcessorContext context, TextureContent content, TextureProcessorOutputFormat format, bool generateMipmaps, bool isSpriteFont);
Exemplo n.º 16
0
 /// <summary>
 /// Returns true if the format is a compressed format.
 /// </summary>
 /// <param name="format">The texture processor output format.</param>
 /// <returns>True if the format is a compressed format.</returns>
 public static bool IsCompressedTextureFormat(TextureProcessorOutputFormat format)
 {
     switch (format)
     {
         case TextureProcessorOutputFormat.AtcCompressed:
         case TextureProcessorOutputFormat.DxtCompressed:
         case TextureProcessorOutputFormat.Etc1Compressed:
         case TextureProcessorOutputFormat.PvrCompressed:
             return true;
     }
     return false;
 }
Exemplo n.º 17
0
 public DDSProcessor()
 {
     GenerateMipmaps = true;
     TextureFormat   = TextureProcessorOutputFormat.NoChange;
 }
 public FontDescriptionProcessor()
 {
     this.TextureFormat = TextureProcessorOutputFormat.Compressed;
 }
Exemplo n.º 19
0
        public override TextureContent Process(TextureContent input, ContentProcessorContext context)
        {
            var bmp = input.Faces[0][0];

            if (ColorKeyEnabled)
            {
                var data = bmp.GetPixelData();
                var idx  = 0;
                for (; idx < data.Length;)
                {
                    var r   = data[idx + 0];
                    var g   = data[idx + 1];
                    var b   = data[idx + 2];
                    var a   = data[idx + 3];
                    var col = new Color(r, g, b, a);
                    if (col.Equals(ColorKeyColor))
                    {
                        data[idx + 0] = 0;
                        data[idx + 1] = 0;
                        data[idx + 2] = 0;
                        data[idx + 3] = 0;
                    }

                    idx += 4;
                }

                bmp.SetPixelData(data);
            }


            if (ResizeToPowerOfTwo)
            {
                if (!GraphicsUtil.IsPowerOfTwo(bmp.Width) || !GraphicsUtil.IsPowerOfTwo(bmp.Height))
                {
                    input.Resize(GraphicsUtil.GetNextPowerOfTwo(bmp.Width), GraphicsUtil.GetNextPowerOfTwo(bmp.Height));
                    bmp = input.Faces[0][0];
                }
            }

            if (PremultiplyAlpha)
            {
                var data = bmp.GetPixelData();
                var idx  = 0;
                for (; idx < data.Length;)
                {
                    var r   = data[idx + 0];
                    var g   = data[idx + 1];
                    var b   = data[idx + 2];
                    var a   = data[idx + 3];
                    var col = Color.FromNonPremultiplied(r, g, b, a);

                    data[idx + 0] = col.R;
                    data[idx + 1] = col.G;
                    data[idx + 2] = col.B;
                    data[idx + 3] = col.A;

                    idx += 4;
                }

                bmp.SetPixelData(data);
            }

            if (TextureFormat == TextureProcessorOutputFormat.NoChange)
            {
                return(input);
            }
            try
            {
                if (TextureFormat == TextureProcessorOutputFormat.DxtCompressed ||
                    TextureFormat == TextureProcessorOutputFormat.Compressed)
                {
                    GraphicsUtil.CompressTexture(context.TargetProfile, input, context, GenerateMipmaps, PremultiplyAlpha, false);
                }
            }
            catch (EntryPointNotFoundException ex) {
                context.Logger.LogImportantMessage("Could not find the entry point to compress the texture", ex.ToString());
                TextureFormat = TextureProcessorOutputFormat.Color;
            }
            catch (DllNotFoundException ex) {
                context.Logger.LogImportantMessage("Could not compress texture. Required shared lib is missing. {0}", ex.ToString());
                TextureFormat = TextureProcessorOutputFormat.Color;
            }
            catch (Exception ex)
            {
                context.Logger.LogImportantMessage("Could not compress texture {0}", ex.ToString());
                TextureFormat = TextureProcessorOutputFormat.Color;
            }

            if (GenerateMipmaps)
            {
                context.Logger.LogMessage("Generating mipmaps.");
                input.GenerateMipmaps(false);
            }

            return(input);
        }
Exemplo n.º 20
0
        private CompilerResults CompilePlugin(string filepath)
        {
            bool hasCs = System.IO.Directory.GetFiles(filepath).Any(item => FileManager.GetDirectory(item) == "cs");

            if (!hasCs)
            {
                return(null);
            }

            CompilePluginOutput("Attempting to compile plugin : " + filepath);

            //Reference types to force assembly load
            const TextureProcessorOutputFormat texture = TextureProcessorOutputFormat.Color;

            using (new ZipFile()) { }

            texture.ToString();// We do this to eliminate "is never used" warnings

            string whyIsntCompatible = GetWhyIsntCompatible(filepath);

            if (string.IsNullOrEmpty(whyIsntCompatible))
            {
                LoadExternalReferenceList(filepath);

                string output;
                string name = Assembly.GetEntryAssembly().GetName().Name;
                PluginCompiler.Compiler.Path = System.IO.Path.GetTempPath() + name + @"Compiled\";
                string details;
                // need to fix this, or pass it a root folder or something.
                CompilerResults results = PluginCompiler.Compiler.CompilePlugin(
                    filepath,
                    mReferenceListInternal,
                    mReferenceListLoaded,
                    mReferenceListExternal,
                    out details);

                // Make sure a non-null result was returned
                if (results == null)
                {
                    return(null);
                }

                string outputString = "";
                foreach (string s in results.Output)
                {
                    outputString += s + "   ";
                }

                string errorString = "";
                foreach (var s in results.Errors)
                {
                    errorString += s.ToString() + "   ";
                }

                if (!results.Errors.HasErrors && results.CompiledAssembly != null)
                {
                    Type[] types = results.CompiledAssembly.GetTypes();

                    bool foundAnExportedType = false;
                    foreach (Type type in types)
                    {
                        var attributes = type.GetCustomAttributes(typeof(ExportAttribute), true);

                        if (attributes != null && attributes.Length > 0)
                        {
                            foundAnExportedType = true;
                            break;
                        }
                    }

                    if (!foundAnExportedType)
                    {
                        CompilePluginError("Could not find any plugins with the [Export] tag for plugin than " + filepath);
                    }
                }

                string message = null;
                // I don't think we care about this anymore - it just clutters output a ton
                //"Plugin compile output: " + outputString;
                if (!string.IsNullOrEmpty(errorString))
                {
                    message += "Compile errors: " + errorString;
                }

                CompilePluginError(message);
                return(results);
            }
            else
            {
                CompilePluginOutput("Error on plugin in folder " + filepath + " : " + whyIsntCompatible);
            }

            return(null);
        }
Exemplo n.º 21
0
 public FontDescriptionProcessor()
 {
     PremultiplyAlpha = true;
     TextureFormat    = TextureProcessorOutputFormat.Compressed;
 }
Exemplo n.º 22
0
        public override TextureContent Process(TextureContent input, ContentProcessorContext context)
        {
            if (ColorKeyEnabled)
            {
                var replaceColor = System.Drawing.Color.FromArgb(0);
                for (var x = 0; x < input._bitmap.Width; x++)
                {
                    for (var y = 0; y < input._bitmap.Height; y++)
                    {
                        var col = input._bitmap.GetPixel(x, y);

                        if (col.ColorsEqual(ColorKeyColor))
                        {
                            input._bitmap.SetPixel(x, y, replaceColor);
                        }
                    }
                }
            }

            var face = input.Faces[0][0];

            if (ResizeToPowerOfTwo)
            {
                if (!GraphicsUtil.IsPowerOfTwo(face.Width) || !GraphicsUtil.IsPowerOfTwo(face.Height))
                {
                    input.Resize(GraphicsUtil.GetNextPowerOfTwo(face.Width), GraphicsUtil.GetNextPowerOfTwo(face.Height));
                }
            }

            if (PremultiplyAlpha)
            {
                for (var x = 0; x < input._bitmap.Width; x++)
                {
                    for (var y = 0; y < input._bitmap.Height; y++)
                    {
                        var oldCol             = input._bitmap.GetPixel(x, y);
                        var preMultipliedColor = Color.FromNonPremultiplied(oldCol.R, oldCol.G, oldCol.B, oldCol.A);
                        input._bitmap.SetPixel(x, y, System.Drawing.Color.FromArgb(preMultipliedColor.A,
                                                                                   preMultipliedColor.R,
                                                                                   preMultipliedColor.G,
                                                                                   preMultipliedColor.B));
                    }
                }
            }

            // Set the first layer
            input.Faces[0][0].SetPixelData(input._bitmap.GetData());

            if (TextureFormat == TextureProcessorOutputFormat.NoChange)
            {
                return(input);
            }
            try
            {
                if (TextureFormat == TextureProcessorOutputFormat.DXTCompressed ||
                    TextureFormat == TextureProcessorOutputFormat.Compressed)
                {
                    context.Logger.LogMessage("Compressing using {0}", TextureFormat);
                }
                GraphicsUtil.CompressTexture(input, context, GenerateMipmaps, PremultiplyAlpha);
                context.Logger.LogMessage("Compression {0} Suceeded", TextureFormat);
            }
            catch (EntryPointNotFoundException ex) {
                context.Logger.LogImportantMessage("Could not find the entry point to compress the texture", ex.ToString());
                TextureFormat = TextureProcessorOutputFormat.Color;
            }
            catch (DllNotFoundException ex) {
                context.Logger.LogImportantMessage("Could not compress texture. Required shared lib is missing. {0}", ex.ToString());
                TextureFormat = TextureProcessorOutputFormat.Color;
            }
            catch (Exception ex)
            {
                context.Logger.LogImportantMessage("Could not compress texture {0}", ex.ToString());
                TextureFormat = TextureProcessorOutputFormat.Color;
            }

            return(input);
        }
Exemplo n.º 23
0
 public LocalizedFontProcessor()
 {
     PremultiplyAlpha = true;
     TextureFormat    = TextureProcessorOutputFormat.Compressed;
 }
Exemplo n.º 24
0
        /// <summary>
        /// If format is TextureProcessorOutputFormat.Compressed, the appropriate compressed texture format for the target
        /// platform is returned. Otherwise the format is returned unchanged.
        /// </summary>
        /// <param name="format">The supplied texture format.</param>
        /// <param name="platform">The target platform.</param>
        /// <returns>The texture format.</returns>
        public static TextureProcessorOutputFormat GetTextureFormatForPlatform(TextureProcessorOutputFormat format, TargetPlatform platform)
        {
            // Select the default texture compression format for the target platform
            if (format == TextureProcessorOutputFormat.Compressed)
            {
                switch (platform)
                {
                    case TargetPlatform.iOS:
                        format = TextureProcessorOutputFormat.PvrCompressed;
                        break;

                    case TargetPlatform.Android:
                        format = TextureProcessorOutputFormat.Etc1Compressed;
                        break;

                    default:
                        format = TextureProcessorOutputFormat.DxtCompressed;
                        break;
                }
            }

            if (IsCompressedTextureFormat(format))
            {
                // Make sure the target platform supports the selected texture compression format
                switch (platform)
                {
                    case TargetPlatform.iOS:
                        if (format != TextureProcessorOutputFormat.PvrCompressed)
                            throw new PlatformNotSupportedException("iOS platform only supports PVR texture compression");
                        break;

                    case TargetPlatform.Windows:
                    case TargetPlatform.WindowsPhone8:
                    case TargetPlatform.WindowsStoreApp:
                    case TargetPlatform.DesktopGL:
                    case TargetPlatform.MacOSX:
                    case TargetPlatform.NativeClient:
                        if (format != TextureProcessorOutputFormat.DxtCompressed)
                            throw new PlatformNotSupportedException(platform.ToString() + " platform only supports DXT texture compression");
                        break;
                }
            }

            return format;
        }
Exemplo n.º 25
0
        /// <summary>
        /// Compresses TextureContent in a format appropriate to the platform
        /// </summary>
        public static void CompressTexture(GraphicsProfile profile, TextureContent content, TextureProcessorOutputFormat format, ContentProcessorContext context, bool generateMipmaps, bool sharpAlpha)
        {
            format = GetTextureFormatForPlatform(format, context.TargetPlatform);

            // Make sure we're in a floating point format
            content.ConvertBitmapType(typeof(PixelBitmapContent<Vector4>));

            switch (format)
            {
                case TextureProcessorOutputFormat.AtcCompressed:
                    CompressAti(content, generateMipmaps);
                    break;

                case TextureProcessorOutputFormat.Color16Bit:
                    CompressColor16Bit(content, generateMipmaps);
                    break;

                case TextureProcessorOutputFormat.DxtCompressed:
                    CompressDxt(profile, content, generateMipmaps, sharpAlpha);
                    break;

                case TextureProcessorOutputFormat.Etc1Compressed:
                    CompressEtc1(content, generateMipmaps);
                    break;

                case TextureProcessorOutputFormat.PvrCompressed:
                    CompressPvrtc(content, generateMipmaps);
                    break;
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Determines if the texture format requires power-of-two dimensions on the target platform.
        /// </summary>
        /// <param name="format">The texture format.</param>
        /// <param name="platform">The target platform.</param>
        /// <param name="profile">The targeted graphics profile.</param>
        /// <returns>True if the texture format requires power-of-two dimensions on the target platform.</returns>
        public static bool RequiresPowerOfTwo(TextureProcessorOutputFormat format, TargetPlatform platform, GraphicsProfile profile)
        {
            if (format == TextureProcessorOutputFormat.Compressed)
                format = GetTextureFormatForPlatform(format, platform);

            switch (format)
            {
                case TextureProcessorOutputFormat.DxtCompressed:
                    return profile == GraphicsProfile.Reach;

                case TextureProcessorOutputFormat.PvrCompressed:
                case TextureProcessorOutputFormat.Etc1Compressed:
                    return true;
            }

            return false;
        }
Exemplo n.º 27
0
        /// <summary>
        /// Compresses TextureContent in a format appropriate to the platform
        /// </summary>
        public static void CompressTexture(GraphicsProfile profile, TextureContent content, TextureProcessorOutputFormat format, ContentProcessorContext context, bool generateMipmaps, bool sharpAlpha)
        {
            format = GetTextureFormatForPlatform(format, context.TargetPlatform);

            // Make sure we're in a floating point format
            content.ConvertBitmapType(typeof(PixelBitmapContent <Vector4>));

            switch (format)
            {
            case TextureProcessorOutputFormat.AtcCompressed:
                CompressAti(content, generateMipmaps);
                break;

            case TextureProcessorOutputFormat.Color16Bit:
                CompressColor16Bit(content, generateMipmaps);
                break;

            case TextureProcessorOutputFormat.DxtCompressed:
                CompressDxt(profile, content, generateMipmaps, sharpAlpha);
                break;

            case TextureProcessorOutputFormat.Etc1Compressed:
                CompressEtc1(content, generateMipmaps);
                break;

            case TextureProcessorOutputFormat.PvrCompressed:
                CompressPvrtc(content, generateMipmaps);
                break;
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Determines if the given texture format requires equal width and height on the target platform.
        /// </summary>
        /// <param name="format">The texture format.</param>
        /// <param name="platform">The target platform.</param>
        /// <returns>True if the texture format requires equal width and height on the target platform.</returns>
        public static bool RequiresSquare(TextureProcessorOutputFormat format, TargetPlatform platform)
        {
            if (format == TextureProcessorOutputFormat.Compressed)
                format = GetTextureFormatForPlatform(format, platform);

            switch (format)
            {
                case TextureProcessorOutputFormat.PvrCompressed:
                    return true;
            }

            return false;
        }
Exemplo n.º 29
0
        public void BuildLocalizedFont(TargetPlatform platform, TextureProcessorOutputFormat format)
        {
            var context   = new TestProcessorContext(platform, "Localized.xnb");
            var processor = new LocalizedFontProcessor()
            {
                TextureFormat    = format,
                PremultiplyAlpha = true,
            };

            LocalizedFontDescription fontDescription = null;

            using (var fs = File.OpenRead(Path.Combine("Assets", "Fonts", "Localized.spritefont")))
                using (var input = XmlReader.Create(new StreamReader(fs)))
                    fontDescription = IntermediateSerializer.Deserialize <LocalizedFontDescription>(input, "");
            fontDescription.Identity = new ContentIdentity("Localized.spritefont");

            var output = processor.Process(fontDescription, context);

            Assert.IsNotNull(output, "output should not be null");
            Assert.IsNotNull(output.Texture, "output.Texture should not be null");
            var textureType = output.Texture.Faces[0][0].GetType();

            switch (format)
            {
            case TextureProcessorOutputFormat.Color:
                Assert.IsTrue(textureType == typeof(PixelBitmapContent <Color>));
                break;

            case TextureProcessorOutputFormat.Color16Bit:
                Assert.IsTrue(textureType == typeof(PixelBitmapContent <Microsoft.Xna.Framework.Graphics.PackedVector.Bgr565>));
                break;

            case TextureProcessorOutputFormat.Compressed:
                switch (platform)
                {
                case TargetPlatform.Windows:
                case TargetPlatform.DesktopGL:
                    Assert.IsTrue(textureType == typeof(Dxt3BitmapContent));
                    break;

                case TargetPlatform.iOS:
                    Assert.IsTrue(textureType == typeof(PixelBitmapContent <Microsoft.Xna.Framework.Graphics.PackedVector.Bgra4444>));
                    break;

                case TargetPlatform.Android:
                    Assert.IsTrue(textureType == typeof(PixelBitmapContent <Microsoft.Xna.Framework.Graphics.PackedVector.Bgra4444>));
                    break;
                }
                break;

            case TextureProcessorOutputFormat.PvrCompressed:
                // because the font is not power of 2 we should use Brga4444
                Assert.IsTrue(textureType == typeof(PixelBitmapContent <Microsoft.Xna.Framework.Graphics.PackedVector.Bgra4444>));
                break;

            case TextureProcessorOutputFormat.Etc1Compressed:
                // because the font has Alpha we should use Brga4444
                Assert.IsTrue(textureType == typeof(PixelBitmapContent <Microsoft.Xna.Framework.Graphics.PackedVector.Bgra4444>));
                break;

            default:
                Assert.Fail("Test not written for " + format);
                break;
            }
        }