Skip to content

Commit

Permalink
fix non-power-of-2 texture in map preview
Browse files Browse the repository at this point in the history
  • Loading branch information
ytinasni committed Apr 11, 2010
1 parent 3271303 commit 62fe4e6
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion OpenRA.Gl/GraphicsDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,16 @@ public Texture(GraphicsDevice dev, Bitmap bitmap)

public void SetData(Bitmap bitmap)
{
if( !IsPowerOf2( bitmap.Width ) || !IsPowerOf2( bitmap.Height ) )
{
//throw new InvalidOperationException( "non-power-of-2-texture" );
bitmap = new Bitmap( bitmap, new Size( NextPowerOf2( bitmap.Width ), NextPowerOf2( bitmap.Height ) ) );
}

Gl.glBindTexture( Gl.GL_TEXTURE_2D, texture );
GraphicsDevice.CheckGlError();

var bits = bitmap.LockBits(
var bits = bitmap.LockBits(
new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb);
Expand All @@ -455,5 +461,21 @@ public void SetData(Bitmap bitmap)

bitmap.UnlockBits(bits);
}

bool IsPowerOf2( int v )
{
return ( v & ( v - 1 ) ) == 0;
}

int NextPowerOf2( int v )
{
--v;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
++v;
return v;
}
}
}

0 comments on commit 62fe4e6

Please sign in to comment.