From 596f0c601f13708f6cb79e78952a5502a41c0c19 Mon Sep 17 00:00:00 2001 From: kidrigger Date: Sun, 2 Feb 2025 01:09:45 +0100 Subject: [PATCH] Prepped for NixOS with clang. --- .envrc | 1 + .gitignore | 3 ++- CMakePresets.json | 16 ++++++++++++ run.sh | 8 +++--- samples/00_util/gui.cpp | 42 +++++++++++++++--------------- samples/04_scenes/asset_loader.cpp | 8 +++--- shell.nix | 38 +++++++++++++++++++++++++++ 7 files changed, 86 insertions(+), 30 deletions(-) create mode 100644 .envrc create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..1d953f4 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use nix diff --git a/.gitignore b/.gitignore index 7d8fa21..f495c32 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea/ .cache/ build/ -.vs/ \ No newline at end of file +.vs/ +.direnv/ diff --git a/CMakePresets.json b/CMakePresets.json index 0c49649..9aa52eb 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -18,6 +18,22 @@ "rhs": "Linux" } }, + { + "name": "nixos", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": true, + "CMAKE_MAKE_PROGRAM": "ninja", + "CMAKE_C_COMPILER": "$env{CC}", + "CMAKE_CXX_COMPILER": "$env{CXX}" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + }, { "name": "windows-debug", "generator": "Ninja", diff --git a/run.sh b/run.sh index 0d12c13..2bcadf8 100755 --- a/run.sh +++ b/run.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash -if [ -d "out" ]; then - pushd ./build/ > /dev/null || exit +if [ -d "build" ]; then + pushd ./build/samples/04_scenes/ > /dev/null || exit if echo "$@" | grep -e "debug" -q then - lldb aster-exe + lldb ./scene_render else - ./aster-exe + ./scene_render fi popd > /dev/null || exit else diff --git a/samples/00_util/gui.cpp b/samples/00_util/gui.cpp index a04bb49..cbfedb4 100644 --- a/samples/00_util/gui.cpp +++ b/samples/00_util/gui.cpp @@ -58,7 +58,7 @@ Init(const Context *context, const Device *device, const Window *window, vk::For CreateContext(); ImGuiIO &io = GetIO(); (void)io; - io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; + // io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Viewports bad StyleColorsDark(); @@ -108,16 +108,16 @@ StartBuild() ImGui_ImplGlfw_NewFrame(); NewFrame(); - static ImGuiDockNodeFlags dockspaceFlags = ImGuiDockNodeFlags_None | ImGuiDockNodeFlags_PassthruCentralNode; + // static ImGuiDockNodeFlags dockspaceFlags = ImGuiDockNodeFlags_None | ImGuiDockNodeFlags_PassthruCentralNode; // We are using the ImGuiWindowFlags_NoDocking flag to make the parent window not dockable into, // because it would be confusing to have two docking targets within each others. - ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoDocking; + ImGuiWindowFlags windowFlags = ImGuiWindowFlags_None; // ImGuiWindowFlags_NoDocking; const ImGuiViewport *viewport = GetMainViewport(); SetNextWindowPos(viewport->WorkPos); SetNextWindowSize(viewport->WorkSize); - SetNextWindowViewport(viewport->ID); + // SetNextWindowViewport(viewport->ID); PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); windowFlags |= @@ -130,18 +130,18 @@ StartBuild() // all active windows docked into it will lose their parent and become undocked. // We cannot preserve the docking relationship between an active window and an inactive docking, otherwise // any change of dockspace/settings would lead to windows being stuck in limbo and never being visible. - PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); - Begin("DockSpace Demo", nullptr, windowFlags); - PopStyleVar(); + // PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); + // Begin("DockSpace Demo", nullptr, windowFlags); + // PopStyleVar(); - PopStyleVar(2); + // PopStyleVar(2); // DockSpace - if (GetIO().ConfigFlags & ImGuiConfigFlags_DockingEnable) - { - const ImGuiID dockspaceId = GetID("MyDockSpace"); - DockSpace(dockspaceId, ImVec2(0.0f, 0.0f), dockspaceFlags); - } + // if (GetIO().ConfigFlags & ImGuiConfigFlags_DockingEnable) + // { + // const ImGuiID dockspaceId = GetID("MyDockSpace"); + // DockSpace(dockspaceId, ImVec2(0.0f, 0.0f), dockspaceFlags); + // } } void @@ -151,13 +151,13 @@ EndBuild() Render(); EndFrame(); - if (GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) - { - GLFWwindow *backupCurrentContext = glfwGetCurrentContext(); - UpdatePlatformWindows(); - RenderPlatformWindowsDefault(); - glfwMakeContextCurrent(backupCurrentContext); - } + // if (GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + // { + // GLFWwindow *backupCurrentContext = glfwGetCurrentContext(); + // UpdatePlatformWindows(); + // RenderPlatformWindowsDefault(); + // glfwMakeContextCurrent(backupCurrentContext); + // } } void @@ -213,4 +213,4 @@ PopDisable() PopStyleVar(); PopItemFlag(); } -} // namespace ImGui \ No newline at end of file +} // namespace ImGui diff --git a/samples/04_scenes/asset_loader.cpp b/samples/04_scenes/asset_loader.cpp index df1a889..22b177f 100644 --- a/samples/04_scenes/asset_loader.cpp +++ b/samples/04_scenes/asset_loader.cpp @@ -753,8 +753,8 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector *vertexPosi entities->push_back(entity); m_Registry->emplace(entity, CMesh{ - .m_VertexPositionPtr = vertexOffset * sizeof vec4, - .m_VertexDataPtr = vertexOffset * sizeof VertexData, + .m_VertexPositionPtr = vertexOffset * sizeof(vec4), + .m_VertexDataPtr = vertexOffset * sizeof(VertexData), .m_FirstIndex = indexOffset, .m_IndexCount = indexCount, }); @@ -764,7 +764,7 @@ AssetLoader::ProcessNode(tinygltf::Model *model, eastl::vector *vertexPosi m_Registry->emplace>(entity, nodeRoot); if (prim.material >= 0) { - m_Registry->emplace(entity, sizeof Material * loadMaterial(prim.material)); + m_Registry->emplace(entity, sizeof(Material) * loadMaterial(prim.material)); m_Registry->emplace>(entity); } @@ -1080,4 +1080,4 @@ AssetLoader::operator=(AssetLoader &&other) noexcept m_TransferQueueIndex = other.m_TransferQueueIndex; m_GraphicsQueueIndex = other.m_GraphicsQueueIndex; return *this; -} \ No newline at end of file +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..e4aaedc --- /dev/null +++ b/shell.nix @@ -0,0 +1,38 @@ +{ pkgs ? import {} }: + +let eabase = pkgs.callPackage ../eabase-nix/eabase.nix {}; in +let eastl = pkgs.callPackage ../eastl-nix/eastl.nix { inherit eabase; }; in +let tinygltf = pkgs.callPackage ../tinygltf-nix/tinygltf.nix {}; in +let debugbreak = pkgs.callPackage ../scottt-debugbreak-nix/debugbreak.nix {}; in + +pkgs.clangStdenv.mkDerivation { + name = "aster-env"; + + nativeBuildInputs = with pkgs; [ + cmake + ninja + (imgui.override {IMGUI_BUILD_VULKAN_BINDING = true; IMGUI_BUILD_GLFW_BINDING=true; }) + ]; + + buildInputs = with pkgs; [ + glm + glfw3 + eastl + fmt + eabase + eastl + entt + tinygltf + debugbreak + stb + + # vulkan + vulkan-headers + vulkan-loader + vulkan-validation-layers + vulkan-memory-allocator + directx-shader-compiler + glslang + shaderc + ]; +}