暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UniversalResourceBase.cs 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using UnityEngine.Rendering.RenderGraphModule;
  2. namespace UnityEngine.Rendering.Universal
  3. {
  4. /// <summary>
  5. /// Base class for URP texture data.
  6. /// </summary>
  7. public abstract class UniversalResourceDataBase : ContextItem
  8. {
  9. /// <summary>
  10. /// Options for the active color &amp; depth target texture.
  11. /// </summary>
  12. internal enum ActiveID
  13. {
  14. /// <summary>The camera buffer.</summary>
  15. Camera,
  16. /// <summary>The backbuffer.</summary>
  17. BackBuffer
  18. }
  19. internal bool isAccessible { get; set; }
  20. internal void InitFrame()
  21. {
  22. isAccessible = true;
  23. }
  24. internal void EndFrame()
  25. {
  26. isAccessible = false;
  27. }
  28. /// <summary>
  29. /// Updates the texture handle if the texture is accessible.
  30. /// </summary>
  31. /// <param name="handle">Handle to update.</param>
  32. /// <param name="newHandle">Handle of the new data.</param>
  33. protected void CheckAndSetTextureHandle(ref TextureHandle handle, TextureHandle newHandle)
  34. {
  35. if (!CheckAndWarnAboutAccessibility())
  36. return;
  37. handle = newHandle;
  38. }
  39. /// <summary>
  40. /// Fetches the texture handle if the texture is accessible.
  41. /// </summary>
  42. /// <param name="handle">Handle to the texture you want to retrieve</param>
  43. /// <returns>Returns the handle if the texture is accessible and a null handle otherwise.</returns>
  44. protected TextureHandle CheckAndGetTextureHandle(ref TextureHandle handle)
  45. {
  46. if (!CheckAndWarnAboutAccessibility())
  47. return TextureHandle.nullHandle;
  48. return handle;
  49. }
  50. /// <summary>
  51. /// Updates the texture handles if the texture is accessible. The current and new handles needs to be of the same size.
  52. /// </summary>
  53. /// <param name="handle">Handles to update.</param>
  54. /// <param name="newHandle">Handles of the new data.</param>
  55. protected void CheckAndSetTextureHandle(ref TextureHandle[] handle, TextureHandle[] newHandle)
  56. {
  57. if (!CheckAndWarnAboutAccessibility())
  58. return;
  59. if (handle == null || handle.Length != newHandle.Length)
  60. handle = new TextureHandle[newHandle.Length];
  61. for (int i = 0; i < newHandle.Length; i++)
  62. handle[i] = newHandle[i];
  63. }
  64. /// <summary>
  65. /// Fetches the texture handles if the texture is accessible.
  66. /// </summary>
  67. /// <param name="handle">Handles to the texture you want to retrieve</param>
  68. /// <returns>Returns the handles if the texture is accessible and a null handle otherwise.</returns>
  69. protected TextureHandle[] CheckAndGetTextureHandle(ref TextureHandle[] handle)
  70. {
  71. if (!CheckAndWarnAboutAccessibility())
  72. return new []{TextureHandle.nullHandle};
  73. return handle;
  74. }
  75. /// <summary>
  76. /// Check if the texture is accessible.
  77. /// </summary>
  78. /// <returns>Returns true if the texture is accessible and false otherwise.</returns>
  79. protected bool CheckAndWarnAboutAccessibility()
  80. {
  81. if (!isAccessible)
  82. Debug.LogError("Trying to access Universal Resources outside of the current frame setup.");
  83. return isAccessible;
  84. }
  85. }
  86. }