BsTimerQuery.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. namespace BansheeEngine
  4. {
  5. /** @cond INTERNAL */
  6. /** @addtogroup RenderAPI
  7. * @{
  8. */
  9. /**
  10. * Represents a GPU query that measures execution time of GPU operations. The query will measure any GPU operations
  11. * that take place between its begin() and end() calls.
  12. *
  13. * @note Core thread only.
  14. */
  15. class BS_CORE_EXPORT TimerQuery
  16. {
  17. public:
  18. virtual ~TimerQuery() {}
  19. /**
  20. * Starts the counter.
  21. *
  22. * @note Place any commands you want to measure after this call. Call "end" when done.
  23. */
  24. virtual void begin() = 0;
  25. /** Stops the counter. */
  26. virtual void end() = 0;
  27. /** Check if GPU has processed the query. */
  28. virtual bool isReady() const = 0;
  29. /**
  30. * Returns the time it took for the query to execute.
  31. *
  32. * @return The time milliseconds.
  33. *
  34. * @note Only valid after isReady() returns true.
  35. */
  36. virtual float getTimeMs() = 0;
  37. /** Triggered when GPU processes the query. As a parameter it provides query duration in milliseconds. */
  38. Event<void(float)> onTriggered;
  39. /** Creates a new query, but does not schedule it on GPU. */
  40. static TimerQueryPtr create();
  41. protected:
  42. friend class QueryManager;
  43. /** Returns true if the has still not been completed by the GPU. */
  44. bool isActive() const { return mActive; }
  45. void setActive(bool active) { mActive = active; }
  46. protected:
  47. bool mActive;
  48. };
  49. /** @} */
  50. /** @endcond */
  51. }