optimize mesh sprite index buffer

instancing
cosmonaut 2020-12-06 19:01:23 -08:00
parent ca6c91446e
commit 46f2cad81a
1 changed files with 11 additions and 14 deletions

View File

@ -6,6 +6,15 @@ namespace Kav
public class MeshSprite
{
private static readonly int PixelScale = 40;
private static readonly short[] Indices = new short[]
{
0,
1,
2,
1,
3,
2
};
public IndexBuffer IndexBuffer { get; }
public VertexBuffer VertexBuffer { get; }
@ -29,7 +38,7 @@ namespace Kav
6,
BufferUsage.WriteOnly
);
IndexBuffer.SetData(GenerateIndexArray());
IndexBuffer.SetData(Indices);
VertexBuffer = new VertexBuffer(
graphicsDevice,
@ -56,7 +65,7 @@ namespace Kav
6,
BufferUsage.WriteOnly
);
IndexBuffer.SetData(GenerateIndexArray());
IndexBuffer.SetData(Indices);
VertexBuffer = new VertexBuffer(
graphicsDevice,
@ -67,18 +76,6 @@ namespace Kav
VertexBuffer.SetData(GenerateVertexArray(Texture));
}
private static short[] GenerateIndexArray()
{
short[] result = new short[6];
result[0] = 0;
result[1] = 1;
result[2] = 2;
result[3] = 1;
result[4] = 3;
result[5] = 2;
return result;
}
private static VertexPositionNormalTexture[] GenerateVertexArray(Texture2D texture)
{
VertexPositionNormalTexture[] result = new VertexPositionNormalTexture[4];