BsTimerQuery.h 1.8 KB

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