// MonoGame - Copyright (C) The MonoGame Team // This file is subject to the terms and conditions defined in // file 'LICENSE.txt', which is part of this source code package. using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework.Content.Pipeline.Processors; namespace Microsoft.Xna.Framework.Content.Pipeline.Graphics { public abstract class TextureProfile { private static readonly LoadedTypeCollection _profiles = new LoadedTypeCollection(); /// /// Find the profile for this target platform. /// /// The platform target for textures. /// public static TextureProfile ForPlatform(TargetPlatform platform) { var profile = _profiles.FirstOrDefault(h => h.Supports(platform)); if (profile != null) return profile; throw new PipelineException("There is no supported texture profile for the '" + platform + "' platform!"); } /// /// Returns true if this profile supports texture processing for this platform. /// public abstract bool Supports(TargetPlatform platform); /// /// Determines if the texture format will require power-of-two dimensions and/or equal width and height. /// /// The processor context. /// The desired texture format. /// True if the texture format requires power-of-two dimensions. /// True if the texture format requires equal width and height. /// True if the texture format requires power-of-two dimensions. public abstract void Requirements(ContentProcessorContext context, TextureProcessorOutputFormat format, out bool requiresPowerOfTwo, out bool requiresSquare); /// /// Performs conversion of the texture content to the correct format. /// /// The processor context. /// The content to be compressed. /// The user requested format for compression. /// If the texture has represents a sprite font, i.e. is greyscale and has sharp black/white contrast. 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)); return; } // Handle this common compression format. if (format == TextureProcessorOutputFormat.Color16Bit) { GraphicsUtil.CompressColor16Bit(context, 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 ex; } catch (DllNotFoundException ex) { context.Logger.LogImportantMessage("Could not compress texture. Required shared lib is missing. " + ex.ToString()); throw ex; } catch (Exception ex) { context.Logger.LogImportantMessage("Could not convert texture. " + ex.ToString()); throw ex; } } protected abstract void PlatformCompressTexture(ContentProcessorContext context, TextureContent content, TextureProcessorOutputFormat format, bool isSpriteFont); } }