BsQueryManager.h 2.8 KB

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