diff --git a/Source/Engine/Content/BinaryAsset.cpp b/Source/Engine/Content/BinaryAsset.cpp index 692fc9329..228a93f29 100644 --- a/Source/Engine/Content/BinaryAsset.cpp +++ b/Source/Engine/Content/BinaryAsset.cpp @@ -191,6 +191,8 @@ bool BinaryAsset::HasDependenciesModified() const FlaxChunk* BinaryAsset::GetOrCreateChunk(int32 index) { + if (IsVirtual()) // Virtual assets don't own storage container + return nullptr; ASSERT(Math::IsInRange(index, 0, ASSET_FILE_DATA_CHUNKS - 1)); // Try get diff --git a/Source/Engine/Content/Upgraders/BinaryAssetUpgrader.h b/Source/Engine/Content/Upgraders/BinaryAssetUpgrader.h index bebb0cf88..9cf459bfb 100644 --- a/Source/Engine/Content/Upgraders/BinaryAssetUpgrader.h +++ b/Source/Engine/Content/Upgraders/BinaryAssetUpgrader.h @@ -75,8 +75,7 @@ public: }; private: - Upgrader const* _upgraders; - int32 _upgradersCount; + Array> _upgraders; public: /// @@ -87,10 +86,8 @@ public: /// True if cannot upgrade or upgrade failed, otherwise false bool Upgrade(uint32 serializedVersion, AssetMigrationContext& context) const { - // Find upgrader - for (int32 i = 0; i < _upgradersCount; i++) + for (auto& upgrader : _upgraders) { - auto& upgrader = _upgraders[i]; if (upgrader.CurrentVersion == serializedVersion) { // Set target version and preserve metadata @@ -105,7 +102,6 @@ public: return upgrader.Handler(context); } } - return true; } @@ -127,7 +123,6 @@ public: context.Output.Header.Chunks[chunkIndex]->Data.Copy(srcChunk->Data); } } - return false; } @@ -176,27 +171,22 @@ public: protected: BinaryAssetUpgrader() { - _upgraders = nullptr; - _upgradersCount = 0; } void setup(Upgrader const* upgraders, int32 upgradersCount) { - _upgraders = upgraders; - _upgradersCount = upgradersCount; + _upgraders.Add(upgraders, upgradersCount); } public: // [IAssetUpgrader] bool ShouldUpgrade(uint32 serializedVersion) const override { - // Find upgrader - for (int32 i = 0; i < _upgradersCount; i++) + for (auto& upgrader : _upgraders) { - if (_upgraders[i].CurrentVersion == serializedVersion) + if (upgrader.CurrentVersion == serializedVersion) return true; } - return false; } }; diff --git a/Source/Engine/Graphics/Materials/MaterialParams.cpp b/Source/Engine/Graphics/Materials/MaterialParams.cpp index 0e56c33a8..607d70473 100644 --- a/Source/Engine/Graphics/Materials/MaterialParams.cpp +++ b/Source/Engine/Graphics/Materials/MaterialParams.cpp @@ -663,7 +663,7 @@ bool MaterialParams::Load(ReadStream* stream) param->_type = static_cast(stream->ReadByte()); param->_isPublic = stream->ReadBool(); param->_override = param->_isPublic; - stream->ReadString(¶m->_name, 10421); + stream->Read(param->_name, 10421); param->_registerIndex = stream->ReadByte(); stream->ReadUint16(¶m->_offset); @@ -738,7 +738,7 @@ bool MaterialParams::Load(ReadStream* stream) stream->Read(param->_paramId); param->_isPublic = stream->ReadBool(); param->_override = param->_isPublic; - stream->ReadString(¶m->_name, 10421); + stream->Read(param->_name, 10421); param->_registerIndex = stream->ReadByte(); stream->ReadUint16(¶m->_offset); diff --git a/Source/Engine/Graphics/Models/Types.h b/Source/Engine/Graphics/Models/Types.h index 20d574029..b7f9a2151 100644 --- a/Source/Engine/Graphics/Models/Types.h +++ b/Source/Engine/Graphics/Models/Types.h @@ -67,6 +67,8 @@ enum class MeshBufferType /// The vertex buffer (third). /// Vertex2 = 3, + + MAX, }; // Vertex structure for all models (versioned) diff --git a/Source/Engine/Graphics/Shaders/GPUVertexLayout.cpp b/Source/Engine/Graphics/Shaders/GPUVertexLayout.cpp index 91f19c701..edf3b9921 100644 --- a/Source/Engine/Graphics/Shaders/GPUVertexLayout.cpp +++ b/Source/Engine/Graphics/Shaders/GPUVertexLayout.cpp @@ -70,7 +70,7 @@ namespace String VertexElement::ToString() const { #if GPU_ENABLE_RESOURCE_NAMING - return String::Format(TEXT("{}, format {}, offset {}, per-instance {}, slot {}"), ScriptingEnum::ToString(Type), ScriptingEnum::ToString(Format), Offset, PerInstance, Slot); + return String::Format(TEXT("{}, {}, offset {}, {}, slot {}"), ScriptingEnum::ToString(Type), ScriptingEnum::ToString(Format), Offset, PerInstance ? TEXT("per-instance") : TEXT("per-vertex"), Slot); #else return TEXT("VertexElement"); #endif @@ -116,6 +116,18 @@ void GPUVertexLayout::SetElements(const Elements& elements, bool explicitOffsets _stride += offset; } +String GPUVertexLayout::GetElementsString() const +{ + String result; + for (int32 i = 0; i < _elements.Count(); i++) + { + if (i != 0) + result += '\n'; + result += _elements[i].ToString(); + } + return result; +} + GPUVertexLayout* GPUVertexLayout::Get(const Elements& elements, bool explicitOffsets) { // Hash input layout diff --git a/Source/Engine/Graphics/Shaders/GPUVertexLayout.h b/Source/Engine/Graphics/Shaders/GPUVertexLayout.h index 56cf413bc..9bf606ec1 100644 --- a/Source/Engine/Graphics/Shaders/GPUVertexLayout.h +++ b/Source/Engine/Graphics/Shaders/GPUVertexLayout.h @@ -34,6 +34,11 @@ public: return _elements; } + /// + /// Gets the list of elements used by this layout as a text (each element in a new line). + /// + API_PROPERTY() String GetElementsString() const; + /// /// Gets the size in bytes of all elements in the layout structure (including their offsets). /// diff --git a/Source/Engine/Tools/ModelTool/MeshAccelerationStructure.cpp b/Source/Engine/Tools/ModelTool/MeshAccelerationStructure.cpp index 5d4caeabd..25f90e235 100644 --- a/Source/Engine/Tools/ModelTool/MeshAccelerationStructure.cpp +++ b/Source/Engine/Tools/ModelTool/MeshAccelerationStructure.cpp @@ -331,11 +331,11 @@ void MeshAccelerationStructure::Add(Model* model, int32 lodIndex) } } -void MeshAccelerationStructure::Add(ModelData* modelData, int32 lodIndex, bool copy) +void MeshAccelerationStructure::Add(const ModelData* modelData, int32 lodIndex, bool copy) { PROFILE_CPU(); lodIndex = Math::Clamp(lodIndex, 0, modelData->LODs.Count() - 1); - ModelLodData& lod = modelData->LODs[lodIndex]; + const ModelLodData& lod = modelData->LODs[lodIndex]; _meshes.EnsureCapacity(_meshes.Count() + lod.Meshes.Count()); for (int32 i = 0; i < lod.Meshes.Count(); i++) { diff --git a/Source/Engine/Tools/ModelTool/MeshAccelerationStructure.h b/Source/Engine/Tools/ModelTool/MeshAccelerationStructure.h index 2c77d63af..edff32168 100644 --- a/Source/Engine/Tools/ModelTool/MeshAccelerationStructure.h +++ b/Source/Engine/Tools/ModelTool/MeshAccelerationStructure.h @@ -61,7 +61,7 @@ public: void Add(Model* model, int32 lodIndex); // Adds the model geometry for the build to the structure. - void Add(ModelData* modelData, int32 lodIndex, bool copy = false); + void Add(const ModelData* modelData, int32 lodIndex, bool copy = false); // Adds the triangles geometry for the build to the structure. void Add(Float3* vb, int32 vertices, void* ib, int32 indices, bool use16BitIndex, bool copy = false); diff --git a/Source/Engine/Tools/ModelTool/ModelTool.cpp b/Source/Engine/Tools/ModelTool/ModelTool.cpp index 641ab1990..9a1721569 100644 --- a/Source/Engine/Tools/ModelTool/ModelTool.cpp +++ b/Source/Engine/Tools/ModelTool/ModelTool.cpp @@ -81,7 +81,7 @@ class GPUModelSDFTask : public GPUTask ConditionVariable* _signal; AssetReference _shader; Model* _inputModel; - ModelData* _modelData; + const ModelData* _modelData; int32 _lodIndex; Int3 _resolution; ModelBase::SDFData* _sdf; @@ -104,7 +104,7 @@ class GPUModelSDFTask : public GPUTask }); public: - GPUModelSDFTask(ConditionVariable& signal, Model* inputModel, ModelData* modelData, int32 lodIndex, const Int3& resolution, ModelBase::SDFData* sdf, GPUTexture* sdfResult, const Float3& xyzToLocalMul, const Float3& xyzToLocalAdd) + GPUModelSDFTask(ConditionVariable& signal, Model* inputModel, const ModelData* modelData, int32 lodIndex, const Int3& resolution, ModelBase::SDFData* sdf, GPUTexture* sdfResult, const Float3& xyzToLocalMul, const Float3& xyzToLocalAdd) : GPUTask(Type::Custom) , _signal(&signal) , _shader(Content::LoadAsyncInternal(TEXT("Shaders/SDF"))) @@ -350,7 +350,7 @@ public: } }; -bool ModelTool::GenerateModelSDF(Model* inputModel, ModelData* modelData, float resolutionScale, int32 lodIndex, ModelBase::SDFData* outputSDF, MemoryWriteStream* outputStream, const StringView& assetName, float backfacesThreshold, bool useGPU) +bool ModelTool::GenerateModelSDF(Model* inputModel, const ModelData* modelData, float resolutionScale, int32 lodIndex, ModelBase::SDFData* outputSDF, MemoryWriteStream* outputStream, const StringView& assetName, float backfacesThreshold, bool useGPU) { PROFILE_CPU(); auto startTime = Platform::GetTimeSeconds(); diff --git a/Source/Engine/Tools/ModelTool/ModelTool.h b/Source/Engine/Tools/ModelTool/ModelTool.h index 708b94342..db7131df1 100644 --- a/Source/Engine/Tools/ModelTool/ModelTool.h +++ b/Source/Engine/Tools/ModelTool/ModelTool.h @@ -98,7 +98,7 @@ API_CLASS(Namespace="FlaxEngine.Tools", Static) class FLAXENGINE_API ModelTool // Optional: inputModel or modelData // Optional: outputSDF or null, outputStream or null - static bool GenerateModelSDF(class Model* inputModel, class ModelData* modelData, float resolutionScale, int32 lodIndex, ModelBase::SDFData* outputSDF, class MemoryWriteStream* outputStream, const StringView& assetName, float backfacesThreshold = 0.6f, bool useGPU = true); + static bool GenerateModelSDF(class Model* inputModel, const class ModelData* modelData, float resolutionScale, int32 lodIndex, ModelBase::SDFData* outputSDF, class MemoryWriteStream* outputStream, const StringView& assetName, float backfacesThreshold = 0.6f, bool useGPU = true); #if USE_EDITOR