BsOcclusionQuery.h 2.1 KB

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