2023-08-28 21:23:13 +02:00
|
|
|
#pragma once
|
2023-11-06 22:24:40 +01:00
|
|
|
#include "Graphics/Initializer.h"
|
2023-10-24 15:01:09 +02:00
|
|
|
#include "Material/MaterialInstance.h"
|
|
|
|
|
#include "Component/Transform.h"
|
2023-10-26 18:37:29 +02:00
|
|
|
#include "Containers/List.h"
|
2023-11-15 17:42:57 +01:00
|
|
|
#include "Graphics/Command.h"
|
2023-10-26 18:37:29 +02:00
|
|
|
#include "Graphics/Descriptor.h"
|
|
|
|
|
#include "Graphics/Buffer.h"
|
2023-12-23 18:26:54 +01:00
|
|
|
#include "Meshlet.h"
|
2023-08-28 21:23:13 +02:00
|
|
|
|
2024-05-06 18:36:16 +02:00
|
|
|
constexpr uint64 MAX_TEXCOORDS = 8;
|
|
|
|
|
|
2023-08-28 21:23:13 +02:00
|
|
|
namespace Seele
|
|
|
|
|
{
|
2023-11-06 14:47:21 +01:00
|
|
|
DECLARE_REF(Mesh)
|
2023-10-24 15:01:09 +02:00
|
|
|
struct MeshId
|
|
|
|
|
{
|
|
|
|
|
uint64 id;
|
2023-10-31 16:16:23 +01:00
|
|
|
std::strong_ordering operator<=>(const MeshId& other) const
|
|
|
|
|
{
|
|
|
|
|
return id <=> other.id;
|
|
|
|
|
}
|
2023-11-22 13:18:54 +01:00
|
|
|
bool operator==(const MeshId& other) const
|
|
|
|
|
{
|
|
|
|
|
return id == other.id;
|
|
|
|
|
}
|
2023-10-31 16:16:23 +01:00
|
|
|
};
|
2023-08-28 21:23:13 +02:00
|
|
|
class VertexData
|
|
|
|
|
{
|
|
|
|
|
public:
|
2023-10-24 15:01:09 +02:00
|
|
|
struct InstanceData
|
|
|
|
|
{
|
|
|
|
|
Matrix4 transformMatrix;
|
2024-05-04 09:25:13 +02:00
|
|
|
Matrix4 inverseTransformMatrix;
|
2023-10-24 15:01:09 +02:00
|
|
|
};
|
2023-11-26 11:27:39 +01:00
|
|
|
struct MeshData
|
|
|
|
|
{
|
2024-05-05 08:31:40 +02:00
|
|
|
AABB bounding;
|
2023-12-14 09:04:23 +01:00
|
|
|
uint32 numMeshlets = 0;
|
2023-11-26 11:27:39 +01:00
|
|
|
uint32 meshletOffset = 0;
|
|
|
|
|
uint32 firstIndex = 0;
|
|
|
|
|
uint32 numIndices = 0;
|
2023-12-14 09:04:23 +01:00
|
|
|
uint32 indicesOffset = 0;
|
|
|
|
|
uint32 pad0[3];
|
2023-11-26 11:27:39 +01:00
|
|
|
};
|
2023-10-24 15:01:09 +02:00
|
|
|
struct MaterialInstanceData
|
|
|
|
|
{
|
|
|
|
|
PMaterialInstance materialInstance;
|
2024-05-08 10:51:59 +02:00
|
|
|
uint32 descriptorOffset;
|
|
|
|
|
uint64 numMeshes;
|
|
|
|
|
MeshId meshId;
|
2023-10-24 15:01:09 +02:00
|
|
|
};
|
|
|
|
|
struct MaterialData
|
|
|
|
|
{
|
|
|
|
|
PMaterial material;
|
|
|
|
|
Map<uint64, MaterialInstanceData> instances;
|
|
|
|
|
};
|
|
|
|
|
void resetMeshData();
|
2023-11-26 09:40:48 +01:00
|
|
|
void updateMesh(PMesh mesh, Component::Transform& transform);
|
2023-10-24 15:01:09 +02:00
|
|
|
void createDescriptors();
|
2024-04-07 16:33:32 +02:00
|
|
|
void loadMesh(MeshId id, Array<uint32> indices, Array<Meshlet> meshlets);
|
2023-10-31 17:55:30 +01:00
|
|
|
MeshId allocateVertexData(uint64 numVertices);
|
2023-11-09 22:15:51 +01:00
|
|
|
uint64 getMeshOffset(MeshId id);
|
|
|
|
|
uint64 getMeshVertexCount(MeshId id);
|
2023-11-01 13:38:49 +01:00
|
|
|
virtual void serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) = 0;
|
|
|
|
|
virtual void deserializeMesh(MeshId id, ArchiveBuffer& buffer) = 0;
|
2023-10-24 15:01:09 +02:00
|
|
|
virtual void bindBuffers(Gfx::PRenderCommand command) = 0;
|
|
|
|
|
virtual Gfx::PDescriptorLayout getVertexDataLayout() = 0;
|
|
|
|
|
virtual Gfx::PDescriptorSet getVertexDataSet() = 0;
|
|
|
|
|
virtual std::string getTypeName() const = 0;
|
2023-11-26 11:27:39 +01:00
|
|
|
Gfx::PIndexBuffer getIndexBuffer() { return indexBuffer; }
|
2023-10-31 17:55:30 +01:00
|
|
|
Gfx::PDescriptorLayout getInstanceDataLayout() { return instanceDataLayout; }
|
2024-05-08 10:51:59 +02:00
|
|
|
Gfx::PDescriptorSet getInstanceDataSet() { return descriptorSet; }
|
2023-10-24 15:01:09 +02:00
|
|
|
const Map<std::string, MaterialData>& getMaterialData() const { return materialData; }
|
|
|
|
|
const Array<MeshData>& getMeshData(MeshId id) { return meshData[id]; }
|
|
|
|
|
static List<VertexData*> getList();
|
2023-11-01 13:38:49 +01:00
|
|
|
static VertexData* findByTypeName(std::string name);
|
2023-10-31 16:16:23 +01:00
|
|
|
virtual void init(Gfx::PGraphics graphics);
|
2023-12-12 11:37:00 +01:00
|
|
|
virtual void destroy();
|
2023-10-24 15:01:09 +02:00
|
|
|
protected:
|
2023-10-31 17:55:30 +01:00
|
|
|
virtual void resizeBuffers() = 0;
|
2023-10-31 16:16:23 +01:00
|
|
|
virtual void updateBuffers() = 0;
|
|
|
|
|
VertexData();
|
|
|
|
|
struct MeshletDescription
|
2023-10-24 15:01:09 +02:00
|
|
|
{
|
2024-05-05 08:31:40 +02:00
|
|
|
AABB bounding;
|
2024-05-08 10:51:59 +02:00
|
|
|
uint32 vertexCount;
|
|
|
|
|
uint32 primitiveCount;
|
|
|
|
|
uint32 vertexOffset;
|
|
|
|
|
uint32 primitiveOffset;
|
2023-12-23 18:26:54 +01:00
|
|
|
Vector color;
|
|
|
|
|
float pad;
|
2023-10-24 15:01:09 +02:00
|
|
|
};
|
2023-12-17 16:16:46 +01:00
|
|
|
std::mutex materialDataLock;
|
2023-10-24 15:01:09 +02:00
|
|
|
Map<std::string, MaterialData> materialData;
|
2024-05-01 14:10:52 +02:00
|
|
|
std::mutex vertexDataLock;
|
2023-10-24 15:01:09 +02:00
|
|
|
Map<MeshId, Array<MeshData>> meshData;
|
2023-11-01 13:38:49 +01:00
|
|
|
Map<MeshId, uint64> meshOffsets;
|
2023-11-09 22:15:51 +01:00
|
|
|
Map<MeshId, uint64> meshVertexCounts;
|
2023-10-31 16:16:23 +01:00
|
|
|
Array<MeshletDescription> meshlets;
|
2024-04-24 23:25:34 +02:00
|
|
|
Array<uint8> primitiveIndices;
|
2024-04-07 16:33:32 +02:00
|
|
|
Array<uint32> vertexIndices;
|
|
|
|
|
Array<uint32> indices;
|
2023-11-05 10:36:01 +01:00
|
|
|
Gfx::PGraphics graphics;
|
2023-11-01 23:12:30 +01:00
|
|
|
Gfx::ODescriptorLayout instanceDataLayout;
|
2023-10-24 15:01:09 +02:00
|
|
|
// for mesh shading
|
2023-11-01 23:12:30 +01:00
|
|
|
Gfx::OShaderBuffer meshletBuffer;
|
|
|
|
|
Gfx::OShaderBuffer vertexIndicesBuffer;
|
|
|
|
|
Gfx::OShaderBuffer primitiveIndicesBuffer;
|
2023-10-24 15:01:09 +02:00
|
|
|
// for legacy pipeline
|
2023-11-01 23:12:30 +01:00
|
|
|
Gfx::OIndexBuffer indexBuffer;
|
2024-05-08 10:51:59 +02:00
|
|
|
// Material data
|
|
|
|
|
Array<InstanceData> instanceData;
|
|
|
|
|
Gfx::OShaderBuffer instanceBuffer;
|
|
|
|
|
Array<MeshData> instanceMeshData;
|
|
|
|
|
Gfx::OShaderBuffer instanceMeshDataBuffer;
|
|
|
|
|
Gfx::PDescriptorSet descriptorSet;
|
2023-10-29 09:20:23 +01:00
|
|
|
uint64 idCounter;
|
2023-10-31 17:55:30 +01:00
|
|
|
uint64 head;
|
|
|
|
|
uint64 verticesAllocated;
|
2023-10-31 16:16:23 +01:00
|
|
|
bool dirty;
|
2023-08-28 21:23:13 +02:00
|
|
|
};
|
2023-10-29 09:20:23 +01:00
|
|
|
}
|