BsEventQuery.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 BansheeEngine
  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. * @note
  29. * Once the query is started you may poll isReady() method to check when query has finished, or you may hook up
  30. * an #onTriggered callback and be notified that way.
  31. */
  32. virtual void begin() = 0;
  33. /** Check if GPU has processed the query. */
  34. virtual bool isReady() const = 0;
  35. /** Triggered when GPU starts processing the query. */
  36. Event<void()> onTriggered;
  37. /**
  38. * Creates a new query, but does not schedule it on GPU.
  39. *
  40. * @param[in] deviceIdx Index of the GPU device to create the query on.
  41. */
  42. static SPtr<EventQuery> create(UINT32 deviceIdx = 0);
  43. protected:
  44. friend class QueryManager;
  45. /** Returns true if the has still not been completed by the GPU. */
  46. bool isActive() const { return mActive; }
  47. void setActive(bool active) { mActive = active; }
  48. protected:
  49. bool mActive;
  50. };
  51. /** @} */
  52. }