core
This commit is contained in:
parent
ebacb9540c
commit
cfc9ca8349
10 changed files with 124 additions and 81 deletions
47
Crafter.Graphics-MeshShader.cppm
Normal file
47
Crafter.Graphics-MeshShader.cppm
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
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 :VulkanElement;
|
||||
|
||||
|
||||
namespace Crafter {
|
||||
export template <typename VertexType>
|
||||
class MeshShader {
|
||||
public:
|
||||
glm::mat4 transform;
|
||||
ComponentRefOwning<Mesh<VertexType>> mesh;
|
||||
ComponentRefOwning<Camera> camera;
|
||||
Buffer<glm::mat4> mvp;
|
||||
MeshShader(Mesh<VertexType>* mesh, Camera* camera) : mvp(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT), mesh(mesh), camera(camera) {
|
||||
|
||||
}
|
||||
void SetGroupSize(VulkanElement* element) {
|
||||
element->sizeX = (mesh.component->indexCount/3)/64;
|
||||
element->sizeY = 1;
|
||||
element->sizeZ = 1;
|
||||
}
|
||||
void WriteDescriptors(VulkanElement* element) {
|
||||
element->WriteDescriptor(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &mvp.descriptor);
|
||||
element->WriteDescriptor(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, &mesh.component->verticies.descriptor);
|
||||
element->WriteDescriptor(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2, &mesh.component->indicies.descriptor);
|
||||
}
|
||||
void Update() {
|
||||
mvp.value[0] = camera.component->projectionView*transform;
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue