RenderGraphResource.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Diagnostics;
  2. namespace UnityEngine.Experimental.Rendering.RenderGraphModule
  3. {
  4. internal enum RenderGraphResourceType
  5. {
  6. Invalid = 0, // Don't change this. We need this to be Zero otherwise default zero initialized RenderGraphResource would have a valid Type
  7. Texture,
  8. RendererList
  9. }
  10. /// <summary>
  11. /// Handle to a read-only Render Graph resource.
  12. /// </summary>
  13. [DebuggerDisplay("{type} ({handle})")]
  14. public struct RenderGraphResource
  15. {
  16. internal int handle { get; private set; }
  17. internal RenderGraphResourceType type { get; private set; }
  18. internal RenderGraphResource(RenderGraphMutableResource mutableResource)
  19. {
  20. handle = mutableResource.handle;
  21. type = mutableResource.type;
  22. }
  23. internal RenderGraphResource(int handle, RenderGraphResourceType type)
  24. {
  25. this.handle = handle;
  26. this.type = type;
  27. }
  28. /// <summary>
  29. /// Is the resource valid?
  30. /// </summary>
  31. /// <returns>True if the resource is valid.</returns>
  32. public bool IsValid() { return type != RenderGraphResourceType.Invalid; }
  33. }
  34. /// <summary>
  35. /// Handle to a writable Render Graph resource.
  36. /// </summary>
  37. [DebuggerDisplay("{type} ({handle})")]
  38. public struct RenderGraphMutableResource
  39. {
  40. internal int handle { get; private set; }
  41. internal RenderGraphResourceType type { get; private set; }
  42. internal int version { get; private set; }
  43. internal RenderGraphMutableResource(int handle, RenderGraphResourceType type)
  44. {
  45. this.handle = handle;
  46. this.type = type;
  47. this.version = 0;
  48. }
  49. internal RenderGraphMutableResource(RenderGraphMutableResource other)
  50. {
  51. handle = other.handle;
  52. type = other.type;
  53. version = other.version + 1;
  54. }
  55. /// <summary>
  56. /// Build a RenderGraphResource from a RenderGraphMutableResource.
  57. /// </summary>
  58. /// <param name="handle">Other render graph resource.</param>
  59. /// <returns>New RenderGraphResource handle.</returns>
  60. public static implicit operator RenderGraphResource(RenderGraphMutableResource handle)
  61. {
  62. return new RenderGraphResource(handle);
  63. }
  64. internal bool IsValid() { return type != RenderGraphResourceType.Invalid; }
  65. }
  66. }