Crafter.Graphics/implementations/main.cpp

68 lines
2.5 KiB
C++
Raw Normal View History

2025-05-07 19:21:51 +02:00
/*
Crafter®.Graphics
Copyright (C) 2025 Catcrafts®
Catcrafts.net
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
2025-04-16 00:43:33 +02:00
#include <iostream>
#include <exception>
2025-04-19 15:46:26 +02:00
#include <thread>
2025-05-24 00:52:06 +02:00
#include <cstdlib>
2025-04-19 15:46:26 +02:00
#include <vulkan/vulkan.h>
2025-06-13 23:59:36 +02:00
#include "../../lib/VulkanInitializers.hpp"
2025-05-24 00:52:06 +02:00
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-05-05 05:14:47 +02:00
import Crafter.Math;
2025-04-16 00:43:33 +02:00
using namespace Crafter;
2025-06-10 22:47:47 +02:00
typedef VulkanShader<"MeshShaderMixedVoxelGrid.spirv", "main", VK_SHADER_STAGE_MESH_BIT_EXT, 2, {{{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1}}}> MeshVulkanShader;
2025-06-13 23:59:36 +02:00
typedef VulkanShader<"FragmentShaderVertexColor.spirv", "main", VK_SHADER_STAGE_FRAGMENT_BIT, 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-05-25 23:04:56 +02:00
Camera camera(1.57079633, 1280.0f / 720.0f, 0.01, 512);
2025-06-10 22:47:47 +02:00
camera.view = MatrixRowMajor<float, 4, 4, 1>::Translation(0, 0, 10);
2025-05-05 05:14:47 +02:00
camera.Update();
2025-05-07 23:49:31 +02:00
VkCommandBuffer cmd = window.StartInit();
2025-05-25 23:04:56 +02:00
2025-05-07 23:49:31 +02:00
DescriptorSet<MeshVulkanShader, FragmentShader> descriptors;
2025-06-10 22:47:47 +02:00
VoxelShader<uint> meshShader(1, 4, 4, &camera);
for(uint32_t i = 0; i < 16; i++) {
meshShader.grid.value[i] = 1;
2025-05-25 23:04:56 +02:00
}
meshShader.WriteDescriptors(descriptors.set[0]);
2025-05-07 23:49:31 +02:00
meshShader.Update();
2025-05-03 06:51:33 +02:00
window.FinishInit();
2025-05-25 23:04:56 +02:00
EventListener<VkCommandBuffer> listener(&window.onDraw, [&descriptors, &meshShader](VkCommandBuffer cmd){
2025-04-27 23:20:52 +02:00
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-06-14 01:45:33 +02:00
window.StartSync();
2025-05-25 23:04:56 +02:00
}