PlayerModel now uses single VB.

This commit is contained in:
UnknownShadow200 2015-06-01 06:29:09 +10:00
parent 2c18ebc5bb
commit b07dff9bf6
5 changed files with 37 additions and 21 deletions

View File

@ -9,7 +9,6 @@ namespace ClassicalSharp.Model {
public class BlockModel : IModel { public class BlockModel : IModel {
byte block = (byte)Block.Air; byte block = (byte)Block.Air;
int vb;
public BlockModel( Game window ) : base( window ) { public BlockModel( Game window ) : base( window ) {
vertices = new VertexPos3fTex2fCol4b[6 * 6]; vertices = new VertexPos3fTex2fCol4b[6 * 6];
vb = window.Graphics.CreateDynamicVb( VertexFormat.Pos3fTex2fCol4b, 6 * 6 ); vb = window.Graphics.CreateDynamicVb( VertexFormat.Pos3fTex2fCol4b, 6 * 6 );

View File

@ -50,7 +50,8 @@ namespace ClassicalSharp.Model {
const float y1 = 0f, y2 = 0.3125f, z2 = 0.0625f, z1 = -0.125f; const float y1 = 0f, y2 = 0.3125f, z2 = 0.0625f, z1 = -0.125f;
YPlane( 32, 0, 3, 3, x2, x1, z1, z2, y1, false ); // bottom feet YPlane( 32, 0, 3, 3, x2, x1, z1, z2, y1, false ); // bottom feet
ZPlane( 36, 3, 1, 5, legX1, legX2, y1, y2, z2, false ); // vertical part of leg ZPlane( 36, 3, 1, 5, legX1, legX2, y1, y2, z2, false ); // vertical part of leg
return new ModelPart( vertices, 2 * 6, graphics ); int vb = graphics.InitVb( vertices, VertexFormat.Pos3fTex2fCol4b, 2 * 6 );
return new ModelPart( vb, 0, 2 * 6, graphics );
} }
public override float NameYOffset { public override float NameYOffset {

View File

@ -49,22 +49,33 @@ namespace ClassicalSharp.Model {
protected FastColour col = new FastColour( 178, 178, 178 ); protected FastColour col = new FastColour( 178, 178, 178 );
protected VertexPos3fTex2fCol4b[] vertices; protected VertexPos3fTex2fCol4b[] vertices;
protected int index = 0; protected int index = 0;
protected int vb = 0;
protected ModelPart MakePart( int x, int y, int sidesW, int sidesH, int endsW, int endsH, int bodyW, int bodyH, protected ModelPart MakePart( int x, int y, int sidesW, int sidesH, int endsW, int endsH, int bodyW, int bodyH,
float x1, float x2, float y1, float y2, float z1, float z2, bool _64x64 ) { float x1, float x2, float y1, float y2, float z1, float z2, bool _64x64 ) {
index = 0; // TODO: temp hack until we change other classes.
if( !( this is PlayerModel ) ) {
index = 0;
}
YPlane( x + sidesW, y, endsW, endsH, x2, x1, z2, z1, y2, _64x64 ); // top YPlane( x + sidesW, y, endsW, endsH, x2, x1, z2, z1, y2, _64x64 ); // top
YPlane( x + sidesW + bodyW, y, endsW, endsH, x2, x1, z1, z2, y1, _64x64 ); // bottom YPlane( x + sidesW + bodyW, y, endsW, endsH, x2, x1, z1, z2, y1, _64x64 ); // bottom
ZPlane( x + sidesW, y + endsH, bodyW, bodyH, x2, x1, y1, y2, z1, _64x64 ); // front ZPlane( x + sidesW, y + endsH, bodyW, bodyH, x2, x1, y1, y2, z1, _64x64 ); // front
ZPlane( x + sidesW + bodyW + sidesW, y + endsH, bodyW, bodyH, x1, x2, y1, y2, z2, _64x64 ); // back ZPlane( x + sidesW + bodyW + sidesW, y + endsH, bodyW, bodyH, x1, x2, y1, y2, z2, _64x64 ); // back
XPlane( x, y + endsH, sidesW, sidesH, z2, z1, y1, y2, x2, _64x64 ); // left XPlane( x, y + endsH, sidesW, sidesH, z2, z1, y1, y2, x2, _64x64 ); // left
XPlane( x + sidesW + bodyW, y + endsH, sidesW, sidesH, z1, z2, y1, y2, x1, _64x64 ); // right XPlane( x + sidesW + bodyW, y + endsH, sidesW, sidesH, z1, z2, y1, y2, x1, _64x64 ); // right
return new ModelPart( vertices, 6 * 6, graphics ); if( !( this is PlayerModel ) ) {
int vb = graphics.InitVb( vertices, VertexFormat.Pos3fTex2fCol4b, 6 * 6 );
return new ModelPart( vb, 0, 6 * 6, graphics );
} else {
return new ModelPart( this.vb, index - 36, 6 * 6, graphics );
}
} }
protected ModelPart MakeRotatedPart( int x, int y, int sidesW, int sidesH, int endsW, int endsH, int bodyW, int bodyH, protected ModelPart MakeRotatedPart( int x, int y, int sidesW, int sidesH, int endsW, int endsH, int bodyW, int bodyH,
float x1, float x2, float y1, float y2, float z1, float z2, bool _64x64 ) { float x1, float x2, float y1, float y2, float z1, float z2, bool _64x64 ) {
index = 0; if( !( this is PlayerModel ) ) {
index = 0;
}
YPlane( x + sidesW + bodyW + sidesW, y + endsH, bodyW, bodyH, x1, x2, z1, z2, y2, _64x64 ); // top YPlane( x + sidesW + bodyW + sidesW, y + endsH, bodyW, bodyH, x1, x2, z1, z2, y2, _64x64 ); // top
YPlane( x + sidesW, y + endsH, bodyW, bodyH, x2, x1, z1, z2, y1, _64x64 ); // bottom YPlane( x + sidesW, y + endsH, bodyW, bodyH, x2, x1, z1, z2, y1, _64x64 ); // bottom
ZPlane( x + sidesW, y, endsW, endsH, x2, x1, y1, y2, z1, _64x64 ); // front ZPlane( x + sidesW, y, endsW, endsH, x2, x1, y1, y2, z1, _64x64 ); // front
@ -79,7 +90,12 @@ namespace ClassicalSharp.Model {
vertex.Y = z; vertex.Y = z;
vertices[i] = vertex; vertices[i] = vertex;
} }
return new ModelPart( vertices, 6 * 6, graphics ); if( !( this is PlayerModel ) ) {
int vb = graphics.InitVb( vertices, VertexFormat.Pos3fTex2fCol4b, 6 * 6 );
return new ModelPart( vb, 0, 6 * 6, graphics );
} else {
return new ModelPart( this.vb, index - 36, 6 * 6, graphics );
}
} }
protected static TextureRectangle SkinTexCoords( int x, int y, int width, int height, float skinWidth, float skinHeight ) { protected static TextureRectangle SkinTexCoords( int x, int y, int width, int height, float skinWidth, float skinHeight ) {

View File

@ -6,17 +6,19 @@ namespace ClassicalSharp {
public class ModelPart { public class ModelPart {
public int VbId; public int VbId;
public int Offset = 0;
public int Count; public int Count;
public IGraphicsApi Graphics; public IGraphicsApi Graphics;
public ModelPart( VertexPos3fTex2fCol4b[] vertices, int count, IGraphicsApi graphics ) { public ModelPart( int vb, int offset, int count, IGraphicsApi graphics ) {
Offset = offset;
Count = count; Count = count;
Graphics = graphics; Graphics = graphics;
VbId = Graphics.InitVb( vertices, VertexFormat.Pos3fTex2fCol4b, count ); VbId = vb;
} }
public void Render() { public void Render() {
Graphics.DrawVb( DrawMode.Triangles, VertexFormat.Pos3fTex2fCol4b, VbId, 0, Count ); Graphics.DrawVb( DrawMode.Triangles, VertexFormat.Pos3fTex2fCol4b, VbId, Offset, Count );
} }
public void Dispose() { public void Dispose() {

View File

@ -10,7 +10,7 @@ namespace ClassicalSharp.Model {
ModelSet Set64x32, Set64x64, Set64x64Slim; ModelSet Set64x32, Set64x64, Set64x64Slim;
public PlayerModel( Game window ) : base( window ) { public PlayerModel( Game window ) : base( window ) {
vertices = new VertexPos3fTex2fCol4b[6 * 6]; vertices = new VertexPos3fTex2fCol4b[( 6 * 6 ) * 7 * 3];
Set64x32 = new ModelSet(); Set64x32 = new ModelSet();
Set64x32.Head = MakeHead( false ); Set64x32.Head = MakeHead( false );
Set64x32.Torso = MakeTorso( false ); Set64x32.Torso = MakeTorso( false );
@ -37,6 +37,11 @@ namespace ClassicalSharp.Model {
Set64x64Slim.LeftArm = MakeLeftArm( 32, 48, 0.25f, 0.4375f, 3, true ); Set64x64Slim.LeftArm = MakeLeftArm( 32, 48, 0.25f, 0.4375f, 3, true );
Set64x64Slim.RightArm = MakeRightArm( 40, 16, 0.25f, 0.4375f, 3, true ); Set64x64Slim.RightArm = MakeRightArm( 40, 16, 0.25f, 0.4375f, 3, true );
Set64x64Slim.Hat = MakeHat( true ); Set64x64Slim.Hat = MakeHat( true );
vb = graphics.InitVb( vertices, VertexFormat.Pos3fTex2fCol4b );
Set64x32.SetVb( vb );
Set64x64.SetVb( vb );
Set64x64Slim.SetVb( vb );
vertices = null; vertices = null;
using( Bitmap bmp = new Bitmap( "char.png" ) ) { using( Bitmap bmp = new Bitmap( "char.png" ) ) {
@ -98,9 +103,7 @@ namespace ClassicalSharp.Model {
} }
public override void Dispose() { public override void Dispose() {
Set64x32.Dispose(); graphics.DeleteVb( vb );
Set64x64.Dispose();
Set64x64Slim.Dispose();
graphics.DeleteTexture( ref DefaultTexId ); graphics.DeleteTexture( ref DefaultTexId );
} }
@ -108,14 +111,9 @@ namespace ClassicalSharp.Model {
public ModelPart Head, Torso, LeftLeg, RightLeg, LeftArm, RightArm, Hat; public ModelPart Head, Torso, LeftLeg, RightLeg, LeftArm, RightArm, Hat;
public void Dispose() { public void SetVb( int vb ) {
Hat.Dispose(); Head.VbId = Torso.VbId = LeftLeg.VbId = RightLeg.VbId =
RightArm.Dispose(); LeftArm.VbId = RightArm.VbId = Hat.VbId = vb;
LeftArm.Dispose();
RightLeg.Dispose();
LeftLeg.Dispose();
Torso.Dispose();
Head.Dispose();
} }
} }
} }