PxSerialFramework.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3  *
4  * NVIDIA CORPORATION and its licensors retain all intellectual property
5  * and proprietary rights in and to this software, related documentation
6  * and any modifications thereto. Any use, reproduction, disclosure or
7  * distribution of this software and related documentation without an express
8  * license agreement from NVIDIA CORPORATION is strictly prohibited.
9  */
10 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12 
13 
14 #ifndef PX_PHYSICS_COMMON_NX_SERIAL_FRAMEWORK
15 #define PX_PHYSICS_COMMON_NX_SERIAL_FRAMEWORK
16 
22 #include "common/PxTypeInfo.h"
23 #include "foundation/PxFlags.h"
24 
25 #ifndef PX_DOXYGEN
26 namespace physx
27 {
28 #endif
29 
30 typedef PxU16 PxType;
31 class PxBase;
32 class PxOutputStream;
34 class PxRepXSerializer;
35 class PxSerializer;
36 class PxPhysics;
37 
39 #define PX_SERIAL_ALIGN 16
40 
42 #define PX_SERIAL_FILE_ALIGN 128
43 
45 #define PX_SERIAL_OBJECT_ID_INVALID 0
46 
49 
51 #define PX_SERIAL_REF_KIND_PTR_TYPE_BIT (1u<<31)
52 
54 #define PX_SERIAL_REF_KIND_PXBASE (0 | PX_SERIAL_REF_KIND_PTR_TYPE_BIT)
55 
57 #define PX_SERIAL_REF_KIND_MATERIAL_IDX (1)
58 
60 #define PX_MAKE_FOURCC(a, b, c, d) ( (a) | ((b)<<8) | ((c)<<16) | ((d)<<24) )
61 
68 {
69 public:
71  virtual void process(PxBase&) = 0;
72 };
73 
74 
86 {
87 public:
88 
110  virtual void registerReference(PxBase& base, PxU32 kind, size_t reference) = 0;
111 
115  virtual const PxCollection& getCollection() const = 0;
116 
124  virtual void writeData(const void* data, PxU32 size) = 0;
125 
133  virtual void alignData(PxU32 alignment = PX_SERIAL_ALIGN) = 0;
134 
142  virtual void writeName(const char* name) = 0;
143 
144 protected:
145 
148 };
149 
150 
161 {
162 public:
163 
182  virtual PxBase* resolveReference(PxU32 kind, size_t reference) const = 0;
183 
189  template<typename T>
190  void translatePxBase(T*& base) { if (base) { base = static_cast<T*>(resolveReference(PX_SERIAL_REF_KIND_PXBASE, size_t(base))); } }
191 
199  PX_INLINE void readName(const char*& name)
200  {
201  PxU32 len = *(PxU32*)mExtraDataAddress;
202  mExtraDataAddress += sizeof(len);
203  name = len ? (const char*)mExtraDataAddress : NULL;
204  mExtraDataAddress += len;
205  }
206 
214  template<typename T>
215  PX_INLINE T* readExtraData(PxU32 count=1)
216  {
217  T* data = reinterpret_cast<T*>(mExtraDataAddress);
218  mExtraDataAddress += sizeof(T)*count;
219  return data;
220  }
221 
229  template<typename T, PxU32 alignment>
230  PX_INLINE T* readExtraData(PxU32 count=1)
231  {
232  alignExtraData(alignment);
233  return readExtraData<T>(count);
234  }
235 
243  PX_INLINE void alignExtraData(PxU32 alignment = PX_SERIAL_ALIGN)
244  {
245  size_t addr = reinterpret_cast<size_t>(mExtraDataAddress);
246  addr = (addr+alignment-1)&~size_t(alignment-1);
247  mExtraDataAddress = reinterpret_cast<PxU8*>(addr);
248  }
249 
250 
255  virtual PxU32 getPhysXVersion() const = 0;
256 
257 protected:
258 
261 
263 };
264 
271 typedef void (*PxBinaryMetaDataCallback)(PxOutputStream& stream);
272 
284 {
285 public:
286  /************************************************************************************************/
287 
291 
300  virtual void registerSerializer(PxType type, PxSerializer& serializer) = 0;
301 
310  virtual PxSerializer* unregisterSerializer(PxType type) = 0;
311 
321  virtual void registerBinaryMetaDataCallback(PxBinaryMetaDataCallback callback) = 0;
322 
331  virtual const PxSerializer* getSerializer(PxType type) const = 0;
332 
334  /************************************************************************************************/
335 
339 
348  virtual void registerRepXSerializer(PxType type, PxRepXSerializer& serializer) = 0;
349 
358  virtual PxRepXSerializer* unregisterRepXSerializer(PxType type) = 0;
359 
368  virtual PxRepXSerializer* getRepXSerializer(const char* typeName) const = 0;
369 
371  /************************************************************************************************/
372 
381  virtual void release() = 0;
382 
383 protected:
385 };
386 
387 #ifndef PX_DOXYGEN
388 } // namespace physx
389 #endif
390 
392 #endif


Copyright © 2008-2015 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com