RavEngine
Loading...
Searching...
No Matches
OmniPvdPxExtensionsSampler.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 OMNI_PVD_EXTENSION_SAMPLER_H
30#define OMNI_PVD_EXTENSION_SAMPLER_H
31
32/*
33The below helper macros are to be used in Extensions code to send information to PVD as unintrusively as possible.
34
35Principles:
36* Data created or changed by the user should be sent as soon as it has been written to an Extensions class, ideally right at the end of the API create() or set() call.
37* Objects should ideally be destroyed from their destructors (since release() calls might just decrement).
38* Data written by the Extensions should be sent at the end of the simulate frame.
39* Ideally use Px-pointers as object handles. Beware that multiple inheritance can result in different pointer values so its best to cast to the Px-type pointer / reference explicitly.
40 Even if the code works by passing in different equivalent pointer types, this will generate unnecessary duplicate template code.
41*/
42#if PX_SUPPORT_OMNI_PVD
43 // You can use this in conditional statements to check for a connection
44 #define OMNI_PVD_ACTIVE (::OmniPvdPxExtensionsSampler::getInstance() != NULL)
45 // Create object reference o of PVD type c. Example: OMNI_PVD_CREATE(scene, static_cast<PxScene &>(*npScene));
46 #define OMNI_PVD_CREATE(c, o) if (::OmniPvdPxExtensionsSampler::getInstance() != NULL) {::OmniPvdPxExtensionsSampler::getInstance()->createObject(OmniPvdPxExtensionsSampler::classHandle_##c, o); }
47 // Destroy object reference o of PVD type c. Example: OMNI_PVD_DESTROY(scene, static_cast<PxScene &>(*npScene));
48 #define OMNI_PVD_DESTROY(c, o) if (::OmniPvdPxExtensionsSampler::getInstance() != NULL) {::OmniPvdPxExtensionsSampler::getInstance()->destroyObject(o); }
49 // Set PVD attribute a of object reference o of PVD type c to value v. v is passed as reference to value; PVD object handles are passed as reference to POINTER here!
50 // Example: OMNI_PVD_SET(actor, isdynamic, a, false)
51 #define OMNI_PVD_SET(c, a, o, v) if (::OmniPvdPxExtensionsSampler::getInstance() != NULL) {::OmniPvdPxExtensionsSampler::getInstance()->setAttribute(OmniPvdPxExtensionsSampler::attributeHandle_##c##_##a, o, v); }
52 // Same as set, but for variable length attributes like vertex buffers. pv is the address of the data, and n is the size in bytes.
53 #define OMNI_PVD_SETB(c, a, o, pv, n)if (::OmniPvdPxExtensionsSampler::getInstance() != NULL) {::OmniPvdPxExtensionsSampler::getInstance()->setAttributeBytes(OmniPvdPxExtensionsSampler::attributeHandle_##c##_##a, o, pv, n); }
54 // Same as set, but for attribute sets of unique things like an array of references. v is passed as a REFERENCE.
55 #define OMNI_PVD_ADD(c, a, o, v) if (::OmniPvdPxExtensionsSampler::getInstance() != NULL) {::OmniPvdPxExtensionsSampler::getInstance()->addToSet(OmniPvdPxExtensionsSampler::attributeHandle_##c##_##a, o, v); }
56 // TO remove a member handle from the set.
57 #define OMNI_PVD_REMOVE(c, a, o, v) if (::OmniPvdPxExtensionsSampler::getInstance() != NULL) {::OmniPvdPxExtensionsSampler::getInstance()->removeFromSet(OmniPvdPxExtensionsSampler::attributeHandle_##c##_##a, o, v); }
58#else
59 #define OMNI_PVD_ACTIVE (false)
60 #define OMNI_PVD_CREATE(c, p)
61 #define OMNI_PVD_DESTROY(c, p)
62 #define OMNI_PVD_SET(c, a, p, v)
63 #define OMNI_PVD_SETB(c, a, p, v, n)
64 #define OMNI_PVD_ADD(c, a, p, v)
65 #define OMNI_PVD_REMOVE(c, a, p, v)
66#endif
67
68
69#if PX_SUPPORT_OMNI_PVD
70
71#include "foundation/PxUserAllocated.h"
72#include "../pvdruntime/include/OmniPvdDefines.h"
73
74class OmniPvdWriter;
75
76class OmniPvdPxExtensionsSampler : public physx::PxUserAllocated
77{
78public:
79 OmniPvdPxExtensionsSampler();
80 ~OmniPvdPxExtensionsSampler();
81 void setOmniPvdWriter(OmniPvdWriter* omniPvdWriter);
82 void registerClasses();
83
84 //simplified generic API to be used via simple macros above:
85 template <typename ClassType> void createObject(OmniPvdClassHandle, ClassType const & objectId);
86 template <typename ClassType> void destroyObject(ClassType const & objectId);
87 template <typename ClassType, typename AttributeType> void setAttribute(OmniPvdAttributeHandle, ClassType const & objectId, AttributeType const & value);
88 template <typename ClassType, typename AttributeType> void setAttributeBytes(OmniPvdAttributeHandle, ClassType const & objectId, AttributeType const * value, unsigned nBytes);
89 template <typename ClassType, typename AttributeType> void addToSet(OmniPvdAttributeHandle, ClassType const & objectId, AttributeType const & value);
90 template <typename ClassType, typename AttributeType> void removeFromSet(OmniPvdAttributeHandle, ClassType const & objectId, AttributeType const & value);
91
92 //handles for all Extensions classes and attributes
93
94#define OMNI_PVD_FAKE_CLASS(c, classT, classStr) static OmniPvdClassHandle classHandle_##c;
95#define OMNI_PVD_CLASS(c, classT) static OmniPvdClassHandle classHandle_##c;
96#define OMNI_PVD_CLASS_DERIVED(c, classT, baseClass) OMNI_PVD_CLASS(c, classT)
97#define OMNI_PVD_ENUM(c, classT) OMNI_PVD_CLASS(c, classT)
98#define OMNI_PVD_ENUM_VALUE(c, a, v)
99#define OMNI_PVD_ATTRIBUTE(c, a, classT, attrT, t, n) static OmniPvdAttributeHandle attributeHandle_##c##_##a;
100#define OMNI_PVD_ATTRIBUTE_SET(c, a, classT, attrT) static OmniPvdAttributeHandle attributeHandle_##c##_##a;
101#define OMNI_PVD_ATTRIBUTE_FLAG(c, a, classT, attrT, enumClass) static OmniPvdAttributeHandle attributeHandle_##c##_##a;
102
103#include "OmniPvdPxExtensionsTypes.h" //Extensions classes and attributes declared here
104
105#undef OMNI_PVD_ENUM
106#undef OMNI_PVD_ENUM_VALUE
107#undef OMNI_PVD_FAKE_CLASS
108#undef OMNI_PVD_CLASS
109#undef OMNI_PVD_CLASS_DERIVED
110#undef OMNI_PVD_ATTRIBUTE
111#undef OMNI_PVD_ATTRIBUTE_SET
112#undef OMNI_PVD_ATTRIBUTE_FLAG
113
114 // OmniPvdPxExtensionsSampler singleton
115 static bool createInstance();
116 static OmniPvdPxExtensionsSampler* getInstance();
117 static void destroyInstance();
118
119private:
120 OmniPvdWriter* mWriter;
121};
122
123#endif
124
125#endif
Used to write debug information to an OmniPvdWriteStream.
Definition OmniPvdWriter.h:47
Definition PxUserAllocated.h:43