Crafter.Graphics/examples/VulkanTriangle/main.cpp

50 lines
1.6 KiB
C++
Raw Normal View History

2025-06-13 23:59:36 +02:00
#include <vulkan/vulkan.h>
import Crafter.Graphics;
using namespace Crafter;
2026-01-28 01:06:48 +01:00
import std;
2025-06-13 23:59:36 +02:00
2026-01-28 23:37:12 +01:00
typedef VulkanShader<"raygen.spv", "main", VK_SHADER_STAGE_RAYGEN_BIT_KHR, 2, {{{VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 0}, {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1}}}> Raygenspv;
2025-06-13 23:59:36 +02:00
int main() {
2026-01-28 23:37:12 +01:00
2025-06-13 23:59:36 +02:00
/*
2026-01-28 01:06:48 +01:00
This sets up all necessary things and creates the vulkan device.
This must be called before any vulkan related things.
Things like VkDevice are static members of the VulkanDevice class.
2025-06-13 23:59:36 +02:00
*/
2026-01-28 01:06:48 +01:00
VulkanDevice::CreateDevice();
2026-01-28 23:37:12 +01:00
Raygenspv::CreateShader();
2026-01-29 00:45:02 +01:00
DescriptorLayoutVulkan<Raygenspv>::Init();
PipelineRTVulkan<Raygenspv, Raygenspv>::Init();
2026-01-28 23:45:33 +01:00
DescriptorPool<1, Raygenspv> pool;
pool.setsCount = 1;
pool.BuildPool(0);
2026-01-28 01:06:48 +01:00
WindowVulkan window(1280, 720, "HelloVulkan");
2025-06-13 23:59:36 +02:00
/*
2026-01-28 01:06:48 +01:00
StartInit gives you a VkCommandBuffer to use before the event loop starts
Use this for inititializing things like textures.
2025-06-13 23:59:36 +02:00
*/
2026-01-28 01:06:48 +01:00
VkCommandBuffer cmd = window.StartInit();
2025-06-13 23:59:36 +02:00
2026-01-28 18:51:11 +01:00
Mesh triangleMesh;
2026-01-28 01:06:48 +01:00
std::array<Vertex, 3> verts {{{-0.1, 0, 0}, {0, 0.1, 0}, {0.1, 0, 0}}};
std::array<std::uint32_t, 3> index {{0,1,2}};
2026-01-28 18:51:11 +01:00
triangleMesh.Build(verts, index, cmd);
2026-01-28 19:16:28 +01:00
RenderingElement3DVulkan::elements.emplace_back(triangleMesh);
RenderingElement3DVulkan::BuildTLAS(cmd);
2025-06-13 23:59:36 +02:00
/*
2026-01-28 01:06:48 +01:00
FinishInit executes all commands recorded to StartInit.
This must be called before the the event loops starts if you called StartInit before.
2025-06-13 23:59:36 +02:00
*/
2026-01-28 01:06:48 +01:00
window.FinishInit();
2025-06-13 23:59:36 +02:00
2026-01-29 01:31:17 +01:00
window.SetPipelineRT<Raygenspv, Raygenspv>();
window.descriptorsRt = pool.sets;
2026-01-28 01:06:48 +01:00
window.Render();
2025-06-13 23:59:36 +02:00
window.StartSync();
}