From 5a9cb13e746906eb1595a76793924ea83a8902a4 Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Wed, 1 Nov 2023 13:38:49 +0100 Subject: [PATCH] Mesh and Material Serializations --- src/Editor/Asset/MeshLoader.cpp | 11 +++-- src/Engine/Asset/MeshAsset.cpp | 48 ++----------------- src/Engine/Component/Camera.h | 1 + src/Engine/Graphics/CMakeLists.txt | 1 + src/Engine/Graphics/Descriptor.h | 6 +-- src/Engine/Graphics/Initializer.cpp | 48 +++++++++++++++++++ src/Engine/Graphics/Initializer.h | 50 ++------------------ src/Engine/Graphics/Mesh.cpp | 20 ++++++++ src/Engine/Graphics/Mesh.h | 6 ++- src/Engine/Graphics/Shader.h | 1 + src/Engine/Graphics/StaticMeshVertexData.cpp | 39 +++++++++++++++ src/Engine/Graphics/StaticMeshVertexData.h | 2 + src/Engine/Graphics/VertexData.cpp | 32 ++++++++++++- src/Engine/Graphics/VertexData.h | 11 +++-- src/Engine/Graphics/Vulkan/Initializer.cpp | 1 + src/Engine/Graphics/Vulkan/PipelineCache.cpp | 4 +- src/Engine/Material/Material.cpp | 21 ++++++-- src/Engine/Material/Material.h | 1 + src/Engine/Material/MaterialInstance.cpp | 37 ++++++++++++++- src/Engine/Material/MaterialInstance.h | 4 ++ 20 files changed, 233 insertions(+), 111 deletions(-) create mode 100644 src/Engine/Graphics/Initializer.cpp diff --git a/src/Editor/Asset/MeshLoader.cpp b/src/Editor/Asset/MeshLoader.cpp index 11dde76..ae58f2c 100644 --- a/src/Editor/Asset/MeshLoader.cpp +++ b/src/Editor/Asset/MeshLoader.cpp @@ -174,9 +174,9 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const ArraymFaces[faceIndex].mIndices[2]; } + Array meshlets; if (Gfx::useMeshShading) { - Array meshlets; meshlets.reserve(indices.size() / (3ull * Gfx::numPrimitivesPerMeshlet)); std::set uniqueVertices; Meshlet current = { @@ -233,6 +233,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const ArrayloadMesh(id, meshlets); } else { @@ -250,10 +251,14 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const ArraycreateIndexBuffer(idxInfo); indexBuffer->transferOwnership(Gfx::QueueType::GRAPHICS); - globalMeshes[meshIndex] = new Mesh(vertexShaderInput, indexBuffer); - globalMeshes[meshIndex]->referencedMaterial = materials[mesh->mMaterialIndex]; + globalMeshes[meshIndex] = new Mesh(); + globalMeshes[meshIndex]->vertexData = vertexData; + globalMeshes[meshIndex]->id = id; + globalMeshes[meshIndex]->referencedMaterial = materials[mesh->mMaterialIndex]->getMaterial()->instantiate(); + globalMeshes[meshIndex]->meshlets = std::move(meshlets); } } + void MeshLoader::convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels) { for(uint32 i = 0; i < numPixels; ++i) diff --git a/src/Engine/Asset/MeshAsset.cpp b/src/Engine/Asset/MeshAsset.cpp index 46afa40..e05de62 100644 --- a/src/Engine/Asset/MeshAsset.cpp +++ b/src/Engine/Asset/MeshAsset.cpp @@ -20,53 +20,11 @@ MeshAsset::~MeshAsset() void MeshAsset::save(ArchiveBuffer& buffer) const { - uint64 numMeshes = meshes.size(); - Serialization::save(buffer, numMeshes); - for (auto mesh : meshes) - { - mesh->vertexInput->save(buffer); - Array rawIndices; - mesh->indexBuffer->download(rawIndices); - Serialization::save(buffer, rawIndices); - Serialization::save(buffer, mesh->indexBuffer->getIndexType()); - Serialization::save(buffer, mesh->referencedMaterial->getAssetIdentifier()); - } + Serialization::save(buffer, meshes); + } void MeshAsset::load(ArchiveBuffer& buffer) { - uint64 numMeshes = 0; - Serialization::load(buffer, numMeshes); - meshes.resize(numMeshes); - for (auto& mesh : meshes) - { - PVertexShaderInput vertexInput = new StaticMeshVertexInput(""); - vertexInput->load(buffer); - Array rawIndices; - Serialization::load(buffer, rawIndices); - Gfx::SeIndexType indexType; - Serialization::load(buffer, indexType); - IndexBufferCreateInfo createInfo = { - .resourceData = { - .size = rawIndices.size(), - .data = rawIndices.data(), - }, - .indexType = indexType, - }; - Gfx::PIndexBuffer indexBuffer = buffer.getGraphics()->createIndexBuffer(createInfo); - mesh = new Mesh(vertexInput, indexBuffer); - std::string matname; - Serialization::load(buffer, matname); - mesh->referencedMaterial = AssetRegistry::findMaterial(matname); - } + Serialization::load(buffer, meshes); } - -void MeshAsset::addMesh(PMesh mesh) -{ - meshes.add(mesh); -} - -const Array MeshAsset::getMeshes() -{ - return meshes; -} \ No newline at end of file diff --git a/src/Engine/Component/Camera.h b/src/Engine/Component/Camera.h index 3a3cc73..b87c5df 100644 --- a/src/Engine/Component/Camera.h +++ b/src/Engine/Component/Camera.h @@ -5,6 +5,7 @@ namespace Seele { +DECLARE_NAME_REF(Gfx, Viewport) namespace Component { struct Camera diff --git a/src/Engine/Graphics/CMakeLists.txt b/src/Engine/Graphics/CMakeLists.txt index f791abd..6351b28 100644 --- a/src/Engine/Graphics/CMakeLists.txt +++ b/src/Engine/Graphics/CMakeLists.txt @@ -10,6 +10,7 @@ target_sources(Engine Graphics.h Graphics.cpp Initializer.h + Initializer.cpp Mesh.h Mesh.cpp RenderTarget.h diff --git a/src/Engine/Graphics/Descriptor.h b/src/Engine/Graphics/Descriptor.h index d488067..d52c7ee 100644 --- a/src/Engine/Graphics/Descriptor.h +++ b/src/Engine/Graphics/Descriptor.h @@ -79,9 +79,9 @@ public: { descriptorBindings.resize(other.descriptorBindings.size()); for(uint32 i = 0; i < descriptorBindings.size(); ++i) - { - descriptorBindings[i] = other.descriptorBindings[i]; - } + { + descriptorBindings[i] = other.descriptorBindings[i]; + } } DescriptorLayout& operator=(const DescriptorLayout& other) { diff --git a/src/Engine/Graphics/Initializer.cpp b/src/Engine/Graphics/Initializer.cpp new file mode 100644 index 0000000..4ec8ac4 --- /dev/null +++ b/src/Engine/Graphics/Initializer.cpp @@ -0,0 +1,48 @@ +#include "Initializer.h" + +using namespace Seele; +using namespace Seele::Graphics; + +LegacyPipelineCreateInfo::LegacyPipelineCreateInfo() + : topology(Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST) + , multisampleState(MultisampleState{ + .samples = 1, + }) + , rasterizationState(RasterizationState{ + .polygonMode = Gfx::SE_POLYGON_MODE_FILL, + .cullMode = Gfx::SE_CULL_MODE_BACK_BIT, + .frontFace = Gfx::SE_FRONT_FACE_COUNTER_CLOCKWISE, + }) + , depthStencilState(DepthStencilState{ + .depthTestEnable = true, + .depthWriteEnable = true, + .stencilTestEnable = false, + .depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL, + .minDepthBounds = 0.0f, + .maxDepthBounds = 1.0f, + }) + , colorBlend(ColorBlendState{ + .logicOpEnable = false, + .attachmentCount = 0, + .blendAttachments = { + ColorBlendState::BlendAttachment{ + .colorWriteMask = + Gfx::SE_COLOR_COMPONENT_R_BIT | + Gfx::SE_COLOR_COMPONENT_G_BIT | + Gfx::SE_COLOR_COMPONENT_B_BIT | + Gfx::SE_COLOR_COMPONENT_A_BIT, + } + }, + .blendConstants = { + 1.0f, + 1.0f, + 1.0f, + 1.0f, + }, + }) +{ +} + +Seele::Gfx::LegacyPipelineCreateInfo::~LegacyPipelineCreateInfo() +{ +} diff --git a/src/Engine/Graphics/Initializer.h b/src/Engine/Graphics/Initializer.h index 9876f52..810d8f7 100644 --- a/src/Engine/Graphics/Initializer.h +++ b/src/Engine/Graphics/Initializer.h @@ -2,6 +2,7 @@ #include "Enums.h" #include "Containers/Map.h" #include "Math/Math.h" +#include "Shader.h" namespace Seele { @@ -189,15 +190,9 @@ struct ColorBlendState } blendAttachments[16]; float blendConstants[4]; }; - DECLARE_REF(VertexDeclaration) -DECLARE_REF(VertexShader) -DECLARE_REF(FragmentShader) -DECLARE_REF(TaskShader) -DECLARE_REF(MeshShader) -DECLARE_REF(ComputeShader) -DECLARE_REF(PipelineLayout) DECLARE_REF(RenderPass) +DECLARE_REF(PipelineLayout) struct LegacyPipelineCreateInfo { PVertexDeclaration vertexDeclaration; @@ -210,45 +205,8 @@ struct LegacyPipelineCreateInfo RasterizationState rasterizationState; DepthStencilState depthStencilState; ColorBlendState colorBlend; - LegacyPipelineCreateInfo() - : topology(Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST) - , multisampleState(MultisampleState{ - .samples = 1, - }) - , rasterizationState(RasterizationState{ - .polygonMode = Gfx::SE_POLYGON_MODE_FILL, - .cullMode = Gfx::SE_CULL_MODE_BACK_BIT, - .frontFace = Gfx::SE_FRONT_FACE_COUNTER_CLOCKWISE, - }) - , depthStencilState(DepthStencilState{ - .depthTestEnable = true, - .depthWriteEnable = true, - .stencilTestEnable = false, - .depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL, - .minDepthBounds = 0.0f, - .maxDepthBounds = 1.0f, - }) - , colorBlend(ColorBlendState{ - .logicOpEnable = false, - .attachmentCount = 0, - .blendAttachments = { - ColorBlendState::BlendAttachment{ - .colorWriteMask = - Gfx::SE_COLOR_COMPONENT_R_BIT | - Gfx::SE_COLOR_COMPONENT_G_BIT | - Gfx::SE_COLOR_COMPONENT_B_BIT | - Gfx::SE_COLOR_COMPONENT_A_BIT, - } - }, - .blendConstants = { - 1.0f, - 1.0f, - 1.0f, - 1.0f, - }, - }) - { - } + LegacyPipelineCreateInfo(); + ~LegacyPipelineCreateInfo(); }; struct MeshPipelineCreateInfo diff --git a/src/Engine/Graphics/Mesh.cpp b/src/Engine/Graphics/Mesh.cpp index 621ddff..3b53100 100644 --- a/src/Engine/Graphics/Mesh.cpp +++ b/src/Engine/Graphics/Mesh.cpp @@ -10,3 +10,23 @@ Mesh::Mesh() Mesh::~Mesh() { } + +void Mesh::save(ArchiveBuffer& buffer) +{ + Serialization::save(buffer, vertexData->getTypeName()); + Serialization::save(buffer, vertexCount); + Serialization::save(buffer, meshlets); + vertexData->serializeMesh(id, vertexCount, buffer); +} + +void Mesh::load(ArchiveBuffer& buffer) +{ + std::string typeName; + Serialization::load(buffer, typeName); + Serialization::load(buffer, vertexCount); + vertexData = VertexData::findByTypeName(typeName); + Serialization::load(buffer, meshlets); + id = vertexData->allocateVertexData(vertexCount); + vertexData->loadMesh(id, meshlets); + vertexData->deserializeMesh(id, buffer); +} diff --git a/src/Engine/Graphics/Mesh.h b/src/Engine/Graphics/Mesh.h index 2b16ec4..6465580 100644 --- a/src/Engine/Graphics/Mesh.h +++ b/src/Engine/Graphics/Mesh.h @@ -12,7 +12,11 @@ public: VertexData* vertexData; MeshId id; - PMaterialInstanceAsset referencedMaterial; + uint64 vertexCount; + PMaterialInstance referencedMaterial; + Array meshlets; + void save(ArchiveBuffer& buffer); + void load(ArchiveBuffer& buffer); private: }; DEFINE_REF(Mesh) diff --git a/src/Engine/Graphics/Shader.h b/src/Engine/Graphics/Shader.h index bddd1a0..6f98d74 100644 --- a/src/Engine/Graphics/Shader.h +++ b/src/Engine/Graphics/Shader.h @@ -1,5 +1,6 @@ #pragma once #include "Enums.h" +#include "CRC.h" namespace Seele { diff --git a/src/Engine/Graphics/StaticMeshVertexData.cpp b/src/Engine/Graphics/StaticMeshVertexData.cpp index dd486d7..e023001 100644 --- a/src/Engine/Graphics/StaticMeshVertexData.cpp +++ b/src/Engine/Graphics/StaticMeshVertexData.cpp @@ -61,6 +61,45 @@ void StaticMeshVertexData::loadBiTangents(MeshId id, const Array& data) dirty = true; } +void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) +{ + uint64 offset = meshOffsets[id]; + Array pos(numVertices); + Array tex(numVertices); + Array nor(numVertices); + Array tan(numVertices); + Array bit(numVertices); + std::copy(positionData.begin() + offset, positionData.begin() + offset + numVertices, pos.begin()); + std::copy(texCoordsData.begin() + offset, texCoordsData.begin() + offset + numVertices, tex.begin()); + std::copy(normalData.begin() + offset, normalData.begin() + offset + numVertices, nor.begin()); + std::copy(tangentData.begin() + offset, tangentData.begin() + offset + numVertices, tan.begin()); + std::copy(biTangentData.begin() + offset, biTangentData.begin() + offset + numVertices, bit.begin()); + Serialization::save(buffer, pos); + Serialization::save(buffer, tex); + Serialization::save(buffer, nor); + Serialization::save(buffer, tan); + Serialization::save(buffer, bit); +} + +void StaticMeshVertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer) +{ + Array pos; + Array tex; + Array nor; + Array tan; + Array bit; + Serialization::load(buffer, pos); + Serialization::load(buffer, tex); + Serialization::load(buffer, nor); + Serialization::load(buffer, tan); + Serialization::load(buffer, bit); + loadPositions(id, pos); + loadTexCoords(id, tex); + loadNormals(id, nor); + loadTangents(id, tan); + loadBiTangents(id, bit); +} + void StaticMeshVertexData::init(Gfx::PGraphics graphics) { VertexData::init(graphics); diff --git a/src/Engine/Graphics/StaticMeshVertexData.h b/src/Engine/Graphics/StaticMeshVertexData.h index 5bea49f..aa8ddd6 100644 --- a/src/Engine/Graphics/StaticMeshVertexData.h +++ b/src/Engine/Graphics/StaticMeshVertexData.h @@ -14,6 +14,8 @@ public: void loadNormals(MeshId id, const Array& data); void loadTangents(MeshId id, const Array& data); void loadBiTangents(MeshId id, const Array& data); + virtual void serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) override; + virtual void deserializeMesh(MeshId id, ArchiveBuffer& buffer) override; virtual void init(Gfx::PGraphics graphics) override; virtual void bindBuffers(Gfx::PRenderCommand command) override; virtual Gfx::PDescriptorLayout getVertexDataLayout() override; diff --git a/src/Engine/Graphics/VertexData.cpp b/src/Engine/Graphics/VertexData.cpp index b415cee..e5fa159 100644 --- a/src/Engine/Graphics/VertexData.cpp +++ b/src/Engine/Graphics/VertexData.cpp @@ -45,10 +45,10 @@ void VertexData::loadMesh(MeshId id, Array loadedMeshlets) Meshlet& m = loadedMeshlets[currentMesh + i]; uint32 vertexOffset = vertexIndices.size(); vertexIndices.resize(vertexOffset + m.numVertices); - std::memcpy(vertexIndices.data() + vertexOffset, m.uniqueVertices, sizeof(m.uniqueVertices)); + std::memcpy(vertexIndices.data() + vertexOffset, m.uniqueVertices.data(), sizeof(m.uniqueVertices)); uint32 primitiveOffset = primitiveIndices.size(); primitiveIndices.resize(primitiveOffset + (m.numPrimitives * 3)); - std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout, sizeof(m.primitiveLayout)); + std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout.data(), sizeof(m.primitiveLayout)); meshlets.add(MeshletDescription{ .boundingBox = MeshletAABB(), .vertexCount = m.numVertices, @@ -156,6 +156,18 @@ List VertexData::getList() return vertexDataList; } +VertexData* Seele::VertexData::findByTypeName(std::string name) +{ + for (auto vd : vertexDataList) + { + if (vd->getTypeName() == name) + { + return vd; + } + } + return nullptr; +} + void Seele::VertexData::init(Gfx::PGraphics graphics) { this->graphics = graphics; @@ -182,3 +194,19 @@ VertexData::VertexData() , dirty(false) { } + +void Meshlet::save(ArchiveBuffer& buffer) +{ + Serialization::save(buffer, uniqueVertices); + Serialization::save(buffer, primitiveLayout); + Serialization::save(buffer, numVertices); + Serialization::save(buffer, numPrimitives); +} + +void Meshlet::load(ArchiveBuffer& buffer) +{ + Serialization::load(buffer, uniqueVertices); + Serialization::load(buffer, primitiveLayout); + Serialization::load(buffer, numVertices); + Serialization::load(buffer, numPrimitives); +} diff --git a/src/Engine/Graphics/VertexData.h b/src/Engine/Graphics/VertexData.h index 48a0a34..2fd81b2 100644 --- a/src/Engine/Graphics/VertexData.h +++ b/src/Engine/Graphics/VertexData.h @@ -22,10 +22,12 @@ struct MeshId }; struct Meshlet { - uint32 uniqueVertices[Gfx::numVerticesPerMeshlet]; // unique vertiex indices in the vertex data - uint8 primitiveLayout[Gfx::numPrimitivesPerMeshlet * 3]; // indices into the uniqueVertices array, only uint8 needed + StaticArray uniqueVertices; // unique vertiex indices in the vertex data + StaticArray primitiveLayout; // indices into the uniqueVertices array, only uint8 needed uint32 numVertices; uint32 numPrimitives; + void save(ArchiveBuffer& buffer); + void load(ArchiveBuffer& buffer); }; class VertexData { @@ -62,6 +64,8 @@ public: void loadMesh(MeshId id, Array meshlets); void createDescriptors(); MeshId allocateVertexData(uint64 numVertices); + virtual void serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) = 0; + virtual void deserializeMesh(MeshId id, ArchiveBuffer& buffer) = 0; virtual void bindBuffers(Gfx::PRenderCommand command) = 0; virtual Gfx::PDescriptorLayout getVertexDataLayout() = 0; virtual Gfx::PDescriptorSet getVertexDataSet() = 0; @@ -70,6 +74,7 @@ public: const Map& getMaterialData() const { return materialData; } const Array& getMeshData(MeshId id) { return meshData[id]; } static List getList(); + static VertexData* findByTypeName(std::string name); virtual void init(Gfx::PGraphics graphics); protected: virtual void resizeBuffers() = 0; @@ -92,7 +97,7 @@ protected: }; Map materialData; Map> meshData; - Map meshOffsets; + Map meshOffsets; Array meshlets; Array primitiveIndices; Array vertexIndices; diff --git a/src/Engine/Graphics/Vulkan/Initializer.cpp b/src/Engine/Graphics/Vulkan/Initializer.cpp index d934652..854905e 100644 --- a/src/Engine/Graphics/Vulkan/Initializer.cpp +++ b/src/Engine/Graphics/Vulkan/Initializer.cpp @@ -1,5 +1,6 @@ #include "Initializer.h" #include +#include "Initializer.h" using namespace Seele::Vulkan; diff --git a/src/Engine/Graphics/Vulkan/PipelineCache.cpp b/src/Engine/Graphics/Vulkan/PipelineCache.cpp index 40cf1c4..aa28f40 100644 --- a/src/Engine/Graphics/Vulkan/PipelineCache.cpp +++ b/src/Engine/Graphics/Vulkan/PipelineCache.cpp @@ -129,7 +129,7 @@ PGraphicsPipeline PipelineCache::createPipeline(const Gfx::LegacyPipelineCreateI ); rasterizationState.depthBiasEnable = gfxInfo.rasterizationState.depthBiasEnable; rasterizationState.depthBiasClamp = gfxInfo.rasterizationState.depthBiasClamp; - rasterizationState.depthBiasConstantFactor = gfxInfo.rasterizationState.depthBoasConstantFactor; + rasterizationState.depthBiasConstantFactor = gfxInfo.rasterizationState.depthBiasConstantFactor; rasterizationState.depthBiasSlopeFactor = gfxInfo.rasterizationState.depthBiasSlopeFactor; rasterizationState.depthClampEnable = gfxInfo.rasterizationState.depthClampEnable; rasterizationState.lineWidth = gfxInfo.rasterizationState.lineWidth; @@ -274,7 +274,7 @@ PGraphicsPipeline PipelineCache::createPipeline(const Gfx::MeshPipelineCreateInf ); rasterizationState.depthBiasEnable = gfxInfo.rasterizationState.depthBiasEnable; rasterizationState.depthBiasClamp = gfxInfo.rasterizationState.depthBiasClamp; - rasterizationState.depthBiasConstantFactor = gfxInfo.rasterizationState.depthBoasConstantFactor; + rasterizationState.depthBiasConstantFactor = gfxInfo.rasterizationState.depthBiasConstantFactor; rasterizationState.depthBiasSlopeFactor = gfxInfo.rasterizationState.depthBiasSlopeFactor; rasterizationState.depthClampEnable = gfxInfo.rasterizationState.depthClampEnable; rasterizationState.lineWidth = gfxInfo.rasterizationState.lineWidth; diff --git a/src/Engine/Material/Material.cpp b/src/Engine/Material/Material.cpp index 268f8b6..6355bcb 100644 --- a/src/Engine/Material/Material.cpp +++ b/src/Engine/Material/Material.cpp @@ -5,6 +5,9 @@ using namespace Seele; +Material::Material() +{ +} Material::Material(Gfx::PGraphics graphics, Array parameter, @@ -37,11 +40,15 @@ PMaterialInstance Seele::Material::instantiate() void Material::save(ArchiveBuffer& buffer) const { - MaterialInterface::save(buffer); + Serialization::save(buffer, brdfName); + Serialization::save(buffer, uniformDataSize); + Serialization::save(buffer, uniformBinding); + Serialization::save(buffer, instanceId); Serialization::save(buffer, materialName); - Serialization::save(buffer, layout->getSetIndex()); Serialization::save(buffer, codeExpressions); + Serialization::save(buffer, parameters); Serialization::save(buffer, brdf); + Serialization::save(buffer, layout->getSetIndex()); const auto& bindings = layout->getBindings(); Serialization::save(buffer, bindings.size()); for (const auto& binding : bindings) @@ -57,12 +64,16 @@ void Material::save(ArchiveBuffer& buffer) const void Material::load(ArchiveBuffer& buffer) { graphics = buffer.getGraphics(); - MaterialInterface::load(buffer); + Serialization::load(buffer, brdfName); + Serialization::load(buffer, uniformDataSize); + Serialization::load(buffer, uniformBinding); + Serialization::load(buffer, instanceId); Serialization::load(buffer, materialName); + Serialization::load(buffer, codeExpressions); + Serialization::load(buffer, parameters); + Serialization::load(buffer, brdf); uint32 setIndex; Serialization::load(buffer, setIndex); - Serialization::load(buffer, codeExpressions); - Serialization::load(buffer, brdf); uint64 numBindings; Serialization::load(buffer, numBindings); layout = graphics->createDescriptorLayout(); diff --git a/src/Engine/Material/Material.h b/src/Engine/Material/Material.h index ba8d2ee..893f0ac 100644 --- a/src/Engine/Material/Material.h +++ b/src/Engine/Material/Material.h @@ -8,6 +8,7 @@ DECLARE_REF(MaterialInstance) class Material { public: + Material(); Material(Gfx::PGraphics graphics, Array parameter, Gfx::PDescriptorLayout layout, diff --git a/src/Engine/Material/MaterialInstance.cpp b/src/Engine/Material/MaterialInstance.cpp index c8c4139..398b110 100644 --- a/src/Engine/Material/MaterialInstance.cpp +++ b/src/Engine/Material/MaterialInstance.cpp @@ -22,6 +22,41 @@ MaterialInstance::~MaterialInstance() } -void Seele::MaterialInstance::updateDescriptor() +void MaterialInstance::updateDescriptor() { + descriptor = layout->allocateDescriptorSet(); + for (auto param : parameters) + { + param->updateDescriptorSet(descriptor, uniformData.data()); + } + descriptor->writeChanges(); +} + +Gfx::PDescriptorSet Seele::MaterialInstance::getDescriptorSet() const +{ + return descriptor; +} + +void MaterialInstance::save(ArchiveBuffer& buffer) const +{ + Serialization::save(buffer, uniformData); + Serialization::save(buffer, uniformBinding); + Serialization::save(buffer, uniformBuffer); + Serialization::save(buffer, parameters); + Serialization::save(buffer, layout); + Serialization::save(buffer, descriptor); + Serialization::save(buffer, baseMaterial); + Serialization::save(buffer, id); +} + +void MaterialInstance::load(ArchiveBuffer& buffer) +{ + Serialization::load(buffer, uniformData); + Serialization::load(buffer, uniformBinding); + Serialization::load(buffer, uniformBuffer); + Serialization::load(buffer, parameters); + Serialization::load(buffer, layout); + Serialization::load(buffer, descriptor); + Serialization::load(buffer, baseMaterial); + Serialization::load(buffer, id); } diff --git a/src/Engine/Material/MaterialInstance.h b/src/Engine/Material/MaterialInstance.h index 2dbdb9d..ee8a7e1 100644 --- a/src/Engine/Material/MaterialInstance.h +++ b/src/Engine/Material/MaterialInstance.h @@ -13,6 +13,10 @@ public: Gfx::PDescriptorSet getDescriptorSet() const; PMaterial getBaseMaterial() const { return baseMaterial; } uint64 getId() const { return id; } + + void save(ArchiveBuffer& buffer) const; + void load(ArchiveBuffer& buffer); + private: Gfx::PGraphics graphics; Array uniformData;