1 | // |
2 | // Redistribution and use in source and binary forms, with or without |
3 | // modification, are permitted provided that the following conditions |
4 | // are met: |
5 | // * Redistributions of source code must retain the above copyright |
6 | // notice, this list of conditions and the following disclaimer. |
7 | // * Redistributions in binary form must reproduce the above copyright |
8 | // notice, this list of conditions and the following disclaimer in the |
9 | // documentation and/or other materials provided with the distribution. |
10 | // * Neither the name of NVIDIA CORPORATION nor the names of its |
11 | // contributors may be used to endorse or promote products derived |
12 | // from this software without specific prior written permission. |
13 | // |
14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
18 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
20 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
21 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 | // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | // |
26 | // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved. |
27 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
28 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
29 | |
30 | |
31 | #ifndef PX_PHYSICS_NX_SCENEQUERYDESC |
32 | #define PX_PHYSICS_NX_SCENEQUERYDESC |
33 | /** \addtogroup physics |
34 | @{ */ |
35 | |
36 | #include "PxPhysXConfig.h" |
37 | #include "PxClient.h" |
38 | #include "PxFiltering.h" |
39 | #include "PxQueryFiltering.h" |
40 | #include "foundation/PxAssert.h" |
41 | |
42 | #if !PX_DOXYGEN |
43 | namespace physx |
44 | { |
45 | #endif |
46 | |
47 | struct PxSweepHit; |
48 | struct PxRaycastHit; |
49 | |
50 | /** |
51 | \brief Batched query status. |
52 | |
53 | \deprecated The batched query feature has been deprecated in PhysX version 3.4 |
54 | */ |
55 | struct PX_DEPRECATED PxBatchQueryStatus |
56 | { |
57 | enum Enum |
58 | { |
59 | /** |
60 | \brief This is the initial state before a query starts. |
61 | */ |
62 | ePENDING = 0, |
63 | |
64 | /** |
65 | \brief The query is finished; results have been written into the result and hit buffers. |
66 | */ |
67 | eSUCCESS, |
68 | |
69 | /** |
70 | \brief The query results were incomplete due to touch hit buffer overflow. Blocking hit is still correct. |
71 | */ |
72 | eOVERFLOW |
73 | }; |
74 | }; |
75 | |
76 | /** |
77 | \brief Generic struct for receiving results of single query in a batch. Gets templated on hit type PxRaycastHit, PxSweepHit or PxOverlapHit. |
78 | |
79 | \deprecated The batched query feature has been deprecated in PhysX version 3.4 |
80 | */ |
81 | template<typename HitType> |
82 | struct PX_DEPRECATED PxBatchQueryResult |
83 | { |
84 | HitType block; //!< Holds the closest blocking hit for a single query in a batch. Only valid if hasBlock is true. |
85 | HitType* touches; //!< This pointer will either be set to NULL for 0 nbTouches or will point |
86 | //!< into the user provided batch query results buffer specified in PxBatchQueryDesc. |
87 | PxU32 nbTouches; //!< Number of touching hits returned by this query, works in tandem with touches pointer. |
88 | void* userData; //!< Copy of the userData pointer specified in the corresponding query. |
89 | PxU8 queryStatus; //!< Takes on values from PxBatchQueryStatus::Enum. |
90 | bool hasBlock; //!< True if there was a blocking hit. |
91 | PxU16 pad; //!< pads the struct to 16 bytes. |
92 | |
93 | /** \brief Computes the number of any hits in this result, blocking or touching. */ |
94 | PX_INLINE PxU32 getNbAnyHits() const { return nbTouches + (hasBlock ? 1 : 0); } |
95 | |
96 | /** \brief Convenience iterator used to access any hits in this result, blocking or touching. */ |
97 | PX_INLINE const HitType& getAnyHit(const PxU32 index) const { PX_ASSERT(index < nbTouches + (hasBlock ? 1 : 0)); |
98 | return index < nbTouches ? touches[index] : block; } |
99 | }; |
100 | |
101 | /** \brief Convenience typedef for the result of a batched raycast query. */ |
102 | typedef PX_DEPRECATED PxBatchQueryResult<PxRaycastHit> PxRaycastQueryResult; |
103 | |
104 | /** \brief Convenience typedef for the result of a batched sweep query. */ |
105 | typedef PX_DEPRECATED PxBatchQueryResult<PxSweepHit> PxSweepQueryResult; |
106 | |
107 | /** \brief Convenience typedef for the result of a batched overlap query. */ |
108 | typedef PX_DEPRECATED PxBatchQueryResult<PxOverlapHit> PxOverlapQueryResult; |
109 | |
110 | /** |
111 | \brief Struct for #PxBatchQuery memory pointers. |
112 | |
113 | \deprecated The batched query feature has been deprecated in PhysX version 3.4 |
114 | |
115 | @see PxBatchQuery PxBatchQueryDesc |
116 | */ |
117 | struct PX_DEPRECATED PxBatchQueryMemory |
118 | { |
119 | /** |
120 | \brief The pointer to the user-allocated buffer for results of raycast queries in corresponding order of issue |
121 | |
122 | \note The size should be large enough to fit the number of expected raycast queries. |
123 | |
124 | @see PxRaycastQueryResult |
125 | */ |
126 | PxRaycastQueryResult* userRaycastResultBuffer; |
127 | |
128 | /** |
129 | \brief The pointer to the user-allocated buffer for raycast touch hits. |
130 | \note The size of this buffer should be large enough to store PxRaycastHit. |
131 | If the buffer is too small to store hits, the related PxRaycastQueryResult.queryStatus will be set to eOVERFLOW |
132 | |
133 | */ |
134 | PxRaycastHit* userRaycastTouchBuffer; |
135 | |
136 | /** |
137 | \brief The pointer to the user-allocated buffer for results of sweep queries in corresponding order of issue |
138 | |
139 | \note The size should be large enough to fit the number of expected sweep queries. |
140 | |
141 | @see PxRaycastQueryResult |
142 | */ |
143 | PxSweepQueryResult* userSweepResultBuffer; |
144 | |
145 | /** |
146 | \brief The pointer to the user-allocated buffer for sweep hits. |
147 | \note The size of this buffer should be large enough to store PxSweepHit. |
148 | If the buffer is too small to store hits, the related PxSweepQueryResult.queryStatus will be set to eOVERFLOW |
149 | |
150 | */ |
151 | PxSweepHit* userSweepTouchBuffer; |
152 | |
153 | /** |
154 | \brief The pointer to the user-allocated buffer for results of overlap queries in corresponding order of issue |
155 | |
156 | \note The size should be large enough to fit the number of expected overlap queries. |
157 | |
158 | @see PxRaycastQueryResult |
159 | */ |
160 | PxOverlapQueryResult* userOverlapResultBuffer; |
161 | |
162 | /** |
163 | \brief The pointer to the user-allocated buffer for overlap hits. |
164 | \note The size of this buffer should be large enough to store the hits returned. |
165 | If the buffer is too small to store hits, the related PxOverlapQueryResult.queryStatus will be set to eABORTED |
166 | |
167 | */ |
168 | PxOverlapHit* userOverlapTouchBuffer; |
169 | |
170 | /** \brief Capacity of the user-allocated userRaycastTouchBuffer in elements */ |
171 | PxU32 raycastTouchBufferSize; |
172 | |
173 | /** \brief Capacity of the user-allocated userSweepTouchBuffer in elements */ |
174 | PxU32 sweepTouchBufferSize; |
175 | |
176 | /** \brief Capacity of the user-allocated userOverlapTouchBuffer in elements */ |
177 | PxU32 overlapTouchBufferSize; |
178 | |
179 | /** \return Capacity of the user-allocated userRaycastResultBuffer in elements (max number of raycast() calls before execute() call) */ |
180 | PX_FORCE_INLINE PxU32 getMaxRaycastsPerExecute() const { return raycastResultBufferSize; } |
181 | |
182 | /** \return Capacity of the user-allocated userSweepResultBuffer in elements (max number of sweep() calls before execute() call) */ |
183 | PX_FORCE_INLINE PxU32 getMaxSweepsPerExecute() const { return sweepResultBufferSize; } |
184 | |
185 | /** \return Capacity of the user-allocated userOverlapResultBuffer in elements (max number of overlap() calls before execute() call) */ |
186 | PX_FORCE_INLINE PxU32 getMaxOverlapsPerExecute() const { return overlapResultBufferSize; } |
187 | |
188 | PxBatchQueryMemory(PxU32 raycastResultBufferSize_, PxU32 sweepResultBufferSize_, PxU32 overlapResultBufferSize_) : |
189 | userRaycastResultBuffer (NULL), |
190 | userRaycastTouchBuffer (NULL), |
191 | userSweepResultBuffer (NULL), |
192 | userSweepTouchBuffer (NULL), |
193 | userOverlapResultBuffer (NULL), |
194 | userOverlapTouchBuffer (NULL), |
195 | raycastTouchBufferSize (0), |
196 | sweepTouchBufferSize (0), |
197 | overlapTouchBufferSize (0), |
198 | raycastResultBufferSize (raycastResultBufferSize_), |
199 | sweepResultBufferSize (sweepResultBufferSize_), |
200 | overlapResultBufferSize (overlapResultBufferSize_) |
201 | { |
202 | } |
203 | |
204 | protected: |
205 | PxU32 raycastResultBufferSize; |
206 | PxU32 sweepResultBufferSize; |
207 | PxU32 overlapResultBufferSize; |
208 | }; |
209 | |
210 | /** |
211 | \brief Descriptor class for #PxBatchQuery. |
212 | |
213 | \deprecated The batched query feature has been deprecated in PhysX version 3.4 |
214 | |
215 | @see PxBatchQuery PxSceneQueryExecuteMode |
216 | */ |
217 | class PX_DEPRECATED PxBatchQueryDesc |
218 | { |
219 | public: |
220 | |
221 | /** |
222 | \brief Shared global filter data which will get passed into the filter shader. |
223 | |
224 | \note The provided data will get copied to internal buffers and this copy will be used for filtering calls. |
225 | |
226 | <b>Default:</b> NULL |
227 | |
228 | @see PxSimulationFilterShader |
229 | */ |
230 | void* filterShaderData; |
231 | |
232 | /** |
233 | \brief Size (in bytes) of the shared global filter data #filterShaderData. |
234 | |
235 | <b>Default:</b> 0 |
236 | |
237 | @see PxSimulationFilterShader filterShaderData |
238 | */ |
239 | PxU32 filterShaderDataSize; |
240 | |
241 | /** |
242 | \brief The custom preFilter shader to use for filtering. |
243 | |
244 | @see PxBatchQueryPreFilterShader PxDefaultPreFilterShader |
245 | */ |
246 | PxBatchQueryPreFilterShader preFilterShader; |
247 | |
248 | /** |
249 | \brief The custom postFilter shader to use for filtering. |
250 | |
251 | @see PxBatchQueryPostFilterShader PxDefaultPostFilterShader |
252 | */ |
253 | PxBatchQueryPostFilterShader postFilterShader; |
254 | |
255 | /** |
256 | \brief User memory buffers for the query. |
257 | |
258 | @see PxBatchQueryMemory |
259 | */ |
260 | PxBatchQueryMemory queryMemory; |
261 | |
262 | /** |
263 | \brief Construct a batch query with specified maximum number of queries per batch. |
264 | |
265 | If the number of raycasts/sweeps/overlaps per execute exceeds the limit, the query will be discarded with a warning. |
266 | |
267 | \param maxRaycastsPerExecute Maximum number of raycast() calls allowed before execute() call. |
268 | This has to match the amount of memory allocated for PxBatchQueryMemory::userRaycastResultBuffer. |
269 | \param maxSweepsPerExecute Maximum number of sweep() calls allowed before execute() call. |
270 | This has to match the amount of memory allocated for PxBatchQueryMemory::userSweepResultBuffer. |
271 | \param maxOverlapsPerExecute Maximum number of overlap() calls allowed before execute() call. |
272 | This has to match the amount of memory allocated for PxBatchQueryMemory::userOverlapResultBuffer. |
273 | */ |
274 | PX_INLINE PxBatchQueryDesc(PxU32 maxRaycastsPerExecute, PxU32 maxSweepsPerExecute, PxU32 maxOverlapsPerExecute); |
275 | PX_INLINE bool isValid() const; |
276 | }; |
277 | |
278 | |
279 | PX_INLINE PxBatchQueryDesc::PxBatchQueryDesc(PxU32 maxRaycastsPerExecute, PxU32 maxSweepsPerExecute, PxU32 maxOverlapsPerExecute) : |
280 | filterShaderData (NULL), |
281 | filterShaderDataSize (0), |
282 | preFilterShader (NULL), |
283 | postFilterShader (NULL), |
284 | queryMemory (maxRaycastsPerExecute, maxSweepsPerExecute, maxOverlapsPerExecute) |
285 | { |
286 | } |
287 | |
288 | |
289 | PX_INLINE bool PxBatchQueryDesc::isValid() const |
290 | { |
291 | if ( ((filterShaderDataSize == 0) && (filterShaderData != NULL)) || |
292 | ((filterShaderDataSize > 0) && (filterShaderData == NULL)) ) |
293 | return false; |
294 | |
295 | return true; |
296 | } |
297 | |
298 | #if !PX_DOXYGEN |
299 | } // namespace physx |
300 | #endif |
301 | |
302 | /** @} */ |
303 | #endif |
304 | |