BsQueryManager.h 2.8 KB

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