mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-25 14:14:46 -04:00
Merge branch 'master' of github.com:UnknownShadow200/ClassicalSharp
This commit is contained in:
commit
994f1cf31b
@ -135,7 +135,7 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
/// <summary> Creates a 2D texture with origin at the specified window coordinates. </summary>
|
/// <summary> Creates a 2D texture with origin at the specified window coordinates. </summary>
|
||||||
public Texture Make2DTexture( Bitmap bmp, Size used, int windowX, int windowY ) {
|
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,
|
return new Texture( texId, windowX, windowY, used.Width, used.Height,
|
||||||
(float)used.Width / bmp.Width, (float)used.Height / bmp.Height );
|
(float)used.Width / bmp.Width, (float)used.Height / bmp.Height );
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,9 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
public void SetData( Bitmap bmp, bool lockBits, bool readOnly ) {
|
public void SetData( Bitmap bmp, bool lockBits, bool readOnly ) {
|
||||||
Bitmap = bmp;
|
Bitmap = bmp;
|
||||||
|
Width = bmp.Width;
|
||||||
|
Height = bmp.Height;
|
||||||
|
|
||||||
if( lockBits ) LockBits();
|
if( lockBits ) LockBits();
|
||||||
ReadOnly = readOnly;
|
ReadOnly = readOnly;
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ namespace ClassicalSharp.Entities {
|
|||||||
row[x] = dist < half * half ? inPix : outPix;
|
row[x] = dist < half * half ? inPix : outPix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shadowTex = graphics.CreateTexture( fastBmp );
|
shadowTex = graphics.CreateTexture( fastBmp, true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ namespace ClassicalSharp.Entities {
|
|||||||
|
|
||||||
if( Model is HumanoidModel )
|
if( Model is HumanoidModel )
|
||||||
ClearHat( bmp, SkinType );
|
ClearHat( bmp, SkinType );
|
||||||
TextureId = game.Graphics.CreateTexture( bmp );
|
TextureId = game.Graphics.CreateTexture( bmp, true );
|
||||||
MobTextureId = -1;
|
MobTextureId = -1;
|
||||||
|
|
||||||
// Custom mob textures.
|
// Custom mob textures.
|
||||||
|
@ -371,9 +371,9 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
if( !Platform.Is32Bpp( bmp ) ) {
|
if( !Platform.Is32Bpp( bmp ) ) {
|
||||||
using( Bitmap bmp32 = Drawer2D.ConvertTo32Bpp( bmp ) )
|
using( Bitmap bmp32 = Drawer2D.ConvertTo32Bpp( bmp ) )
|
||||||
texId = Graphics.CreateTexture( bmp32 );
|
texId = Graphics.CreateTexture( bmp32, true );
|
||||||
} else {
|
} else {
|
||||||
texId = Graphics.CreateTexture( bmp );
|
texId = Graphics.CreateTexture( bmp, true );
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -164,8 +164,9 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
set { if( !value ) device.SetTexture( 0, null ); }
|
set { if( !value ) device.SetTexture( 0, null ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int CreateTexture( int width, int height, IntPtr scan0 ) {
|
protected override int CreateTexture( int width, int height, IntPtr scan0, bool managedPool ) {
|
||||||
D3D.Texture texture = device.CreateTexture( width, height, 0, Usage.None, Format.A8R8G8B8, Pool.Managed );
|
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 );
|
texture.SetData( 0, LockFlags.None, scan0, width * height * 4 );
|
||||||
return GetOrExpand( ref textures, texture, texBufferSize );
|
return GetOrExpand( ref textures, texture, texBufferSize );
|
||||||
}
|
}
|
||||||
|
@ -49,21 +49,26 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
/// <remarks> Note that should make every effort you can to ensure that the dimensions of the bitmap
|
/// <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/>
|
/// 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>
|
/// 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 ) ) {
|
if( !Platform.Is32Bpp( bmp ) ) {
|
||||||
throw new ArgumentOutOfRangeException( "Bitmap must be 32bpp" );
|
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
|
/// <summary> Creates a new native texture with the specified dimensions and FastBitmap instance
|
||||||
/// that encapsulates the pointer to the 32bpp image data.</summary>
|
/// 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,
|
/// <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>
|
/// because otherwise they will not display properly on certain graphics cards. </remarks>
|
||||||
public int CreateTexture( FastBitmap bmp ) {
|
public int CreateTexture( FastBitmap bmp, bool managedPool ) {
|
||||||
if( !bmp.IsLocked ) bmp.LockBits();
|
if( !Utils.IsPowerOf2( bmp.Width ) || !Utils.IsPowerOf2( bmp.Height ) ) {
|
||||||
int texId = CreateTexture( bmp.Width, bmp.Height, bmp.Scan0 );
|
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();
|
bmp.UnlockBits();
|
||||||
return texId;
|
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>
|
/// <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,
|
/// <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>
|
/// 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)
|
/// <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>
|
/// of the native texture associated with the given ID, with the pixels encapsulated in the 'part' instance. </summary>
|
||||||
|
@ -151,10 +151,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
else GL.Disable( EnableCap.Texture2D ); }
|
else GL.Disable( EnableCap.Texture2D ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int CreateTexture( int width, int height, IntPtr scan0 ) {
|
protected override int CreateTexture( int width, int height, IntPtr scan0, bool managedPool ) {
|
||||||
if( !Utils.IsPowerOf2( width ) || !Utils.IsPowerOf2( height ) )
|
|
||||||
Utils.LogDebug( "Creating a non power of two texture." );
|
|
||||||
|
|
||||||
int texId = 0;
|
int texId = 0;
|
||||||
GL.GenTextures( 1, &texId );
|
GL.GenTextures( 1, &texId );
|
||||||
GL.BindTexture( TextureTarget.Texture2D, texId );
|
GL.BindTexture( TextureTarget.Texture2D, texId );
|
||||||
|
@ -118,10 +118,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
|
|
||||||
public override bool Texturing { set { Toggle( All.Texture2D, value ); } }
|
public override bool Texturing { set { Toggle( All.Texture2D, value ); } }
|
||||||
|
|
||||||
public override int CreateTexture( int width, int height, IntPtr scan0 ) {
|
protected override int CreateTexture( int width, int height, IntPtr scan0, bool managedPool ) {
|
||||||
if( !Utils.IsPowerOf2( width ) || !Utils.IsPowerOf2( height ) )
|
|
||||||
Utils.LogDebug( "Creating a non power of two texture." );
|
|
||||||
|
|
||||||
int texId = 0;
|
int texId = 0;
|
||||||
GL.GenTextures( 1, &texId );
|
GL.GenTextures( 1, &texId );
|
||||||
GL.BindTexture( All.Texture2D, texId );
|
GL.BindTexture( All.Texture2D, texId );
|
||||||
|
@ -96,8 +96,6 @@ namespace ClassicalSharp {
|
|||||||
if( x >= width ) break;
|
if( x >= width ) break;
|
||||||
|
|
||||||
byte rawBlock = mapPtr[index];
|
byte rawBlock = mapPtr[index];
|
||||||
if( rawBlock == Block.StillWater ) rawBlock = Block.Water;
|
|
||||||
if( rawBlock == Block.StillLava ) rawBlock = Block.Lava;
|
|
||||||
|
|
||||||
allAir = allAir && rawBlock == 0;
|
allAir = allAir && rawBlock == 0;
|
||||||
allSolid = allSolid && info.IsOpaque[rawBlock];
|
allSolid = allSolid && info.IsOpaque[rawBlock];
|
||||||
|
@ -74,7 +74,7 @@ namespace ClassicalSharp.TexturePack {
|
|||||||
0, index1D * elemSize, atlas, dst, elemSize );
|
0, index1D * elemSize, atlas, dst, elemSize );
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
TexIds[i] = graphics.CreateTexture( dst );
|
TexIds[i] = graphics.CreateTexture( dst, true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ namespace ClassicalSharp {
|
|||||||
{
|
{
|
||||||
int x = index % ElementsPerRow, y = index / ElementsPerRow;
|
int x = index % ElementsPerRow, y = index / ElementsPerRow;
|
||||||
FastBitmap.MovePortion( x * size, y * size, 0, 0, atlas, dst, size );
|
FastBitmap.MovePortion( x * size, y * size, 0, 0, atlas, dst, size );
|
||||||
return graphics.CreateTexture( dst );
|
return graphics.CreateTexture( dst, true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user