BsOcclusionQuery.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. namespace BansheeEngine
  6. {
  7. /** @addtogroup RenderAPI
  8. * @{
  9. */
  10. /**
  11. * Represents a query that counts number of samples rendered by the GPU while the query is active.
  12. *
  13. * @note Core thread only.
  14. */
  15. class BS_CORE_EXPORT OcclusionQuery
  16. {
  17. public:
  18. OcclusionQuery(bool binary);
  19. virtual ~OcclusionQuery() {}
  20. /**
  21. * Starts the query. Any draw calls after this call will have any rendered samples counted in the query.
  22. *
  23. * @note Place any commands you want to measure after this call. Call end() when done.
  24. */
  25. virtual void begin() = 0;
  26. /**
  27. * Stops the query.
  28. *
  29. * @note Be aware that queries are executed on the GPU and the results will not be immediately available.
  30. */
  31. virtual void end() = 0;
  32. /** Check if GPU has processed the query. */
  33. virtual bool isReady() const = 0;
  34. /**
  35. * Returns the number of samples that passed the depth and stencil test between query start and end.
  36. *
  37. * @note
  38. * If the query is binary, this will return 0 or 1. 1 meaning one or more samples were rendered, but will not give
  39. * you the exact count.
  40. */
  41. virtual UINT32 getNumSamples() = 0;
  42. /** Triggered when the query has completed. Argument provided is the number of samples counted by the query. */
  43. Event<void(UINT32)> onComplete;
  44. /**
  45. * Creates a new occlusion query.
  46. *
  47. * @param[in] binary If query is binary it will not give you an exact count of samples rendered, but will instead
  48. * just return 0 (no samples were rendered) or 1 (one or more samples were rendered). Binary
  49. * queries can return sooner as they potentially do not need to wait until all of the geometry
  50. * is rendered.
  51. */
  52. static SPtr<OcclusionQuery> create(bool binary);
  53. protected:
  54. friend class QueryManager;
  55. /** Returns true if the has still not been completed by the GPU. */
  56. bool isActive() const { return mActive; }
  57. void setActive(bool active) { mActive = active; }
  58. protected:
  59. bool mActive;
  60. bool mBinary;
  61. };
  62. /** @} */
  63. }