BaseRenderTextureInput.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using UnityEngine;
  2. namespace UnityEditor.Recorder
  3. {
  4. /// <summary>
  5. /// Base class for all Recorder inputs that capture images.
  6. /// </summary>
  7. public abstract class BaseRenderTextureInput : RecorderInput
  8. {
  9. /// <summary>
  10. /// Enables asynchronous readback of GPU resources if the platform supports it.
  11. /// Set this property to a valid instance and ensure that ReadbackTexture is not set.
  12. /// </summary>
  13. protected internal RenderTexture OutputRenderTexture { get; set; }
  14. /// <summary>
  15. /// Indicates the synchronous GPU readback destination.
  16. /// </summary>
  17. protected internal Texture2D ReadbackTexture { get; set; }
  18. /// <summary>
  19. /// Stores the output image width.
  20. /// </summary>
  21. public int OutputWidth { get; protected set; }
  22. /// <summary>
  23. /// Stores the output image height.
  24. /// </summary>
  25. public int OutputHeight { get; protected set; }
  26. /// <summary>
  27. /// Releases all resources allocated by this class instance.
  28. /// </summary>
  29. protected void ReleaseBuffer()
  30. {
  31. if (OutputRenderTexture != null)
  32. {
  33. if (OutputRenderTexture == RenderTexture.active)
  34. RenderTexture.active = null;
  35. OutputRenderTexture.Release();
  36. OutputRenderTexture = null;
  37. }
  38. }
  39. /// <summary>
  40. /// Releases all resources allocated by this instance.
  41. /// </summary>
  42. /// <param name="disposing">If true, releases buffers allocated by this class as well.</param>
  43. protected override void Dispose(bool disposing)
  44. {
  45. base.Dispose(disposing);
  46. if (disposing)
  47. ReleaseBuffer();
  48. }
  49. }
  50. }