Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DrawModule <T>
- {
- public GraphicsDevice Device;
- public VertexDeclaration VertexDeclaration;
- private VertexBuffer _vertexBuffer;
- private IndexBuffer _indexBuffer;
- private List<T> _vertices;
- private List<ushort> _indices;
- private const ushort MaxPrimitives = 65535;
- private ushort _primitiveCount;
- private bool _readyToDraw;
- public DrawModule(GraphicsDevice device, VertexDeclaration vertexDeclaration)
- {
- VertexDeclaration = vertexDeclaration;
- Device = device;
- _primitiveCount = 0;
- _readyToDraw = false;
- _vertices = new List<T>();
- _indices = new List<ushort>();
- }
- public bool HasSpace(List<ushort> indices)
- {
- return ((indices.Count + _indices.Count)/3 < MaxPrimitives);
- }
- public bool AddData(List<T> vertices, List<ushort> indices)
- {
- if (HasSpace(indices))
- {
- ushort offset = (ushort)_vertices.Count();
- _vertices.AddRange(vertices);
- foreach (ushort index in indices)
- {
- _indices.Add((ushort)(index + offset));
- }
- }
- return false;
- }
- public void PrepareToDraw()
- {
- _vertexBuffer = new VertexBuffer(Device, VertexDeclaration, _vertices.Count, BufferUsage.WriteOnly);
- _vertexBuffer.SetData(_vertices.ToArray());
- _indexBuffer = new IndexBuffer(Device, typeof(ushort), _indices.Count, BufferUsage.WriteOnly);
- }
- public void Draw()
- {
- if (_readyToDraw)
- {
- // do stuffs
- }
Advertisement
Add Comment
Please, Sign In to add comment