BsTimerQuery.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. /** @cond INTERNAL */
  8. /** @addtogroup RenderAPI
  9. * @{
  10. */
  11. /**
  12. * Represents a GPU query that measures execution time of GPU operations. The query will measure any GPU operations
  13. * that take place between its begin() and end() calls.
  14. *
  15. * @note Core thread only.
  16. */
  17. class BS_CORE_EXPORT TimerQuery
  18. {
  19. public:
  20. virtual ~TimerQuery() {}
  21. /**
  22. * Starts the counter.
  23. *
  24. * @note Place any commands you want to measure after this call. Call "end" when done.
  25. */
  26. virtual void begin() = 0;
  27. /** Stops the counter. */
  28. virtual void end() = 0;
  29. /** Check if GPU has processed the query. */
  30. virtual bool isReady() const = 0;
  31. /**
  32. * Returns the time it took for the query to execute.
  33. *
  34. * @return The time milliseconds.
  35. *
  36. * @note Only valid after isReady() returns true.
  37. */
  38. virtual float getTimeMs() = 0;
  39. /** Triggered when GPU processes the query. As a parameter it provides query duration in milliseconds. */
  40. Event<void(float)> onTriggered;
  41. /** Creates a new query, but does not schedule it on GPU. */
  42. static TimerQueryPtr create();
  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. /** @endcond */
  53. }