/* 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 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(); Mesh* mesh = Mesh::FromAssetUV(asset.entries[0].data.data()); DescriptorSet descriptors; Pipeline::GetDescriptorSet(descriptors); MeshShader meshShader(mesh, &camera); meshShader.WriteDescriptors(descriptors); meshShader.Update(); Asset asset2; asset2.LoadFull("texture.cras"); VkCommandBuffer cmd = window.StartInit(); VulkanTexture* txt = VulkanTexture::FromAsset(asset2.entries[0].data.data(), cmd); TextureShader texShader(txt); texShader.WriteDescriptors(descriptors); 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); }); window.Start(); while(true) { } }