68 lines
No EOL
2.5 KiB
C++
68 lines
No EOL
2.5 KiB
C++
/*
|
|
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 <iostream>
|
|
#include <exception>
|
|
#include <thread>
|
|
#include <cstdlib>
|
|
#include <vulkan/vulkan.h>
|
|
#include "../../lib/VulkanInitializers.hpp"
|
|
|
|
import Crafter.Graphics;
|
|
import Crafter.Asset;
|
|
import Crafter.Event;
|
|
import Crafter.Math;
|
|
using namespace Crafter;
|
|
|
|
typedef VulkanShader<"MeshShaderMixedVoxelGrid.spirv", "main", VK_SHADER_STAGE_MESH_BIT_EXT, 2, {{{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1}}}> MeshVulkanShader;
|
|
typedef VulkanShader<"FragmentShaderVertexColor.spirv", "main", VK_SHADER_STAGE_FRAGMENT_BIT, 0, {}> FragmentShader;
|
|
typedef VulkanPipeline<MeshVulkanShader, FragmentShader> Pipeline;
|
|
|
|
int main() {
|
|
VulkanDevice::CreateDevice();
|
|
MeshVulkanShader::CreateShader();
|
|
FragmentShader::CreateShader();
|
|
Pipeline::CreatePipeline();
|
|
|
|
WindowWaylandVulkan window("Crafter.Graphics", 1280, 720);
|
|
|
|
Camera camera(1.57079633, 1280.0f / 720.0f, 0.01, 512);
|
|
camera.view = MatrixRowMajor<float, 4, 4, 1>::Translation(0, 0, 10);
|
|
camera.Update();
|
|
VkCommandBuffer cmd = window.StartInit();
|
|
|
|
DescriptorSet<MeshVulkanShader, FragmentShader> descriptors;
|
|
VoxelShader<uint> meshShader(1, 4, 4, &camera);
|
|
for(uint32_t i = 0; i < 16; i++) {
|
|
meshShader.grid.value[i] = 1;
|
|
}
|
|
meshShader.WriteDescriptors(descriptors.set[0]);
|
|
meshShader.Update();
|
|
|
|
window.FinishInit();
|
|
|
|
EventListener<VkCommandBuffer> 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.StartSync();
|
|
} |