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..725e3e2 --- /dev/null +++ b/shell.nix @@ -0,0 +1,38 @@ +{ pkgs ? import {} }: + +let eabase = pkgs.callPackage ./vendored-nix/eabase {}; in +let eastl = pkgs.callPackage ./vendored-nix/eastl { inherit eabase; }; in +let tinygltf = pkgs.callPackage ./vendored-nix/tinygltf {}; in +let debugbreak = pkgs.callPackage ./vendored-nix/scottt-debugbreak {}; 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 + ]; +} diff --git a/vendored-nix/eabase/cmake_install_fix.patch b/vendored-nix/eabase/cmake_install_fix.patch new file mode 100644 index 0000000..8f201f7 --- /dev/null +++ b/vendored-nix/eabase/cmake_install_fix.patch @@ -0,0 +1,105 @@ +From 56d58f6863feafa1fccddbe1d828bad2aa9d62e3 Mon Sep 17 00:00:00 2001 +From: kidrigger +Date: Sat, 1 Feb 2025 23:20:58 +0100 +Subject: [PATCH] Fix Installation and add Config. + +--- + CMakeLists.txt | 61 ++++++++++++++++++++++++++++++++++--------- + EABaseConfig.cmake.in | 6 +++++ + 2 files changed, 55 insertions(+), 12 deletions(-) + create mode 100644 EABaseConfig.cmake.in + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 652f07f..933b113 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -4,6 +4,9 @@ + cmake_minimum_required(VERSION 3.1) + project(EABase CXX) + ++include(GNUInstallDirs) ++include(CMakePackageConfigHelpers) ++ + #------------------------------------------------------------------------------------------- + # Options + #------------------------------------------------------------------------------------------- +@@ -21,17 +24,51 @@ endif() + #------------------------------------------------------------------------------------------- + add_definitions(-D_CHAR16T) + +-#------------------------------------------------------------------------------------------- +-# Header only library +-#------------------------------------------------------------------------------------------- +-add_library(EABase INTERFACE) ++if (NOT EABASE_BUILD_TESTS) ++ #------------------------------------------------------------------------------------------- ++ # Header only library ++ #------------------------------------------------------------------------------------------- ++ add_library(EABase INTERFACE) ++ add_library(EABase::EABase ALIAS EABase) + +-#------------------------------------------------------------------------------------------- +-# Include dirs +-#------------------------------------------------------------------------------------------- +-target_include_directories(EABase INTERFACE include/Common) ++ #------------------------------------------------------------------------------------------- ++ # Include dirs ++ #------------------------------------------------------------------------------------------- ++ target_include_directories(EABase INTERFACE ++ $ ++ $ ++ ) + +-#------------------------------------------------------------------------------------------- +-# Installation +-#------------------------------------------------------------------------------------------- +-install(DIRECTORY include/Common/EABase DESTINATION include) ++ # create and install an export set for eabase target as EABase::EABase ++ set(EABase_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/EABase") ++ ++ configure_package_config_file( ++ EABaseConfig.cmake.in ++ ${CMAKE_CURRENT_BINARY_DIR}/EABaseConfig.cmake ++ INSTALL_DESTINATION ${EABase_CMAKE_CONFIG_DESTINATION} ++ ) ++ ++ # create and install an export set for Terra target as Terra ++ install( ++ TARGETS EABase EXPORT EABaseTargets ++ DESTINATION ${CMAKE_INSTALL_LIBDIR} ++ ) ++ ++ install(EXPORT EABaseTargets DESTINATION ${EABase_CMAKE_CONFIG_DESTINATION}) ++ ++ write_basic_package_version_file( ++ "${CMAKE_CURRENT_BINARY_DIR}/EABaseConfigVersion.cmake" ++ VERSION 2.09.12 ++ COMPATIBILITY SameMajorVersion ++ ) ++ ++ install(TARGETS EABase LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") ++ install(DIRECTORY "include/Common/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") ++ ++ install( ++ FILES ++ "${CMAKE_CURRENT_BINARY_DIR}/EABaseConfig.cmake" ++ "${CMAKE_CURRENT_BINARY_DIR}/EABaseConfigVersion.cmake" ++ DESTINATION ${EABase_CMAKE_CONFIG_DESTINATION} ++ ) ++endif() +diff --git a/EABaseConfig.cmake.in b/EABaseConfig.cmake.in +new file mode 100644 +index 0000000..afc9b10 +--- /dev/null ++++ b/EABaseConfig.cmake.in +@@ -0,0 +1,6 @@ ++@PACKAGE_INIT@ ++ ++# Provide path for scripts ++list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") ++ ++include(${CMAKE_CURRENT_LIST_DIR}/EABaseTargets.cmake) +\ No newline at end of file +-- +2.47.0 + diff --git a/vendored-nix/eabase/default.nix b/vendored-nix/eabase/default.nix new file mode 100644 index 0000000..f90ed5c --- /dev/null +++ b/vendored-nix/eabase/default.nix @@ -0,0 +1,32 @@ +{ stdenv, fetchFromGitHub, cmake }: +stdenv.mkDerivation { + pname = "eabase"; + version = "2.09.06"; + + nativeBuildInputs = [ + cmake + ]; + + src = fetchFromGitHub { + owner = "electronicarts"; + repo = "EABase"; + rev = "123363eb82e132c0181ac53e43226d8ee76dea12"; + sha256 = "sha256-tQcGoOeyptMf/KQGC+o9P6XiTfJhi0xjwB2M/3JtnW4="; + fetchSubmodules = false; + }; + + patches = [ ./cmake_install_fix.patch ]; + + # buildPhase = '' + # runHook preBuild + # cp ${cmakeConfigFile} $build/ + # runHook postBuild + # ''; + + # installPhase = '' + # runHook preInstall + # mkdir -p $out + # cmake --install . --prefix $out/ + # runHook postInstall + # ''; +} diff --git a/vendored-nix/eastl/default.nix b/vendored-nix/eastl/default.nix new file mode 100644 index 0000000..5b8d59f --- /dev/null +++ b/vendored-nix/eastl/default.nix @@ -0,0 +1,48 @@ +{ stdenv, fetchFromGitHub, cmake, ninja, eabase }: +let buildFolder = "out/"; in +stdenv.mkDerivation { + pname = "eastl"; + version = "3.21.23"; + + src = fetchFromGitHub { + owner = "electronicarts"; + repo = "EASTL"; + rev = "3.21.23"; + sha256 = "sha256-8imixecWN/FOHY/9IxkIMbkxK7NXZ0TecZ4/SvOqf14="; + }; + + nativeBuildInputs = [ + cmake + ninja + ]; + + patches = [ + ./fix-cmake-install.patch + ]; + + configurePhase = '' + runHook preConfigure + mkdir -p ${buildFolder} + pushd ${buildFolder} + cmake .. -GNinja -DEASTL_BUILD_TESTS:BOOL=OFF -DEASTL_BUILD_BENCHMARK:BOOL=OFF -DCMAKE_PREFIX_PATH=${eabase} + popd + runHook postConfigure + ''; + + buildPhase = '' + runHook preBuild + pushd ${buildFolder} + cmake --build . --config Release + popd + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + pushd ${buildFolder} + cmake --install . --prefix $out + rm $out/lib64/libEASTL.a + popd + runHook postInstall + ''; +} diff --git a/vendored-nix/eastl/fix-cmake-install.patch b/vendored-nix/eastl/fix-cmake-install.patch new file mode 100644 index 0000000..1528f4e --- /dev/null +++ b/vendored-nix/eastl/fix-cmake-install.patch @@ -0,0 +1,126 @@ +From 133f26c80a5e79f66769d33e2d01252d12016e69 Mon Sep 17 00:00:00 2001 +From: kidrigger +Date: Sat, 1 Feb 2025 23:30:50 +0100 +Subject: [PATCH] Fix installation and VCPKG patch. + +--- + CMakeLists.txt | 49 ++++++++++++++++++++++++------ + EASTLConfig.cmake.in | 9 ++++++ + scripts/CMake/CommonCppFlags.cmake | 3 ++ + 3 files changed, 52 insertions(+), 9 deletions(-) + create mode 100644 EASTLConfig.cmake.in + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index a5870f8..fd64807 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -5,6 +5,9 @@ cmake_minimum_required(VERSION 3.11) + include(FetchContent) + project(EASTL CXX) + ++include(GNUInstallDirs) ++include(CMakePackageConfigHelpers) ++ + #------------------------------------------------------------------------------------------- + # Options + #------------------------------------------------------------------------------------------- +@@ -12,7 +15,6 @@ option(EASTL_BUILD_BENCHMARK "Enable generation of build files for benchmark" OF + option(EASTL_BUILD_TESTS "Enable generation of build files for tests" OFF) + option(EASTL_STD_ITERATOR_CATEGORY_ENABLED "Enable compatibility with std:: iterator categories" OFF) + +- + option(EASTL_DISABLE_APRIL_2024_DEPRECATIONS "Enable use of API marked for removal in April 2024." OFF) + option(EASTL_DISABLE_SEPT_2024_DEPRECATIONS "Enable use of API marked for removal in September 2024." OFF) + option(EASTL_DISABLE_APRIL_2025_DEPRECATIONS "Enable use of API marked for removal in April 2025." OFF) +@@ -65,21 +67,50 @@ endif() + #------------------------------------------------------------------------------------------- + # Include dirs + #------------------------------------------------------------------------------------------- +-target_include_directories(EASTL PUBLIC include) ++target_include_directories(EASTL PUBLIC ++ $ ++ $ ++ ) + + #------------------------------------------------------------------------------------------- + # Dependencies + #------------------------------------------------------------------------------------------- +-FetchContent_Declare( +- EABase +- GIT_REPOSITORY https://github.com/electronicarts/EABase.git +- GIT_TAG 123363eb82e132c0181ac53e43226d8ee76dea12 +- GIT_SUBMODULES "" # This should be temporary until we update the cyclic submodule dependencies in EABase. ++find_package(EABase CONFIG REQUIRED) ++target_link_libraries(EASTL PUBLIC EABase) ++ ++# create and install an export set for eabase target as EABase::EABase ++set(EASTL_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/EASTL") ++ ++configure_package_config_file( ++ EASTLConfig.cmake.in ++ ${CMAKE_CURRENT_BINARY_DIR}/EASTLConfig.cmake ++ INSTALL_DESTINATION ${EASTL_CMAKE_CONFIG_DESTINATION} ++) ++ ++# create and install an export set for Terra target as Terra ++install( ++ TARGETS EASTL EXPORT EASTLTargets ++ DESTINATION ${CMAKE_INSTALL_LIBDIR} ++) ++ ++ ++install(EXPORT EASTLTargets DESTINATION ${EASTL_CMAKE_CONFIG_DESTINATION}) ++ ++write_basic_package_version_file( ++ "${CMAKE_CURRENT_BINARY_DIR}/EASTLConfigVersion.cmake" ++ VERSION 3.16.05 ++ COMPATIBILITY SameMajorVersion + ) + +-FetchContent_MakeAvailable(EABase) ++install(TARGETS EASTL LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") ++install(DIRECTORY "include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") + +-target_link_libraries(EASTL EABase) ++install( ++ FILES ++ "${CMAKE_CURRENT_BINARY_DIR}/EASTLConfig.cmake" ++ "${CMAKE_CURRENT_BINARY_DIR}/EASTLConfigVersion.cmake" ++ DESTINATION ${EASTL_CMAKE_CONFIG_DESTINATION} ++) + + #------------------------------------------------------------------------------------------- + # Deprecations +diff --git a/EASTLConfig.cmake.in b/EASTLConfig.cmake.in +new file mode 100644 +index 0000000..92fb2b1 +--- /dev/null ++++ b/EASTLConfig.cmake.in +@@ -0,0 +1,9 @@ ++@PACKAGE_INIT@ ++ ++include(CMakeFindDependencyMacro) ++find_dependency(EABase CONFIG REQUIRED) ++ ++# Provide path for scripts ++list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") ++ ++include(${CMAKE_CURRENT_LIST_DIR}/EASTLTargets.cmake) +\ No newline at end of file +diff --git a/scripts/CMake/CommonCppFlags.cmake b/scripts/CMake/CommonCppFlags.cmake +index 08b6af5..281665e 100644 +--- a/scripts/CMake/CommonCppFlags.cmake ++++ b/scripts/CMake/CommonCppFlags.cmake +@@ -74,6 +74,9 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + endif() + elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest /W4 /permissive-") ++ if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "19.31.30911.95") ++ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:static_assert-") ++ endif() + endif() + + +-- +2.47.0 + diff --git a/vendored-nix/scottt-debugbreak/default.nix b/vendored-nix/scottt-debugbreak/default.nix new file mode 100644 index 0000000..37f85ba --- /dev/null +++ b/vendored-nix/scottt-debugbreak/default.nix @@ -0,0 +1,30 @@ +{ stdenv, fetchFromGitHub}: +stdenv.mkDerivation { + pname = "scottt-debugbreak"; + version = "1.0"; + + src = fetchFromGitHub { + owner = "scottt"; + repo = "debugbreak"; + rev = "v1.0"; + sha256 = "sha256-lFMBSbA4mwAgW/+T+G1pfrwYjcZFuoKr6t8JYMB65Yw="; + fetchSubmodules = false; + }; + + configurePhase = '' + runHook preConfigure + runHook postConfigure + ''; + + buildPhase = '' + runHook preBuild + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out/include + cp debugbreak.h $out/include + runHook postInstall + ''; +} diff --git a/vendored-nix/tinygltf/default.nix b/vendored-nix/tinygltf/default.nix new file mode 100644 index 0000000..59542da --- /dev/null +++ b/vendored-nix/tinygltf/default.nix @@ -0,0 +1,17 @@ +{ stdenv, fetchFromGitHub, cmake }: +stdenv.mkDerivation { + pname = "tinygltf"; + version = "2.9.5"; + + nativeBuildInputs = [ + cmake + ]; + + src = fetchFromGitHub { + owner = "syoyo"; + repo = "tinygltf"; + rev = "v2.9.5"; + sha256 = "sha256-7GsLdjOAZvi/Lqu7mTWwvQTa5WokbGQlHy/CPoHipD8="; + fetchSubmodules = false; + }; +}