TextureWrapper.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics.CodeAnalysis;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Veldrid.Common
  9. {
  10. /// <summary>
  11. /// A wrapper with <see cref="ITexture2D"/> interface.
  12. /// </summary>
  13. public struct TextureWrapper : ITexture2D, IEquatable<TextureWrapper>
  14. {
  15. /// <summary>
  16. /// Creates a new instance of <see cref="TextureWrapper"/>.
  17. /// </summary>
  18. /// <param name="texture">The texture.</param>
  19. /// <exception cref="ArgumentNullException"></exception>
  20. public TextureWrapper(Texture texture)
  21. {
  22. if (texture is null)
  23. throw new ArgumentNullException(nameof(texture));
  24. Texture = texture;
  25. }
  26. /// <summary>
  27. /// Texture
  28. /// </summary>
  29. public Texture Texture { get; }
  30. /// <summary>
  31. /// Size of texture
  32. /// </summary>
  33. public Size Size => new Size((int)Texture.Width, (int)Texture.Height);
  34. /// <inheritdoc/>
  35. public bool IsDisposed => Texture.IsDisposed;
  36. /// <inheritdoc/>
  37. public override int GetHashCode() => Texture.GetHashCode();
  38. /// <inheritdoc/>
  39. public bool Equals(TextureWrapper other) => Texture == other.Texture;
  40. /// <inheritdoc/>
  41. public override bool Equals([NotNullWhen(true)] object? obj) =>
  42. obj is TextureWrapper tw && Equals(tw);
  43. /// <inheritdoc/>
  44. public override string? ToString() => Texture.ToString();
  45. /// <inheritdoc/>
  46. public void Dispose() => Texture.Dispose();
  47. /// <inheritdoc/>
  48. public static implicit operator TextureWrapper(Texture t) => new TextureWrapper(t);
  49. /// <inheritdoc/>
  50. public static implicit operator Texture(TextureWrapper t) => t.Texture;
  51. }
  52. }