RavEngine
Loading...
Searching...
No Matches
SnConvX.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
27#ifndef SN_CONVX_H
28#define SN_CONVX_H
29
30#include "foundation/PxErrors.h"
31#include "common/PxTypeInfo.h"
32#include "extensions/PxBinaryConverter.h"
33
34#include "foundation/PxUserAllocated.h"
35#include "foundation/PxArray.h"
36#include "foundation/PxHashMap.h"
37#include "SnConvX_Common.h"
38#include "SnConvX_Union.h"
39#include "SnConvX_MetaData.h"
40#include "SnConvX_Align.h"
41
42#define CONVX_ZERO_BUFFER_SIZE 256
43
44namespace physx {
45
46class PxSerializationRegistry;
47
48namespace Sn {
49
50 struct HeightFieldData;
52 {
53 public:
56
57 void setObjectRef(PxU64 object64, PxU32 ref);
58 bool getObjectRef(PxU64 object64, PxU32& ref) const;
59
61 PointerMap mData;
62 };
63
65 {
66 public:
69
70 void setObjectRef(PxU16 object, PxU16 ref);
71 bool getObjectRef(PxU16 object, PxU16& ref) const;
72
74 Handle16Map mData;
75 };
76
78 {
79 public:
80 ConvX();
81 virtual ~ConvX();
82
83 virtual void release();
84 virtual void setReportMode(PxConverterReportMode::Enum mode) { mReportMode = mode; }
85 PX_FORCE_INLINE bool silentMode() const { return mReportMode==PxConverterReportMode::eNONE; }
86 PX_FORCE_INLINE bool verboseMode() const { return mReportMode==PxConverterReportMode::eVERBOSE; }
87
88 virtual bool setMetaData(PxInputStream& srcMetaData, PxInputStream& dstMetaData);
89 virtual bool compareMetaData() const;
90 virtual bool convert(PxInputStream& srcStream, PxU32 srcSize, PxOutputStream& targetStream);
91
92 private:
93 ConvX& operator=(const ConvX&);
94 bool setMetaData(PxInputStream& inputStream, MetaDataType type);
95
96 // Meta-data
97 void releaseMetaData();
98 const MetaData* loadMetaData(PxInputStream& inputStream, MetaDataType type);
99 const MetaData* getBinaryMetaData(MetaDataType type);
100 int getNbMetaClasses(MetaDataType type);
101 MetaClass* getMetaClass(unsigned int i, MetaDataType type) const;
102 MetaClass* getMetaClass(const char* name, MetaDataType type) const;
103 MetaClass* getMetaClass(PxConcreteType::Enum concreteType, MetaDataType type);
104 MetaData* mMetaData_Src;
105 MetaData* mMetaData_Dst;
106
107 // Convert
108
109 bool convert(const void* buffer, int fileSize);
110 void resetConvexFlags();
111 void _enumerateFields(const MetaClass* mc, ExtraDataEntry2* entries, int& nb, int baseOffset, MetaDataType type) const;
112 void _enumerateExtraData(const char* address, const MetaClass* mc, ExtraDataEntry* entries, int& nb, int offset, MetaDataType type) const;
113 PxU64 read64(const void*& buffer);
114 int read32(const void*& buffer);
115 short read16(const void*& buffer);
116 bool convertClass(const char* buffer, const MetaClass* mc, int offset);
117 const char* convertExtraData_Array(const char* Address, const char* lastAddress, const char* objectAddress, const ExtraDataEntry& ed);
118 const char* convertExtraData_Ptr(const char* Address, const char* lastAddress, const PxMetaDataEntry& entry, int count, int ptrSize_Src, int ptrSize_Dst);
119 const char* convertExtraData_Handle(const char* Address, const char* lastAddress, const PxMetaDataEntry& entry, int count);
120 int getConcreteType(const char* buffer);
121 bool convertCollection(const void* buffer, int fileSize, int nbObjects);
122 const void* convertManifestTable(const void* buffer, int& fileSize);
123 const void* convertImportReferences(const void* buffer, int& fileSize);
124 const void* convertExportReferences(const void* buffer, int& fileSize);
125 const void* convertInternalReferences(const void* buffer, int& fileSize);
126 const void* convertReferenceTables(const void* buffer, int& fileSize, int& nbObjectsInCollection);
127 bool checkPaddingBytes(const char* buffer, int byteCount);
128
129 // ---- big convex surgery ----
130 PsArray<bool> mConvexFlags;
131 // Align
132 const char* alignStream(const char* buffer, int alignment=ALIGN_DEFAULT);
133 void alignTarget(int alignment);
134
135 char mZeros[CONVX_ZERO_BUFFER_SIZE];
136 // Unions
137 bool registerUnion(const char* name);
138 bool registerUnionType(const char* unionName, const char* typeName, int typeValue);
139 const char* getTypeName(const char* unionName, int typeValue);
140 void resetUnions();
141 PsArray<Union> mUnions;
142 // Output
143 void setNullPtr(bool);
144 void setNoOutput(bool);
145 bool initOutput(PxOutputStream& targetStream);
146 void closeOutput();
147 int getCurrentOutputSize();
148 void output(short value);
149 void output(int value);
150 void output(PxU64 value);
151 void output(const char* buffer, int nbBytes);
152 void convert8 (const char* src, const PxMetaDataEntry& entry, const PxMetaDataEntry& dstEntry);
153 void convertPad8 (const char* src, const PxMetaDataEntry& entry, const PxMetaDataEntry& dstEntry);
154 void convert16 (const char* src, const PxMetaDataEntry& entry, const PxMetaDataEntry& dstEntry);
155 void convert32 (const char* src, const PxMetaDataEntry& entry, const PxMetaDataEntry& dstEntry);
156 void convert64 (const char* src, const PxMetaDataEntry& entry, const PxMetaDataEntry& dstEntry);
157 void convertFloat(const char* src, const PxMetaDataEntry& entry, const PxMetaDataEntry& dstEntry);
158 void convertPtr (const char* src, const PxMetaDataEntry& entry, const PxMetaDataEntry& dstEntry);
159 void convertHandle16(const char* src, const PxMetaDataEntry& entry, const PxMetaDataEntry& dstEntry);
160 PxOutputStream* mOutStream;
161 bool mMustFlip;
162 int mOutputSize;
163 int mSrcPtrSize;
164 int mDstPtrSize;
165 bool mNullPtr;
166 bool mNoOutput;
167 bool mMarkedPadding;
168
169 // Errors
170 void resetNbErrors();
171 int getNbErrors() const;
172 void displayMessage(physx::PxErrorCode::Enum code, const char* format, ...);
173 int mNbErrors;
174 int mNbWarnings;
175
176 // Settings
177 PxConverterReportMode::Enum mReportMode;
178 bool mPerformConversion;
179
180 // Remap pointers
181 void exportIntAsPtr(int value);
182 void exportInt(int value);
183 void exportInt64(PxU64 value);
184 PointerRemap mPointerRemap;
185 PointerRemap* mPointerActiveRemap;
186 PxU32 mPointerRemapCounter;
187 Handle16Remap mHandle16Remap;
188 Handle16Remap* mHandle16ActiveRemap;
189 PxU16 mHandle16RemapCounter;
190
191 friend class MetaData;
192 friend struct MetaClass;
193 };
194} }
195#endif
Binary converter for serialized streams.
Definition PxBinaryConverter.h:69
Definition PxHashMap.h:78
Definition PxUserAllocated.h:43
Definition SnConvX.h:78
virtual void setReportMode(PxConverterReportMode::Enum mode)
Sets desired report mode.
Definition SnConvX.h:84
virtual bool compareMetaData() const
Test utility function to compare two sets of meta data.
Definition SnConvX.cpp:104
virtual bool setMetaData(PxInputStream &srcMetaData, PxInputStream &dstMetaData)
Setups source and target meta-data streams.
Definition SnConvX.cpp:91
virtual void release()
Releases binary converter.
Definition SnConvX.cpp:80
virtual bool convert(PxInputStream &srcStream, PxU32 srcSize, PxOutputStream &targetStream)
Converts binary stream from source platform to target platform.
Definition SnConvX.cpp:115
Definition SnConvX.h:65
Definition SnConvX.h:52
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Enum
Definition PxBinaryConverter.h:45
@ eNONE
Silent mode. If enabled, no information is sent to the error stream.
Definition PxBinaryConverter.h:46
@ eVERBOSE
Verbose mode. If enabled, detailed information is sent to the error stream.
Definition PxBinaryConverter.h:48
Enum
Definition PxErrors.h:52