2
0

BsQueryManager.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsEventQuery.h"
  4. #include "BsModule.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Handles creation and destruction of GPU queries.
  9. *
  10. * @note Core thread only.
  11. */
  12. class BS_CORE_EXPORT QueryManager : public Module<QueryManager>
  13. {
  14. public:
  15. QueryManager();
  16. ~QueryManager();
  17. /**
  18. * @brief Creates a new event query that allows you to get notified
  19. * when GPU starts executing the query.
  20. */
  21. virtual EventQueryPtr createEventQuery() const = 0;
  22. /**
  23. * @brief Creates a new timer query that allows you to get notified
  24. * of how much time has passed between query start and end.
  25. */
  26. virtual TimerQueryPtr createTimerQuery() const = 0;
  27. /**
  28. * @brief Creates a new occlusion query that allows you to know
  29. * how many fragments were rendered between query start and end.
  30. *
  31. * @param binary If query is binary it will not give you an exact count of fragments rendered, but will instead
  32. * just return 0 (no fragments were rendered) or 1 (one or more fragments were rendered). Binary
  33. * queries can return sooner as they potentially do not need to wait until all of the geometry is rendered.
  34. */
  35. virtual OcclusionQueryPtr createOcclusionQuery(bool binary) const = 0;
  36. /**
  37. * @note Internal method, called every frame.
  38. */
  39. void _update();
  40. protected:
  41. friend class EventQuery;
  42. friend class TimerQuery;
  43. friend class OcclusionQuery;
  44. /**
  45. * @brief Deletes an Event query. Always use this method and don't delete them manually.
  46. * Actual deletion will be delayed until next update.
  47. */
  48. static void deleteEventQuery(EventQuery* query);
  49. /**
  50. * @brief Deletes a Timer query. Always use this method and don't delete them manually.
  51. * Actual deletion will be delayed until next update.
  52. */
  53. static void deleteTimerQuery(TimerQuery* query);
  54. /**
  55. * @brief Deletes an Occlusion query. Always use this method and don't delete them manually.
  56. * Actual deletion will be delayed until next update.
  57. */
  58. static void deleteOcclusionQuery(OcclusionQuery* query);
  59. /**
  60. * @brief Deletes any queued queries.
  61. */
  62. void processDeletedQueue();
  63. protected:
  64. mutable Vector<EventQuery*> mEventQueries;
  65. mutable Vector<TimerQuery*> mTimerQueries;
  66. mutable Vector<OcclusionQuery*> mOcclusionQueries;
  67. mutable Vector<EventQuery*> mDeletedEventQueries;
  68. mutable Vector<TimerQuery*> mDeletedTimerQueries;
  69. mutable Vector<OcclusionQuery*> mDeletedOcclusionQueries;
  70. };
  71. }