Move IsPowerOf2 to Exts.
This commit is contained in:
@@ -137,6 +137,11 @@ namespace OpenRA
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsPowerOf2(int v)
|
||||||
|
{
|
||||||
|
return (v & (v - 1)) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
public static Size NextPowerOf2(this Size s) { return new Size(NextPowerOf2(s.Width), NextPowerOf2(s.Height)); }
|
public static Size NextPowerOf2(this Size s) { return new Size(NextPowerOf2(s.Width), NextPowerOf2(s.Height)); }
|
||||||
|
|
||||||
public static string JoinWith<T>(this IEnumerable<T> ts, string j)
|
public static string JoinWith<T>(this IEnumerable<T> ts, string j)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
|
|
||||||
public void SetData(byte[] colors, int width, int height)
|
public void SetData(byte[] colors, int width, int height)
|
||||||
{
|
{
|
||||||
if (!IsPowerOf2(width) || !IsPowerOf2(height))
|
if (!Exts.IsPowerOf2(width) || !Exts.IsPowerOf2(height))
|
||||||
throw new InvalidDataException("Non-power-of-two array {0}x{1}".F(width, height));
|
throw new InvalidDataException("Non-power-of-two array {0}x{1}".F(width, height));
|
||||||
|
|
||||||
unsafe
|
unsafe
|
||||||
@@ -78,7 +78,7 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
int width = colors.GetUpperBound(1) + 1;
|
int width = colors.GetUpperBound(1) + 1;
|
||||||
int height = colors.GetUpperBound(0) + 1;
|
int height = colors.GetUpperBound(0) + 1;
|
||||||
|
|
||||||
if (!IsPowerOf2(width) || !IsPowerOf2(height))
|
if (!Exts.IsPowerOf2(width) || !Exts.IsPowerOf2(height))
|
||||||
throw new InvalidDataException("Non-power-of-two array {0}x{1}".F(width,height));
|
throw new InvalidDataException("Non-power-of-two array {0}x{1}".F(width,height));
|
||||||
|
|
||||||
unsafe
|
unsafe
|
||||||
@@ -96,11 +96,8 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
|
|
||||||
public void SetData(Bitmap bitmap)
|
public void SetData(Bitmap bitmap)
|
||||||
{
|
{
|
||||||
if (!IsPowerOf2(bitmap.Width) || !IsPowerOf2(bitmap.Height))
|
if (!Exts.IsPowerOf2(bitmap.Width) || !Exts.IsPowerOf2(bitmap.Height))
|
||||||
{
|
|
||||||
//throw new InvalidOperationException( "non-power-of-2-texture" );
|
|
||||||
bitmap = new Bitmap(bitmap, bitmap.Size.NextPowerOf2());
|
bitmap = new Bitmap(bitmap, bitmap.Size.NextPowerOf2());
|
||||||
}
|
|
||||||
|
|
||||||
var bits = bitmap.LockBits(bitmap.Bounds(),
|
var bits = bitmap.LockBits(bitmap.Bounds(),
|
||||||
ImageLockMode.ReadOnly,
|
ImageLockMode.ReadOnly,
|
||||||
@@ -112,10 +109,5 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
ErrorHandler.CheckGlError();
|
ErrorHandler.CheckGlError();
|
||||||
bitmap.UnlockBits(bits);
|
bitmap.UnlockBits(bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsPowerOf2(int v)
|
|
||||||
{
|
|
||||||
return (v & (v - 1)) == 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user