diff --git a/ClassicalSharp/2D/Drawing/IDrawer2D.cs b/ClassicalSharp/2D/Drawing/IDrawer2D.cs
index d83394640..7b3f58904 100644
--- a/ClassicalSharp/2D/Drawing/IDrawer2D.cs
+++ b/ClassicalSharp/2D/Drawing/IDrawer2D.cs
@@ -135,7 +135,7 @@ namespace ClassicalSharp {
/// Creates a 2D texture with origin at the specified window coordinates.
public Texture Make2DTexture( Bitmap bmp, Size used, int windowX, int windowY ) {
- int texId = graphics.CreateTexture( bmp );
+ int texId = graphics.CreateTexture( bmp, true );
return new Texture( texId, windowX, windowY, used.Width, used.Height,
(float)used.Width / bmp.Width, (float)used.Height / bmp.Height );
}
diff --git a/ClassicalSharp/2D/Utils/FastBitmap.cs b/ClassicalSharp/2D/Utils/FastBitmap.cs
index 13c98db59..878cdf91e 100644
--- a/ClassicalSharp/2D/Utils/FastBitmap.cs
+++ b/ClassicalSharp/2D/Utils/FastBitmap.cs
@@ -25,6 +25,9 @@ namespace ClassicalSharp {
public void SetData( Bitmap bmp, bool lockBits, bool readOnly ) {
Bitmap = bmp;
+ Width = bmp.Width;
+ Height = bmp.Height;
+
if( lockBits ) LockBits();
ReadOnly = readOnly;
}
diff --git a/ClassicalSharp/Entities/Components/ShadowComponent.cs b/ClassicalSharp/Entities/Components/ShadowComponent.cs
index 7a58336cc..c8694b4d7 100644
--- a/ClassicalSharp/Entities/Components/ShadowComponent.cs
+++ b/ClassicalSharp/Entities/Components/ShadowComponent.cs
@@ -215,7 +215,7 @@ namespace ClassicalSharp.Entities {
row[x] = dist < half * half ? inPix : outPix;
}
}
- shadowTex = graphics.CreateTexture( fastBmp );
+ shadowTex = graphics.CreateTexture( fastBmp, true );
}
}
}
diff --git a/ClassicalSharp/Entities/Player.cs b/ClassicalSharp/Entities/Player.cs
index 0665ea821..fa58b0008 100644
--- a/ClassicalSharp/Entities/Player.cs
+++ b/ClassicalSharp/Entities/Player.cs
@@ -128,7 +128,7 @@ namespace ClassicalSharp.Entities {
if( Model is HumanoidModel )
ClearHat( bmp, SkinType );
- TextureId = game.Graphics.CreateTexture( bmp );
+ TextureId = game.Graphics.CreateTexture( bmp, true );
MobTextureId = -1;
// Custom mob textures.
diff --git a/ClassicalSharp/Game/Game.cs b/ClassicalSharp/Game/Game.cs
index ac0b88ae0..64d0c6189 100644
--- a/ClassicalSharp/Game/Game.cs
+++ b/ClassicalSharp/Game/Game.cs
@@ -371,9 +371,9 @@ namespace ClassicalSharp {
if( !Platform.Is32Bpp( bmp ) ) {
using( Bitmap bmp32 = Drawer2D.ConvertTo32Bpp( bmp ) )
- texId = Graphics.CreateTexture( bmp32 );
+ texId = Graphics.CreateTexture( bmp32, true );
} else {
- texId = Graphics.CreateTexture( bmp );
+ texId = Graphics.CreateTexture( bmp, true );
}
return true;
}
diff --git a/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs b/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs
index 0936fd4dd..6390bbf41 100644
--- a/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs
+++ b/ClassicalSharp/GraphicsAPI/Direct3D9Api.cs
@@ -164,8 +164,9 @@ namespace ClassicalSharp.GraphicsAPI {
set { if( !value ) device.SetTexture( 0, null ); }
}
- public override int CreateTexture( int width, int height, IntPtr scan0 ) {
- D3D.Texture texture = device.CreateTexture( width, height, 0, Usage.None, Format.A8R8G8B8, Pool.Managed );
+ protected override int CreateTexture( int width, int height, IntPtr scan0, bool managedPool ) {
+ Pool pool = managedPool ? Pool.Managed : Pool.Default;
+ D3D.Texture texture = device.CreateTexture( width, height, 0, Usage.None, Format.A8R8G8B8, pool );
texture.SetData( 0, LockFlags.None, scan0, width * height * 4 );
return GetOrExpand( ref textures, texture, texBufferSize );
}
diff --git a/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs b/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs
index 54100848f..a196422f1 100644
--- a/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs
+++ b/ClassicalSharp/GraphicsAPI/IGraphicsApi.cs
@@ -49,21 +49,26 @@ namespace ClassicalSharp.GraphicsAPI {
/// Note that should make every effort you can to ensure that the dimensions of the bitmap
/// are powers of two, because otherwise they will not display properly on certain graphics cards.
/// This method returns -1 if the input image is not a 32bpp format.
- public int CreateTexture( Bitmap bmp ) {
+ public int CreateTexture( Bitmap bmp, bool managedPool ) {
if( !Platform.Is32Bpp( bmp ) ) {
throw new ArgumentOutOfRangeException( "Bitmap must be 32bpp" );
}
- bmpBuffer.SetData( bmp, false, true );
- return CreateTexture( bmpBuffer );
+
+ bmpBuffer.SetData( bmp, true, true );
+ return CreateTexture( bmpBuffer, managedPool );
}
/// Creates a new native texture with the specified dimensions and FastBitmap instance
/// that encapsulates the pointer to the 32bpp image data.
/// Note that should make every effort you can to ensure that the dimensions are powers of two,
/// because otherwise they will not display properly on certain graphics cards.
- public int CreateTexture( FastBitmap bmp ) {
- if( !bmp.IsLocked ) bmp.LockBits();
- int texId = CreateTexture( bmp.Width, bmp.Height, bmp.Scan0 );
+ public int CreateTexture( FastBitmap bmp, bool managedPool ) {
+ if( !Utils.IsPowerOf2( bmp.Width ) || !Utils.IsPowerOf2( bmp.Height ) ) {
+ throw new ArgumentOutOfRangeException( "Bitmap must have power of two dimensions" );
+ }
+
+ if( !bmp.IsLocked ) bmp.LockBits();
+ int texId = CreateTexture( bmp.Width, bmp.Height, bmp.Scan0, managedPool );
bmp.UnlockBits();
return texId;
}
@@ -71,7 +76,7 @@ namespace ClassicalSharp.GraphicsAPI {
/// Creates a new native texture with the specified dimensions and pointer to the 32bpp image data.
/// Note that should make every effort you can to ensure that the dimensions are powers of two,
/// because otherwise they will not display properly on certain graphics cards.
- public abstract int CreateTexture( int width, int height, IntPtr scan0 );
+ protected abstract int CreateTexture( int width, int height, IntPtr scan0, bool managedPool );
/// Updates the sub-rectangle (texX, texY) -> (texX + part.Width, texY + part.Height)
/// of the native texture associated with the given ID, with the pixels encapsulated in the 'part' instance.
diff --git a/ClassicalSharp/GraphicsAPI/OpenGLApi.cs b/ClassicalSharp/GraphicsAPI/OpenGLApi.cs
index 57d32d0b6..7330b826d 100644
--- a/ClassicalSharp/GraphicsAPI/OpenGLApi.cs
+++ b/ClassicalSharp/GraphicsAPI/OpenGLApi.cs
@@ -151,10 +151,7 @@ namespace ClassicalSharp.GraphicsAPI {
else GL.Disable( EnableCap.Texture2D ); }
}
- public override int CreateTexture( int width, int height, IntPtr scan0 ) {
- if( !Utils.IsPowerOf2( width ) || !Utils.IsPowerOf2( height ) )
- Utils.LogDebug( "Creating a non power of two texture." );
-
+ protected override int CreateTexture( int width, int height, IntPtr scan0, bool managedPool ) {
int texId = 0;
GL.GenTextures( 1, &texId );
GL.BindTexture( TextureTarget.Texture2D, texId );
diff --git a/ClassicalSharp/GraphicsAPI/OpenGLESApi.cs b/ClassicalSharp/GraphicsAPI/OpenGLESApi.cs
index dab61d4c0..f9d9d8880 100644
--- a/ClassicalSharp/GraphicsAPI/OpenGLESApi.cs
+++ b/ClassicalSharp/GraphicsAPI/OpenGLESApi.cs
@@ -118,10 +118,7 @@ namespace ClassicalSharp.GraphicsAPI {
public override bool Texturing { set { Toggle( All.Texture2D, value ); } }
- public override int CreateTexture( int width, int height, IntPtr scan0 ) {
- if( !Utils.IsPowerOf2( width ) || !Utils.IsPowerOf2( height ) )
- Utils.LogDebug( "Creating a non power of two texture." );
-
+ protected override int CreateTexture( int width, int height, IntPtr scan0, bool managedPool ) {
int texId = 0;
GL.GenTextures( 1, &texId );
GL.BindTexture( All.Texture2D, texId );
diff --git a/ClassicalSharp/MeshBuilder/Builder.cs b/ClassicalSharp/MeshBuilder/Builder.cs
index 915937ef3..5e3463bae 100644
--- a/ClassicalSharp/MeshBuilder/Builder.cs
+++ b/ClassicalSharp/MeshBuilder/Builder.cs
@@ -96,8 +96,6 @@ namespace ClassicalSharp {
if( x >= width ) break;
byte rawBlock = mapPtr[index];
- if( rawBlock == Block.StillWater ) rawBlock = Block.Water;
- if( rawBlock == Block.StillLava ) rawBlock = Block.Lava;
allAir = allAir && rawBlock == 0;
allSolid = allSolid && info.IsOpaque[rawBlock];
diff --git a/ClassicalSharp/TexturePack/TerrainAtlas1D.cs b/ClassicalSharp/TexturePack/TerrainAtlas1D.cs
index a6098bfd9..e410312c3 100644
--- a/ClassicalSharp/TexturePack/TerrainAtlas1D.cs
+++ b/ClassicalSharp/TexturePack/TerrainAtlas1D.cs
@@ -74,7 +74,7 @@ namespace ClassicalSharp.TexturePack {
0, index1D * elemSize, atlas, dst, elemSize );
index++;
}
- TexIds[i] = graphics.CreateTexture( dst );
+ TexIds[i] = graphics.CreateTexture( dst, true );
}
}
diff --git a/ClassicalSharp/TexturePack/TerrainAtlas2D.cs b/ClassicalSharp/TexturePack/TerrainAtlas2D.cs
index c4d66ebda..347230aca 100644
--- a/ClassicalSharp/TexturePack/TerrainAtlas2D.cs
+++ b/ClassicalSharp/TexturePack/TerrainAtlas2D.cs
@@ -45,7 +45,7 @@ namespace ClassicalSharp {
{
int x = index % ElementsPerRow, y = index / ElementsPerRow;
FastBitmap.MovePortion( x * size, y * size, 0, 0, atlas, dst, size );
- return graphics.CreateTexture( dst );
+ return graphics.CreateTexture( dst, true );
}
}