BsEventQuery.h 1.7 KB

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