TiledMapLayerModel.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using Microsoft.Xna.Framework.Graphics;
  3. namespace MonoGame.Extended.Tiled.Renderers
  4. {
  5. public abstract class TiledMapLayerModel : IDisposable
  6. {
  7. protected TiledMapLayerModel(GraphicsDevice graphicsDevice, Texture2D texture, VertexPositionTexture[] vertices, ushort[] indices)
  8. {
  9. Texture = texture;
  10. // ReSharper disable once VirtualMemberCallInConstructor
  11. VertexBuffer = CreateVertexBuffer(graphicsDevice, vertices.Length);
  12. VertexBuffer.SetData(vertices, 0, vertices.Length);
  13. // ReSharper disable once VirtualMemberCallInConstructor
  14. IndexBuffer = CreateIndexBuffer(graphicsDevice, indices.Length);
  15. IndexBuffer.SetData(indices, 0, indices.Length);
  16. TriangleCount = indices.Length / 3;
  17. }
  18. public void Dispose()
  19. {
  20. IndexBuffer.Dispose();
  21. VertexBuffer.Dispose();
  22. }
  23. public Texture2D Texture { get; }
  24. public VertexBuffer VertexBuffer { get; }
  25. public IndexBuffer IndexBuffer { get; }
  26. public int TriangleCount { get; }
  27. protected abstract VertexBuffer CreateVertexBuffer(GraphicsDevice graphicsDevice, int vertexCount);
  28. protected abstract IndexBuffer CreateIndexBuffer(GraphicsDevice graphicsDevice, int indexCount);
  29. }
  30. }