BsOcclusionQuery.h 2.0 KB

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