/// <summary> /// Utility function to check that the texture size is supported on the graphics platform for the provided graphics profile. /// </summary> /// <param name="textureFormat">The desired type of format for the output texture</param> /// <param name="platform">The graphics platform</param> /// <param name="graphicsProfile">The graphics profile</param> /// <param name="textureSizeInput">The texture size input.</param> /// <param name="textureSizeRequested">The texture size requested.</param> /// <param name="generateMipmaps">Indicate if mipmaps should be generated for the output texture</param> /// <param name="logger">The logger.</param> /// <returns>true if the texture size is supported</returns> /// <exception cref="System.ArgumentOutOfRangeException">graphicsProfile</exception> public static Size2 FindBestTextureSize(TextureFormat textureFormat, GraphicsPlatform platform, GraphicsProfile graphicsProfile, Size2 textureSizeInput, Size2 textureSizeRequested, bool generateMipmaps, ILogger logger) { var textureSize = textureSizeRequested; // compressed DDS files has to have a size multiple of 4. if (platform == GraphicsPlatform.Direct3D11 && textureFormat == TextureFormat.Compressed && ((textureSizeRequested.Width % 4) != 0 || (textureSizeRequested.Height % 4) != 0)) { textureSize.Width = unchecked((int)(((uint)(textureSizeRequested.Width + 3)) & ~(uint)3)); textureSize.Height = unchecked((int)(((uint)(textureSizeRequested.Height + 3)) & ~(uint)3)); } var maxTextureSize = 0; // determine if the desired size if valid depending on the graphics profile switch (graphicsProfile) { case GraphicsProfile.Level_9_1: case GraphicsProfile.Level_9_2: case GraphicsProfile.Level_9_3: if (generateMipmaps && (!IsPowerOfTwo(textureSize.Width) || !IsPowerOfTwo(textureSize.Height))) { // TODO: TEMPORARY SETUP A MAX TEXTURE OF 1024. THIS SHOULD BE SPECIFIED DONE IN THE ASSET INSTEAD textureSize.Width = Math.Min(MathUtil.NextPowerOfTwo(textureSize.Width), 1024); textureSize.Height = Math.Min(MathUtil.NextPowerOfTwo(textureSize.Height), 1024); logger.Warning("Graphic profiles 9.1/9.2/9.3 do not support mipmaps with textures that are not power of 2. Asset is automatically resized to " + textureSize); } maxTextureSize = graphicsProfile >= GraphicsProfile.Level_9_3 ? 4096 : 2048; break; case GraphicsProfile.Level_10_0: case GraphicsProfile.Level_10_1: maxTextureSize = 8192; break; case GraphicsProfile.Level_11_0: case GraphicsProfile.Level_11_1: case GraphicsProfile.Level_11_2: maxTextureSize = 16384; break; default: throw new ArgumentOutOfRangeException("graphicsProfile"); } if (textureSize.Width > maxTextureSize || textureSize.Height > maxTextureSize) { logger.Error("Graphic profile {0} do not support texture with resolution {2} x {3} because it is larger than {1}. " + "Please reduce texture size or upgrade your graphic profile.", graphicsProfile, maxTextureSize, textureSize.Width, textureSize.Height); return new Size2(Math.Min(textureSize.Width, maxTextureSize), Math.Min(textureSize.Height, maxTextureSize)); } return textureSize; }
public ImportParameters(TextureConvertParameters textureParameters) { var asset = textureParameters.Texture; IsSRgb = asset.SRgb; DesiredSize = new Size2((int)asset.Width, (int)asset.Height); IsSizeInPercentage = asset.IsSizeInPercentage; DesiredFormat = asset.Format; DesiredAlpha = asset.Alpha; TextureHint = asset.Hint; GenerateMipmaps = asset.GenerateMipmaps; PremultiplyAlpha = asset.PremultiplyAlpha; ColorKeyColor = asset.ColorKeyColor; ColorKeyEnabled = asset.ColorKeyEnabled; TextureQuality = textureParameters.TextureQuality; GraphicsPlatform = textureParameters.GraphicsPlatform; GraphicsProfile = textureParameters.GraphicsProfile; Platform = textureParameters.Platform; }
public ImportParameters(TextureConvertParameters textureParameters) { var asset = textureParameters.Texture; // Compute SRgb usage // If Texture is in auto mode, use the global settings, else use the settings overridden by the texture asset. IsSRgb = textureParameters.Texture.ColorSpace.ToColorSpace(textureParameters.ColorSpace, asset.Hint) == ColorSpace.Linear; DesiredSize = new Size2((int)asset.Width, (int)asset.Height); IsSizeInPercentage = asset.IsSizeInPercentage; DesiredFormat = asset.Format; DesiredAlpha = asset.Alpha; TextureHint = asset.Hint; GenerateMipmaps = asset.GenerateMipmaps; PremultiplyAlpha = asset.PremultiplyAlpha; ColorKeyColor = asset.ColorKeyColor; ColorKeyEnabled = asset.ColorKeyEnabled; TextureQuality = textureParameters.TextureQuality; GraphicsPlatform = textureParameters.GraphicsPlatform; GraphicsProfile = textureParameters.GraphicsProfile; Platform = textureParameters.Platform; }
public ImportParameters(SpriteSheetAssetCompiler.SpriteSheetParameters spriteSheetParameters) { var asset = spriteSheetParameters.SheetAsset; // Compute SRgb usage // If Texture is in auto mode, use the global settings, else use the settings overridden by the texture asset. IsSRgb = asset.ColorSpace.ToColorSpace(spriteSheetParameters.ColorSpace, TextureHint.Color) == ColorSpace.Linear; DesiredSize = new Size2(100, 100); IsSizeInPercentage = true; DesiredFormat = asset.Format; DesiredAlpha = asset.Alpha; TextureHint = TextureHint.Color; GenerateMipmaps = asset.GenerateMipmaps; PremultiplyAlpha = asset.PremultiplyAlpha; ColorKeyColor = asset.ColorKeyColor; ColorKeyEnabled = asset.ColorKeyEnabled; TextureQuality = spriteSheetParameters.TextureQuality; GraphicsPlatform = spriteSheetParameters.GraphicsPlatform; GraphicsProfile = spriteSheetParameters.GraphicsProfile; Platform = spriteSheetParameters.Platform; }
public MyScreenCanvas(GraphicsPlatform platform, int horizontalPageNum, int verticalPageNum, int left, int top, int width, int height) { //platform specific Win32 //1. this.platform = platform; this.pageNumFlags = (horizontalPageNum << 8) | verticalPageNum; //2. dimension this.left = left; this.top = top; this.right = left + width; this.bottom = top + height; CreateGraphicsFromNativeHdc(width, height); //------------------------------------------------------- currentClipRect = new System.Drawing.Rectangle(0, 0, width, height); var fontInfo = platform.GetFont("tahoma", 10, FontStyle.Regular); this.CurrentFont = defaultFont = fontInfo.ResolvedFont; this.CurrentTextColor = Color.Black; internalPen = new System.Drawing.Pen(System.Drawing.Color.Black); internalSolidBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); #if DEBUG debug_canvas_id = dbug_canvasCount + 1; dbug_canvasCount += 1; #endif this.StrokeWidth = 1; }
/// <summary> /// Utility function to check that the texture size is supported on the graphics platform for the provided graphics profile. /// </summary> /// <param name="textureFormat">The desired type of format for the output texture</param> /// <param name="textureSize">The size of the texture</param> /// <param name="graphicsProfile">The graphics profile</param> /// <param name="platform">The graphics platform</param> /// <param name="generateMipmaps">Indicate if mipmaps should be generated for the output texture</param> /// <param name="logger">The logger used to log messages</param> /// <returns>true if the texture size is supported</returns> public static bool TextureSizeSupported(TextureFormat textureFormat, GraphicsPlatform platform, GraphicsProfile graphicsProfile, Int2 textureSize, bool generateMipmaps, Logger logger) { // compressed DDS files has to have a size multiple of 4. if (platform == GraphicsPlatform.Direct3D11 && textureFormat == TextureFormat.Compressed && ((textureSize.X % 4) != 0 || (textureSize.Y % 4) != 0)) { logger.Error("DDS compression does not support texture files that do not have a size multiple of 4." + "Please disable texture compression or adjust your texture size to multiple of 4."); return(false); } // determine if the desired size if valid depending on the graphics profile switch (graphicsProfile) { case GraphicsProfile.Level_9_1: case GraphicsProfile.Level_9_2: case GraphicsProfile.Level_9_3: if (generateMipmaps && (!IsPowerOfTwo(textureSize.Y) || !IsPowerOfTwo(textureSize.X))) { logger.Error("Graphic profiles 9.1/9.2/9.3 do not support mipmaps with textures that are not power of 2. " + "Please disable mipmap generation, modify your texture resolution or upgrade your graphic profile to a value >= 10.0."); return(false); } break; case GraphicsProfile.Level_10_0: case GraphicsProfile.Level_10_1: case GraphicsProfile.Level_11_0: case GraphicsProfile.Level_11_1: break; default: throw new ArgumentOutOfRangeException("graphicsProfile"); } return(true); }
/// <summary> /// Ignore the test on the given graphic platform /// </summary> public static void IgnoreGraphicPlatform(GraphicsPlatform platform) { Skip.If(GraphicsDevice.Platform == platform, $"This test is not valid for the '{platform}' graphic platform. It has been ignored"); }
public LayoutVisitor(GraphicsPlatform gfxPlatform) { this.gfxPlatform = gfxPlatform; }
public Form1() { InitializeComponent(); GraphicsPlatform.RegisterGlobalService(SkiaGraphicsService.Instance); skglControl1_SizeChanged(null, null); }
/// <summary> /// Ignore the test on the given graphic platform /// </summary> public static void IgnoreGraphicPlatform(GraphicsPlatform platform) { if (GraphicsDevice.Platform == platform) Assert.Ignore("This test is not valid for the '{0}' graphic platform. It has been ignored", platform); }
/// <summary> /// Creates a rounded rectangle using the specified corner radius /// </summary> /// <param name="rect">Rectangle to round</param> /// <param name="nwRadius">Radius of the north east corner</param> /// <param name="neRadius">Radius of the north west corner</param> /// <param name="seRadius">Radius of the south east corner</param> /// <param name="swRadius">Radius of the south west corner</param> /// <returns>GraphicsPath with the lines of the rounded rectangle ready to be painted</returns> public static GraphicsPath GetRoundRect(GraphicsPlatform p, RectangleF rect, float nwRadius, float neRadius, float seRadius, float swRadius) { // NW-----NE // | | // | | // SW-----SE var path = p.CreateGraphicsPath(); nwRadius *= 2; neRadius *= 2; seRadius *= 2; swRadius *= 2; //NW ---- NE path.AddLine(rect.X + nwRadius, rect.Y, rect.Right - neRadius, rect.Y); //NE Arc if (neRadius > 0f) { path.AddArc( RectangleF.FromLTRB(rect.Right - neRadius, rect.Top, rect.Right, rect.Top + neRadius), -90, 90); } // NE // | // SE path.AddLine(rect.Right, rect.Top + neRadius, rect.Right, rect.Bottom - seRadius); //SE Arc if (seRadius > 0f) { path.AddArc( RectangleF.FromLTRB(rect.Right - seRadius, rect.Bottom - seRadius, rect.Right, rect.Bottom), 0, 90); } // SW --- SE path.AddLine(rect.Right - seRadius, rect.Bottom, rect.Left + swRadius, rect.Bottom); //SW Arc if (swRadius > 0f) { path.AddArc( RectangleF.FromLTRB(rect.Left, rect.Bottom - swRadius, rect.Left + swRadius, rect.Bottom), 90, 90); } // NW // | // SW path.AddLine(rect.Left, rect.Bottom - swRadius, rect.Left, rect.Top + nwRadius); //NW Arc if (nwRadius > 0f) { path.AddArc( RectangleF.FromLTRB(rect.Left, rect.Top, rect.Left + nwRadius, rect.Top + nwRadius), 180, 90); } path.CloseFigure(); return(path); }
public ImportParameters(SpriteSheetAssetCompiler.SpriteSheetParameters spriteSheetParameters) { var asset = spriteSheetParameters.SheetAsset; IsSRgb = asset.SRgb; DesiredSize = new Size2(100, 100); IsSizeInPercentage = true; DesiredFormat = asset.Format; DesiredAlpha = asset.Alpha; TextureHint = TextureHint.Color; GenerateMipmaps = asset.GenerateMipmaps; PremultiplyAlpha = asset.PremultiplyAlpha; ColorKeyColor = asset.ColorKeyColor; ColorKeyEnabled = asset.ColorKeyEnabled; TextureQuality = spriteSheetParameters.TextureQuality; GraphicsPlatform = spriteSheetParameters.GraphicsPlatform; GraphicsProfile = spriteSheetParameters.GraphicsProfile; Platform = spriteSheetParameters.Platform; }
//----------- //if this is custom box then must implement these methods public virtual void CustomRecomputedValue(CssBox containingBlock, GraphicsPlatform gfxPlatform) { throw new NotImplementedException(); }
/// <summary> /// Ignore the test on any other graphic platform than the provided one. /// </summary> public static void RequireGraphicPlatform(GraphicsPlatform platform) { Skip.If(GraphicsDevice.Platform != platform, $"This test requires the '{platform}' platform. It has been ignored"); }
/// <summary> /// Determine the output format of the texture depending on the platform and asset properties. /// </summary> /// <param name="parameters">The conversion request parameters</param> /// <param name="graphicsPlatform">The graphics platform</param> /// <param name="graphicsProfile">The graphics profile</param> /// <param name="imageSize">The texture output size</param> /// <param name="inputImageFormat">The pixel format of the input image</param> /// <param name="textureAsset">The texture asset</param> /// <returns>The pixel format to use as output</returns> public static PixelFormat DetermineOutputFormat(TextureAsset textureAsset, TextureConvertParameters parameters, Int2 imageSize, PixelFormat inputImageFormat, PlatformType platform, GraphicsPlatform graphicsPlatform, GraphicsProfile graphicsProfile) { if (textureAsset.SRgb && ((int)parameters.GraphicsProfile < (int)GraphicsProfile.Level_9_2 && parameters.GraphicsPlatform != GraphicsPlatform.Direct3D11)) throw new NotSupportedException("sRGB is not supported on OpenGl profile level {0}".ToFormat(parameters.GraphicsProfile)); var hint = textureAsset.Hint; // Default output format var outputFormat = PixelFormat.R8G8B8A8_UNorm; switch (textureAsset.Format) { case TextureFormat.Compressed: switch (parameters.Platform) { case PlatformType.Android: if (inputImageFormat.IsHDR()) { outputFormat = inputImageFormat; } else if (textureAsset.SRgb) { outputFormat = PixelFormat.R8G8B8A8_UNorm_SRgb; } else { switch (graphicsProfile) { case GraphicsProfile.Level_9_1: case GraphicsProfile.Level_9_2: case GraphicsProfile.Level_9_3: outputFormat = textureAsset.Alpha == AlphaFormat.None ? PixelFormat.ETC1 : PixelFormat.R8G8B8A8_UNorm; break; case GraphicsProfile.Level_10_0: case GraphicsProfile.Level_10_1: case GraphicsProfile.Level_11_0: case GraphicsProfile.Level_11_1: case GraphicsProfile.Level_11_2: // GLES3.0 starting from Level_10_0, this profile enables ETC2 compression on Android outputFormat = textureAsset.Alpha == AlphaFormat.None ? PixelFormat.ETC1 : PixelFormat.ETC2_RGBA; break; default: throw new ArgumentOutOfRangeException("graphicsProfile"); } } break; case PlatformType.iOS: // PVRTC works only for square POT textures if (inputImageFormat.IsHDR()) { outputFormat = inputImageFormat; } else if (textureAsset.SRgb) { outputFormat = PixelFormat.R8G8B8A8_UNorm_SRgb; } else if (SupportPVRTC(imageSize)) { switch (textureAsset.Alpha) { case AlphaFormat.None: // DXT1 handles 1-bit alpha channel outputFormat = PixelFormat.PVRTC_4bpp_RGB; break; case AlphaFormat.Mask: // DXT1 handles 1-bit alpha channel // TODO: Not sure about the equivalent here? outputFormat = PixelFormat.PVRTC_4bpp_RGBA; break; case AlphaFormat.Explicit: case AlphaFormat.Interpolated: // DXT3 is good at sharp alpha transitions // TODO: Not sure about the equivalent here? outputFormat = PixelFormat.PVRTC_4bpp_RGBA; break; default: throw new ArgumentOutOfRangeException(); } } else { outputFormat = PixelFormat.R8G8B8A8_UNorm; } break; case PlatformType.Windows: case PlatformType.WindowsPhone: case PlatformType.WindowsStore: switch (parameters.GraphicsPlatform) { case GraphicsPlatform.Direct3D11: // https://msdn.microsoft.com/en-us/library/windows/desktop/hh308955%28v=vs.85%29.aspx // http://www.reedbeta.com/blog/2012/02/12/understanding-bcn-texture-compression-formats/ // ---------------------------------------------- ---------------------------------------------------- --- --------------------------------- // Source data Minimum required data compression resolution Recommended format Minimum supported feature level // ---------------------------------------------- ---------------------------------------------------- --- --------------------------------- // Three-channel color with alpha channel Three color channels (5 bits:6 bits:5 bits), with 0 or 1 bit(s) of alpha BC1 Direct3D 9.1 (color maps, cutout color maps - 1 bit alpha, normal maps if memory is tight) // Three-channel color with alpha channel Three color channels (5 bits:6 bits:5 bits), with 4 bits of alpha BC2 Direct3D 9.1 (idem) // Three-channel color with alpha channel Three color channels (5 bits:6 bits:5 bits) with 8 bits of alpha BC3 Direct3D 9.1 (color maps with alpha, packing color and mono maps together) // One-channel color One color channel (8 bits) BC4 Direct3D 10 (Height maps, gloss maps, font atlases, any gray scales image) // Two-channel color Two color channels (8 bits:8 bits) BC5 Direct3D 10 (Tangent space normal maps) // Three-channel high dynamic range (HDR) color Three color channels (16 bits:16 bits:16 bits) in "half" floating point* BC6H Direct3D 11 (HDR images) // Three-channel color, alpha channel optional Three color channels (4 to 7 bits per channel) with 0 to 8 bits of alpha BC7 Direct3D 11 (High quality color maps, Color maps with full alpha) switch (textureAsset.Alpha) { case AlphaFormat.None: case AlphaFormat.Mask: // DXT1 handles 1-bit alpha channel outputFormat = textureAsset.SRgb ? PixelFormat.BC1_UNorm_SRgb : PixelFormat.BC1_UNorm; break; case AlphaFormat.Explicit: // DXT3 is good at sharp alpha transitions outputFormat = textureAsset.SRgb ? PixelFormat.BC2_UNorm_SRgb : PixelFormat.BC2_UNorm; break; case AlphaFormat.Interpolated: // DXT5 is good at alpha gradients outputFormat = textureAsset.SRgb ? PixelFormat.BC3_UNorm_SRgb : PixelFormat.BC3_UNorm; break; default: throw new ArgumentOutOfRangeException(); } // Overrides the format when profile is >= 10.0 // Support some specific optimized formats based on the hint or input type if (parameters.GraphicsProfile >= GraphicsProfile.Level_10_0) { if (hint == TextureHint.NormalMap) { outputFormat = PixelFormat.BC5_SNorm; } else if (hint == TextureHint.Grayscale) { outputFormat = PixelFormat.BC4_UNorm; } else if (inputImageFormat.IsHDR()) { // BC6H is too slow to compile //outputFormat = parameters.GraphicsProfile >= GraphicsProfile.Level_11_0 && textureAsset.Alpha == AlphaFormat.None ? PixelFormat.BC6H_Uf16 : inputImageFormat; outputFormat = inputImageFormat; } // TODO support the BC6/BC7 but they are so slow to compile that we can't use them right now } break; case GraphicsPlatform.OpenGLES: // OpenGLES on Windows if (inputImageFormat.IsHDR()) { outputFormat = inputImageFormat; } else if (textureAsset.SRgb) { outputFormat = PixelFormat.R8G8B8A8_UNorm_SRgb; } else { switch (graphicsProfile) { case GraphicsProfile.Level_9_1: case GraphicsProfile.Level_9_2: case GraphicsProfile.Level_9_3: outputFormat = textureAsset.Alpha == AlphaFormat.None ? PixelFormat.ETC1 : PixelFormat.R8G8B8A8_UNorm; break; case GraphicsProfile.Level_10_0: case GraphicsProfile.Level_10_1: case GraphicsProfile.Level_11_0: case GraphicsProfile.Level_11_1: case GraphicsProfile.Level_11_2: // GLES3.0 starting from Level_10_0, this profile enables ETC2 compression on Android outputFormat = textureAsset.Alpha == AlphaFormat.None ? PixelFormat.ETC1 : PixelFormat.ETC2_RGBA; break; default: throw new ArgumentOutOfRangeException("graphicsProfile"); } } break; default: // OpenGL on Windows // TODO: Need to handle OpenGL Desktop compression outputFormat = textureAsset.SRgb ? PixelFormat.R8G8B8A8_UNorm_SRgb : PixelFormat.R8G8B8A8_UNorm; break; } break; default: throw new NotSupportedException("Platform " + parameters.Platform + " is not supported by TextureTool"); } break; case TextureFormat.Color16Bits: if (textureAsset.SRgb) { outputFormat = PixelFormat.R8G8B8A8_UNorm_SRgb; } else { if (textureAsset.Alpha == AlphaFormat.None) { outputFormat = PixelFormat.B5G6R5_UNorm; } else if (textureAsset.Alpha == AlphaFormat.Mask) { outputFormat = PixelFormat.B5G5R5A1_UNorm; } } break; case TextureFormat.Color32Bits: if (textureAsset.SRgb) { outputFormat = PixelFormat.R8G8B8A8_UNorm_SRgb; } break; case TextureFormat.AsIs: outputFormat = inputImageFormat; break; default: throw new ArgumentOutOfRangeException(); } return outputFormat; }
/// <summary> /// Determine the output format of the texture depending on the platform and asset properties. /// </summary> /// <param name="parameters">The conversion request parameters</param> /// <param name="graphicsPlatform">The graphics platform</param> /// <param name="graphicsProfile">The graphics profile</param> /// <param name="imageSize">The texture output size</param> /// <param name="inputImageFormat">The pixel format of the input image</param> /// <param name="textureAsset">The texture asset</param> /// <returns>The pixel format to use as output</returns> public static PixelFormat DetermineOutputFormat(TextureAsset textureAsset, TextureConvertParameters parameters, Int2 imageSize, PixelFormat inputImageFormat, PlatformType platform, GraphicsPlatform graphicsPlatform, GraphicsProfile graphicsProfile) { if (textureAsset.SRgb && ((int)parameters.GraphicsProfile < (int)GraphicsProfile.Level_9_2 && parameters.GraphicsPlatform != GraphicsPlatform.Direct3D11)) { throw new NotSupportedException("sRGB is not supported on OpenGl profile level {0}".ToFormat(parameters.GraphicsProfile)); } var hint = textureAsset.Hint; // Default output format var outputFormat = PixelFormat.R8G8B8A8_UNorm; switch (textureAsset.Format) { case TextureFormat.Compressed: switch (parameters.Platform) { case PlatformType.Android: if (inputImageFormat.IsHDR()) { outputFormat = inputImageFormat; } else if (textureAsset.SRgb) { outputFormat = PixelFormat.R8G8B8A8_UNorm_SRgb; } else { switch (graphicsProfile) { case GraphicsProfile.Level_9_1: case GraphicsProfile.Level_9_2: case GraphicsProfile.Level_9_3: outputFormat = textureAsset.Alpha == AlphaFormat.None ? PixelFormat.ETC1 : PixelFormat.R8G8B8A8_UNorm; break; case GraphicsProfile.Level_10_0: case GraphicsProfile.Level_10_1: case GraphicsProfile.Level_11_0: case GraphicsProfile.Level_11_1: case GraphicsProfile.Level_11_2: // GLES3.0 starting from Level_10_0, this profile enables ETC2 compression on Android outputFormat = textureAsset.Alpha == AlphaFormat.None ? PixelFormat.ETC1 : PixelFormat.ETC2_RGBA; break; default: throw new ArgumentOutOfRangeException("graphicsProfile"); } } break; case PlatformType.iOS: // PVRTC works only for square POT textures if (textureAsset.SRgb) { outputFormat = PixelFormat.R8G8B8A8_UNorm_SRgb; } else if (SupportPVRTC(imageSize)) { switch (textureAsset.Alpha) { case AlphaFormat.None: // DXT1 handles 1-bit alpha channel outputFormat = PixelFormat.PVRTC_4bpp_RGB; break; case AlphaFormat.Mask: // DXT1 handles 1-bit alpha channel // TODO: Not sure about the equivalent here? outputFormat = PixelFormat.PVRTC_4bpp_RGBA; break; case AlphaFormat.Explicit: case AlphaFormat.Interpolated: // DXT3 is good at sharp alpha transitions // TODO: Not sure about the equivalent here? outputFormat = PixelFormat.PVRTC_4bpp_RGBA; break; default: throw new ArgumentOutOfRangeException(); } } else { outputFormat = PixelFormat.R8G8B8A8_UNorm; } break; case PlatformType.Windows: case PlatformType.WindowsPhone: case PlatformType.WindowsStore: switch (parameters.GraphicsPlatform) { case GraphicsPlatform.Direct3D11: // https://msdn.microsoft.com/en-us/library/windows/desktop/hh308955%28v=vs.85%29.aspx // http://www.reedbeta.com/blog/2012/02/12/understanding-bcn-texture-compression-formats/ // ---------------------------------------------- ---------------------------------------------------- --- --------------------------------- // Source data Minimum required data compression resolution Recommended format Minimum supported feature level // ---------------------------------------------- ---------------------------------------------------- --- --------------------------------- // Three-channel color with alpha channel Three color channels (5 bits:6 bits:5 bits), with 0 or 1 bit(s) of alpha BC1 Direct3D 9.1 (color maps, cutout color maps - 1 bit alpha, normal maps if memory is tight) // Three-channel color with alpha channel Three color channels (5 bits:6 bits:5 bits), with 4 bits of alpha BC2 Direct3D 9.1 (idem) // Three-channel color with alpha channel Three color channels (5 bits:6 bits:5 bits) with 8 bits of alpha BC3 Direct3D 9.1 (color maps with alpha, packing color and mono maps together) // One-channel color One color channel (8 bits) BC4 Direct3D 10 (Height maps, gloss maps, font atlases, any gray scales image) // Two-channel color Two color channels (8 bits:8 bits) BC5 Direct3D 10 (Tangent space normal maps) // Three-channel high dynamic range (HDR) color Three color channels (16 bits:16 bits:16 bits) in "half" floating point* BC6H Direct3D 11 (HDR images) // Three-channel color, alpha channel optional Three color channels (4 to 7 bits per channel) with 0 to 8 bits of alpha BC7 Direct3D 11 (High quality color maps, Color maps with full alpha) switch (textureAsset.Alpha) { case AlphaFormat.None: case AlphaFormat.Mask: // DXT1 handles 1-bit alpha channel outputFormat = textureAsset.SRgb ? PixelFormat.BC1_UNorm_SRgb : PixelFormat.BC1_UNorm; break; case AlphaFormat.Explicit: // DXT3 is good at sharp alpha transitions outputFormat = textureAsset.SRgb ? PixelFormat.BC2_UNorm_SRgb : PixelFormat.BC2_UNorm; break; case AlphaFormat.Interpolated: // DXT5 is good at alpha gradients outputFormat = textureAsset.SRgb ? PixelFormat.BC3_UNorm_SRgb : PixelFormat.BC3_UNorm; break; default: throw new ArgumentOutOfRangeException(); } // Overrides the format when profile is >= 10.0 // Support some specific optimized formats based on the hint or input type if (parameters.GraphicsProfile >= GraphicsProfile.Level_10_0) { if (hint == TextureHint.NormalMap) { outputFormat = PixelFormat.BC5_SNorm; } else if (hint == TextureHint.Grayscale) { outputFormat = PixelFormat.BC4_UNorm; } else if (inputImageFormat.IsHDR()) { // BC6H is too slow to compile //outputFormat = parameters.GraphicsProfile >= GraphicsProfile.Level_11_0 && textureAsset.Alpha == AlphaFormat.None ? PixelFormat.BC6H_Uf16 : inputImageFormat; outputFormat = inputImageFormat; } // TODO support the BC6/BC7 but they are so slow to compile that we can't use them right now } break; case GraphicsPlatform.OpenGLES: // OpenGLES on Windows if (inputImageFormat.IsHDR()) { outputFormat = inputImageFormat; } else if (textureAsset.SRgb) { outputFormat = PixelFormat.R8G8B8A8_UNorm_SRgb; } else { switch (graphicsProfile) { case GraphicsProfile.Level_9_1: case GraphicsProfile.Level_9_2: case GraphicsProfile.Level_9_3: outputFormat = textureAsset.Alpha == AlphaFormat.None ? PixelFormat.ETC1 : PixelFormat.R8G8B8A8_UNorm; break; case GraphicsProfile.Level_10_0: case GraphicsProfile.Level_10_1: case GraphicsProfile.Level_11_0: case GraphicsProfile.Level_11_1: case GraphicsProfile.Level_11_2: // GLES3.0 starting from Level_10_0, this profile enables ETC2 compression on Android outputFormat = textureAsset.Alpha == AlphaFormat.None ? PixelFormat.ETC1 : PixelFormat.ETC2_RGBA; break; default: throw new ArgumentOutOfRangeException("graphicsProfile"); } } break; default: // OpenGL on Windows // TODO: Need to handle OpenGL Desktop compression outputFormat = textureAsset.SRgb ? PixelFormat.R8G8B8A8_UNorm_SRgb : PixelFormat.R8G8B8A8_UNorm; break; } break; default: throw new NotSupportedException("Platform " + parameters.Platform + " is not supported by TextureTool"); } break; case TextureFormat.Color16Bits: if (textureAsset.SRgb) { outputFormat = PixelFormat.R8G8B8A8_UNorm_SRgb; } else { if (textureAsset.Alpha == AlphaFormat.None) { outputFormat = PixelFormat.B5G6R5_UNorm; } else if (textureAsset.Alpha == AlphaFormat.Mask) { outputFormat = PixelFormat.B5G5R5A1_UNorm; } } break; case TextureFormat.Color32Bits: if (textureAsset.SRgb) { outputFormat = PixelFormat.R8G8B8A8_UNorm_SRgb; } break; case TextureFormat.AsIs: outputFormat = inputImageFormat; break; default: throw new ArgumentOutOfRangeException(); } return(outputFormat); }
/// <summary> /// Determine the output format of the texture depending on the platform and asset properties. /// </summary> /// <param name="textureFormat">The desired texture output format type</param> /// <param name="alphaFormat">The alpha format desired in output</param> /// <param name="platform">The platform type</param> /// <param name="graphicsPlatform">The graphics platform</param> /// <param name="graphicsProfile">The graphics profile</param> /// <param name="imageSize">The texture output size</param> /// <param name="inputImageFormat">The pixel format of the input image</param> /// <returns>The pixel format to use as output</returns> public static PixelFormat DetermineOutputFormat(TextureFormat textureFormat, AlphaFormat alphaFormat, PlatformType platform, GraphicsPlatform graphicsPlatform, GraphicsProfile graphicsProfile, Int2 imageSize, PixelFormat inputImageFormat) { PixelFormat outputFormat; switch (textureFormat) { case TextureFormat.Compressed: switch (platform) { case PlatformType.Android: switch (graphicsProfile) { case GraphicsProfile.Level_9_1: case GraphicsProfile.Level_9_2: case GraphicsProfile.Level_9_3: outputFormat = alphaFormat == AlphaFormat.None ? PixelFormat.ETC1 : PixelFormat.R8G8B8A8_UNorm; break; case GraphicsProfile.Level_10_0: case GraphicsProfile.Level_10_1: case GraphicsProfile.Level_11_0: case GraphicsProfile.Level_11_1: case GraphicsProfile.Level_11_2: // GLES3.0 starting from Level_10_0, this profile enables ETC2 compression on Android outputFormat = alphaFormat == AlphaFormat.None ? PixelFormat.ETC1 : PixelFormat.ETC2_RGBA; break; default: throw new ArgumentOutOfRangeException("graphicsProfile"); } break; case PlatformType.iOS: // PVRTC works only for square POT textures if (SupportPVRTC(imageSize)) { switch (alphaFormat) { case AlphaFormat.None: // DXT1 handles 1-bit alpha channel outputFormat = PixelFormat.PVRTC_4bpp_RGB; break; case AlphaFormat.Mask: // DXT1 handles 1-bit alpha channel // TODO: Not sure about the equivalent here? outputFormat = PixelFormat.PVRTC_4bpp_RGBA; break; case AlphaFormat.Explicit: case AlphaFormat.Interpolated: // DXT3 is good at sharp alpha transitions // TODO: Not sure about the equivalent here? outputFormat = PixelFormat.PVRTC_4bpp_RGBA; break; default: throw new ArgumentOutOfRangeException(); } } else { outputFormat = PixelFormat.R8G8B8A8_UNorm; } break; case PlatformType.Windows: case PlatformType.WindowsPhone: case PlatformType.WindowsStore: switch (graphicsPlatform) { case GraphicsPlatform.Direct3D11: switch (alphaFormat) { case AlphaFormat.None: case AlphaFormat.Mask: // DXT1 handles 1-bit alpha channel outputFormat = PixelFormat.BC1_UNorm; break; case AlphaFormat.Explicit: // DXT3 is good at sharp alpha transitions outputFormat = PixelFormat.BC2_UNorm; break; case AlphaFormat.Interpolated: // DXT5 is good at alpha gradients outputFormat = PixelFormat.BC3_UNorm; break; default: throw new ArgumentOutOfRangeException(); } break; case GraphicsPlatform.OpenGLES: // OpenGLES on Windows switch (graphicsProfile) { case GraphicsProfile.Level_9_1: case GraphicsProfile.Level_9_2: case GraphicsProfile.Level_9_3: outputFormat = alphaFormat == AlphaFormat.None ? PixelFormat.ETC1 : PixelFormat.R8G8B8A8_UNorm; break; case GraphicsProfile.Level_10_0: case GraphicsProfile.Level_10_1: case GraphicsProfile.Level_11_0: case GraphicsProfile.Level_11_1: case GraphicsProfile.Level_11_2: // GLES3.0 starting from Level_10_0, this profile enables ETC2 compression on Android outputFormat = alphaFormat == AlphaFormat.None ? PixelFormat.ETC1 : PixelFormat.ETC2_RGBA; break; default: throw new ArgumentOutOfRangeException("graphicsProfile"); } break; default: // OpenGL on Windows // TODO: Need to handle OpenGL Desktop compression outputFormat = PixelFormat.R8G8B8A8_UNorm; break; } break; default: throw new NotSupportedException("Platform " + platform + " is not supported by TextureTool"); } break; case TextureFormat.HighColor: if (alphaFormat == AlphaFormat.None) { outputFormat = PixelFormat.B5G6R5_UNorm; } else if (alphaFormat == AlphaFormat.Mask) { outputFormat = PixelFormat.B5G5R5A1_UNorm; } else { throw new NotImplementedException("This alpha format requires a TrueColor texture format."); } break; case TextureFormat.TrueColor: outputFormat = PixelFormat.R8G8B8A8_UNorm; break; //case TextureFormat.Custom: // throw new NotSupportedException(); // break; case TextureFormat.AsIs: outputFormat = inputImageFormat; break; default: throw new ArgumentOutOfRangeException(); } return(outputFormat); }
/// <summary> /// Ignore the test on any other graphic platform than the provided one. /// </summary> public static void RequireGraphicPlatform(GraphicsPlatform platform) { if (GraphicsDevice.Platform != platform) Assert.Ignore("This test requires the '{0}' platform. It has been ignored", platform); }
static GraphicsPath CreateRoundRectGraphicPath(GraphicsPlatform gfxPlatform, float x, float y, float w, float h, float c_rx, float c_ry) { var _path = gfxPlatform.CreateGraphicsPath(); var arcBounds = new RectangleF(); var lineStart = new PointF(); var lineEnd = new PointF(); var width = w; var height = h; var rx = c_rx * 2; var ry = c_ry * 2; // Start _path.StartFigure(); // Add first arc arcBounds.Location = new PointF(x, y); arcBounds.Width = rx; arcBounds.Height = ry; _path.AddArc(arcBounds, 180, 90); // Add first line lineStart.X = Math.Min(x + rx, x + width * 0.5f); lineStart.Y = y; lineEnd.X = Math.Max(x + width - rx, x + width * 0.5f); lineEnd.Y = lineStart.Y; _path.AddLine(lineStart, lineEnd); // Add second arc arcBounds.Location = new PointF(x + width - rx, y); _path.AddArc(arcBounds, 270, 90); // Add second line lineStart.X = x + width; lineStart.Y = Math.Min(y + ry, y + height * 0.5f); lineEnd.X = lineStart.X; lineEnd.Y = Math.Max(y + height - ry, y + height * 0.5f); _path.AddLine(lineStart, lineEnd); // Add third arc arcBounds.Location = new PointF(x + width - rx, y + height - ry); _path.AddArc(arcBounds, 0, 90); // Add third line lineStart.X = Math.Max(x + width - rx, x + width * 0.5f); lineStart.Y = y + height; lineEnd.X = Math.Min(x + rx, x + width * 0.5f); lineEnd.Y = lineStart.Y; _path.AddLine(lineStart, lineEnd); // Add third arc arcBounds.Location = new PointF(x, y + height - ry); _path.AddArc(arcBounds, 90, 90); // Add fourth line lineStart.X = x; lineStart.Y = Math.Max(y + height - ry, y + height * 0.5f); lineEnd.X = lineStart.X; lineEnd.Y = Math.Min(y + ry, y + height * 0.5f); _path.AddLine(lineStart, lineEnd); // Close _path.CloseFigure(); return(_path); }