why cmake sucks ass

This commit is contained in:
Ben Kyd
2023-11-24 18:51:44 +00:00
parent 972a784071
commit f0b4cd4e84
6 changed files with 27 additions and 167 deletions

131
;:w
View File

@@ -1,131 +0,0 @@
#include "vkrenderer.hpp"
#include "device.hpp"
#include "graphics.hpp"
#include "pipeline.hpp"
#include "renderpass.hpp"
#include "swapchain.hpp"
#include "yolo/yolo.hpp"
namespace inferno::graphics {
VulkanRenderer* renderer_create(GraphicsDevice* device, SwapChain* swapchain)
{
auto renderer = new VulkanRenderer();
renderer->Device = device;
renderer->Swap = swapchain;
// Creating the synchronization objects
VkSemaphoreCreateInfo semaphoreInfo = {};
semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
VkFenceCreateInfo fenceInfo = {};
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; // Start in signaled state
if (vkCreateSemaphore(device->VulkanDevice, &semaphoreInfo, nullptr,
&renderer->ImageAvailableSemaphore)
!= VK_SUCCESS
|| vkCreateSemaphore(device->VulkanDevice, &semaphoreInfo, nullptr,
&renderer->RenderFinishedSemaphore)
!= VK_SUCCESS
|| vkCreateFence(
device->VulkanDevice, &fenceInfo, nullptr, &renderer->InFlightFence)
!= VK_SUCCESS) {
yolo::error("failed to create synchronization objects for a frame!");
}
return renderer;
}
void renderer_cleanup(VulkanRenderer* renderer)
{
vkDestroyCommandPool(
renderer->Device->VulkanDevice, renderer->CommandPool, nullptr);
vkDestroySemaphore(
renderer->Device->VulkanDevice, renderer->RenderFinishedSemaphore, nullptr);
vkDestroySemaphore(
renderer->Device->VulkanDevice, renderer->ImageAvailableSemaphore, nullptr);
vkDestroyFence(renderer->Device->VulkanDevice, renderer->InFlightFence, nullptr);
}
void renderer_configure_command_buffer(Renderer* renderer)
{
QueueFamilyIndices i = device_get_queue_families(
renderer->Device, renderer->Device->VulkanPhysicalDevice);
VkCommandPoolCreateInfo poolInfo {};
poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
poolInfo.queueFamilyIndex = i.graphicsFamily.value();
poolInfo.flags = 0; // Optional
if (vkCreateCommandPool(renderer->Device->VulkanDevice, &poolInfo, nullptr,
&renderer->CommandPool)
!= VK_SUCCESS) {
yolo::error("failed to create command pool!");
}
VkCommandBufferAllocateInfo allocInfo {};
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocInfo.commandPool = renderer->CommandPool;
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocInfo.commandBufferCount = 1;
if (vkAllocateCommandBuffers(
renderer->Device->VulkanDevice, &allocInfo, &renderer->CommandBuffer)
!= VK_SUCCESS) {
yolo::error("failed to allocate command buffers!");
}
yolo::debug("Command buffer created");
}
void renderer_begin_frame(VulkanRenderer* renderer, RenderPass* renderpass)
{
vkWaitForFences(
renderer->Device->VulkanDevice, 1, &renderer->InFlightFence, VK_TRUE, UINT64_MAX);
vkResetFences(renderer->Device->VulkanDevice, 1, &renderer->InFlightFence);
uint32_t imageIndex;
vkAcquireNextImageKHR(renderer->Device->VulkanDevice, renderer->Swap->Handle,
UINT64_MAX, renderer->ImageAvailableSemaphore, VK_NULL_HANDLE, &imageIndex);
vkResetCommandBuffer(renderer->CommandBuffer, 0);
VkCommandBufferBeginInfo beginInfo {};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
beginInfo.flags = 0; // Optional
beginInfo.pInheritanceInfo = nullptr; // Optional
if (vkBeginCommandBuffer(renderer->CommandBuffer, &beginInfo) != VK_SUCCESS) {
yolo::error("failed to begin recording command buffer!");
}
VkRenderPassBeginInfo renderPassInfo {};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
renderPassInfo.renderPass = renderpass->VulkanRenderPass;
renderPassInfo.framebuffer
= renderpass->RenderPipeline->Swap->SwapFramebuffers[imageIndex];
renderPassInfo.renderArea.offset = { 0, 0 };
renderPassInfo.renderArea.extent = renderpass->RenderPipeline->Swap->Extent;
VkClearValue clearColor = { { { 0.0f, 0.3f, 0.3f, 1.0f } } };
renderPassInfo.clearValueCount = 1;
renderPassInfo.pClearValues = &clearColor;
vkCmdBeginRenderPass(
renderer->CommandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
}
void renderer_draw_frame(Renderer* renderer, RenderPass* renderpass)
{
vkCmdEndRenderPass(renderer->CommandBuffer);
if (vkEndCommandBuffer(renderer->CommandBuffer) != VK_SUCCESS) {
yolo::error("failed to record command buffer!");
}
}
}

View File

@@ -56,24 +56,13 @@ add_custom_target(
add_dependencies(inferno shaders)
# Copy resources
file(GLOB_RECURSE RES "res/*")
foreach(RESOURCE ${RES})
# get_filename_component(FILENAME ${RESOURCE} NAME)
file(RELATIVE_PATH FILENAME ${CMAKE_CURRENT_SOURCE_DIR}/res ${RESOURCE})
add_custom_command(
TARGET inferno POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${RESOURCE} ${CMAKE_CURRENT_BINARY_DIR}/res/${FILENAME}
DEPENDS ${RESOURCE}
)
endforeach(RESOURCE)
add_custom_target(
resources
DEPENDS ${RES}
#invole install_res.sh on compile with make
add_custom_command(TARGET shaders POST_BUILD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/install_res.sh
COMMENT "Copying resources"
)
add_dependencies(inferno resources)
# "Universal" libraries
set(THREADS_PREFER_PTHREAD_FLAD ON)
find_package(Threads REQUIRED)

0
a.out
View File

1
install_res.sh Normal file
View File

@@ -0,0 +1 @@
rsync -a --progress res/ build/res/

Binary file not shown.

View File

@@ -6,6 +6,7 @@
#include <graphics.hpp>
#include <version.hpp>
#include "imgui/imgui_impl_glfw.h"
#include "yolo/yolo.hpp"
#include <map>
@@ -44,7 +45,7 @@ void setupWindow(std::string title)
Window = glfwCreateWindow(Width, Height, title.c_str(), nullptr, nullptr);
}
void setupImGui()
void setupImGui(GraphicsDevice* device)
{
// // 1: create descriptor pool for IMGUI
// // the size of the pool is very oversize, but it's copied from imgui demo itself.
@@ -70,37 +71,37 @@ void setupImGui()
// pool_info.pPoolSizes = pool_sizes;
//
// VkDescriptorPool imguiPool;
// VK_CHECK(vkCreateDescriptorPool(_device, &pool_info, nullptr, &imguiPool));
// // 2: initialize imgui library
//
// // this initializes the core structures of imgui
// vkCreateDescriptorPool(device->VulkanDevice, &pool_info, nullptr, &imguiPool);
// 2: initialize imgui librar/* */y
// this initializes the core structures of imgui
// ImGui::CreateContext();
//
// // this initializes imgui for SDL
// ImGui_ImplSDL2_InitForVulkan(_window);
//
// // this initializes imgui for Vulkan
// this initializes imgui for SDL
// ImGui_ImplGlfw_InitForVulkan(Window, true);
// this initializes imgui for Vulkan
// ImGui_ImplVulkan_InitInfo init_info = {};
// init_info.Instance = _instance;
// init_info.PhysicalDevice = _chosenGPU;
// init_info.Device = _device;
// init_info.Queue = _graphicsQueue;
// init_info.Instance = device->VulkanInstance;
// init_info.PhysicalDevice = device->VulkanPhysicalDevice;
// init_info.Device = device->VulkanDevice;
// init_info.Queue = device->VulkanGraphicsQueue;
// init_info.DescriptorPool = imguiPool;
// init_info.MinImageCount = 3;
// init_info.ImageCount = 3;
// init_info.MSAASamples = VK_SAMPLE_COUNT_1_BIT;
//
// ImGui_ImplVulkan_Init(&init_info, _renderPass);
//
// ImGui_ImplVulkan_Init(&init_info, device->VulkanRenderPass);
// // execute a gpu command to upload imgui font textures
// immediate_submit([&](VkCommandBuffer cmd) {
// ImGui_ImplVulkan_CreateFontsTexture(cmd);
// });
//
// // clear font textures from cpu data
// clear font textures from cpu data
// ImGui_ImplVulkan_DestroyFontUploadObjects();
//
// // add the destroy the imgui created structures
// add the destroy the imgui created structures
// _mainDeletionQueue.push_function([=]() {
// vkDestroyDescriptorPool(_device, imguiPool, nullptr);
// ImGui_ImplVulkan_Shutdown();