BsQueryManager.h 2.8 KB

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