BsCommandBuffer.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsModule.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup RenderAPI
  9. * @{
  10. */
  11. /**
  12. * Contains a list of render API commands that can be queued for execution on the GPU. User is allowed to populate the
  13. * command buffer from any thread, ensuring render API command generation can be multi-threaded. Command buffers
  14. * must always be created on the core thread. Same command buffer cannot be used on multiple threads simulateously
  15. * without external synchronization.
  16. */
  17. class BS_CORE_EXPORT CommandBuffer
  18. {
  19. public:
  20. /** @copydoc CommandBufferManager::create */
  21. static SPtr<CommandBuffer> create(CommandBufferType type, UINT32 deviceIdx = 0, UINT32 syncMask = 0xFFFFFFFF,
  22. bool secondary = false);
  23. protected:
  24. CommandBuffer(CommandBufferType type, UINT32 syncMask, bool secondary);
  25. CommandBufferType mType;
  26. UINT32 mSyncMask;
  27. bool mIsSecondary;
  28. };
  29. /** @} */
  30. /** @addtogroup RenderAPI-Internal
  31. * @{
  32. */
  33. /**
  34. * Command buffer implementation for render API's that do not support multi-threaded command generation. Instead all
  35. * commands are stored in an internal buffer, and then sent to the actual render API when the buffer is executed.
  36. */
  37. class BS_CORE_EXPORT SimpleCommandBuffer : CommandBuffer
  38. {
  39. public:
  40. /** Registers a new command in the command buffer. */
  41. void queueCommand(const std::function<void()> command);
  42. /** Appends all commands from the secondary buffer into this command buffer. */
  43. void appendSecondary(const SPtr<SimpleCommandBuffer>& secondaryBuffer);
  44. /** Executes all commands in the command buffer. Not supported on secondary buffer. */
  45. void executeCommands();
  46. /** Removes all commands from the command buffer. */
  47. void clear();
  48. private:
  49. friend class CommandBufferManager;
  50. SimpleCommandBuffer(CommandBufferType type, UINT32 deviceIdx, UINT32 syncMask, bool secondary);
  51. UINT32 mDeviceIdx;
  52. Vector<std::function<void()>> mCommands;
  53. };
  54. /** @} */
  55. }