From 154a81721ddbddbd02f760f5c18177758169c86a Mon Sep 17 00:00:00 2001 From: Mars Date: Tue, 15 Oct 2024 19:49:39 -0400 Subject: [PATCH] blegh --- _sources/generated.nix | 6 +---- flake.lock | 6 ++--- flake.nix | 8 ++++++- meson.build | 1 + src/main.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 9 deletions(-) diff --git a/_sources/generated.nix b/_sources/generated.nix index af0fe60..f71bde3 100644 --- a/_sources/generated.nix +++ b/_sources/generated.nix @@ -1,10 +1,6 @@ # This file was generated by nvfetcher, please do not modify it manually. +{ fetchgit, fetchurl, fetchFromGitHub, dockerTools }: { - fetchgit, - fetchurl, - fetchFromGitHub, - dockerTools, -}: { fmt = { pname = "fmt"; version = "11.0.2"; diff --git a/flake.lock b/flake.lock index 9ac47d5..957baf6 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1728698577, - "narHash": "sha256-hdbJjMr9myxGcByVlR9zAbQsWfZwl6NKzZodmyTzACc=", + "lastModified": 1729022018, + "narHash": "sha256-fsZYL4ggDUvVvIcnBk16dSsSsLlg3H4cMzs26FZuqCs=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "d4c28e77c38d73b23346656c102a94d90af3cf60", + "rev": "f490aba9999744d0ecb5e5594760a606de441ad6", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index b85de34..7661eb2 100644 --- a/flake.nix +++ b/flake.nix @@ -40,10 +40,16 @@ fmt = mkPkg "fmt"; + imgui = pkgs.imgui.override { + IMGUI_BUILD_GLFW_BINDING = true; + IMGUI_BUILD_VULKAN_BINDING = true; + }; + deps = with pkgs; [ fmt glfw glm + imgui shaderc vulkan-extension-layer vulkan-memory-allocator @@ -106,7 +112,7 @@ meson nil ninja - nvfetcher + #nvfetcher pkg-config unzip diff --git a/meson.build b/meson.build index 93263ef..1544847 100644 --- a/meson.build +++ b/meson.build @@ -29,6 +29,7 @@ deps = [ dependency('glfw3', include_type: 'system'), dependency('glm', include_type: 'system'), dependency('vulkan', include_type: 'system'), + cpp.find_library('imgui'), ] executable( diff --git a/src/main.cpp b/src/main.cpp index 53ba0a5..2e0d9bf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,6 +35,11 @@ VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE // Vertex class #include "util/vertex.h" +// ImGui +#include +#include +#include + // Use {} instead of () #define VKFW_NO_STRUCT_CONSTRUCTORS // GLFW C++ wrapper @@ -77,6 +82,12 @@ class VulkanApp { initVulkan(); // Render loop mainLoop(); + + cleanupSwapChain(); + + ImGui_ImplVulkan_Shutdown(); + ImGui_ImplGlfw_Shutdown(); + ImGui::DestroyContext(); } private: @@ -239,6 +250,39 @@ class VulkanApp { createDescriptorSets(); createCommandBuffers(); createSyncObjects(); + initImGui(); + } + + void initImGui() { + // Create ImGui context + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + + // Setup Dear ImGui style + ImGui::StyleColorsDark(); + + // Initialize ImGui for GLFW and Vulkan + ImGui_ImplGlfw_InitForVulkan(mWindow.get(), true); + + ImGui_ImplVulkan_InitInfo initInfo = {}; + initInfo.Instance = mInstance.get(); + initInfo.PhysicalDevice = mPhysicalDevice; + initInfo.Device = mDevice.get(); + initInfo.QueueFamily = findQueueFamilies(mPhysicalDevice).graphics_family.value(); + initInfo.Queue = mGraphicsQueue; + initInfo.PipelineCache = VK_NULL_HANDLE; + initInfo.DescriptorPool = mDescriptorPool.get(); + initInfo.RenderPass = mRenderPass.get(); + initInfo.MSAASamples = static_cast(mMsaaSamples); + initInfo.Allocator = nullptr; + initInfo.MinImageCount = MAX_FRAMES_IN_FLIGHT; + initInfo.ImageCount = static_cast(mSwapChainImages.size()); + initInfo.CheckVkResultFn = nullptr; + + ImGui_ImplVulkan_Init(&initInfo); + + // Upload Fonts + ImGui_ImplVulkan_CreateFontsTexture(); } // Main loop @@ -1565,6 +1609,16 @@ class VulkanApp { // Draw the indexed vertices commandBuffer.drawIndexed(static_cast(mIndices.size()), 1, 0, 0, 0); + ImGui_ImplVulkan_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); + + // Your ImGui code here + ImGui::ShowDemoWindow(); + + ImGui::Render(); + ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), commandBuffer); + // End the render pass commandBuffer.endRenderPass();