Crafter.Graphics/main.cpp

88 lines
3.7 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>
#include <vulkan/vulkan.h>
2025-05-07 23:49:31 +02:00
#include "VulkanInitializers.hpp"
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-05-03 06:51:33 +02:00
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;
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-04-27 22:16:56 +02:00
Asset asset;
2025-05-04 05:15:31 +02:00
asset.LoadFull("cannon.cras");
2025-04-27 01:57:25 +02:00
2025-05-05 05:14:47 +02:00
Camera camera(1.57079633, 16 / 9, 0.01, 512);
camera.Update();
2025-05-07 23:49:31 +02:00
VkCommandBuffer cmd = window.StartInit();
2025-05-08 01:13:59 +02:00
Mesh<VertexUV> mesh = Mesh<VertexUV>(asset.entries[0].data.data());
MeshShader<VertexUV> meshShader(&mesh, &camera);
2025-05-03 06:51:33 +02:00
Asset asset2;
2025-05-04 05:15:31 +02:00
asset2.LoadFull("texture.cras");
2025-05-03 06:51:33 +02:00
VulkanTexture<Pixel_RU8_GU8_BU8_AU8>* txt = VulkanTexture<Pixel_RU8_GU8_BU8_AU8>::FromAsset(asset2.entries[0].data.data(), cmd);
TextureShader texShader(txt);
2025-05-07 23:49:31 +02:00
DescriptorSet<MeshVulkanShader, FragmentShader> descriptors;
EventListener<void> 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]);
2025-05-08 01:13:59 +02:00
// MeshShader<VertexUV> meshShader2(&mesh, &camera);
// TextureShader texShader2(txt);
// DescriptorSet<MeshVulkanShader, FragmentShader> descriptors2;
// meshShader2.WriteDescriptors(&descriptors2.set[0]);
// texShader2.WriteDescriptors(&descriptors2.set[0]);
2025-05-07 23:49:31 +02:00
meshShader.Update();
2025-05-08 01:13:59 +02:00
//meshShader2.Update();
2025-05-03 06:51:33 +02:00
window.FinishInit();
2025-05-08 01:13:59 +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-05-07 23:49:31 +02:00
2025-05-08 01:13:59 +02:00
// 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);
2025-04-27 23:20:52 +02:00
});
2025-04-16 00:43:33 +02:00
window.Start();
2025-04-19 15:46:26 +02:00
while(true) {
}
2025-04-16 00:43:33 +02:00
}