Permalink
Browse files

Updating PR 1498 with a new NextPOT and fix on the condition trigger …

…to resize the bitmap rendering buffer.
  • Loading branch information...
1 parent 82e604b commit 5f32641e1bccb1c24f7faf6eec2cbae461f6b613 @totallyevil totallyevil committed May 1, 2013
@@ -5,6 +5,24 @@ namespace MonoGameContentProcessors
{
static public class ContentHelper
{
+ /// <summary>
+ /// Returns the next Power of Two for the given value. If x = 3, then this returns 4.
+ /// If x = 4 then 4 is returned. If the value is a power of two, then the same value
+ /// is returned.
+ /// </summary>
+ /// <param name="x">The base of the POT test</param>
+ /// <returns>The next power of 2 (1, 2, 4, 8, 16, 32, 64, 128, etc)</returns>
+ static public int NextPOT(int x)
+ {
+ x = x - 1;
+ x = x | (x >> 1);
+ x = x | (x >> 2);
+ x = x | (x >> 4);
+ x = x | (x >> 8);
+ x = x | (x >> 16);
+ return x + 1;
+ }
+
static public MonoGamePlatform GetMonoGamePlatform()
{
// Stock XNA uses a hardcoded enum for platforms... this disallows
@@ -31,11 +31,11 @@ public override SpriteFontContent Process(FontDescription input, ContentProcesso
// or even Process is tricky. This works for now, but should be replaced when the content pipeline
// moves a bit further
- var texWidth = texture.Faces[0][0].Width;
- var texHeight = texture.Faces[0][0].Height;
+ var texWidth = ContentHelper.NextPOT(texture.Faces[0][0].Width);
+ var texHeight = ContentHelper.NextPOT(texture.Faces[0][0].Height);
// Resize to square, power of two if necessary.
- if (texWidth != texHeight)
+ if (texWidth != texHeight || texture.Faces[0][0].Width != texture.Faces[0][0].Height || texWidth != texture.Faces[0][0].Width || texHeight != texture.Faces[0][0].Height)
{
texHeight = texWidth = Math.Max(texHeight, texWidth);
var resizedBitmap = (BitmapContent)Activator.CreateInstance(typeof(PixelBitmapContent<Color>), new object[] { texWidth, texHeight });
@@ -44,6 +44,8 @@ public override SpriteFontContent Process(FontDescription input, ContentProcesso
texture.Faces[0].Clear();
texture.Faces[0].Add(resizedBitmap);
+
+ context.Logger.LogImportantMessage(string.Format("Resized font texture {0} to {1}x{2}", input.Name, resizedBitmap.Width, resizedBitmap.Height));
}
else
texture.ConvertBitmapType(typeof(PixelBitmapContent<Color>));

0 comments on commit 5f32641

Please sign in to comment.