Merge branch 'master' of github.com:UnknownShadow200/ClassicalSharp

This commit is contained in:
UnknownShadow200 2016-10-06 13:03:50 +11:00
commit 994f1cf31b
12 changed files with 27 additions and 26 deletions

View File

@ -135,7 +135,7 @@ namespace ClassicalSharp {
/// <summary> Creates a 2D texture with origin at the specified window coordinates. </summary>
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 );
}

View File

@ -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;
}

View File

@ -215,7 +215,7 @@ namespace ClassicalSharp.Entities {
row[x] = dist < half * half ? inPix : outPix;
}
}
shadowTex = graphics.CreateTexture( fastBmp );
shadowTex = graphics.CreateTexture( fastBmp, true );
}
}
}

View File

@ -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.

View File

@ -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;
}

View File

@ -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 );
}

View File

@ -49,21 +49,26 @@ namespace ClassicalSharp.GraphicsAPI {
/// <remarks> 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. <br/>
/// This method returns -1 if the input image is not a 32bpp format. </remarks>
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 );
}
/// <summary> Creates a new native texture with the specified dimensions and FastBitmap instance
/// that encapsulates the pointer to the 32bpp image data.</summary>
/// <remarks> 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. </remarks>
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 {
/// <summary> Creates a new native texture with the specified dimensions and pointer to the 32bpp image data. </summary>
/// <remarks> 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. </remarks>
public abstract int CreateTexture( int width, int height, IntPtr scan0 );
protected abstract int CreateTexture( int width, int height, IntPtr scan0, bool managedPool );
/// <summary> 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. </summary>

View File

@ -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 );

View File

@ -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 );

View File

@ -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];

View File

@ -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 );
}
}

View File

@ -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 );
}
}