diff --git a/examples/VulkanTriangle/main.cpp b/examples/VulkanTriangle/main.cpp index 026e5a5..c57d968 100644 --- a/examples/VulkanTriangle/main.cpp +++ b/examples/VulkanTriangle/main.cpp @@ -1,82 +1,35 @@ #include -import Crafter.Event; import Crafter.Graphics; using namespace Crafter; - -/* - This typedefs a shader configuration we will use, this includes all necessary info to load in the shader from a file. -*/ -typedef VulkanShader< - "MeshShaderXYZ.spirv", //the filename of the shader - "main", //the name of the entrypoint symbol of the shader - VK_SHADER_STAGE_MESH_BIT_EXT, //the shader stage - 3, //how many descriptors this shader has - {{{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2}}}//an array of descriptor types and their binding slot, 1 unfiform for the mvp and 2 for vertex and index. -> MeshShaderSpirv; -typedef VulkanShader<"FragmentShaderSolidWhite.spirv", "main", VK_SHADER_STAGE_FRAGMENT_BIT, 0, {}> FragmentShader; - -/* - This typedefs the pipeline we will use, for each combination of mesh and fragment shader a new pipeline must be used, but this pipeline can be shared with each object using this combination. -*/ -typedef VulkanPipeline Pipeline; +import std; int main() { + /* + 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. + */ VulkanDevice::CreateDevice(); - WindowWaylandVulkan window("HelloWindow", 1280, 720); + WindowVulkan window(1280, 720, "HelloVulkan"); /* - Each shader and pipeline must be created before use. + StartInit gives you a VkCommandBuffer to use before the event loop starts + Use this for inititializing things like textures. */ - MeshShaderSpirv::CreateShader(); - FragmentShader::CreateShader(); - Pipeline::CreatePipeline(); + VkCommandBuffer cmd = window.StartInit(); + + Mesh triangle; + std::array verts {{{-0.1, 0, 0}, {0, 0.1, 0}, {0.1, 0, 0}}}; + std::array index {{0,1,2}}; + triangle.Build(verts, index, cmd); /* - Create a mesh typed on Vertex, which is a vertex type with only a position, it holds 3 vertexes and 3 indexes for our triangle. + FinishInit executes all commands recorded to StartInit. + This must be called before the the event loops starts if you called StartInit before. */ - Mesh triangle(3, 3); - triangle.verticies.value[0] = {0, -0.3, 0, 1}; - triangle.verticies.value[1] = {0.3, 0.3, 0, 1}; - triangle.verticies.value[2] = {-0.3, 0.3, 0, 1}; - - triangle.indicies.value[0] = 0; - triangle.indicies.value[1] = 1; - triangle.indicies.value[2] = 2; - - /* - Use the created traingle mesh in a meshShader to render it. - */ - MeshShader meshShader(&triangle); - - /* - Create a DescriptorSet to hold the descriptors of our meshShader, since our fragment shader doesn't use any. - We are writing to the 0 index in the set because the mesh shader is the first stage. - For fragment shaders write to the 1 index. - */ - DescriptorSet descriptors; - meshShader.WriteDescriptors(descriptors.set[0]); - - - /* - Create a listener on the window onDraw event that gets a command buffer, this event is called for each frame and where drawing happens. - */ - EventListener listener(&window.onDraw, [&descriptors, &meshShader](VkCommandBuffer cmd){ - /* - Bind the descriptor set we created earlier, CreatePipeline() creates Pipeline::pipelineLayout and Pipeline::pipeline. - */ - vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, Pipeline::pipelineLayout, 0, 2, &descriptors.set[0], 0, NULL); - - /* - Bind our pipeline, these can use static members because of the templating. - */ - vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, Pipeline::pipeline); - - /* - Launch our mesh shader with the required threads. - */ - VulkanDevice::vkCmdDrawMeshTasksEXTProc(cmd, meshShader.threadCount, 1, 1); - }); + window.FinishInit(); + window.Render(); window.StartSync(); } diff --git a/examples/VulkanTriangle/project.json b/examples/VulkanTriangle/project.json index 2a743e7..a4b0e06 100644 --- a/examples/VulkanTriangle/project.json +++ b/examples/VulkanTriangle/project.json @@ -2,19 +2,12 @@ "name": "crafter-graphics", "configurations": [ { - "name": "example", - "standard": "c++26", - "source_files": ["main"], - "module_files": [], - "build_dir": "build", - "output_dir": "bin", - "type":"executable", - "libs": [], - "flags": ["-Wno-uninitialized"], + "name": "executable", + "implementations": ["main"], "dependencies": [ { "path":"../../project.json", - "configuration":"lib-debug" + "configuration":"lib-vulkan" } ] }