CommandBufferPool.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. // Set to empty on purpose, does not create profiling markers.
  19. cmd.name = "";
  20. return cmd;
  21. }
  22. /// <summary>
  23. /// Get a new Command Buffer and assign a name to it.
  24. /// Named Command Buffers will add profiling makers implicitly for the buffer execution.
  25. /// </summary>
  26. /// <param name="name"></param>
  27. /// <returns></returns>
  28. public static CommandBuffer Get(string name)
  29. {
  30. var cmd = s_BufferPool.Get();
  31. cmd.name = name;
  32. return cmd;
  33. }
  34. /// <summary>
  35. /// Release a Command Buffer.
  36. /// </summary>
  37. /// <param name="buffer"></param>
  38. public static void Release(CommandBuffer buffer)
  39. {
  40. s_BufferPool.Release(buffer);
  41. }
  42. }
  43. }