43 lines
1.4 KiB
C++
43 lines
1.4 KiB
C++
module;
|
|
|
|
#include <cstdint>
|
|
#include <vulkan/vulkan.h>
|
|
#include <cstring>
|
|
#include <iostream>
|
|
#define GLM_FORCE_RADIANS
|
|
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
|
#define GLM_ENABLE_EXPERIMENTAL
|
|
#include <glm/glm.hpp>
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
#include <glm/gtc/matrix_inverse.hpp>
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
|
|
export module Crafter.Graphics:MeshShader;
|
|
import Crafter.Component;
|
|
import :Mesh;
|
|
import :Camera;
|
|
import :VulkanPipeline;
|
|
|
|
|
|
namespace Crafter {
|
|
export template <typename VertexType>
|
|
class MeshShader {
|
|
public:
|
|
glm::mat4 transform;
|
|
ComponentRefOwning<Mesh<VertexType>> mesh;
|
|
ComponentRefOwning<Camera> camera;
|
|
Buffer<glm::mat4> mvp;
|
|
std::uint32_t threadCount;
|
|
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) {
|
|
|
|
}
|
|
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);
|
|
}
|
|
void Update() {
|
|
mvp.value[0] = camera.component->projectionView*transform;
|
|
}
|
|
};
|
|
}
|