2023-10-24 15:01:09 +02:00
|
|
|
#include "VertexData.h"
|
2023-10-31 23:44:46 +01:00
|
|
|
#include "Graphics/Enums.h"
|
|
|
|
|
#include "Graphics/Initializer.h"
|
2023-10-24 15:01:09 +02:00
|
|
|
#include "Material/Material.h"
|
|
|
|
|
#include "Graphics/Graphics.h"
|
2023-10-26 18:37:29 +02:00
|
|
|
#include "Graphics/Descriptor.h"
|
|
|
|
|
#include "Component/Mesh.h"
|
2023-11-15 17:42:57 +01:00
|
|
|
#include "Graphics/Shader.h"
|
2024-01-24 23:10:33 +01:00
|
|
|
#include "Graphics/Mesh.h"
|
2023-12-22 19:46:07 +01:00
|
|
|
#include "Containers/Set.h"
|
2023-10-24 15:01:09 +02:00
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
|
2023-11-30 11:51:53 +01:00
|
|
|
constexpr static uint64 NUM_DEFAULT_ELEMENTS = 1024 * 1024;
|
2023-10-31 17:55:30 +01:00
|
|
|
|
2023-10-24 15:01:09 +02:00
|
|
|
void VertexData::resetMeshData()
|
|
|
|
|
{
|
2023-12-17 16:16:46 +01:00
|
|
|
std::unique_lock l(materialDataLock);
|
2023-11-17 18:46:37 +01:00
|
|
|
for (auto& [_, mat] : materialData)
|
|
|
|
|
{
|
|
|
|
|
mat.material->getDescriptorLayout()->reset();
|
|
|
|
|
}
|
2023-11-26 09:40:48 +01:00
|
|
|
materialData.clear();
|
2023-10-31 16:16:23 +01:00
|
|
|
if (dirty)
|
|
|
|
|
{
|
|
|
|
|
updateBuffers();
|
2023-11-08 23:27:21 +01:00
|
|
|
dirty = false;
|
2023-10-31 16:16:23 +01:00
|
|
|
}
|
2023-10-24 15:01:09 +02:00
|
|
|
}
|
|
|
|
|
|
2023-11-26 09:40:48 +01:00
|
|
|
void VertexData::updateMesh(PMesh mesh, Component::Transform& transform)
|
2023-10-24 15:01:09 +02:00
|
|
|
{
|
2023-12-17 16:16:46 +01:00
|
|
|
std::unique_lock l(materialDataLock);
|
2024-01-18 18:39:44 +01:00
|
|
|
PMaterialInstance referencedInstance = mesh->referencedMaterial->getHandle();
|
|
|
|
|
PMaterial mat = referencedInstance->getBaseMaterial();
|
2023-10-24 15:01:09 +02:00
|
|
|
MaterialData& matData = materialData[mat->getName()];
|
2023-11-08 23:27:21 +01:00
|
|
|
matData.material = mat;
|
2024-01-18 18:39:44 +01:00
|
|
|
MaterialInstanceData& matInstanceData = matData.instances[referencedInstance->getId()];
|
2023-12-17 16:16:46 +01:00
|
|
|
for (const auto& data : meshData[mesh->id])
|
2023-11-26 11:27:39 +01:00
|
|
|
{
|
2024-05-04 09:25:13 +02:00
|
|
|
Matrix4 transformMatrix = transform.toMatrix() * mesh->transform;
|
2023-11-26 11:27:39 +01:00
|
|
|
matInstanceData.meshes.add(MeshInstanceData{
|
|
|
|
|
.instance = InstanceData {
|
2024-05-04 09:25:13 +02:00
|
|
|
.transformMatrix = transformMatrix,
|
|
|
|
|
.inverseTransformMatrix = glm::inverse(transformMatrix),
|
2023-11-26 11:27:39 +01:00
|
|
|
},
|
2023-12-15 11:57:13 +01:00
|
|
|
.data = data,
|
2023-11-26 11:27:39 +01:00
|
|
|
});
|
2024-05-05 08:31:40 +02:00
|
|
|
for (size_t i = 0; i < 0; ++i)
|
2024-05-04 13:25:19 +02:00
|
|
|
{
|
|
|
|
|
auto bounding = meshlets[data.meshletOffset + i].bounding;
|
|
|
|
|
StaticArray<Vector, 8> corners;
|
2024-05-05 08:31:40 +02:00
|
|
|
Vector min = bounding.min;//bounding.center - bounding.radius * Vector(1, 1, 1);
|
|
|
|
|
Vector max = bounding.max;//bounding.center + bounding.radius * Vector(1, 1, 1);
|
2024-05-04 13:25:19 +02:00
|
|
|
corners[0] = transformMatrix * Vector4(min.x, min.y, min.z, 1);
|
|
|
|
|
corners[1] = transformMatrix * Vector4(min.x, min.y, max.z, 1);
|
|
|
|
|
corners[2] = transformMatrix * Vector4(min.x, max.y, min.z, 1);
|
|
|
|
|
corners[3] = transformMatrix * Vector4(min.x, max.y, max.z, 1);
|
|
|
|
|
corners[4] = transformMatrix * Vector4(max.x, min.y, min.z, 1);
|
|
|
|
|
corners[5] = transformMatrix * Vector4(max.x, min.y, max.z, 1);
|
|
|
|
|
corners[6] = transformMatrix * Vector4(max.x, max.y, min.z, 1);
|
|
|
|
|
corners[7] = transformMatrix * Vector4(max.x, max.y, max.z, 1);
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[0], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[1], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[0], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[2], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[1], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[3], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[2], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[3], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[0], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[4], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[1], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[5], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[2], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[6], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[3], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[7], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[4], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[5], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[4], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[6], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[6], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[7], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[5], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
addDebugVertex(DebugVertex{ .position = corners[7], .color = meshlets[data.meshletOffset + i].color });
|
|
|
|
|
}
|
2023-11-26 11:27:39 +01:00
|
|
|
}
|
2024-01-18 18:39:44 +01:00
|
|
|
matInstanceData.materialInstance = referencedInstance;
|
|
|
|
|
referencedInstance->updateDescriptor();
|
2023-10-24 15:01:09 +02:00
|
|
|
}
|
|
|
|
|
|
2023-11-26 09:40:48 +01:00
|
|
|
void VertexData::createDescriptors()
|
2023-11-22 13:18:54 +01:00
|
|
|
{
|
2023-12-17 16:16:46 +01:00
|
|
|
std::unique_lock l(materialDataLock);
|
2023-11-22 13:18:54 +01:00
|
|
|
instanceDataLayout->reset();
|
|
|
|
|
for (const auto& [_, mat] : materialData)
|
|
|
|
|
{
|
|
|
|
|
for (auto& [_, matInst] : mat.instances)
|
|
|
|
|
{
|
|
|
|
|
Array<InstanceData> instanceData;
|
2023-11-26 09:40:48 +01:00
|
|
|
Array<MeshData> meshes;
|
2023-11-22 13:18:54 +01:00
|
|
|
for (auto& inst : matInst.meshes)
|
|
|
|
|
{
|
2023-11-26 11:27:39 +01:00
|
|
|
meshes.add(inst.data);
|
|
|
|
|
instanceData.add(inst.instance);
|
2023-11-22 13:18:54 +01:00
|
|
|
}
|
|
|
|
|
matInst.instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
|
|
|
|
.sourceData = {
|
|
|
|
|
.size = sizeof(InstanceData) * instanceData.size(),
|
|
|
|
|
.data = (uint8*)instanceData.data(),
|
|
|
|
|
},
|
|
|
|
|
.numElements = instanceData.size(),
|
|
|
|
|
.dynamic = false,
|
2024-04-20 21:35:43 +02:00
|
|
|
.name = "InstanceBuffer"
|
2023-11-22 13:18:54 +01:00
|
|
|
});
|
2024-01-26 16:26:22 +01:00
|
|
|
matInst.instanceBuffer->pipelineBarrier(
|
|
|
|
|
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
|
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
|
Gfx::SE_ACCESS_MEMORY_READ_BIT,
|
|
|
|
|
Gfx::SE_PIPELINE_STAGE_VERTEX_SHADER_BIT
|
|
|
|
|
);
|
2023-11-22 13:18:54 +01:00
|
|
|
matInst.descriptorSet = instanceDataLayout->allocateDescriptorSet();
|
2023-11-26 09:40:48 +01:00
|
|
|
|
|
|
|
|
matInst.meshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
2023-11-10 19:18:09 +01:00
|
|
|
.sourceData = {
|
2023-11-26 09:40:48 +01:00
|
|
|
.size = sizeof(MeshData) * meshes.size(),
|
|
|
|
|
.data = (uint8*)meshes.data(),
|
2023-11-10 19:18:09 +01:00
|
|
|
},
|
2023-11-26 09:40:48 +01:00
|
|
|
.numElements = meshes.size(),
|
2023-11-15 17:42:57 +01:00
|
|
|
.dynamic = false,
|
2024-04-20 21:35:43 +02:00
|
|
|
.name = "MeshDataBuffer"
|
2023-11-10 19:18:09 +01:00
|
|
|
});
|
2024-01-26 16:26:22 +01:00
|
|
|
matInst.meshDataBuffer->pipelineBarrier(
|
|
|
|
|
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
|
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
|
Gfx::SE_ACCESS_MEMORY_READ_BIT,
|
|
|
|
|
Gfx::SE_PIPELINE_STAGE_VERTEX_SHADER_BIT
|
|
|
|
|
);
|
2023-11-26 11:27:39 +01:00
|
|
|
matInst.descriptorSet->updateBuffer(0, matInst.instanceBuffer);
|
2023-11-26 09:40:48 +01:00
|
|
|
matInst.descriptorSet->updateBuffer(1, matInst.meshDataBuffer);
|
|
|
|
|
matInst.descriptorSet->updateBuffer(2, meshletBuffer);
|
|
|
|
|
matInst.descriptorSet->updateBuffer(3, primitiveIndicesBuffer);
|
|
|
|
|
matInst.descriptorSet->updateBuffer(4, vertexIndicesBuffer);
|
|
|
|
|
|
2023-11-10 19:18:09 +01:00
|
|
|
matInst.descriptorSet->writeChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-07 16:33:32 +02:00
|
|
|
void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet> loadedMeshlets)
|
2023-10-31 16:16:23 +01:00
|
|
|
{
|
2024-05-01 14:10:52 +02:00
|
|
|
std::unique_lock l(vertexDataLock);
|
2023-11-22 13:18:54 +01:00
|
|
|
meshlets.reserve(meshlets.size() + loadedMeshlets.size());
|
|
|
|
|
vertexIndices.reserve(vertexIndices.size() + loadedMeshlets.size() * Gfx::numVerticesPerMeshlet);
|
2023-11-26 11:27:39 +01:00
|
|
|
primitiveIndices.reserve(primitiveIndices.size() + loadedMeshlets.size() * Gfx::numPrimitivesPerMeshlet * 3);
|
2023-10-31 17:55:30 +01:00
|
|
|
uint32 currentMesh = 0;
|
|
|
|
|
while (currentMesh < loadedMeshlets.size())
|
2023-10-31 16:16:23 +01:00
|
|
|
{
|
2023-10-31 17:55:30 +01:00
|
|
|
uint32 numMeshlets = std::min<uint32>(512, loadedMeshlets.size() - currentMesh);
|
|
|
|
|
uint32 meshletOffset = meshlets.size();
|
2023-12-28 21:42:18 +01:00
|
|
|
AABB meshAABB;
|
2023-10-31 16:16:23 +01:00
|
|
|
for (uint32 i = 0; i < numMeshlets; ++i)
|
|
|
|
|
{
|
2023-10-31 17:55:30 +01:00
|
|
|
Meshlet& m = loadedMeshlets[currentMesh + i];
|
2023-12-28 21:42:18 +01:00
|
|
|
meshAABB = meshAABB.combine(m.boundingBox);
|
2023-10-31 17:55:30 +01:00
|
|
|
uint32 vertexOffset = vertexIndices.size();
|
|
|
|
|
vertexIndices.resize(vertexOffset + m.numVertices);
|
2023-11-27 22:50:37 +01:00
|
|
|
std::memcpy(vertexIndices.data() + vertexOffset, m.uniqueVertices, m.numVertices * sizeof(uint32));
|
2023-10-31 17:55:30 +01:00
|
|
|
uint32 primitiveOffset = primitiveIndices.size();
|
|
|
|
|
primitiveIndices.resize(primitiveOffset + (m.numPrimitives * 3));
|
2024-04-24 23:25:34 +02:00
|
|
|
std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout, m.numPrimitives * 3 * sizeof(uint8));
|
2023-10-31 17:55:30 +01:00
|
|
|
meshlets.add(MeshletDescription{
|
2024-05-05 08:31:40 +02:00
|
|
|
.bounding = m.boundingBox,//.toSphere(),
|
2023-10-31 16:16:23 +01:00
|
|
|
.vertexCount = m.numVertices,
|
|
|
|
|
.primitiveCount = m.numPrimitives,
|
2023-10-31 17:55:30 +01:00
|
|
|
.vertexOffset = vertexOffset,
|
|
|
|
|
.primitiveOffset = primitiveOffset,
|
2023-12-23 18:26:54 +01:00
|
|
|
.color = Vector((float)rand() / RAND_MAX,(float)rand() / RAND_MAX,(float)rand() / RAND_MAX),
|
2023-10-31 16:16:23 +01:00
|
|
|
});
|
|
|
|
|
}
|
2023-10-31 17:55:30 +01:00
|
|
|
meshData[id].add(MeshData{
|
2024-05-05 08:31:40 +02:00
|
|
|
.bounding = meshAABB,//.toSphere(),
|
2023-12-14 09:04:23 +01:00
|
|
|
.numMeshlets = numMeshlets,
|
2023-10-31 17:55:30 +01:00
|
|
|
.meshletOffset = meshletOffset,
|
2023-12-14 09:04:23 +01:00
|
|
|
.indicesOffset = (uint32)meshOffsets[id],
|
2023-11-10 19:18:09 +01:00
|
|
|
});
|
2023-10-31 17:55:30 +01:00
|
|
|
currentMesh += numMeshlets;
|
2023-10-31 16:16:23 +01:00
|
|
|
}
|
2023-11-26 11:27:39 +01:00
|
|
|
meshData[id][0].firstIndex = indices.size();
|
|
|
|
|
meshData[id][0].numIndices = loadedIndices.size();
|
2024-05-04 09:25:13 +02:00
|
|
|
if (!graphics->supportMeshShading())
|
|
|
|
|
{
|
|
|
|
|
indices.resize(indices.size() + loadedIndices.size());
|
|
|
|
|
std::memcpy(indices.data() + meshData[id][0].firstIndex, loadedIndices.data(), loadedIndices.size() * sizeof(uint32));
|
|
|
|
|
indexBuffer = graphics->createIndexBuffer(IndexBufferCreateInfo{
|
|
|
|
|
.sourceData = {
|
|
|
|
|
.size = sizeof(uint32) * indices.size(),
|
|
|
|
|
.data = (uint8*)indices.data(),
|
|
|
|
|
},
|
|
|
|
|
.indexType = Gfx::SE_INDEX_TYPE_UINT32,
|
|
|
|
|
.name = "IndexBuffer",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
2023-11-10 19:18:09 +01:00
|
|
|
meshletBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
2023-11-01 23:12:30 +01:00
|
|
|
.sourceData = {
|
2023-10-31 23:44:46 +01:00
|
|
|
.size = sizeof(MeshletDescription) * meshlets.size(),
|
|
|
|
|
.data = (uint8*)meshlets.data()
|
|
|
|
|
},
|
2023-11-15 17:42:57 +01:00
|
|
|
.numElements = meshlets.size(),
|
2023-11-26 11:27:39 +01:00
|
|
|
.dynamic = false,
|
2024-04-20 21:35:43 +02:00
|
|
|
.name = "MeshletBuffer"
|
2023-11-15 17:42:57 +01:00
|
|
|
});
|
2023-11-10 19:18:09 +01:00
|
|
|
vertexIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
2023-11-01 23:12:30 +01:00
|
|
|
.sourceData = {
|
2024-04-07 16:33:32 +02:00
|
|
|
.size = sizeof(uint32) * vertexIndices.size(),
|
2023-10-31 23:44:46 +01:00
|
|
|
.data = (uint8*)vertexIndices.data(),
|
|
|
|
|
},
|
2023-11-15 17:42:57 +01:00
|
|
|
.numElements = vertexIndices.size(),
|
2023-11-26 11:27:39 +01:00
|
|
|
.dynamic = false,
|
2024-04-20 21:35:43 +02:00
|
|
|
.name = "VertexIndicesBuffer"
|
2023-11-15 17:42:57 +01:00
|
|
|
});
|
2023-11-10 19:18:09 +01:00
|
|
|
primitiveIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
2023-11-01 23:12:30 +01:00
|
|
|
.sourceData = {
|
2024-04-24 23:25:34 +02:00
|
|
|
.size = sizeof(uint8) * primitiveIndices.size(),
|
2023-10-31 23:44:46 +01:00
|
|
|
.data = (uint8*)primitiveIndices.data(),
|
|
|
|
|
},
|
2023-11-15 17:42:57 +01:00
|
|
|
.numElements = primitiveIndices.size(),
|
2023-11-26 11:27:39 +01:00
|
|
|
.dynamic = false,
|
2024-04-20 21:35:43 +02:00
|
|
|
.name = "PrimitiveIndicesBuffer",
|
2023-11-15 17:42:57 +01:00
|
|
|
});
|
2023-10-24 15:01:09 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-31 17:55:30 +01:00
|
|
|
MeshId VertexData::allocateVertexData(uint64 numVertices)
|
|
|
|
|
{
|
2024-05-01 14:10:52 +02:00
|
|
|
std::unique_lock l(vertexDataLock);
|
2023-10-31 17:55:30 +01:00
|
|
|
MeshId res{ idCounter++ };
|
|
|
|
|
meshOffsets[res] = head;
|
2023-11-09 22:15:51 +01:00
|
|
|
meshVertexCounts[res] = numVertices;
|
2023-10-31 17:55:30 +01:00
|
|
|
head += numVertices;
|
|
|
|
|
if (head > verticesAllocated)
|
|
|
|
|
{
|
2023-11-30 11:51:53 +01:00
|
|
|
verticesAllocated = std::max(head, verticesAllocated + NUM_DEFAULT_ELEMENTS);
|
2023-10-31 17:55:30 +01:00
|
|
|
resizeBuffers();
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-09 22:15:51 +01:00
|
|
|
uint64 VertexData::getMeshOffset(MeshId id)
|
2023-11-06 22:24:40 +01:00
|
|
|
{
|
|
|
|
|
return meshOffsets[id];
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-09 22:15:51 +01:00
|
|
|
uint64 VertexData::getMeshVertexCount(MeshId id)
|
|
|
|
|
{
|
|
|
|
|
return meshVertexCounts[id];
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-24 15:01:09 +02:00
|
|
|
List<VertexData*> vertexDataList;
|
|
|
|
|
|
|
|
|
|
List<VertexData*> VertexData::getList()
|
|
|
|
|
{
|
|
|
|
|
return vertexDataList;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-01 13:38:49 +01:00
|
|
|
VertexData* Seele::VertexData::findByTypeName(std::string name)
|
|
|
|
|
{
|
|
|
|
|
for (auto vd : vertexDataList)
|
|
|
|
|
{
|
|
|
|
|
if (vd->getTypeName() == name)
|
|
|
|
|
{
|
|
|
|
|
return vd;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-10 22:27:59 +01:00
|
|
|
void Seele::VertexData::init(Gfx::PGraphics _graphics)
|
2023-10-24 15:01:09 +02:00
|
|
|
{
|
2023-12-10 22:27:59 +01:00
|
|
|
graphics = _graphics;
|
2023-10-31 17:55:30 +01:00
|
|
|
verticesAllocated = NUM_DEFAULT_ELEMENTS;
|
2024-04-19 18:23:36 +02:00
|
|
|
instanceDataLayout = graphics->createDescriptorLayout("pScene");
|
2024-05-04 09:25:13 +02:00
|
|
|
instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,});
|
2023-11-26 09:40:48 +01:00
|
|
|
|
|
|
|
|
// meshData
|
2024-04-19 22:44:00 +02:00
|
|
|
instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,});
|
2023-11-26 09:40:48 +01:00
|
|
|
// meshletData
|
2024-04-24 23:25:34 +02:00
|
|
|
instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
|
2023-11-26 09:40:48 +01:00
|
|
|
// primitiveIndices
|
2024-04-24 23:25:34 +02:00
|
|
|
instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 3, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
|
2023-11-26 09:40:48 +01:00
|
|
|
// vetexIndices
|
2024-04-24 23:25:34 +02:00
|
|
|
instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
|
2023-11-26 09:40:48 +01:00
|
|
|
|
2023-10-24 15:01:09 +02:00
|
|
|
instanceDataLayout->create();
|
2023-10-31 17:55:30 +01:00
|
|
|
resizeBuffers();
|
2023-11-05 10:36:01 +01:00
|
|
|
graphics->getShaderCompiler()->registerVertexData(this);
|
2023-10-29 09:20:23 +01:00
|
|
|
}
|
2023-10-31 16:16:23 +01:00
|
|
|
|
2023-12-12 11:37:00 +01:00
|
|
|
void VertexData::destroy()
|
|
|
|
|
{
|
|
|
|
|
instanceDataLayout = nullptr;
|
|
|
|
|
meshletBuffer = nullptr;
|
|
|
|
|
vertexIndicesBuffer = nullptr;
|
|
|
|
|
primitiveIndicesBuffer = nullptr;
|
|
|
|
|
indexBuffer = nullptr;
|
|
|
|
|
meshData.clear();
|
|
|
|
|
materialData.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-31 16:16:23 +01:00
|
|
|
VertexData::VertexData()
|
|
|
|
|
: idCounter(0)
|
2023-11-05 10:36:01 +01:00
|
|
|
, head(0)
|
|
|
|
|
, verticesAllocated(0)
|
2023-11-06 14:47:21 +01:00
|
|
|
, dirty(false)
|
2023-10-31 16:16:23 +01:00
|
|
|
{
|
|
|
|
|
}
|