BsEventQuery.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. namespace BansheeEngine
  4. {
  5. /**
  6. * @brief Represents a GPU query that gets triggered when GPU starts processing the query.
  7. *
  8. * @note Normally GPU will have many commands in its command buffer. When EventQuery::begin is called it is placed
  9. * in that command buffer. Once the buffer empties and GPU reaches the EventQuery command, the query
  10. * callback is triggered.
  11. *
  12. * Core thread only.
  13. */
  14. class BS_CORE_EXPORT EventQuery
  15. {
  16. public:
  17. EventQuery()
  18. :mActive(false) {}
  19. virtual ~EventQuery() {}
  20. /**
  21. * @brief Starts the query.
  22. *
  23. * @note Once the query is started you may poll "isReady" method to check when query has finished,
  24. * or you may hook up an "onTriggered" callback and be notified that way.
  25. */
  26. virtual void begin() = 0;
  27. /**
  28. * @brief Check if GPU has processed the query.
  29. */
  30. virtual bool isReady() const = 0;
  31. /**
  32. * @brief Triggered when GPU starts processing the query.
  33. */
  34. Event<void()> onTriggered;
  35. /**
  36. * @brief Creates a new query, but does not schedule it on GPU.
  37. */
  38. static EventQueryPtr create();
  39. protected:
  40. friend class QueryManager;
  41. /**
  42. * @brief Returns true if the has still not been completed by the GPU.
  43. */
  44. bool isActive() const { return mActive; }
  45. void setActive(bool active) { mActive = active; }
  46. protected:
  47. bool mActive;
  48. };
  49. }