2019-08-09 04:18:08 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Rendering
|
|
|
|
|
{
|
2019-08-13 02:12:04 +00:00
|
|
|
|
internal class Mesh : IDisposable
|
2019-08-09 04:18:08 +00:00
|
|
|
|
{
|
2019-08-15 00:52:21 +00:00
|
|
|
|
public Mesh(RenderDevice graphics, VertexElement[] vertexDecl, WorldVertex[] vertexData, int[] indexData)
|
2019-08-09 04:18:08 +00:00
|
|
|
|
{
|
|
|
|
|
VertexDecl = new VertexDeclaration(vertexDecl);
|
|
|
|
|
unsafe { Vertices = new VertexBuffer(sizeof(WorldVertex)); }
|
2019-08-15 00:52:21 +00:00
|
|
|
|
graphics.SetBufferData(Vertices, vertexData);
|
2019-08-09 04:18:08 +00:00
|
|
|
|
Indices = new IndexBuffer(sizeof(int) * indexData.Length);
|
2019-08-15 00:52:21 +00:00
|
|
|
|
graphics.SetBufferData(Indices, indexData);
|
2019-08-13 02:12:04 +00:00
|
|
|
|
Count = indexData.Length;
|
2019-08-09 04:18:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~Mesh()
|
|
|
|
|
{
|
|
|
|
|
Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-13 02:12:04 +00:00
|
|
|
|
internal void Draw(RenderDevice device)
|
2019-08-09 04:18:08 +00:00
|
|
|
|
{
|
2019-08-13 02:12:04 +00:00
|
|
|
|
device.SetVertexDeclaration(VertexDecl);
|
|
|
|
|
device.SetVertexBuffer(0, Vertices, 0, WorldVertex.Stride);
|
|
|
|
|
device.SetIndexBuffer(Indices);
|
2019-08-15 12:49:49 +00:00
|
|
|
|
device.DrawIndexed(PrimitiveType.TriangleList, 0, Count / 3);
|
2019-08-13 02:12:04 +00:00
|
|
|
|
device.SetIndexBuffer(null);
|
|
|
|
|
device.SetVertexBuffer(0, null, 0, 0);
|
|
|
|
|
device.SetVertexDeclaration(null);
|
2019-08-09 04:18:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
if (Vertices != null) Vertices.Dispose();
|
|
|
|
|
if (Indices != null) Indices.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VertexDeclaration VertexDecl;
|
|
|
|
|
VertexBuffer Vertices;
|
|
|
|
|
IndexBuffer Indices;
|
2019-08-13 02:12:04 +00:00
|
|
|
|
int Count;
|
2019-08-09 04:18:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|