PxSerialFramework.h
Go to the documentation of this file.00001 // This code contains NVIDIA Confidential Information and is disclosed to you 00002 // under a form of NVIDIA software license agreement provided separately to you. 00003 // 00004 // Notice 00005 // NVIDIA Corporation and its licensors retain all intellectual property and 00006 // proprietary rights in and to this software and related documentation and 00007 // any modifications thereto. Any use, reproduction, disclosure, or 00008 // distribution of this software and related documentation without an express 00009 // license agreement from NVIDIA Corporation is strictly prohibited. 00010 // 00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES 00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO 00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, 00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. 00015 // 00016 // Information and code furnished is believed to be accurate and reliable. 00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such 00018 // information or for any infringement of patents or other rights of third parties that may 00019 // result from its use. No license is granted by implication or otherwise under any patent 00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice. 00021 // This code supersedes and replaces all information previously supplied. 00022 // NVIDIA Corporation products are not authorized for use as critical 00023 // components in life support devices or systems without express written approval of 00024 // NVIDIA Corporation. 00025 // 00026 // Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. 00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. 00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. 00029 00030 00031 #ifndef PX_PHYSICS_COMMON_NX_SERIAL_FRAMEWORK 00032 #define PX_PHYSICS_COMMON_NX_SERIAL_FRAMEWORK 00033 00038 #include "common/PxPhysXCommonConfig.h" 00039 00040 #if !PX_DOXYGEN 00041 namespace physx 00042 { 00043 #endif 00044 00045 typedef PxU16 PxType; 00046 class PxBase; 00047 class PxSerializationContext; 00048 class PxRepXSerializer; 00049 class PxSerializer; 00050 class PxPhysics; 00051 00053 #define PX_SERIAL_ALIGN 16 00054 00056 #define PX_SERIAL_FILE_ALIGN 128 00057 00059 #define PX_SERIAL_OBJECT_ID_INVALID 0 00060 00062 typedef PxU64 PxSerialObjectId; 00063 00065 #define PX_SERIAL_REF_KIND_PTR_TYPE_BIT (1u<<31) 00066 00068 #define PX_SERIAL_REF_KIND_PXBASE (0 | PX_SERIAL_REF_KIND_PTR_TYPE_BIT) 00069 00071 #define PX_SERIAL_REF_KIND_MATERIAL_IDX (1) 00072 00074 #define PX_MAKE_FOURCC(a, b, c, d) ( (a) | ((b)<<8) | ((c)<<16) | ((d)<<24) ) 00075 00081 class PxProcessPxBaseCallback 00082 { 00083 public: 00084 virtual ~PxProcessPxBaseCallback() {} 00085 virtual void process(PxBase&) = 0; 00086 }; 00087 00088 00099 class PxSerializationContext 00100 { 00101 public: 00102 00124 virtual void registerReference(PxBase& base, PxU32 kind, size_t reference) = 0; 00125 00129 virtual const PxCollection& getCollection() const = 0; 00130 00138 virtual void writeData(const void* data, PxU32 size) = 0; 00139 00147 virtual void alignData(PxU32 alignment = PX_SERIAL_ALIGN) = 0; 00148 00156 virtual void writeName(const char* name) = 0; 00157 00158 protected: 00159 00160 PxSerializationContext() {} 00161 virtual ~PxSerializationContext() {} 00162 }; 00163 00164 00174 class PxDeserializationContext 00175 { 00176 public: 00177 00196 virtual PxBase* resolveReference(PxU32 kind, size_t reference) const = 0; 00197 00203 template<typename T> 00204 void translatePxBase(T*& base) { if (base) { base = static_cast<T*>(resolveReference(PX_SERIAL_REF_KIND_PXBASE, size_t(base))); } } 00205 00213 PX_INLINE void readName(const char*& name) 00214 { 00215 PxU32 len = *reinterpret_cast<PxU32*>(mExtraDataAddress); 00216 mExtraDataAddress += sizeof(len); 00217 name = len ? reinterpret_cast<const char*>(mExtraDataAddress) : NULL; 00218 mExtraDataAddress += len; 00219 } 00220 00228 template<typename T> 00229 PX_INLINE T* readExtraData(PxU32 count=1) 00230 { 00231 T* data = reinterpret_cast<T*>(mExtraDataAddress); 00232 mExtraDataAddress += sizeof(T)*count; 00233 return data; 00234 } 00235 00243 template<typename T, PxU32 alignment> 00244 PX_INLINE T* readExtraData(PxU32 count=1) 00245 { 00246 alignExtraData(alignment); 00247 return readExtraData<T>(count); 00248 } 00249 00257 PX_INLINE void alignExtraData(PxU32 alignment = PX_SERIAL_ALIGN) 00258 { 00259 size_t addr = reinterpret_cast<size_t>(mExtraDataAddress); 00260 addr = (addr+alignment-1)&~size_t(alignment-1); 00261 mExtraDataAddress = reinterpret_cast<PxU8*>(addr); 00262 } 00263 00264 00269 virtual PxU32 getPhysXVersion() const = 0; 00270 00271 protected: 00272 00273 PxDeserializationContext() {} 00274 virtual ~PxDeserializationContext() {} 00275 00276 PxU8* mExtraDataAddress; 00277 }; 00278 00285 typedef void (*PxBinaryMetaDataCallback)(PxOutputStream& stream); 00286 00297 class PxSerializationRegistry 00298 { 00299 public: 00300 /************************************************************************************************/ 00301 00305 00314 virtual void registerSerializer(PxType type, PxSerializer& serializer) = 0; 00315 00324 virtual PxSerializer* unregisterSerializer(PxType type) = 0; 00325 00335 virtual void registerBinaryMetaDataCallback(PxBinaryMetaDataCallback callback) = 0; 00336 00345 virtual const PxSerializer* getSerializer(PxType type) const = 0; 00346 00348 /************************************************************************************************/ 00349 00353 00362 virtual void registerRepXSerializer(PxType type, PxRepXSerializer& serializer) = 0; 00363 00372 virtual PxRepXSerializer* unregisterRepXSerializer(PxType type) = 0; 00373 00382 virtual PxRepXSerializer* getRepXSerializer(const char* typeName) const = 0; 00383 00385 /************************************************************************************************/ 00386 00395 virtual void release() = 0; 00396 00397 protected: 00398 virtual ~PxSerializationRegistry(){} 00399 }; 00400 00401 #if !PX_DOXYGEN 00402 } // namespace physx 00403 #endif 00404 00406 #endif
Copyright © 2008-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com