This commit is contained in:
Jorijn van der Graaf 2025-06-14 01:45:33 +02:00
commit 53df70b4f1
70 changed files with 108 additions and 11285 deletions

View file

@ -38,10 +38,20 @@ namespace Crafter {
std::uint32_t indexCount;
Buffer<VertexType> verticies;
Buffer<std::uint32_t> indicies;
/**
* @brief Constructs Mesh with empty vertex and index buffer.
* @param vertexCount count of the vertex buffer
* @param vertexCount count of the index buffer
*/
Mesh(std::uint32_t vertexCount, std::uint32_t indexCount) : vertexCount(vertexCount), indexCount(indexCount), verticies(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, vertexCount), indicies(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, indexCount) {
}
/**
* @brief Constructs Mesh from an in memory char buffer
* @param asset pointer to the char buffer
*/
Mesh(const char* asset) requires(std::same_as<VertexType, Vertex>) : vertexCount(reinterpret_cast<const std::uint32_t*>(asset)[0]), indexCount(((reinterpret_cast<const std::uint32_t*>(asset)[1]) + 63) & ~63), verticies(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, vertexCount), indicies(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, indexCount) {
uint32_t indexCountNoPadding = reinterpret_cast<const std::uint32_t*>(asset)[1];
const float* verticies = reinterpret_cast<const float*>(asset+sizeof(std::uint32_t)*2);
@ -62,6 +72,10 @@ namespace Crafter {
}
/**
* @brief Constructs UV Mesh from an in memory char buffer
* @param asset pointer to the char buffer
*/
Mesh(const char* asset) requires(std::same_as<VertexType, VertexUV>) : vertexCount(reinterpret_cast<const std::uint32_t*>(asset)[0]), indexCount(((reinterpret_cast<const std::uint32_t*>(asset)[1]) + 63) & ~63), verticies(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, vertexCount), indicies(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, indexCount) {
uint32_t indexCountNoPadding = reinterpret_cast<const std::uint32_t*>(asset)[1];
const float* verticies = reinterpret_cast<const float*>(asset+sizeof(std::uint32_t)*2);
@ -81,8 +95,13 @@ namespace Crafter {
}
}
/**
* @brief Constructs heightmap Mesh from an in memory char buffer
* @param heights pointer to heights
* @param sizeX size in the X dimension
* @param sizeZ size in the Y dimension
* @param spacing spacing between the points
*/
Mesh(float* heights, uint32_t sizeX, uint32_t sizeZ, float spacing) : vertexCount(sizeX*sizeZ), indexCount(((((sizeX-1)*(sizeZ-1))*6)+ 63) & ~63), verticies(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, vertexCount), indicies(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, indexCount) {
uint32_t indexCountNoPadding = ((sizeX-1)*(sizeZ-1))*6;
for (float x = 0; x < sizeX; x++)