BsOcclusionQuery.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #pragma once
  5. #include "BsCorePrerequisites.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Represents a query that counts number of samples rendered by the GPU
  10. * while the query is active.
  11. *
  12. * @note Core thread only.
  13. */
  14. class BS_CORE_EXPORT OcclusionQuery
  15. {
  16. public:
  17. OcclusionQuery(bool binary);
  18. virtual ~OcclusionQuery() {}
  19. /**
  20. * @brief Starts the query. Any draw calls after this call will have any rendered samples
  21. * 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. * @brief 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. /**
  33. * @brief Check if GPU has processed the query.
  34. */
  35. virtual bool isReady() const = 0;
  36. /**
  37. * @brief Returns the number of samples that passed the depth and stencil test between
  38. * query start and end.
  39. *
  40. * @note If the query is binary, this will return 0 or 1. 1 meaning one or more samples were rendered,
  41. * but will not give you the exact count.
  42. */
  43. virtual UINT32 getNumSamples() = 0;
  44. /**
  45. * @brief Triggered when the query has completed. Argument provided
  46. * is the number of samples counted by the query.
  47. */
  48. Event<void(UINT32)> onComplete;
  49. /**
  50. * @brief Creates a new occlusion query.
  51. *
  52. * @param binary If query is binary it will not give you an exact count of samples rendered, but will instead
  53. * just return 0 (no samples were rendered) or 1 (one or more samples were rendered). Binary
  54. * queries can return sooner as they potentially do not need to wait until all of the geometry is rendered.
  55. */
  56. static OcclusionQueryPtr create(bool binary);
  57. protected:
  58. friend class QueryManager;
  59. /**
  60. * @brief Returns true if the has still not been completed by the GPU.
  61. */
  62. bool isActive() const { return mActive; }
  63. void setActive(bool active) { mActive = active; }
  64. protected:
  65. bool mActive;
  66. bool mBinary;
  67. };
  68. }