diff --git a/CMakeLists.txt b/CMakeLists.txt index f2f528f..01fbc94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) if(WIN32) set(CMAKE_CXX_FLAGS "-D_DEBUG") else() -set(CMAKE_CXX_FLAGS "-D_DEBUG -Wall -D_GLIBCXX_DEBUG -fsanitize=address") +set(CMAKE_CXX_FLAGS "-D_DEBUG -Wall -D_GLIBCXX_DEBUG -g -fsanitize=address") endif() project(Pleascach) diff --git a/Renderer/Renderer.cpp b/Renderer/Renderer.cpp index bad327c..90d9bb4 100644 --- a/Renderer/Renderer.cpp +++ b/Renderer/Renderer.cpp @@ -363,6 +363,10 @@ void Renderer::draw() { auto sz = win.getDimensions(); + /* re-upload objects if out-of-sync */ + if(uniform_buffer->data_copy.n_objects != objects.size()) + shader_buffer->upload(objects); + uniform_buffer->upload(UniformData{ .cam_pos = cam.pos, .time = time, @@ -372,6 +376,8 @@ void Renderer::draw() { .rad = rad, }); + + command_buffer->bind(*pipeline); command_buffer->command_buffer.setViewport(0, viewport); command_buffer->command_buffer.setScissor(0, scissor); diff --git a/Renderer/ShaderBuffer.hpp b/Renderer/ShaderBuffer.hpp index 17d2e7f..cab4d14 100644 --- a/Renderer/ShaderBuffer.hpp +++ b/Renderer/ShaderBuffer.hpp @@ -45,10 +45,10 @@ struct ShaderBuffer { } inline void upload(const std::vector& scene) { - buffer->upload(reinterpret_cast(scene.data())); + buffer->upload(reinterpret_cast(scene.data()), scene.size() * sizeof(Object)); } ~ShaderBuffer() { buffer.reset(); } -}; \ No newline at end of file +}; diff --git a/Renderer/UniformBuffer.cpp b/Renderer/UniformBuffer.cpp index c344d5b..c598fcb 100644 --- a/Renderer/UniformBuffer.cpp +++ b/Renderer/UniformBuffer.cpp @@ -11,5 +11,6 @@ UniformBuffer::UniformBuffer(vk::PhysicalDevice phys_dev, vk::Device dev) { } void UniformBuffer::upload(const UniformData& data) { + data_copy = data; buffer->upload(reinterpret_cast(&data), sizeof(UniformData)); } \ No newline at end of file diff --git a/Renderer/UniformBuffer.hpp b/Renderer/UniformBuffer.hpp index 6c75c42..4c77197 100644 --- a/Renderer/UniformBuffer.hpp +++ b/Renderer/UniformBuffer.hpp @@ -38,6 +38,7 @@ struct UniformBuffer { UniformBuffer(vk::PhysicalDevice phys_dev, vk::Device dev); std::unique_ptr buffer; + UniformData data_copy { 0.0 }; void upload(const UniformData& data); diff --git a/UI/UI.cpp b/UI/UI.cpp index 5864259..ff7abb6 100644 --- a/UI/UI.cpp +++ b/UI/UI.cpp @@ -35,9 +35,6 @@ static void scene_write(csys::String fname) { March::writeFile(fname.m_String, __ren->objects, __ren->scene_map); } -static void add_sphere() { - -} UI::UI(Renderer* ren) : ren(ren) { __ren = ren; @@ -113,7 +110,7 @@ UI::UI(Renderer* ren) : ren(ren) { auto& io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; - console = std::make_unique("developer console"); + console = new ImGuiConsole("developer console"); console->System().RegisterCommand("pause", "Pauses or unpauses the engine", [this]() { this->ren->paused = !this->ren->paused; console->System().Log(csys::ItemType::eINFO) << "Paused: " << (this->ren->paused ? "True" : "False") << csys::endl; @@ -219,7 +216,6 @@ void UI::render(vk::CommandBuffer cmd) { } UI::~UI() { - console.reset(); // dev.destroyDescriptorPool(desc_pool); ImGui_ImplVulkan_Shutdown(); diff --git a/UI/UI.hpp b/UI/UI.hpp index 8bb66d7..4334ce3 100644 --- a/UI/UI.hpp +++ b/UI/UI.hpp @@ -21,7 +21,7 @@ struct UI { UI(Renderer* ren); - std::unique_ptr console; + ImGuiConsole* console; void newFrame(); void render(vk::CommandBuffer cmd); diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a47bfd9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1743315132, + "narHash": "sha256-6hl6L/tRnwubHcA4pfUUtk542wn2Om+D4UnDhlDW9BE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "52faf482a3889b7619003c0daec593a1912fddc1", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..fa5aa47 --- /dev/null +++ b/flake.nix @@ -0,0 +1,31 @@ +{ + description = "Flake for Vulkan and GLSLC Project"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + in { + devShells.default = pkgs.mkShell { + buildInputs = [ + pkgs.git + pkgs.cmake + pkgs.vulkan-loader + pkgs.vulkan-headers + pkgs.vulkan-tools + pkgs.vulkan-validation-layers + pkgs.shaderc + pkgs.glfw3 + ]; + shellHook = '' + echo "Vulkan development environment loaded." + ''; + }; + } + ); +} diff --git a/pléascach.cpp b/pléascach.cpp index f3696cb..f50ab1c 100644 --- a/pléascach.cpp +++ b/pléascach.cpp @@ -33,9 +33,8 @@ int main(int argc, char* argv[]) { switch (event.tag) { case InputEvent::Tag::eRESIZE: Log::info("Event Processed: Resized to %dx%d\n", event.resize.width, event.resize.height); - /* no need to have a resize() function in the renderer, b/c swapchain images will be - * automatically marked out-of-date, and recreation will be triggered in our code - */ + + ren.swapchain->recreate(); /* but still block while waiting for window to be opened again */ if (event.resize.height == 0 || event.resize.width == 0) { int h = event.resize.height; diff --git a/util/log.hpp b/util/log.hpp index 83e077f..9646905 100644 --- a/util/log.hpp +++ b/util/log.hpp @@ -33,10 +33,32 @@ namespace Log { level_txt = "[DEBUG] "; break; } - std::fprintf(stderr, level_txt); + std::fputs(level_txt, stderr); std::fprintf(stderr, fmt.c_str(), args...); } + static void print(MessageLevelBit level, const std::string& str) { + if (!(log_mask & level)) + return; + + /* appearently C++ doesn't have designated array indices :( */ + const char* level_txt = "[UNKNOWN] "; + switch (level) { + case eERROR: + level_txt = "[ERROR] "; + break; + case eINFO: + level_txt = "[INFO] "; + break; + case eDEBUG: + level_txt = "[DEBUG] "; + break; + } + + std::fputs(level_txt, stderr); + std::fprintf(stderr, "%s", str.c_str()); + } + template static void error(const std::string& fmt, Args... args) { print(MessageLevelBit::eERROR, fmt, args...); @@ -54,4 +76,4 @@ namespace Log { static void debug(const std::string& fmt, Args... args) { print(MessageLevelBit::eDEBUG, fmt, args...); } -} \ No newline at end of file +}