CommandBufferPool.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections.Generic;
  2. using UnityEngine.Events;
  3. namespace UnityEngine.Rendering
  4. {
  5. /// <summary>
  6. /// Command Buffer Pool
  7. /// </summary>
  8. public static class CommandBufferPool
  9. {
  10. static ObjectPool<CommandBuffer> s_BufferPool = new ObjectPool<CommandBuffer>(null, x => x.Clear());
  11. /// <summary>
  12. /// Get a new Command Buffer.
  13. /// </summary>
  14. /// <returns></returns>
  15. public static CommandBuffer Get()
  16. {
  17. var cmd = s_BufferPool.Get();
  18. cmd.name = "Unnamed Command Buffer";
  19. return cmd;
  20. }
  21. /// <summary>
  22. /// Get a new Command Buffer and assign a name to it.
  23. /// </summary>
  24. /// <param name="name"></param>
  25. /// <returns></returns>
  26. public static CommandBuffer Get(string name)
  27. {
  28. var cmd = s_BufferPool.Get();
  29. cmd.name = name;
  30. return cmd;
  31. }
  32. /// <summary>
  33. /// Release a Command Buffer.
  34. /// </summary>
  35. /// <param name="buffer"></param>
  36. public static void Release(CommandBuffer buffer)
  37. {
  38. s_BufferPool.Release(buffer);
  39. }
  40. }
  41. }