GraphicsResourceTracker.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.Xna.Framework.Graphics;
  4. namespace SharpGLTF.Runtime.Pipeline
  5. {
  6. /// <summary>
  7. /// tracks all the disposable objects of a model during loading.
  8. /// </summary>
  9. /// <remarks>
  10. /// During the process of loading a model, resources like textures, effects and device buffers<br/>
  11. /// are gathered as a collection of disposables, so when the whole model is disposed, we can also
  12. /// dispose of the device resources.
  13. /// </remarks>
  14. public class GraphicsResourceTracker
  15. {
  16. #region data
  17. private readonly List<GraphicsResource> _Disposables = new List<GraphicsResource>();
  18. #endregion
  19. #region properties
  20. public IReadOnlyList<GraphicsResource> Disposables => _Disposables;
  21. #endregion
  22. #region API
  23. public void AddDisposable(GraphicsResource resource)
  24. {
  25. ArgumentNullException.ThrowIfNull(resource);
  26. if (_Disposables.Contains(resource)) throw new ArgumentException($"resource used more than once {resource}");
  27. _Disposables.Add(resource);
  28. }
  29. #endregion
  30. }
  31. }