2
0

BsTimerQuery.h 1.7 KB

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