Add Mesh class

This commit is contained in:
Drew DeVault 2015-05-13 17:02:03 -06:00
parent dfa3132759
commit 0149af3ba2
2 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,40 @@
using System;
using Microsoft.Xna.Framework.Graphics;
namespace TrueCraft.Client.Linux.Rendering
{
public class Mesh
{
public VertexBuffer Verticies { get; set; }
public IndexBuffer Indicies { get; set; }
public Mesh(GraphicsDevice device, VertexPositionNormalTexture[] verticies, int[] indicies)
{
Verticies = new VertexBuffer(device, VertexPositionNormalTexture.VertexDeclaration,
verticies.Length, BufferUsage.None);
Verticies.SetData(verticies);
Indicies = new IndexBuffer(device, IndexElementSize.ThirtyTwoBits, indicies.Length, BufferUsage.None);
Indicies.SetData(indicies);
}
~Mesh()
{
if (Verticies != null)
Verticies.Dispose();
if (Indicies != null)
Indicies.Dispose();
}
public void Draw(Effect effect)
{
effect.GraphicsDevice.SetVertexBuffer(Verticies);
effect.GraphicsDevice.Indices = Indicies;
foreach (var pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
effect.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList,
0, 0, Indicies.IndexCount, 0, Indicies.IndexCount / 3);
}
}
}
}

View File

@ -73,6 +73,7 @@
<Compile Include="Events\ChunkEventArgs.cs" /> <Compile Include="Events\ChunkEventArgs.cs" />
<Compile Include="ChunkConverter.cs" /> <Compile Include="ChunkConverter.cs" />
<Compile Include="PhysicsEngine.cs" /> <Compile Include="PhysicsEngine.cs" />
<Compile Include="Rendering\Mesh.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>
@ -105,6 +106,7 @@
<Folder Include="Interface\" /> <Folder Include="Interface\" />
<Folder Include="Events\" /> <Folder Include="Events\" />
<Folder Include="Content\" /> <Folder Include="Content\" />
<Folder Include="Rendering\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="OpenTK.dll.config" /> <None Include="OpenTK.dll.config" />