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