2025-04-27 22:16:56 +02:00
|
|
|
module;
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <iostream>
|
2025-05-04 05:15:31 +02:00
|
|
|
#include <cmath>
|
2025-04-27 22:16:56 +02:00
|
|
|
|
|
|
|
|
export module Crafter.Graphics:MeshShader;
|
|
|
|
|
import Crafter.Component;
|
|
|
|
|
import :Mesh;
|
|
|
|
|
import :Camera;
|
2025-04-27 23:20:52 +02:00
|
|
|
import :VulkanPipeline;
|
2025-04-27 22:16:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Crafter {
|
|
|
|
|
export template <typename VertexType>
|
|
|
|
|
class MeshShader {
|
|
|
|
|
public:
|
2025-05-04 05:15:31 +02:00
|
|
|
//glm::mat4 transform;
|
2025-04-27 22:16:56 +02:00
|
|
|
ComponentRefOwning<Mesh<VertexType>> mesh;
|
|
|
|
|
ComponentRefOwning<Camera> camera;
|
2025-05-04 05:15:31 +02:00
|
|
|
Buffer<float> mvp;
|
2025-04-27 23:20:52 +02:00
|
|
|
std::uint32_t threadCount;
|
2025-05-03 06:51:33 +02:00
|
|
|
MeshShader(Mesh<VertexType>* mesh, Camera* camera) : threadCount(std::ceil(static_cast<double>(mesh->indexCount)/64/3)), mvp(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT), mesh(mesh), camera(camera) {
|
2025-04-27 22:16:56 +02:00
|
|
|
|
|
|
|
|
}
|
2025-04-27 23:20:52 +02:00
|
|
|
void WriteDescriptors(DescriptorSet& set) {
|
|
|
|
|
set.Write(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &mvp.descriptor);
|
|
|
|
|
set.Write(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, &mesh.component->verticies.descriptor);
|
|
|
|
|
set.Write(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2, &mesh.component->indicies.descriptor);
|
2025-04-27 22:16:56 +02:00
|
|
|
}
|
|
|
|
|
void Update() {
|
2025-05-04 05:15:31 +02:00
|
|
|
//mvp.value[0] = camera.component->projectionView*transform;
|
2025-04-27 22:16:56 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|