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#ifndef PXPVDSDK_PXPVDDATASTREAM_H
28#define PXPVDSDK_PXPVDDATASTREAM_H
29
30/** \addtogroup pvd
31@{
32*/
33#include "pvd/PxPvd.h"
34#include "PxPvdErrorCodes.h"
35#include "PxPvdObjectModelBaseTypes.h"
36
37#if !PX_DOXYGEN
38namespace physx
39{
40namespace pvdsdk
41{
42#endif
43
44class PvdPropertyDefinitionHelper;
45
46class PvdMetaDataStream
47{
48 protected:
49 virtual ~PvdMetaDataStream()
50 {
51 }
52
53 public:
54 virtual PvdError createClass(const NamespacedName& nm) = 0;
55 template <typename TDataType>
56 PvdError createClass()
57 {
58 return createClass(getPvdNamespacedNameForType<TDataType>());
59 }
60
61 virtual PvdError deriveClass(const NamespacedName& parent, const NamespacedName& child) = 0;
62 template <typename TParentType, typename TChildType>
63 PvdError deriveClass()
64 {
65 return deriveClass(getPvdNamespacedNameForType<TParentType>(), getPvdNamespacedNameForType<TChildType>());
66 }
67
68 virtual bool isClassExist(const NamespacedName& nm) = 0;
69 template <typename TDataType>
70 bool isClassExist()
71 {
72 return isClassExist(getPvdNamespacedNameForType<TDataType>());
73 }
74
75 virtual PvdError createProperty(const NamespacedName& clsName, const char* name, const char* semantic,
76 const NamespacedName& dtypeName, PropertyType::Enum propertyType,
77 DataRef<NamedValue> values = DataRef<NamedValue>()) = 0;
78 template <typename TClsType, typename TDataType>
79 PvdError createProperty(String name, String semantic = "", PropertyType::Enum propertyType = PropertyType::Scalar,
80 DataRef<NamedValue> values = DataRef<NamedValue>())
81 {
82 return createProperty(getPvdNamespacedNameForType<TClsType>(), name, semantic,
83 getPvdNamespacedNameForType<TDataType>(), propertyType, values);
84 }
85
86 virtual PvdError createPropertyMessage(const NamespacedName& cls, const NamespacedName& msgName,
87 DataRef<PropertyMessageArg> entries, uint32_t messageSizeInBytes) = 0;
88
89 template <typename TClsType, typename TMsgType>
90 PvdError createPropertyMessage(DataRef<PropertyMessageArg> entries)
91 {
92 return createPropertyMessage(getPvdNamespacedNameForType<TClsType>(), getPvdNamespacedNameForType<TMsgType>(),
93 entries, sizeof(TMsgType));
94 }
95};
96
97class PvdInstanceDataStream
98{
99 protected:
100 virtual ~PvdInstanceDataStream()
101 {
102 }
103
104 public:
105 virtual PvdError createInstance(const NamespacedName& cls, const void* instance) = 0;
106
107 template <typename TDataType>
108 PvdError createInstance(const TDataType* inst)
109 {
110 return createInstance(getPvdNamespacedNameForType<TDataType>(), inst);
111 }
112 virtual bool isInstanceValid(const void* instance) = 0;
113
114 // If the property will fit or is already completely in memory
115 virtual PvdError setPropertyValue(const void* instance, String name, DataRef<const uint8_t> data,
116 const NamespacedName& incomingTypeName) = 0;
117 template <typename TDataType>
118 PvdError setPropertyValue(const void* instance, String name, const TDataType& value)
119 {
120 const uint8_t* dataStart = reinterpret_cast<const uint8_t*>(&value);
121 return setPropertyValue(instance, name, DataRef<const uint8_t>(dataStart, dataStart + sizeof(TDataType)),
122 getPvdNamespacedNameForType<TDataType>());
123 }
124
125 template <typename TDataType>
126 PvdError setPropertyValue(const void* instance, String name, const TDataType* value, uint32_t numItems)
127 {
128 const uint8_t* dataStart = reinterpret_cast<const uint8_t*>(value);
129 return setPropertyValue(instance, name,
130 DataRef<const uint8_t>(dataStart, dataStart + sizeof(TDataType) * numItems),
131 getPvdNamespacedNameForType<TDataType>());
132 }
133
134 // Else if the property is very large (contact reports) you can send it in chunks.
135 virtual PvdError beginSetPropertyValue(const void* instance, String name, const NamespacedName& incomingTypeName) = 0;
136
137 template <typename TDataType>
138 PvdError beginSetPropertyValue(const void* instance, String name)
139 {
140 return beginSetPropertyValue(instance, name, getPvdNamespacedNameForType<TDataType>());
141 }
142 virtual PvdError appendPropertyValueData(DataRef<const uint8_t> data) = 0;
143
144 template <typename TDataType>
145 PvdError appendPropertyValueData(const TDataType* value, uint32_t numItems)
146 {
147 const uint8_t* dataStart = reinterpret_cast<const uint8_t*>(value);
148 return appendPropertyValueData(data: DataRef<const uint8_t>(dataStart, dataStart + numItems * sizeof(TDataType)));
149 }
150
151 virtual PvdError endSetPropertyValue() = 0;
152
153 // Set a set of properties to various values on an object.
154
155 virtual PvdError setPropertyMessage(const void* instance, const NamespacedName& msgName,
156 DataRef<const uint8_t> data) = 0;
157
158 template <typename TDataType>
159 PvdError setPropertyMessage(const void* instance, const TDataType& value)
160 {
161 const uint8_t* dataStart = reinterpret_cast<const uint8_t*>(&value);
162 return setPropertyMessage(instance, getPvdNamespacedNameForType<TDataType>(),
163 DataRef<const uint8_t>(dataStart, sizeof(TDataType)));
164 }
165 // If you need to send of lot of identical messages, this avoids a hashtable lookup per message.
166 virtual PvdError beginPropertyMessageGroup(const NamespacedName& msgName) = 0;
167
168 template <typename TDataType>
169 PvdError beginPropertyMessageGroup()
170 {
171 return beginPropertyMessageGroup(getPvdNamespacedNameForType<TDataType>());
172 }
173 virtual PvdError sendPropertyMessageFromGroup(const void* instance, DataRef<const uint8_t> data) = 0;
174
175 template <typename TDataType>
176 PvdError sendPropertyMessageFromGroup(const void* instance, const TDataType& value)
177 {
178 const uint8_t* dataStart = reinterpret_cast<const uint8_t*>(&value);
179 return sendPropertyMessageFromGroup(instance, data: DataRef<const uint8_t>(dataStart, sizeof(TDataType)));
180 }
181
182 virtual PvdError endPropertyMessageGroup() = 0;
183
184 // These functions ensure the target array doesn't contain duplicates
185 virtual PvdError pushBackObjectRef(const void* instId, String propName, const void* objRef) = 0;
186 virtual PvdError removeObjectRef(const void* instId, String propName, const void* objRef) = 0;
187
188 // Instance elimination.
189 virtual PvdError destroyInstance(const void* key) = 0;
190
191 // Profiling hooks
192 virtual PvdError beginSection(const void* instance, String name) = 0;
193 virtual PvdError endSection(const void* instance, String name) = 0;
194
195 // Origin Shift
196 virtual PvdError originShift(const void* scene, PxVec3 shift) = 0;
197
198 public:
199 /*For some cases, pvd command cannot be run immediately. For example, when create joints, while the actors may still
200 *pending for insert, the joints update commands can be run deffered.
201 */
202 class PvdCommand
203 {
204 public:
205 // Assigned is needed for copying
206 PvdCommand(const PvdCommand&)
207 {
208 }
209 PvdCommand& operator=(const PvdCommand&)
210 {
211 return *this;
212 }
213
214 public:
215 PvdCommand()
216 {
217 }
218 virtual ~PvdCommand()
219 {
220 }
221
222 // Not pure virtual so can have default PvdCommand obj
223 virtual bool canRun(PvdInstanceDataStream&)
224 {
225 return false;
226 }
227 virtual void run(PvdInstanceDataStream&)
228 {
229 }
230 };
231
232 // PVD SDK provide this helper function to allocate cmd's memory and release them at after flush the command queue
233 virtual void* allocateMemForCmd(uint32_t length) = 0;
234
235 // PVD will call the destructor of PvdCommand object at the end fo flushPvdCommand
236 virtual void pushPvdCommand(PvdCommand& cmd) = 0;
237 virtual void flushPvdCommand() = 0;
238};
239
240class PvdDataStream : public PvdInstanceDataStream, public PvdMetaDataStream
241{
242 protected:
243 virtual ~PvdDataStream()
244 {
245 }
246
247 public:
248 virtual void release() = 0;
249 virtual bool isConnected() = 0;
250
251 virtual void addProfileZone(void* zone, const char* name) = 0;
252 virtual void addProfileZoneEvent(void* zone, const char* name, uint16_t eventId, bool compileTimeEnabled) = 0;
253
254 virtual PvdPropertyDefinitionHelper& getPropertyDefinitionHelper() = 0;
255
256 virtual void setIsTopLevelUIElement(const void* instance, bool topLevel) = 0;
257 virtual void sendErrorMessage(uint32_t code, const char* message, const char* file, uint32_t line) = 0;
258 virtual void updateCamera(const char* name, const PxVec3& origin, const PxVec3& up, const PxVec3& target) = 0;
259
260/**
261 \brief Create a new PvdDataStream.
262 \param pvd A pointer to a valid PxPvd instance. This must be non-null.
263*/
264 static PvdDataStream* create(PxPvd* pvd);
265};
266#if !PX_DOXYGEN
267} // pvdsdk
268} // physx
269#endif
270
271/** @} */
272#endif // PXPVDSDK_PXPVDDATASTREAM_H
273

source code of qtquick3dphysics/src/3rdparty/PhysX/source/pvd/include/PxPvdDataStream.h