BsOcclusionQuery.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 bs { namespace ct
  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(const SPtr<CommandBuffer>& cb = nullptr) = 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(const SPtr<CommandBuffer>& cb = nullptr) = 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
  48. * instead just return 0 (no samples were rendered) or 1 (one or more samples were
  49. * rendered). Binary queries can return sooner as they potentially do not need to wait
  50. * until all of the geometry is rendered.
  51. * @param[in] deviceIdx Index of the GPU device to create the query on.
  52. */
  53. static SPtr<OcclusionQuery> create(bool binary, UINT32 deviceIdx = 0);
  54. protected:
  55. friend class QueryManager;
  56. /** Returns true if the has still not been completed by the GPU. */
  57. bool isActive() const { return mActive; }
  58. void setActive(bool active) { mActive = active; }
  59. protected:
  60. bool mActive;
  61. bool mBinary;
  62. };
  63. /** @} */
  64. }}