/* 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 */ #include #include #include #include #include "VulkanInitializers.hpp" import Crafter.Graphics; import Crafter.Asset; import Crafter.Event; import Crafter.Math; using namespace Crafter; 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; typedef VulkanPipeline Pipeline; int main() { VulkanDevice::CreateDevice(); MeshVulkanShader::CreateShader(); FragmentShader::CreateShader(); Pipeline::CreatePipeline(); WindowWaylandVulkan window("Crafter.Graphics", 1280, 720); Asset asset; asset.LoadFull("cannon.cras"); Camera camera(1.57079633, 16 / 9, 0.01, 512); camera.Update(); VkCommandBuffer cmd = window.StartInit(); Mesh mesh = Mesh(asset.entries[0].data.data()); MeshShader meshShader(&mesh, &camera); Asset asset2; asset2.LoadFull("texture.cras"); VulkanTexture* txt = VulkanTexture::FromAsset(asset2.entries[0].data.data(), cmd); TextureShader texShader(txt); DescriptorSet descriptors; EventListener bruhlistener(&descriptors.onDescriptorRefresh, [&meshShader, &texShader, &camera, &descriptors](){ meshShader.WriteDescriptors(&descriptors.set[0]); texShader.WriteDescriptors(&descriptors.set[0]); }); meshShader.WriteDescriptors(&descriptors.set[0]); texShader.WriteDescriptors(&descriptors.set[0]); // MeshShader meshShader2(&mesh, &camera); // TextureShader texShader2(txt); // DescriptorSet descriptors2; // meshShader2.WriteDescriptors(&descriptors2.set[0]); // texShader2.WriteDescriptors(&descriptors2.set[0]); meshShader.Update(); //meshShader2.Update(); window.FinishInit(); EventListener 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); // vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, Pipeline::pipelineLayout, 0, 2, &descriptors2.set[0], 0, NULL); // vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, Pipeline::pipeline); // VulkanDevice::vkCmdDrawMeshTasksEXTProc(cmd, meshShader2.threadCount, 1, 1); }); window.Start(); while(true) { } }