summaryrefslogtreecommitdiffstats
path: root/src/runtimerender/Qt3DSRenderGraphObjectSerializer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtimerender/Qt3DSRenderGraphObjectSerializer.cpp')
-rw-r--r--src/runtimerender/Qt3DSRenderGraphObjectSerializer.cpp143
1 files changed, 56 insertions, 87 deletions
diff --git a/src/runtimerender/Qt3DSRenderGraphObjectSerializer.cpp b/src/runtimerender/Qt3DSRenderGraphObjectSerializer.cpp
index 358c5aa..bb75a40 100644
--- a/src/runtimerender/Qt3DSRenderGraphObjectSerializer.cpp
+++ b/src/runtimerender/Qt3DSRenderGraphObjectSerializer.cpp
@@ -122,6 +122,18 @@ struct SSerializerWriteContext
#endif
}
+ template <typename TObjType, typename Type>
+ void AddPtrOffset(Type type, const TObjType *inObject)
+ {
+ QT3DSU32 objOffset = m_MemoryBuffer.size() - m_DataBlockStart;
+ m_OffsetMap.insert(eastl::make_pair(inObject, objOffset));
+// In debug we keep stats on how much each type of object
+// contributes to the file size.
+#ifdef _DEBUG
+ GetStatEntry(type) += sizeof(TObjType);
+#endif
+ }
+
void Remap(CRegisteredString &inStr) { inStr.Remap(m_StrRemapMap); }
template <typename TObjType>
@@ -138,6 +150,7 @@ struct SSerializerWriteContext
}
void RemapMaterial(SGraphObject *&inPtr) { Remap(inPtr); }
+ void RemapDynamicObject(GraphObjectTypes::Enum type, SDynamicObject *&inPtr) { Remap(inPtr); }
template <typename TObjType>
void NullPtr(TObjType *&inPtr)
@@ -187,6 +200,7 @@ struct SSerializerReadContext : public SDataReader
}
}
void RemapMaterial(SGraphObject *&inPtr) { Remap(inPtr); }
+ void RemapDynamicObject(GraphObjectTypes::Enum type, SDynamicObject *&inPtr) { Remap(inPtr); }
// Nulling out pointers was done on write, so we don't do it here.
template <typename TObjType>
void NullPtr(TObjType *&)
@@ -202,6 +216,8 @@ struct SGraphObjectSerializerImpl
static TObjType *Read(SSerializerReadContext &inReadContext);
};
+static SDynamicObject *Write(GraphObjectTypes::Enum type, const SDynamicObject &ioObject, SSerializerWriteContext &outSavedBuffer);
+
struct SWriteRemapper
{
SSerializerWriteContext &m_WriteBuffer;
@@ -249,6 +265,11 @@ struct SWriteRemapper
}
}
}
+ void RemapDynamicObject(GraphObjectTypes::Enum inType, const SDynamicObject *inObj)
+ {
+ if (inObj)
+ Write(inType, *inObj, m_WriteBuffer);
+ }
template <typename TObjType>
void NullPtr(const TObjType *)
{
@@ -282,6 +303,21 @@ TObject *WriteGenericGraphObjectNoRemap(const TObject &ioObject,
return reinterpret_cast<TObject *>(outSavedBuffer.m_MemoryBuffer.begin() + theOffset);
}
+template <typename TObject, typename Type>
+TObject *WriteGenericGraphObjectNoRemap(Type type, const TObject &ioObject,
+ SSerializerWriteContext &outSavedBuffer)
+{
+ if (outSavedBuffer.HasWrittenObject(&ioObject))
+ return NULL;
+
+ outSavedBuffer.AddPtrOffset(type, &ioObject);
+ QT3DSU32 theOffset = outSavedBuffer.m_MemoryBuffer.size();
+ outSavedBuffer.m_MemoryBuffer.write(ioObject);
+ // Probably the buffer stays aligned but we want to work to keep it that way.
+ Align(outSavedBuffer.m_MemoryBuffer);
+ return reinterpret_cast<TObject *>(outSavedBuffer.m_MemoryBuffer.begin() + theOffset);
+}
+
template <typename TObject>
TObject *WriteGenericGraphObject(const TObject &ioObject, SSerializerWriteContext &outSavedBuffer)
{
@@ -335,7 +371,7 @@ void RemapProperties(SDynamicObject &ioObject, SSerializerWriteContext &outSaved
const SPropertyDefinition &theDef(theObjectProps[idx]);
if (theDef.m_DataType == qt3ds::render::NVRenderShaderDataTypes::NVRenderTexture2DPtr) {
CRegisteredString *theStr = reinterpret_cast<CRegisteredString *>(
- ioObject.GetDataSectionBegin() + theDef.m_Offset);
+ ioObject.GetDataSectionOffset(theDef.m_Offset));
outSavedBuffer.Remap(*theStr);
}
}
@@ -353,99 +389,32 @@ void RemapProperties(SDynamicObject &ioObject, SSerializerReadContext &inReadCon
const SPropertyDefinition &theDefinition(theProperties[idx]);
if (theDefinition.m_DataType == NVRenderShaderDataTypes::NVRenderTexture2DPtr) {
CRegisteredString *theString = reinterpret_cast<CRegisteredString *>(
- ioObject.GetDataSectionBegin() + theDefinition.m_Offset);
+ ioObject.GetDataSectionOffset(theDefinition.m_Offset));
inReadContext.Remap(*theString);
}
}
}
-template <>
-struct SGraphObjectSerializerImpl<SEffect>
+static SDynamicObject *Write(GraphObjectTypes::Enum type, const SDynamicObject &ioObject, SSerializerWriteContext &outSavedBuffer)
{
- static SGraphObject *Write(const SEffect &ioObject, SSerializerWriteContext &outSavedBuffer)
- {
- size_t itemOffset = outSavedBuffer.m_MemoryBuffer.size();
- SEffect *theNewEffect =
- static_cast<SEffect *>(WriteGenericGraphObjectNoRemap(ioObject, outSavedBuffer));
- if (theNewEffect) {
- theNewEffect->m_Context = NULL;
- // Writing it out is easy. Reading it back in means we have to have a correctly setup
- // IEffectManager so we
- // can remap strings.
- outSavedBuffer.m_MemoryBuffer.write(ioObject.GetDataSectionBegin(),
- ioObject.m_DataSectionByteSize);
- Align(outSavedBuffer.m_MemoryBuffer);
- SWriteRemapper theWriteRemapper(outSavedBuffer);
- // Write any connected objects.
- theNewEffect =
- reinterpret_cast<SEffect *>(outSavedBuffer.m_MemoryBuffer.begin() + itemOffset);
- theNewEffect->Remap(theWriteRemapper);
- }
- return theNewEffect;
- }
-
- static void Remap(SEffect &ioObject, SSerializerWriteContext &outSavedBuffer)
- {
- CRegisteredString theClassName = ioObject.m_ClassName;
- ioObject.Remap(outSavedBuffer);
- RemapProperties(ioObject, outSavedBuffer, theClassName);
- }
-
- static SEffect *Read(SSerializerReadContext &inReadContext)
- {
- SEffect *theEffect = ReadGenericGraphObject<SEffect>(inReadContext);
- if (theEffect) {
- inReadContext.m_CurrentPtr += theEffect->m_DataSectionByteSize;
- inReadContext.Align();
- RemapProperties(*theEffect, inReadContext);
- }
- return theEffect;
- }
-};
-
-template <>
-struct SGraphObjectSerializerImpl<SCustomMaterial>
-{
- static SGraphObject *Write(const SCustomMaterial &ioObject,
- SSerializerWriteContext &outSavedBuffer)
- {
- size_t itemOffset = outSavedBuffer.m_MemoryBuffer.size();
- SCustomMaterial *theNewObject = static_cast<SCustomMaterial *>(
- WriteGenericGraphObjectNoRemap(ioObject, outSavedBuffer));
- if (theNewObject) {
- // Writing it out is easy. Reading it back in means we have to have a correctly setup
- // IEffectManager so we
- // can remap strings.
- outSavedBuffer.m_MemoryBuffer.write(ioObject.GetDataSectionBegin(),
- ioObject.m_DataSectionByteSize);
- Align(outSavedBuffer.m_MemoryBuffer);
- theNewObject = reinterpret_cast<SCustomMaterial *>(outSavedBuffer.m_MemoryBuffer.begin()
- + itemOffset);
- SWriteRemapper theWriteRemapper(outSavedBuffer);
- // Write any connected objects.
- theNewObject->Remap(theWriteRemapper);
- }
- return theNewObject;
- }
-
- static void Remap(SCustomMaterial &ioObject, SSerializerWriteContext &outSavedBuffer)
- {
- CRegisteredString theClassName(ioObject.m_ClassName);
- ioObject.Remap(outSavedBuffer);
- RemapProperties(ioObject, outSavedBuffer, theClassName);
- }
-
- static SCustomMaterial *Read(SSerializerReadContext &inReadContext)
- {
- SCustomMaterial *theMaterial = ReadGenericGraphObject<SCustomMaterial>(inReadContext);
- if (theMaterial) {
- inReadContext.m_CurrentPtr += theMaterial->m_DataSectionByteSize;
- inReadContext.Align();
- RemapProperties(*theMaterial, inReadContext);
- }
- return theMaterial;
+ size_t itemOffset = outSavedBuffer.m_MemoryBuffer.size();
+ SDynamicObject *theNewObject = static_cast<SDynamicObject *>(
+ WriteGenericGraphObjectNoRemap(type, ioObject, outSavedBuffer));
+ if (theNewObject) {
+ // Writing it out is easy. Reading it back in means we have to have a correctly setup
+ // IEffectManager so we
+ // can remap strings.
+ outSavedBuffer.m_MemoryBuffer.write(ioObject.GetDataSectionBegin(),
+ ioObject.m_DataSectionByteSize);
+ Align(outSavedBuffer.m_MemoryBuffer);
+ theNewObject = reinterpret_cast<SDynamicObject *>(outSavedBuffer.m_MemoryBuffer.begin()
+ + itemOffset);
+ SWriteRemapper theWriteRemapper(outSavedBuffer);
+ // Write any connected objects.
+ theNewObject->Remap(theWriteRemapper);
}
-};
+ return theNewObject;
+}
#ifdef _INTEGRITYPLATFORM
template <typename TObjType>