Crafter.Graphics/main.cpp

63 lines
2.3 KiB
C++
Raw Normal View History

2025-04-16 00:43:33 +02:00
#include <iostream>
#include <exception>
2025-04-19 15:46:26 +02:00
#include <thread>
#include <vulkan/vulkan.h>
2025-04-27 22:16:56 +02:00
#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>
2025-04-16 00:43:33 +02:00
import Crafter.Graphics;
2025-04-27 22:16:56 +02:00
import Crafter.Asset;
2025-04-27 23:20:52 +02:00
import Crafter.Event;
2025-04-16 00:43:33 +02:00
using namespace Crafter;
2025-05-03 06:51:33 +02:00
typedef VulkanShader<"MeshShaderXYZUV.spirv", "main", VK_SHADER_STAGE_MESH_BIT_EXT, 3, {{{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2}}}> MeshVulkanShader;
typedef VulkanShader<"FragmentShaderTexture.spirv", "main", VK_SHADER_STAGE_FRAGMENT_BIT, 1, {{{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0}}}> FragmentShader;
2025-04-27 22:16:56 +02:00
typedef VulkanPipeline<MeshVulkanShader, FragmentShader> Pipeline;
2025-04-26 20:49:56 +02:00
2025-04-16 00:43:33 +02:00
int main() {
2025-04-19 15:46:26 +02:00
VulkanDevice::CreateDevice();
2025-04-27 22:16:56 +02:00
MeshVulkanShader::CreateShader();
2025-04-26 20:49:56 +02:00
FragmentShader::CreateShader();
Pipeline::CreatePipeline();
2025-04-27 01:57:25 +02:00
2025-04-27 22:16:56 +02:00
WindowWaylandVulkan window("Crafter.Graphics", 1280, 720);
2025-04-27 01:57:25 +02:00
2025-04-27 22:16:56 +02:00
Asset asset;
2025-05-04 05:15:31 +02:00
asset.LoadFull("cannon.cras");
2025-04-27 01:57:25 +02:00
2025-04-26 23:05:11 +02:00
Camera camera;
2025-05-04 05:15:31 +02:00
Mesh<VertexUV>* mesh = Mesh<VertexUV>::FromAssetUV(asset.entries[0].data.data());
2025-04-27 23:20:52 +02:00
DescriptorSet descriptors;
Pipeline::GetDescriptorSet(descriptors);
2025-04-27 22:16:56 +02:00
2025-05-04 05:15:31 +02:00
MeshShader<VertexUV> meshShader(mesh, &camera);
2025-04-27 23:20:52 +02:00
meshShader.WriteDescriptors(descriptors);
2025-04-27 22:16:56 +02:00
meshShader.transform = glm::mat4(1.0f);
meshShader.Update();
2025-04-27 01:57:25 +02:00
2025-05-03 06:51:33 +02:00
Asset asset2;
2025-05-04 05:15:31 +02:00
asset2.LoadFull("texture.cras");
2025-05-03 06:51:33 +02:00
VkCommandBuffer cmd = window.StartInit();
VulkanTexture<Pixel_RU8_GU8_BU8_AU8>* txt = VulkanTexture<Pixel_RU8_GU8_BU8_AU8>::FromAsset(asset2.entries[0].data.data(), cmd);
TextureShader texShader(txt);
texShader.WriteDescriptors(descriptors);
window.FinishInit();
2025-04-27 23:20:52 +02:00
EventListener<VkCommandBuffer> listener(&window.onDraw, [&descriptors, &meshShader](VkCommandBuffer cmd){
vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, Pipeline::pipelineLayout, 0, 2, &descriptors.set[0], 0, NULL);
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, Pipeline::pipeline);
VulkanDevice::vkCmdDrawMeshTasksEXTProc(cmd, meshShader.threadCount, 1, 1);
});
2025-04-16 00:43:33 +02:00
window.Start();
2025-04-19 15:46:26 +02:00
while(true) {
}
2025-04-16 00:43:33 +02:00
}