BsEventQuery.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. namespace bs { namespace ct
  6. {
  7. /** @addtogroup RenderAPI-Internal
  8. * @{
  9. */
  10. /**
  11. * Represents a GPU query that gets triggered when GPU starts processing the query.
  12. *
  13. * @note
  14. * Normally GPU will have many commands in its command buffer. When begin() is called it is placed in that command
  15. * buffer. Once the buffer empties and GPU reaches the EventQuery command, the query callback is triggered.
  16. * @note
  17. * Core thread only.
  18. */
  19. class BS_CORE_EXPORT EventQuery
  20. {
  21. public:
  22. EventQuery()
  23. :mActive(false) {}
  24. virtual ~EventQuery() {}
  25. /**
  26. * Starts the query.
  27. *
  28. * @param[in] cb Optional command buffer to queue the operation on. If not provided operation
  29. * is executed on the main command buffer. Otherwise it is executed when
  30. * RenderAPI::executeCommands() is called. Buffer must support graphics or compute operations.
  31. *
  32. * @note
  33. * Once the query is started you may poll isReady() method to check when query has finished, or you may hook up
  34. * an #onTriggered callback and be notified that way.
  35. */
  36. virtual void begin(const SPtr<CommandBuffer>& cb = nullptr) = 0;
  37. /** Check if GPU has processed the query. */
  38. virtual bool isReady() const = 0;
  39. /** Triggered when GPU starts processing the query. */
  40. Event<void()> onTriggered;
  41. /**
  42. * Creates a new query, but does not schedule it on GPU.
  43. *
  44. * @param[in] deviceIdx Index of the GPU device to create the query on.
  45. */
  46. static SPtr<EventQuery> create(UINT32 deviceIdx = 0);
  47. protected:
  48. friend class QueryManager;
  49. /** Returns true if the has still not been completed by the GPU. */
  50. bool isActive() const { return mActive; }
  51. void setActive(bool active) { mActive = active; }
  52. protected:
  53. bool mActive;
  54. };
  55. /** @} */
  56. }}