BsQueryManager.h 2.6 KB

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