RavEngine
Loading...
Searching...
No Matches
PxBroadPhase.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PX_BROAD_PHASE_H
30#define PX_BROAD_PHASE_H
35#include "PxPhysXConfig.h"
36#include "foundation/PxBounds3.h"
37
38#if !PX_DOXYGEN
39namespace physx
40{
41#endif
42
43 class PxBaseTask;
44 class PxCudaContextManager;
45
77 {
78 enum Enum
79 {
85 eLAST
86 };
87 };
88
114
126
131 {
133 };
134
149 {
150 public:
151 PxBroadPhaseDesc(PxBroadPhaseType::Enum type = PxBroadPhaseType::eLAST) :
152 mType (type),
153 mContextID (0),
154 mContextManager (NULL),
155 mFoundLostPairsCapacity (256 * 1024),
158 {}
159
162
163 PxCudaContextManager* mContextManager;
165
168
169 PX_INLINE bool isValid() const
170 {
171 if(PxU32(mType)>=PxBroadPhaseType::eLAST)
172 return false;
173
175 return false;
176
177 return true;
178 }
179 };
180
181 typedef PxU32 PxBpIndex;
182 typedef PxU32 PxBpFilterGroup;
183 #define PX_INVALID_BP_FILTER_GROUP 0xffffffff
184
195 PX_C_EXPORT PX_PHYSX_CORE_API PxBpFilterGroup PxGetBroadPhaseStaticFilterGroup();
196
209 PX_C_EXPORT PX_PHYSX_CORE_API PxBpFilterGroup PxGetBroadPhaseDynamicFilterGroup(PxU32 id);
210
222 PX_C_EXPORT PX_PHYSX_CORE_API PxBpFilterGroup PxGetBroadPhaseKinematicFilterGroup(PxU32 id);
223
244 {
245 public:
246
247 PxBroadPhaseUpdateData( const PxBpIndex* created, PxU32 nbCreated,
248 const PxBpIndex* updated, PxU32 nbUpdated,
249 const PxBpIndex* removed, PxU32 nbRemoved,
250 const PxBounds3* bounds, const PxBpFilterGroup* groups, const float* distances,
251 PxU32 capacity) :
252 mCreated (created), mNbCreated (nbCreated),
253 mUpdated (updated), mNbUpdated (nbUpdated),
254 mRemoved (removed), mNbRemoved (nbRemoved),
255 mBounds (bounds), mGroups (groups), mDistances (distances),
256 mCapacity (capacity)
257 {
258 }
259
261 mCreated (other.mCreated), mNbCreated (other.mNbCreated),
262 mUpdated (other.mUpdated), mNbUpdated (other.mNbUpdated),
263 mRemoved (other.mRemoved), mNbRemoved (other.mNbRemoved),
264 mBounds (other.mBounds), mGroups (other.mGroups), mDistances (other.mDistances),
265 mCapacity (other.mCapacity)
266 {
267 }
268
269 PxBroadPhaseUpdateData& operator=(const PxBroadPhaseUpdateData& other);
270
272 const PxU32 mNbCreated;
273
275 const PxU32 mNbUpdated;
276
278 const PxU32 mNbRemoved;
279
282 const float* mDistances;
283 const PxU32 mCapacity;
284 };
285
298
316
325 {
326 protected:
328 virtual ~PxBroadPhaseRegions() {}
329 public:
330
336 virtual PxU32 getNbRegions() const = 0;
337
347 virtual PxU32 getRegions(PxBroadPhaseRegionInfo* userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const = 0;
348
379 virtual PxU32 addRegion(const PxBroadPhaseRegion& region, bool populateRegion, const PxBounds3* bounds, const float* distances) = 0;
380
394 virtual bool removeRegion(PxU32 handle) = 0;
395
396 /*
397 \brief Return the number of objects that are not in any region.
398 */
399 virtual PxU32 getNbOutOfBoundsObjects() const = 0;
400
401 /*
402 \brief Return an array of objects that are not in any region.
403 */
404 virtual const PxU32* getOutOfBoundsObjects() const = 0;
405 };
406
424 {
425 protected:
426 PxBroadPhase() {}
427 virtual ~PxBroadPhase() {}
428 public:
429
430 /*
431 \brief Releases the broadphase.
432 */
433 virtual void release() = 0;
434
441 virtual PxBroadPhaseType::Enum getType() const = 0;
442
449 virtual void getCaps(PxBroadPhaseCaps& caps) const = 0;
450
460
472
479 virtual PxU64 getContextID() const = 0;
480
492 virtual void setScratchBlock(void* scratchBlock, PxU32 size) = 0;
493
507 virtual void update(const PxBroadPhaseUpdateData& updateData, PxBaseTask* continuation=NULL) = 0;
508
518 virtual void fetchResults(PxBroadPhaseResults& results) = 0;
519
530 {
531 update(updateData);
532 fetchResults(results);
533 }
534 };
535
545 PX_C_EXPORT PX_PHYSX_CORE_API PxBroadPhase* PxCreateBroadPhase(const PxBroadPhaseDesc& desc);
546
559 {
560 protected:
561 PxAABBManager() {}
562 virtual ~PxAABBManager() {}
563 public:
564
565 /*
566 \brief Releases the AABB manager.
567 */
568 virtual void release() = 0;
569
577
586 virtual const PxBounds3* getBounds() const = 0;
587
595 virtual const float* getDistances() const = 0;
596
602 virtual const PxBpFilterGroup* getGroups() const = 0;
603
611 virtual PxU32 getCapacity() const = 0;
612
626 virtual void addObject(PxBpIndex index, const PxBounds3& bounds, PxBpFilterGroup group, float distance=0.0f) = 0;
627
634 virtual void removeObject(PxBpIndex index) = 0;
635
647 virtual void updateObject(PxBpIndex index, const PxBounds3* bounds=NULL, const float* distance=NULL) = 0;
648
661 virtual void update(PxBaseTask* continuation=NULL) = 0;
662
672 virtual void fetchResults(PxBroadPhaseResults& results) = 0;
673
683 {
684 update();
685 fetchResults(results);
686 }
687 };
688
698 PX_C_EXPORT PX_PHYSX_CORE_API PxAABBManager* PxCreateAABBManager(PxBroadPhase& broadphase);
699
700#if !PX_DOXYGEN
701} // namespace physx
702#endif
703
705#endif
High-level broadphase API.
Definition PxBroadPhase.h:559
virtual void updateObject(PxBpIndex index, const PxBounds3 *bounds=NULL, const float *distance=NULL)=0
Updates an object in the manager.
virtual const PxBounds3 * getBounds() const =0
Retrieves the managed bounds.
virtual void fetchResults(PxBroadPhaseResults &results)=0
Retrieves the broadphase results after an update.
virtual PxU32 getCapacity() const =0
Retrieves the managed buffers' capacity.
virtual PxBroadPhase & getBroadPhase()=0
Retrieves the underlying broadphase.
virtual void addObject(PxBpIndex index, const PxBounds3 &bounds, PxBpFilterGroup group, float distance=0.0f)=0
Adds an object to the manager.
virtual const PxBpFilterGroup * getGroups() const =0
Retrieves the managed filter groups.
PX_FORCE_INLINE void update(PxBroadPhaseResults &results)
Helper for single-threaded updates.
Definition PxBroadPhase.h:682
virtual void removeObject(PxBpIndex index)=0
Removes an object from the manager.
virtual const float * getDistances() const =0
Retrieves the managed distances.
virtual void update(PxBaseTask *continuation=NULL)=0
Updates the broadphase and computes the lists of created/deleted pairs.
Abstract base class for an application defined memory allocator that can be used by the Nv library.
Definition PxAllocatorCallback.h:53
Base class of all task types.
Definition PxTask.h:45
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
Broadphase descriptor.
Definition PxBroadPhase.h:149
PxU32 mFoundLostPairsCapacity
(GPU) Capacity of found and lost buffers allocated in GPU global memory. This is used for the found/l...
Definition PxBroadPhase.h:164
bool mDiscardStaticVsKinematic
Static-vs-kinematic filtering flag. Not supported by PxBroadPhaseType::eGPU.
Definition PxBroadPhase.h:166
PxBroadPhaseType::Enum mType
Desired broadphase implementation.
Definition PxBroadPhase.h:160
PxU64 mContextID
Context ID for profiler. See PxProfilerCallback.
Definition PxBroadPhase.h:161
bool mDiscardKinematicVsKinematic
kinematic-vs-kinematic filtering flag. Not supported by PxBroadPhaseType::eGPU.
Definition PxBroadPhase.h:167
PxCudaContextManager * mContextManager
(GPU) CUDA context manager, must be provided for PxBroadPhaseType::eGPU.
Definition PxBroadPhase.h:163
Broadphase regions.
Definition PxBroadPhase.h:325
virtual PxU32 getNbRegions() const =0
Returns number of regions currently registered in the broad-phase.
virtual PxU32 addRegion(const PxBroadPhaseRegion &region, bool populateRegion, const PxBounds3 *bounds, const float *distances)=0
Adds a new broad-phase region.
virtual bool removeRegion(PxU32 handle)=0
Removes a broad-phase region.
virtual PxU32 getRegions(PxBroadPhaseRegionInfo *userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const =0
Gets broad-phase regions.
Broadphase data update structure.
Definition PxBroadPhase.h:244
const PxBpFilterGroup * mGroups
(Persistent) array of groups.
Definition PxBroadPhase.h:281
const PxU32 mCapacity
Capacity of bounds / groups / distance buffers.
Definition PxBroadPhase.h:283
const PxBounds3 * mBounds
(Persistent) array of bounds.
Definition PxBroadPhase.h:280
const PxU32 mNbCreated
Number of created objects.
Definition PxBroadPhase.h:272
const PxBpIndex * mCreated
Indices of created objects.
Definition PxBroadPhase.h:271
const PxBpIndex * mRemoved
Indices of removed objects.
Definition PxBroadPhase.h:277
const PxU32 mNbUpdated
Number of updated objects.
Definition PxBroadPhase.h:275
const float * mDistances
(Persistent) array of distances.
Definition PxBroadPhase.h:282
const PxBpIndex * mUpdated
Indices of updated objects.
Definition PxBroadPhase.h:274
const PxU32 mNbRemoved
Number of removed objects.
Definition PxBroadPhase.h:278
Low-level broadphase API.
Definition PxBroadPhase.h:424
virtual void setScratchBlock(void *scratchBlock, PxU32 size)=0
Sets a scratch buffer.
virtual PxAllocatorCallback * getAllocator()=0
Retrieves the broadphase allocator.
PX_FORCE_INLINE void update(PxBroadPhaseResults &results, const PxBroadPhaseUpdateData &updateData)
Helper for single-threaded updates.
Definition PxBroadPhase.h:529
virtual PxBroadPhaseType::Enum getType() const =0
Gets the broadphase type.
virtual void fetchResults(PxBroadPhaseResults &results)=0
Retrieves the broadphase results after an update.
virtual PxBroadPhaseRegions * getRegions()=0
Retrieves the regions API if applicable.
virtual PxU64 getContextID() const =0
Retrieves the profiler's context ID.
virtual void getCaps(PxBroadPhaseCaps &caps) const =0
Gets broad-phase caps.
virtual void update(const PxBroadPhaseUpdateData &updateData, PxBaseTask *continuation=NULL)=0
Updates the broadphase and computes the lists of created/deleted pairs.
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxU32 PxBpFilterGroup
Broadphase filter group.
Definition PxBroadPhase.h:182
PX_C_EXPORT PX_PHYSX_CORE_API PxAABBManager * PxCreateAABBManager(PxBroadPhase &broadphase)
AABB manager factory function.
Definition NpImmediateMode.cpp:2898
PxU32 PxBpIndex
Broadphase index. Indexes bounds, groups and distance arrays.
Definition PxBroadPhase.h:181
PX_C_EXPORT PX_PHYSX_CORE_API PxBpFilterGroup PxGetBroadPhaseStaticFilterGroup()
Retrieves the filter group for static objects.
Definition NpImmediateMode.cpp:2171
PX_C_EXPORT PX_PHYSX_CORE_API PxBroadPhase * PxCreateBroadPhase(const PxBroadPhaseDesc &desc)
Broadphase factory function.
Definition NpImmediateMode.cpp:2559
PX_C_EXPORT PX_PHYSX_CORE_API PxBpFilterGroup PxGetBroadPhaseDynamicFilterGroup(PxU32 id)
Retrieves a filter group for dynamic objects.
Definition NpImmediateMode.cpp:2176
PX_C_EXPORT PX_PHYSX_CORE_API PxBpFilterGroup PxGetBroadPhaseKinematicFilterGroup(PxU32 id)
Retrieves a filter group for kinematic objects.
Definition NpImmediateMode.cpp:2181
Caps class for broad phase.
Definition PxBroadPhase.h:131
PxU32 mMaxNbRegions
Max number of regions supported by the broad-phase (0 = explicit regions not needed)
Definition PxBroadPhase.h:132
Broadphase pair.
Definition PxBroadPhase.h:294
PxBpIndex mID0
Index of first object.
Definition PxBroadPhase.h:295
PxBpIndex mID1
Index of second object.
Definition PxBroadPhase.h:296
Information & stats structure for a region.
Definition PxBroadPhase.h:119
PxU32 mNbStaticObjects
Number of static objects in the region.
Definition PxBroadPhase.h:121
bool mActive
True if region is currently used, i.e. it has not been removed.
Definition PxBroadPhase.h:123
PxBroadPhaseRegion mRegion
User-provided region data.
Definition PxBroadPhase.h:120
PxU32 mNbDynamicObjects
Number of dynamic objects in the region.
Definition PxBroadPhase.h:122
bool mOverlap
True if region overlaps other regions (regions that are just touching are not considering overlapping...
Definition PxBroadPhase.h:124
"Region of interest" for the broad-phase.
Definition PxBroadPhase.h:110
void * mUserData
Region's user-provided data.
Definition PxBroadPhase.h:112
PxBounds3 mBounds
Region's bounds.
Definition PxBroadPhase.h:111
Broadphase results.
Definition PxBroadPhase.h:307
const PxBroadPhasePair * mCreatedPairs
Array of new/found/created pairs.
Definition PxBroadPhase.h:311
PxU32 mNbDeletedPairs
Number of lost/deleted pairs.
Definition PxBroadPhase.h:313
PxU32 mNbCreatedPairs
Number of new/found/created pairs.
Definition PxBroadPhase.h:310
const PxBroadPhasePair * mDeletedPairs
Array of lost/deleted pairs.
Definition PxBroadPhase.h:314
Broad phase algorithm used in the simulation.
Definition PxBroadPhase.h:77
Enum
Definition PxBroadPhase.h:79
@ eABP
Automatic box pruning.
Definition PxBroadPhase.h:82
@ ePABP
Parallel automatic box pruning.
Definition PxBroadPhase.h:83
@ eMBP
Multi box pruning.
Definition PxBroadPhase.h:81
@ eGPU
GPU broad phase.
Definition PxBroadPhase.h:84
@ eSAP
3-axes sweep-and-prune
Definition PxBroadPhase.h:80