diff --git a/.clang-tidy b/.clang-tidy index fabf0a67..0d368ede 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -2,8 +2,12 @@ Checks: '*,-fuchsia-*,-google-*,-zircon-*,-abseil-*,-modernize-use-trailing-return-type,-llvm*,\ -hicpp-uppercase-literal-suffix, -readability-uppercase-literal-suffix, -readability-implicit-bool-conversion,\ -cppcoreguidelines-avoid-magic-numbers, -readability-magic-numbers, -cppcoreguidelines-pro-type-union-access,\ - -cppcoreguidelines-pro-bounds-pointer-arithmetic, -cppcoreguidelines-pro-type-reinterpret-cast\ - -cppcoreguidelines-pro-type-vararg' + -cppcoreguidelines-pro-bounds-pointer-arithmetic, -cppcoreguidelines-pro-type-reinterpret-cast,\ + -cppcoreguidelines-pro-type-vararg, -altera-unroll-loops, -hicpp-vararg, -avoid-non-const-global-variables,\ + -cppcoreguidelines-avoid-non-const-global-variables, -altera-id-dependent-backward-branch, -hicpp-signed-bitwise,\ + -readability-identifier-length, -readability-redundant-access-specifiers, -bugprone-easily-swappable-parameters,\ + -misc-non-private-member-variables-in-classes, -altera-struct-pack-align, -cppcoreguidelines-non-private-member-variables-in-classes,\ + -misc-no-recursion, -cppcoreguidelines-pro-bounds-constant-array-index' WarningsAsErrors: '*' HeaderFilterRegex: '' FormatStyle: none \ No newline at end of file diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml index 7d05d9f5..43ee52d0 100644 --- a/.github/workflows/code_quality.yml +++ b/.github/workflows/code_quality.yml @@ -17,12 +17,12 @@ jobs: root_dir=\${1} build_dir=\${2} - pip install conan + pip install conan==1.59.0 conan install \$root_dir --install-folder=build --build=missing --settings=build_type=Release -c tools.system.package_manager:mode=install - wget https://sdk.lunarg.com/sdk/download/1.2.170.0/linux/vulkansdk-linux-x86_64-1.2.170.0.tar.gz - tar xf vulkansdk-linux-x86_64-1.2.170.0.tar.gz -C \$root_dir/lib - source \$root_dir/lib/1.2.170.0/setup-env.sh" > init_script.sh + wget https://sdk.lunarg.com/sdk/download/1.3.216.0/linux/vulkansdk-linux-x86_64-1.3.216.0.tar.gz + tar xf vulkansdk-linux-x86_64-1.3.216.0.tar.gz -C \$root_dir/lib + source \$root_dir/lib/1.3.216.0/setup-env.sh" > init_script.sh - name: Run static analysis uses: JacobDomagala/StaticAnalysis@master diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index b188b383..4c2e21e1 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -31,7 +31,7 @@ jobs: libxcb-sync-dev libxcb-xfixes0-dev libxcb-xinerama0-dev libxcb-dri3-dev \ libxcb-util-dev libxcb-util0-dev - pip install conan + pip install conan==1.59.0 wget https://sdk.lunarg.com/sdk/download/$SDK_VERSION/linux/vulkansdk-linux-x86_64-$SDK_VERSION.tar.gz tar xf vulkansdk-linux-x86_64-$SDK_VERSION.tar.gz diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 12d0cb7a..71c89491 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -36,6 +36,8 @@ jobs: - name: Install Conan id: conan uses: turtlebrowser/get-conan@main + with: + version: 1.59.0 - name: Cache Conan packages id: cache-conan @@ -70,4 +72,4 @@ jobs: compile_result_file: ${{runner.workspace}}/build/output.txt compiler: MSVC exclude_dir: ${{github.workspace}}/lib - debug_output: true + debug_output: true \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 74beea86..7abc5388 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,9 +38,6 @@ add_executable(${PROJECT_NAME} # time src/time/timer.hpp src/time/timer.cpp src/time/scoped_timer.hpp src/time/scoped_timer.cpp src/time/utils.hpp src/time/utils.cpp - # render - src/render/helpers.hpp - # render/vulkan "src/render/renderer.hpp" "src/render/renderer.cpp" "src/render/shader.hpp" "src/render/shader.cpp" "src/render/buffer.hpp" "src/render/buffer.cpp" "src/render/texture.hpp" "src/render/texture.cpp" diff --git a/src/app/gui/gui.cpp b/src/app/gui/gui.cpp index 3952deae..d3c00598 100644 --- a/src/app/gui/gui.cpp +++ b/src/app/gui/gui.cpp @@ -21,11 +21,11 @@ static inline void SetStyle() { ImGuiStyle& style = ImGui::GetStyle(); - auto* colors = style.Colors; + auto* colors = &style.Colors[0]; /// 0 = FLAT APPEARENCE /// 1 = MORE "3D" LOOK - int is3D = 1; + const int is3D = 1; colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); colors[ImGuiCol_TextDisabled] = ImVec4(0.40f, 0.40f, 0.40f, 1.00f); @@ -118,9 +118,9 @@ Gui::Init(const glm::ivec2& windowSize) ImGui::CreateContext(); // Dimensions - ImGuiIO& io = ImGui::GetIO(); - io.DisplaySize = ImVec2(static_cast< float >(windowSize.x), static_cast< float >(windowSize.y)); - io.DisplayFramebufferScale = ImVec2(1.0f, 1.0f); + ImGuiIO& io_handle = ImGui::GetIO(); + io_handle.DisplaySize = ImVec2(static_cast< float >(windowSize.x), static_cast< float >(windowSize.y)); + io_handle.DisplayFramebufferScale = ImVec2(1.0f, 1.0f); SetStyle(); @@ -146,9 +146,9 @@ Gui::UpdateBuffers() }; // Note: Alignment is done inside buffer creation - VkDeviceSize vertexBufferSize = + const VkDeviceSize vertexBufferSize = static_cast< uint32_t >(imDrawData->TotalVtxCount) * sizeof(ImDrawVert); - VkDeviceSize indexBufferSize = + const VkDeviceSize indexBufferSize = static_cast< uint32_t >(imDrawData->TotalIdxCount) * sizeof(ImDrawIdx); // Update buffers only if vertex or index count has been changed compared to current buffer size @@ -158,7 +158,7 @@ Gui::UpdateBuffers() } // Vertex buffer - if ((m_vertexBuffer.m_buffer == VK_NULL_HANDLE) || (m_vertexCount != imDrawData->TotalVtxCount)) + if ((m_vertexBuffer.GetBuffer() == VK_NULL_HANDLE) || (m_vertexCount != imDrawData->TotalVtxCount)) { m_vertexBuffer.Unmap(); m_vertexBuffer.Destroy(); @@ -172,7 +172,7 @@ Gui::UpdateBuffers() } // Index buffer - if ((m_indexBuffer.m_buffer == VK_NULL_HANDLE) || (m_indexCount < imDrawData->TotalIdxCount)) + if ((m_indexBuffer.GetBuffer() == VK_NULL_HANDLE) || (m_indexCount < imDrawData->TotalIdxCount)) { m_indexBuffer.Unmap(); m_indexBuffer.Destroy(); @@ -186,12 +186,12 @@ Gui::UpdateBuffers() } // Upload data - auto* vtxDst = reinterpret_cast< ImDrawVert* >(m_vertexBuffer.m_mappedMemory); - auto* idxDst = reinterpret_cast< ImDrawIdx* >(m_indexBuffer.m_mappedMemory); + auto* vtxDst = static_cast< ImDrawVert* >(m_vertexBuffer.GetMappedMemory()); + auto* idxDst = static_cast< ImDrawIdx* >(m_indexBuffer.GetMappedMemory()); - for (int n = 0; n < imDrawData->CmdListsCount; n++) + for (int cmd_idx = 0; cmd_idx < imDrawData->CmdListsCount; cmd_idx++) { - const ImDrawList* cmd_list = imDrawData->CmdLists[n]; + const ImDrawList* cmd_list = imDrawData->CmdLists[cmd_idx]; memcpy(vtxDst, cmd_list->VtxBuffer.Data, static_cast< size_t >(cmd_list->VtxBuffer.Size) * sizeof(ImDrawVert)); memcpy(idxDst, cmd_list->IdxBuffer.Data, @@ -210,14 +210,14 @@ Gui::UpdateBuffers() bool Gui::UpdateUI(const glm::ivec2& windowSize, scene::Scene& scene) { - ImGuiIO& io = ImGui::GetIO(); - io.DisplaySize = ImVec2(static_cast< float >(windowSize.x), static_cast< float >(windowSize.y)); + ImGuiIO& io_handle = ImGui::GetIO(); + io_handle.DisplaySize = ImVec2(static_cast< float >(windowSize.x), static_cast< float >(windowSize.y)); auto mousePos = input::InputManager::GetMousePos(); - io.MousePos = ImVec2(mousePos.x, mousePos.y); - io.MouseDown[0] = input::InputManager::CheckButtonPressed(GLFW_MOUSE_BUTTON_1); - io.MouseDown[1] = input::InputManager::CheckButtonPressed(GLFW_MOUSE_BUTTON_2); + io_handle.MousePos = ImVec2(mousePos.x, mousePos.y); + io_handle.MouseDown[0] = input::InputManager::CheckButtonPressed(GLFW_MOUSE_BUTTON_1); + io_handle.MouseDown[1] = input::InputManager::CheckButtonPressed(GLFW_MOUSE_BUTTON_2); ImGui::NewFrame(); @@ -236,7 +236,7 @@ Gui::UpdateUI(const glm::ivec2& windowSize, scene::Scene& scene) std::to_array({"Full scene", "Position", "Normal", "Albedo", "Specular", "ShadowMap"}); // Label to preview before opening the combo - const auto* combo_label = items.at(static_cast< uint32_t >(Data::m_debugData.displayDebugTarget)); + const auto* combo_label = items.at(Data::m_debugData.displayDebugTarget); if (ImGui::BeginCombo("Render target", combo_label, ImGuiComboFlags_HeightSmall)) { @@ -267,7 +267,7 @@ Gui::UpdateUI(const glm::ivec2& windowSize, scene::Scene& scene) auto cameraUp = camera.GetUpVec(); auto rightVec = camera.GetRightVec(); - ImGui::Text(""); + ImGui::Text(" "); ImGui::Text("Camera"); ImGui::InputFloat3("Position", &cameraPos[0], "%.3f", ImGuiInputTextFlags_ReadOnly); ImGui::InputFloat3("Direction", &cameraLookAt[0], "%.3f", ImGuiInputTextFlags_ReadOnly); @@ -277,6 +277,7 @@ Gui::UpdateUI(const glm::ivec2& windowSize, scene::Scene& scene) if (ImGui::CollapsingHeader("Shadows")) { + //NOLINTNEXTLINE ImGui::Checkbox("Render PCF", reinterpret_cast< bool* >(&Data::m_debugData.pcfShadow)); if (ImGui::SliderFloat("Shadow Factor", &Data::m_debugData.shadowFactor, 0.0f, 1.0f)) @@ -308,13 +309,13 @@ Gui::UpdateUI(const glm::ivec2& windowSize, scene::Scene& scene) UpdateBuffers(); - return io.WantCaptureMouse; + return io_handle.WantCaptureMouse; } void Gui::Render(VkCommandBuffer commandBuffer) { - ImDrawData* imDrawData = ImGui::GetDrawData(); + auto* imDrawData = ImGui::GetDrawData(); int32_t vertexOffset = 0; uint32_t indexOffset = 0; @@ -323,27 +324,27 @@ Gui::Render(VkCommandBuffer commandBuffer) return; } - ImGuiIO& io = ImGui::GetIO(); + const auto& io_handle = ImGui::GetIO(); vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipeline); vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, &m_descriptorSet, 0, nullptr); - m_pushConstant.scale = glm::vec2(2.0f / io.DisplaySize.x, 2.0f / io.DisplaySize.y); + m_pushConstant.scale = glm::vec2(2.0f / io_handle.DisplaySize.x, 2.0f / io_handle.DisplaySize.y); m_pushConstant.translate = glm::vec2(-1.0f); vkCmdPushConstants(commandBuffer, m_pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(PushConstBlock), &m_pushConstant); std::array offsets = {0}; - vkCmdBindVertexBuffers(commandBuffer, 0, 1, &m_vertexBuffer.m_buffer, offsets.data()); - vkCmdBindIndexBuffer(commandBuffer, m_indexBuffer.m_buffer, 0, VK_INDEX_TYPE_UINT16); + vkCmdBindVertexBuffers(commandBuffer, 0, 1, &m_vertexBuffer.GetBuffer(), offsets.data()); + vkCmdBindIndexBuffer(commandBuffer, m_indexBuffer.GetBuffer(), 0, VK_INDEX_TYPE_UINT16); for (int32_t i = 0; i < imDrawData->CmdListsCount; i++) { const ImDrawList* cmd_list = imDrawData->CmdLists[i]; - for (int32_t j = 0; j < cmd_list->CmdBuffer.Size; j++) + for (int32_t cmd_buffer_idx = 0; cmd_buffer_idx < cmd_list->CmdBuffer.Size; cmd_buffer_idx++) { - const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[j]; + const auto* pcmd = &cmd_list->CmdBuffer[cmd_buffer_idx]; VkRect2D scissorRect; scissorRect.offset.x = static_cast< int32_t >(glm::max(pcmd->ClipRect.x, 0.0f)); scissorRect.offset.y = static_cast< int32_t >(glm::max(pcmd->ClipRect.y, 0.0f)); @@ -360,7 +361,7 @@ Gui::Render(VkCommandBuffer commandBuffer) void Gui::PrepareResources() { - ImGuiIO& io = ImGui::GetIO(); + ImGuiIO& io_handle = ImGui::GetIO(); // Create font texture unsigned char* fontData = nullptr; @@ -369,9 +370,9 @@ Gui::PrepareResources() const auto fontFilename = (utils::FileManager::FONTS_DIR / "Roboto-Medium.ttf").string(); - io.Fonts->AddFontFromFileTTF(fontFilename.c_str(), 16.0f); + io_handle.Fonts->AddFontFromFileTTF(fontFilename.c_str(), 16.0f); - io.Fonts->GetTexDataAsRGBA32(&fontData, &texWidth, &texHeight); + io_handle.Fonts->GetTexDataAsRGBA32(&fontData, &texWidth, &texHeight); std::tie(m_fontImage, m_fontMemory) = diff --git a/src/app/gui/gui.hpp b/src/app/gui/gui.hpp index b1aed837..6aa5b1a4 100644 --- a/src/app/gui/gui.hpp +++ b/src/app/gui/gui.hpp @@ -15,7 +15,7 @@ class Scene; namespace shady::app::gui { -struct alignas(16) PushConstBlock +struct PushConstBlock { glm::vec2 scale; glm::vec2 translate; diff --git a/src/app/input/event.hpp b/src/app/input/event.hpp index d26422e4..a28f6e1d 100644 --- a/src/app/input/event.hpp +++ b/src/app/input/event.hpp @@ -1,11 +1,17 @@ #pragma once -#include +#include namespace shady::app::input { struct Event { + Event(const Event&) = default; + Event(Event&&) = default; + Event& operator=(const Event&) = default; + Event& operator=(Event&&) = default; + virtual ~Event() = default; + enum class EventType { KEY, @@ -14,61 +20,156 @@ struct Event MOUSE_SCROLL }; - explicit Event(EventType t) : m_type(t) + explicit Event(EventType t) : type_(t) + { + } + + [[nodiscard]] EventType + GetType() const + { + return type_; + } + + [[nodiscard]] bool + IsHandled() const { + return handled_; } - EventType m_type; - bool m_handled = false; + private: + EventType type_; + bool handled_ = false; }; struct KeyEvent : public Event { KeyEvent(int32_t key, int32_t scanCode, int32_t action, int32_t mods) - : Event(EventType::KEY), m_key(key), m_scanCode(scanCode), m_action(action), m_mods(mods) + : Event(EventType::KEY), key_(key), scanCode_(scanCode), action_(action), mods_(mods) + { + } + + [[nodiscard]] int32_t + GetKey() const { + return key_; } - int32_t m_key; - int32_t m_scanCode; - int32_t m_action; - int32_t m_mods; + [[nodiscard]] int32_t + GetScanCode() const + { + return scanCode_; + } + + [[nodiscard]] int32_t + GetAction() const + { + return action_; + } + + [[nodiscard]] int32_t + GetMods() const + { + return mods_; + } + + private: + int32_t key_; + int32_t scanCode_; + int32_t action_; + int32_t mods_; }; struct MouseButtonEvent : public Event { MouseButtonEvent(int32_t button, int32_t action, int32_t mods) - : Event(EventType::MOUSE_BUTTON), m_buttton(button), m_action(action), m_mods(mods) + : Event(EventType::MOUSE_BUTTON), buttton_(button), action_(action), mods_(mods) + { + } + + [[nodiscard]] int32_t + GetButton() const + { + return buttton_; + } + + [[nodiscard]] int32_t + GetAction() const + { + return action_; + } + + [[nodiscard]] int32_t + GetMods() const { + return mods_; } - int32_t m_buttton; - int32_t m_action; - int32_t m_mods; + private: + int32_t buttton_; + int32_t action_; + int32_t mods_; }; struct CursorPositionEvent : public Event { CursorPositionEvent(double x, double y, double xDelta, double yDelta) - : Event(EventType::MOUSE_CURSOR), m_xPos(x), m_yPos(y), m_xDelta(xDelta), m_yDelta(yDelta) + : Event(EventType::MOUSE_CURSOR), xPos_(x), yPos_(y), xDelta_(xDelta), yDelta_(yDelta) + { + } + + [[nodiscard]] double + GetXPos() const + { + return xPos_; + } + + [[nodiscard]] double + GetYPos() const { + return yPos_; } - double m_xPos; - double m_yPos; - double m_xDelta; - double m_yDelta; + [[nodiscard]] double + GetXDelta() const + { + return xDelta_; + } + + [[nodiscard]] double + GetYDelta() const + { + return yDelta_; + } + + private: + double xPos_; + double yPos_; + double xDelta_; + double yDelta_; }; struct MouseScrollEvent : public Event { MouseScrollEvent(double xOffset, double yOffset) - : Event(EventType::MOUSE_SCROLL), m_xOffset(xOffset), m_yOffset(yOffset) + : Event(EventType::MOUSE_SCROLL), xOffset_(xOffset), yOffset_(yOffset) + { + } + + [[nodiscard]] double + GetXOffset() const + { + return xOffset_; + } + + [[nodiscard]] double + GetYOffset() const { + return yOffset_; } - double m_xOffset; - double m_yOffset; + private: + double xOffset_; + double yOffset_; }; } // namespace shady::app::input diff --git a/src/app/input/input_listener.hpp b/src/app/input/input_listener.hpp index ba6088c0..1221003d 100644 --- a/src/app/input/input_listener.hpp +++ b/src/app/input/input_listener.hpp @@ -7,6 +7,11 @@ namespace shady::app::input { class InputListener { public: + InputListener() = default; + InputListener(const InputListener&) = default; + InputListener(InputListener&&) = default; + InputListener& operator=(const InputListener&) = default; + InputListener& operator=(InputListener&&) = default; virtual ~InputListener() = default; virtual void diff --git a/src/app/input/input_manager.cpp b/src/app/input/input_manager.cpp index 185ef91d..79b1aaca 100644 --- a/src/app/input/input_manager.cpp +++ b/src/app/input/input_manager.cpp @@ -50,12 +50,12 @@ InputManager::InternalMouseScrollCallback(GLFWwindow* /* window */, double xoffs void InputManager::BroadcastEvent(const Event& event) { - switch (event.m_type) + switch (event.GetType()) { case Event::EventType::KEY: { for (auto* listener : s_keyListeners) { - listener->KeyCallback(static_cast< const KeyEvent& >(event)); + listener->KeyCallback(dynamic_cast< const KeyEvent& >(event)); } } break; @@ -63,7 +63,7 @@ InputManager::BroadcastEvent(const Event& event) case Event::EventType::MOUSE_BUTTON: { for (auto* listener : s_mouseButtonListeners) { - listener->MouseButtonCallback(static_cast< const MouseButtonEvent& >(event)); + listener->MouseButtonCallback(dynamic_cast< const MouseButtonEvent& >(event)); } } break; @@ -71,7 +71,7 @@ InputManager::BroadcastEvent(const Event& event) case Event::EventType::MOUSE_CURSOR: { for (auto* listener : s_mouseMovementListeners) { - listener->CursorPositionCallback(static_cast< const CursorPositionEvent& >(event)); + listener->CursorPositionCallback(dynamic_cast< const CursorPositionEvent& >(event)); } } break; @@ -79,7 +79,7 @@ InputManager::BroadcastEvent(const Event& event) case Event::EventType::MOUSE_SCROLL: { for (auto* listener : s_mouseScrollListeners) { - listener->MouseScrollCallback(static_cast< const MouseScrollEvent& >(event)); + listener->MouseScrollCallback(dynamic_cast< const MouseScrollEvent& >(event)); } } break; diff --git a/src/app/shady.cpp b/src/app/shady.cpp index 4ee8692c..3fb8ad5c 100644 --- a/src/app/shady.cpp +++ b/src/app/shady.cpp @@ -113,7 +113,7 @@ Shady::OnUpdate() void Shady::KeyCallback(const input::KeyEvent& event) { - switch (event.m_key) + switch (event.GetKey()) { case GLFW_KEY_ESCAPE: { m_active = false; @@ -133,7 +133,7 @@ Shady::CursorPositionCallback(const input::CursorPositionEvent& event) if (input::InputManager::CheckButtonPressed(GLFW_MOUSE_BUTTON_LEFT) and !app::gui::Gui::UpdateUI({m_windowWidth, m_windowHeight}, m_currentScene)) { - m_currentScene.GetCamera().MouseMovement({event.m_xDelta, event.m_yDelta}); + m_currentScene.GetCamera().MouseMovement({event.GetXDelta(), event.GetYDelta()}); } } diff --git a/src/app/shady.hpp b/src/app/shady.hpp index 5bc8b174..1bd44a00 100644 --- a/src/app/shady.hpp +++ b/src/app/shady.hpp @@ -11,7 +11,12 @@ namespace shady::app { class Shady : public input::InputListener { public: - ~Shady() override = default; + Shady() = default; + Shady(const Shady&) = delete; + Shady(Shady&&) = delete; + Shady& operator=(const Shady&) = delete; + Shady& operator=(Shady&&) = delete; + ~Shady() override = default; void Init(); diff --git a/src/app/window.cpp b/src/app/window.cpp index e8afe74f..d04c8de0 100644 --- a/src/app/window.cpp +++ b/src/app/window.cpp @@ -91,7 +91,7 @@ Window::SwapBuffers() void Window::ShowCursor(bool choice) { - int mode = choice ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_DISABLED; + const int mode = choice ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_DISABLED; glfwSetInputMode(m_pWindow, GLFW_CURSOR, mode); } @@ -112,7 +112,7 @@ Window::GetCursorNormalized() { auto cursorPos = GetCursor(); - glm::vec2 centerOfScreen(static_cast< float >(m_width) / 2.0f, + const glm::vec2 centerOfScreen(static_cast< float >(m_width) / 2.0f, static_cast< float >(m_height) / 2.0f); cursorPos -= centerOfScreen; @@ -133,7 +133,7 @@ Window::GetCursor() glm::ivec2 Window::GetSize() const { - return glm::ivec2(m_width, m_height); + return {m_width, m_height}; } GLFWwindow* diff --git a/src/app/window.hpp b/src/app/window.hpp index b4e76e7c..4d82e339 100644 --- a/src/app/window.hpp +++ b/src/app/window.hpp @@ -13,6 +13,11 @@ class Window { public: Window() = default; + Window(const Window&) = delete; + Window(Window&&) = delete; + Window& operator=(const Window&) = delete; + Window& operator=(Window&&) = delete; + Window(int32_t width, int32_t height, const std::string& title); ~Window(); @@ -22,6 +27,7 @@ class Window void ShutDown(); + [[nodiscard]] glm::ivec2 GetSize() const; @@ -44,18 +50,22 @@ class Window // update and get cursor position <-1, 1> // with positive 'y' is up + [[nodiscard]] glm::vec2 GetCursorScreenPosition(const glm::mat4& projectionMatrix); // update and get cursor position <-1, 1> // with positive 'y' is down + [[nodiscard]] glm::vec2 GetCursorNormalized(); // return current cursor position on window + [[nodiscard]] glm::vec2 GetCursor(); + [[nodiscard]] GLFWwindow* GetWindowHandle(); diff --git a/src/render/buffer.cpp b/src/render/buffer.cpp index 04bf5d60..855f2b86 100644 --- a/src/render/buffer.cpp +++ b/src/render/buffer.cpp @@ -10,56 +10,56 @@ namespace shady::render { void Buffer::Map(VkDeviceSize size) { - vkMapMemory(Data::vk_device, m_bufferMemory, 0, size, 0, &m_mappedMemory); - m_mapped = true; + vkMapMemory(Data::vk_device, bufferMemory_, 0, size, 0, &mappedMemory_); + mapped_ = true; } void Buffer::Unmap() { - if (m_mapped) + if (mapped_) { - vkUnmapMemory(Data::vk_device, m_bufferMemory); - m_mapped = false; - m_mappedMemory = nullptr; + vkUnmapMemory(Data::vk_device, bufferMemory_); + mapped_ = false; + mappedMemory_ = nullptr; } } void -Buffer::CopyData(const void* data) +Buffer::CopyData(const void* data) const { - utils::Assert(m_mapped, "Buffer is not mapped!"); - memcpy(m_mappedMemory, data, m_bufferSize); + utils::Assert(mapped_, "Buffer is not mapped!"); + memcpy(mappedMemory_, data, bufferSize_); } void Buffer::CopyDataWithStaging(void* data, size_t dataSize) { - VkBuffer stagingBuffer; - VkDeviceMemory stagingBufferMemory; + VkBuffer stagingBuffer{}; + VkDeviceMemory stagingBufferMemory{}; Buffer::CreateBuffer(dataSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, stagingBuffer, stagingBufferMemory); - void* mapped_data; + void* mapped_data{}; vkMapMemory(Data::vk_device, stagingBufferMemory, 0, dataSize, 0, &mapped_data); memcpy(mapped_data, data, dataSize); vkUnmapMemory(Data::vk_device, stagingBufferMemory); - Buffer::CopyBuffer(stagingBuffer, m_buffer, dataSize); + Buffer::CopyBuffer(stagingBuffer, buffer_, dataSize); } void Buffer::CopyDataToImageWithStaging(VkImage image, void* data, size_t dataSize, const std::vector< VkBufferImageCopy >& copyRegions) { - VkBuffer stagingBuffer; - VkDeviceMemory stagingBufferMemory; + VkBuffer stagingBuffer{}; + VkDeviceMemory stagingBufferMemory{}; Buffer::CreateBuffer(dataSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, stagingBuffer, stagingBufferMemory); - void* mapped_data; + void* mapped_data{}; vkMapMemory(Data::vk_device, stagingBufferMemory, 0, dataSize, 0, &mapped_data); memcpy(mapped_data, data, dataSize); vkUnmapMemory(Data::vk_device, stagingBufferMemory); @@ -67,7 +67,7 @@ Buffer::CopyDataToImageWithStaging(VkImage image, void* data, size_t dataSize, VkCommandBuffer commandBuffer = Command::BeginSingleTimeCommands(); vkCmdCopyBufferToImage(commandBuffer, stagingBuffer, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, - static_cast(copyRegions.size()), copyRegions.data()); + static_cast< uint32_t >(copyRegions.size()), copyRegions.data()); Command::EndSingleTimeCommands(commandBuffer); @@ -78,9 +78,9 @@ Buffer::CopyDataToImageWithStaging(VkImage image, void* data, size_t dataSize, void Buffer::SetupDescriptor(VkDeviceSize /*size*/, VkDeviceSize offset) { - m_descriptor.offset = offset; - m_descriptor.buffer = m_buffer; - m_descriptor.range = m_bufferSize; + descriptor_.offset = offset; + descriptor_.buffer = buffer_; + descriptor_.range = bufferSize_; } void @@ -120,8 +120,8 @@ Buffer Buffer::CreateBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties) { Buffer newBuffer; - newBuffer.m_bufferSize = size; - CreateBuffer(size, usage, properties, newBuffer.m_buffer, newBuffer.m_bufferMemory); + newBuffer.bufferSize_ = size; + CreateBuffer(size, usage, properties, newBuffer.buffer_, newBuffer.bufferMemory_); newBuffer.SetupDescriptor(); return newBuffer; @@ -162,7 +162,7 @@ Buffer::Flush(VkDeviceSize size, VkDeviceSize offset) const { VkMappedMemoryRange mappedRange = {}; mappedRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; - mappedRange.memory = m_bufferMemory; + mappedRange.memory = bufferMemory_; mappedRange.offset = offset; mappedRange.size = size; @@ -172,14 +172,32 @@ Buffer::Flush(VkDeviceSize size, VkDeviceSize offset) const void Buffer::Destroy() { - if (m_buffer) + if (buffer_) { - vkDestroyBuffer(Data::vk_device, m_buffer, nullptr); + vkDestroyBuffer(Data::vk_device, buffer_, nullptr); } - if (m_bufferMemory) + if (bufferMemory_) { - vkFreeMemory(Data::vk_device, m_bufferMemory, nullptr); + vkFreeMemory(Data::vk_device, bufferMemory_, nullptr); } } +VkBuffer& +Buffer::GetBuffer() +{ + return buffer_; +} + +void* +Buffer::GetMappedMemory() +{ + return mappedMemory_; +} + +[[nodiscard]] VkDescriptorBufferInfo& +Buffer::GetDescriptor() +{ + return descriptor_; +} + } // namespace shady::render diff --git a/src/render/buffer.hpp b/src/render/buffer.hpp index 594b79dc..891aeb8c 100644 --- a/src/render/buffer.hpp +++ b/src/render/buffer.hpp @@ -1,7 +1,8 @@ #pragma once -#include #include +#include + namespace shady::render { @@ -33,7 +34,7 @@ class Buffer Unmap(); void - CopyData(const void* data); + CopyData(const void* data) const; void CopyDataWithStaging(void* data, size_t dataSize); @@ -51,14 +52,23 @@ class Buffer void Destroy(); - public: - void* m_mappedMemory = nullptr; - bool m_mapped = false; - VkBuffer m_buffer = {}; - VkDeviceMemory m_bufferMemory = {}; - VkDeviceSize m_bufferSize = {}; - VkDescriptorBufferInfo m_descriptor = {}; + [[nodiscard]] VkBuffer& + GetBuffer(); + + [[nodiscard]] void* + GetMappedMemory(); + + [[nodiscard]] VkDescriptorBufferInfo& + GetDescriptor(); + + private: + void* mappedMemory_ = nullptr; + bool mapped_ = false; + VkBuffer buffer_ = {}; + VkDeviceMemory bufferMemory_ = {}; + VkDeviceSize bufferSize_ = {}; + VkDescriptorBufferInfo descriptor_ = {}; }; -} // namespace shady::render::vulkan +} // namespace shady::render diff --git a/src/render/command.cpp b/src/render/command.cpp index b8a15799..4dd8a483 100644 --- a/src/render/command.cpp +++ b/src/render/command.cpp @@ -12,7 +12,7 @@ Command::BeginSingleTimeCommands() allocInfo.commandPool = Data::vk_commandPool; allocInfo.commandBufferCount = 1; - VkCommandBuffer commandBuffer; + VkCommandBuffer commandBuffer{}; vkAllocateCommandBuffers(Data::vk_device, &allocInfo, &commandBuffer); VkCommandBufferBeginInfo beginInfo{}; diff --git a/src/render/common.cpp b/src/render/common.cpp index 51872309..01a88da7 100644 --- a/src/render/common.cpp +++ b/src/render/common.cpp @@ -26,7 +26,7 @@ VkFormat FindSupportedFormat(const std::vector< VkFormat >& candidates, VkImageTiling tiling, VkFormatFeatureFlags features) { - for (VkFormat format : candidates) + for (const VkFormat format : candidates) { VkFormatProperties props; vkGetPhysicalDeviceFormatProperties(Data::vk_physicalDevice, format, &props); @@ -35,8 +35,8 @@ FindSupportedFormat(const std::vector< VkFormat >& candidates, VkImageTiling til { return format; } - else if (tiling == VK_IMAGE_TILING_OPTIMAL - && (props.optimalTilingFeatures & features) == features) + + if (tiling == VK_IMAGE_TILING_OPTIMAL && (props.optimalTilingFeatures & features) == features) { return format; } diff --git a/src/render/common.hpp b/src/render/common.hpp index 568e92f3..38d390e8 100644 --- a/src/render/common.hpp +++ b/src/render/common.hpp @@ -9,25 +9,26 @@ #include #include #include +#include #include #include -#include #include - -// This should make use of when it's supported by clang/mvcc -#define VK_CHECK(vkFunction, errorMessage) \ - do \ - { \ - const auto result = vkFunction; \ - if (result != VK_SUCCESS) \ - { \ - utils::Assert(false, fmt::format("{} Return value {}", errorMessage, string_VkResult(result))); \ - } \ - } while (0); +#include +#include namespace shady::render { +// This should make use of when it's supported by clang/mvcc +constexpr void +VK_CHECK(VkResult result, std::string_view errorMessage) +{ + if (result != VK_SUCCESS) + { + utils::Assert(false, + fmt::format("{} Return value {}", errorMessage, string_VkResult(result))); + } +} static constexpr bool ENABLE_VALIDATION = true; static constexpr std::array< const char*, 1 > VALIDATION_LAYERS = {"VK_LAYER_KHRONOS_validation"}; diff --git a/src/render/deferred_pipeline.cpp b/src/render/deferred_pipeline.cpp index 903089d3..44f2c958 100644 --- a/src/render/deferred_pipeline.cpp +++ b/src/render/deferred_pipeline.cpp @@ -6,10 +6,11 @@ #include "texture.hpp" #include "vertex.hpp" +#include #include #include #include -#include + namespace shady::render { @@ -26,19 +27,19 @@ struct Light glm::mat4 viewMatrix = {}; }; -struct +struct UboOffscreenVS { glm::mat4 projection = {}; glm::mat4 model = {}; glm::mat4 view = {}; -} uboOffscreenVS; +}; -struct +struct UboComposition { Light light = {}; glm::vec4 viewPos = {}; DebugData debugData = {}; -} uboComposition; +}; VkDescriptorSet& DeferredPipeline::GetDescriptorSet() @@ -68,9 +69,11 @@ DeferredPipeline::GetOffscreenSemaphore() void DeferredPipeline::UpdateUniformBufferOffscreen(const scene::Camera* camera) { + UboOffscreenVS uboOffscreenVS{}; uboOffscreenVS.projection = camera->GetProjection(); uboOffscreenVS.view = camera->GetView(); uboOffscreenVS.model = glm::mat4(1.0f); + m_offscreenBuffer.CopyData(&uboOffscreenVS); m_skybox.UpdateBuffers(camera); } @@ -86,15 +89,15 @@ void DeferredPipeline::UpdateUniformBufferComposition(const scene::Camera* camera, const scene::Light* light) { + UboComposition uboComposition{}; uboComposition.light.position = glm::vec4(camera->GetPosition(), 1.0f); uboComposition.light.target = glm::vec4(light->GetLookAt(), 1.0); uboComposition.light.color = glm::vec4{light->GetColor(), 1.0f}; uboComposition.light.viewMatrix = light->GetLightSpaceMat(); uboComposition.viewPos = glm::vec4(camera->GetPosition(), 0.0f); - uboComposition.debugData = Data::m_debugData; - memcpy(m_compositionBuffer.m_mappedMemory, &uboComposition, sizeof(uboComposition)); + memcpy(m_compositionBuffer.GetMappedMemory(), &uboComposition, sizeof(uboComposition)); } void @@ -139,12 +142,12 @@ DeferredPipeline::PrepareUniformBuffers() { // Offscreen vertex shader m_offscreenBuffer = Buffer::CreateBuffer( - sizeof(uboOffscreenVS), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, + sizeof(UboOffscreenVS), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); // Deferred fragment shader m_compositionBuffer = Buffer::CreateBuffer( - sizeof(uboComposition), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, + sizeof(UboComposition), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); // Map persistent @@ -308,7 +311,7 @@ DeferredPipeline::PreparePipelines() static_cast< uint32_t >(dynamicStateEnables.size()); pipelineDynamicStateCreateInfo.flags = 0; - std::array< VkPipelineShaderStageCreateInfo, 2 > shaderStages; + std::array< VkPipelineShaderStageCreateInfo, 2 > shaderStages{}; auto [vertexInfo, fragmentInfo] = Shader::CreateShader( Data::vk_device, "default/deferred.vert.spv", "default/deferred.frag.spv"); @@ -439,7 +442,7 @@ DeferredPipeline::PreparePipelines() // The shadow mapping pipeline uses geometry shader instancing (invocations layout modifier) to // output shadow maps for multiple lights sources into the different shadow map layers in one // single render pass - std::array< VkPipelineShaderStageCreateInfo, 1 > shadowStages; + std::array< VkPipelineShaderStageCreateInfo, 1 > shadowStages{}; shadowStages[0] = Shader::LoadShader("default/shadow.vert.spv", VK_SHADER_STAGE_VERTEX_BIT).shaderInfo; @@ -566,7 +569,7 @@ DeferredPipeline::SetupDescriptorSet() descriptorWrites[3].dstArrayElement = 0; descriptorWrites[3].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; descriptorWrites[3].descriptorCount = 1; - descriptorWrites[3].pBufferInfo = &m_compositionBuffer.m_descriptor; + descriptorWrites[3].pBufferInfo = &m_compositionBuffer.GetDescriptor(); // Binding 8 : Shadowmap texture descriptorWrites[4].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; @@ -675,7 +678,7 @@ DeferredPipeline::BuildDeferredCommandBuffer(const std::vector< VkImageView >& s cmdBufInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; // Clear values for all attachments written in the fragment shader - std::array< VkClearValue, 4 > clearValues; + std::array< VkClearValue, 4 > clearValues{}; VkRenderPassBeginInfo renderPassBeginInfo = {}; renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; @@ -717,8 +720,8 @@ DeferredPipeline::BuildDeferredCommandBuffer(const std::vector< VkImageView >& s m_shadowMapPipeline); { - VkDeviceSize offsets[] = {0}; - vkCmdBindVertexBuffers(m_offscreenCommandBuffer, 0, 1, &Data::m_vertexBuffer, offsets); + std::array< VkDeviceSize, 1 > offsets = {0}; + vkCmdBindVertexBuffers(m_offscreenCommandBuffer, 0, 1, &Data::m_vertexBuffer, offsets.data()); vkCmdBindIndexBuffer(m_offscreenCommandBuffer, Data::m_indexBuffer, 0, VK_INDEX_TYPE_UINT32); @@ -774,8 +777,8 @@ DeferredPipeline::BuildDeferredCommandBuffer(const std::vector< VkImageView >& s m_offscreenPipeline); - VkDeviceSize offsets[] = {0}; - vkCmdBindVertexBuffers(m_offscreenCommandBuffer, 0, 1, &Data::m_vertexBuffer, offsets); + std::array offsets = {0}; + vkCmdBindVertexBuffers(m_offscreenCommandBuffer, 0, 1, &Data::m_vertexBuffer, offsets.data()); vkCmdBindIndexBuffer(m_offscreenCommandBuffer, Data::m_indexBuffer, 0, VK_INDEX_TYPE_UINT32); diff --git a/src/render/deferred_pipeline.hpp b/src/render/deferred_pipeline.hpp index d4dbf57d..92e186ec 100644 --- a/src/render/deferred_pipeline.hpp +++ b/src/render/deferred_pipeline.hpp @@ -19,57 +19,58 @@ namespace shady::render { class DeferredPipeline { public: - void + static void Initialize(VkRenderPass mainRenderPass, const std::vector< VkImageView >& swapChainImageViews, VkPipelineCache pipelineCache); - VkDescriptorSet& + static VkDescriptorSet& GetDescriptorSet(); - VkPipelineLayout + static VkPipelineLayout GetPipelineLayout(); - VkPipeline + static VkPipeline GetCompositionPipeline(); - VkCommandBuffer& + static VkCommandBuffer& GetOffscreenCmdBuffer(); - VkSemaphore& + static VkSemaphore& GetOffscreenSemaphore(); - void + static void UpdateDeferred(const scene::Camera* camera, const scene::Light* light); private: - void + static void ShadowSetup(); // Prepare a new framebuffer and attachments for offscreen rendering (G-Buffer) - void + static void PrepareOffscreenFramebuffer(); - void + static void PrepareUniformBuffers(); - void + static void SetupDescriptorSetLayout(); - void + static void PreparePipelines(); - void + static void SetupDescriptorPool(); - void + static void SetupDescriptorSet(); - void + static void BuildDeferredCommandBuffer(const std::vector< VkImageView >& swapChainImageViews); - void + static void UpdateUniformBufferComposition(const scene::Camera* camera, const scene::Light* light); - void + + static void UpdateUniformBufferOffscreen(const scene::Camera* camera); inline static VkRenderPass m_mainRenderPass = {}; diff --git a/src/render/framebuffer.cpp b/src/render/framebuffer.cpp index f2102129..3fa8aa56 100644 --- a/src/render/framebuffer.cpp +++ b/src/render/framebuffer.cpp @@ -1,9 +1,11 @@ #include "framebuffer.hpp" +#include "assert.hpp" #include "common.hpp" +#include #include #include -#include + namespace shady::render { @@ -15,30 +17,30 @@ Framebuffer::Create(int32_t width, int32_t height) // Four attachments (3 color, 1 depth) AttachmentCreateInfo attachmentInfo = {}; - attachmentInfo.width = static_cast< uint32_t >(width); - attachmentInfo.height = static_cast< uint32_t >(height); - attachmentInfo.layerCount = 1; - attachmentInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; + attachmentInfo.width_ = static_cast< uint32_t >(width); + attachmentInfo.height_ = static_cast< uint32_t >(height); + attachmentInfo.layerCount_ = 1; + attachmentInfo.usage_ = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; // Color attachments // Attachment 0: (World space) Positions - attachmentInfo.format = VK_FORMAT_R16G16B16A16_SFLOAT; + attachmentInfo.format_ = VK_FORMAT_R16G16B16A16_SFLOAT; AddAttachment(attachmentInfo); // Attachment 1: (World space) Normals - attachmentInfo.format = VK_FORMAT_R16G16B16A16_SFLOAT; + attachmentInfo.format_ = VK_FORMAT_R16G16B16A16_SFLOAT; AddAttachment(attachmentInfo); // Attachment 2: Albedo (color) - attachmentInfo.format = VK_FORMAT_R8G8B8A8_UNORM; + attachmentInfo.format_ = VK_FORMAT_R8G8B8A8_UNORM; AddAttachment(attachmentInfo); // Depth attachment // Find a suitable depth format const auto attDepthFormat = FindDepthFormat(); - attachmentInfo.format = attDepthFormat; - attachmentInfo.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + attachmentInfo.format_ = attDepthFormat; + attachmentInfo.usage_ = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; AddAttachment(attachmentInfo); // Create sampler to sample from the color attachments @@ -64,11 +66,11 @@ Framebuffer::CreateShadowMap(int32_t width, int32_t height, int32_t numLights) // instancing We will pass the matrices of the lights to the GS that selects the layer by the // current invocation AttachmentCreateInfo attachmentInfo = {}; - attachmentInfo.format = SHADOWMAP_FORMAT; - attachmentInfo.width = static_cast< uint32_t >(width); - attachmentInfo.height = static_cast< uint32_t >(height); - attachmentInfo.layerCount = static_cast< uint32_t >(numLights); - attachmentInfo.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; + attachmentInfo.format_ = SHADOWMAP_FORMAT; + attachmentInfo.width_ = static_cast< uint32_t >(width); + attachmentInfo.height_ = static_cast< uint32_t >(height); + attachmentInfo.layerCount_ = static_cast< uint32_t >(numLights); + attachmentInfo.usage_ = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; AddAttachment(attachmentInfo); @@ -108,35 +110,35 @@ Framebuffer::GetSampler() const VkImageView Framebuffer::GetPositionsImageView() const { - utils::Assert(m_attachments.size() > 0, ""); - return m_attachments[0].view; + utils::Assert(not m_attachments.empty(), ""); + return m_attachments[0].view_; } VkImageView Framebuffer::GetNormalsImageView() const { utils::Assert(m_attachments.size() > 1, ""); - return m_attachments[1].view; + return m_attachments[1].view_; } VkImageView Framebuffer::GetAlbedoImageView() const { utils::Assert(m_attachments.size() > 2, ""); - return m_attachments[2].view; + return m_attachments[2].view_; } VkImageView Framebuffer::GetShadowMapView() const { - utils::Assert(m_attachments.size() > 0, ""); - return m_attachments[0].view; + utils::Assert(not m_attachments.empty(), ""); + return m_attachments[0].view_; } VkSampler Framebuffer::CreateSampler(VkFilter magFilter, VkFilter minFilter, VkSamplerAddressMode adressMode) { - VkSampler sampler; + VkSampler sampler{}; VkSamplerCreateInfo samplerInfo{}; samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; @@ -160,22 +162,22 @@ Framebuffer::CreateSampler(VkFilter magFilter, VkFilter minFilter, VkSamplerAddr uint32_t Framebuffer::AddAttachment(AttachmentCreateInfo createinfo) { - FramebufferAttachment attachment; + FramebufferAttachment attachment{}; - attachment.format = createinfo.format; + attachment.format_ = createinfo.format_; - VkImageAspectFlags aspectMask = 0; + VkImageAspectFlags aspectMask = VK_IMAGE_ASPECT_NONE_KHR; // Select aspect mask and layout depending on usage // Color attachment - if (createinfo.usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) + if (createinfo.usage_ & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) { aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; } // Depth (and/or stencil) attachment - if (createinfo.usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) + if (createinfo.usage_ & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { if (attachment.hasDepth()) { @@ -187,71 +189,71 @@ Framebuffer::AddAttachment(AttachmentCreateInfo createinfo) } } - assert(aspectMask > 0); + utils::Assert(aspectMask > 0, "Framebuffer::AddAttachment: aspectMask > 0 failed!\n"); VkImageCreateInfo image = {}; image.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; image.imageType = VK_IMAGE_TYPE_2D; - image.format = createinfo.format; - image.extent.width = createinfo.width; - image.extent.height = createinfo.height; + image.format = createinfo.format_; + image.extent.width = createinfo.width_; + image.extent.height = createinfo.height_; image.extent.depth = 1; image.mipLevels = 1; - image.arrayLayers = createinfo.layerCount; - image.samples = createinfo.imageSampleCount; + image.arrayLayers = createinfo.layerCount_; + image.samples = createinfo.imageSampleCount_; image.tiling = VK_IMAGE_TILING_OPTIMAL; - image.usage = createinfo.usage; + image.usage = createinfo.usage_; VkMemoryAllocateInfo memAlloc = {}; memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; VkMemoryRequirements memReqs; // Create image for this attachment - VK_CHECK(vkCreateImage(Data::vk_device, &image, nullptr, &attachment.image), ""); - vkGetImageMemoryRequirements(Data::vk_device, attachment.image, &memReqs); + VK_CHECK(vkCreateImage(Data::vk_device, &image, nullptr, &attachment.image_), ""); + vkGetImageMemoryRequirements(Data::vk_device, attachment.image_, &memReqs); memAlloc.allocationSize = memReqs.size; memAlloc.memoryTypeIndex = FindMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); - VK_CHECK(vkAllocateMemory(Data::vk_device, &memAlloc, nullptr, &attachment.memory), ""); - VK_CHECK(vkBindImageMemory(Data::vk_device, attachment.image, attachment.memory, 0), ""); + VK_CHECK(vkAllocateMemory(Data::vk_device, &memAlloc, nullptr, &attachment.memory_), ""); + VK_CHECK(vkBindImageMemory(Data::vk_device, attachment.image_, attachment.memory_, 0), ""); - attachment.subresourceRange = {}; - attachment.subresourceRange.aspectMask = aspectMask; - attachment.subresourceRange.levelCount = 1; - attachment.subresourceRange.layerCount = createinfo.layerCount; + attachment.subresourceRange_ = {}; + attachment.subresourceRange_.aspectMask = aspectMask; + attachment.subresourceRange_.levelCount = 1; + attachment.subresourceRange_.layerCount = createinfo.layerCount_; VkImageViewCreateInfo imageView = {}; imageView.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; imageView.viewType = - (createinfo.layerCount == 1) ? VK_IMAGE_VIEW_TYPE_2D : VK_IMAGE_VIEW_TYPE_2D_ARRAY; - imageView.format = createinfo.format; - imageView.subresourceRange = attachment.subresourceRange; + (createinfo.layerCount_ == 1) ? VK_IMAGE_VIEW_TYPE_2D : VK_IMAGE_VIEW_TYPE_2D_ARRAY; + imageView.format = createinfo.format_; + imageView.subresourceRange = attachment.subresourceRange_; // todo: workaround for depth+stencil attachments imageView.subresourceRange.aspectMask = (attachment.hasDepth()) ? VK_IMAGE_ASPECT_DEPTH_BIT : aspectMask; - imageView.image = attachment.image; - VK_CHECK(vkCreateImageView(Data::vk_device, &imageView, nullptr, &attachment.view), ""); + imageView.image = attachment.image_; + VK_CHECK(vkCreateImageView(Data::vk_device, &imageView, nullptr, &attachment.view_), ""); // Fill attachment description - attachment.description = {}; - attachment.description.samples = createinfo.imageSampleCount; - attachment.description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; - attachment.description.storeOp = (createinfo.usage & VK_IMAGE_USAGE_SAMPLED_BIT) - ? VK_ATTACHMENT_STORE_OP_STORE - : VK_ATTACHMENT_STORE_OP_DONT_CARE; - attachment.description.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - attachment.description.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; - attachment.description.format = createinfo.format; - attachment.description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + attachment.description_ = {}; + attachment.description_.samples = createinfo.imageSampleCount_; + attachment.description_.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; + attachment.description_.storeOp = (createinfo.usage_ & VK_IMAGE_USAGE_SAMPLED_BIT) + ? VK_ATTACHMENT_STORE_OP_STORE + : VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachment.description_.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; + attachment.description_.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachment.description_.format = createinfo.format_; + attachment.description_.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; // Final layout // If not, final layout depends on attachment type if (attachment.hasDepth() || attachment.hasStencil()) { - attachment.description.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; + attachment.description_.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; } else { - attachment.description.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + attachment.description_.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; } m_attachments.push_back(attachment); @@ -265,7 +267,7 @@ Framebuffer::CreateRenderPass() std::vector< VkAttachmentDescription > attachmentDescriptions; std::transform(m_attachments.begin(), m_attachments.end(), std::back_inserter(attachmentDescriptions), - [](const auto& attachment) { return attachment.description; }); + [](const auto& attachment) { return attachment.description_; }); // Collect attachment references std::vector< VkAttachmentReference > colorReferences; @@ -275,12 +277,13 @@ Framebuffer::CreateRenderPass() uint32_t attachmentIndex = 0; - for (auto& attachment : m_attachments) + for (const auto& attachment : m_attachments) { if (attachment.isDepthStencil()) { // Only one depth attachment allowed - assert(!hasDepth); + utils::Assert(!hasDepth, + "Framebuffer::CreateRenderPass: Only one depth attackment allowed!\n"); depthReference.attachment = attachmentIndex; depthReference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; hasDepth = true; @@ -307,7 +310,7 @@ Framebuffer::CreateRenderPass() } // Use subpass dependencies for attachment layout transitions - std::array< VkSubpassDependency, 2 > dependencies; + std::array< VkSubpassDependency, 2 > dependencies{}; dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL; dependencies[0].dstSubpass = 0; @@ -340,13 +343,13 @@ Framebuffer::CreateRenderPass() std::vector< VkImageView > attachmentViews; std::transform(m_attachments.begin(), m_attachments.end(), std::back_inserter(attachmentViews), - [](const auto& attachment) { return attachment.view; }); + [](const auto& attachment) { return attachment.view_; }); // Find. max number of layers across attachments - uint32_t maxLayers = + const uint32_t maxLayers = std::accumulate(m_attachments.begin(), m_attachments.end(), uint32_t{0}, [](uint32_t curMax, const auto& right) { - return std::max({curMax, right.subresourceRange.layerCount}); + return std::max({curMax, right.subresourceRange_.layerCount}); }); VkFramebufferCreateInfo framebufferInfo = {}; diff --git a/src/render/framebuffer.hpp b/src/render/framebuffer.hpp index 43377fed..9918633f 100644 --- a/src/render/framebuffer.hpp +++ b/src/render/framebuffer.hpp @@ -1,10 +1,11 @@ #pragma once +#include #include #include -#include #include + namespace shady::render { /** @@ -12,31 +13,24 @@ namespace shady::render { */ struct FramebufferAttachment { - VkImage image; - VkDeviceMemory memory; - VkImageView view; - VkFormat format; - VkImageSubresourceRange subresourceRange; - VkAttachmentDescription description; - /** * @brief Returns true if the attachment has a depth component */ - bool - hasDepth() + [[nodiscard]] bool + hasDepth() const { std::vector< VkFormat > formats = { VK_FORMAT_D16_UNORM, VK_FORMAT_X8_D24_UNORM_PACK32, VK_FORMAT_D32_SFLOAT, VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT, }; - return std::find(formats.begin(), formats.end(), format) != std::end(formats); + return std::find(formats.begin(), formats.end(), format_) != std::end(formats); } /** * @brief Returns true if the attachment has a stencil component */ - bool - hasStencil() + [[nodiscard]] bool + hasStencil() const { std::vector< VkFormat > formats = { VK_FORMAT_S8_UINT, @@ -44,17 +38,25 @@ struct FramebufferAttachment VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT, }; - return std::find(formats.begin(), formats.end(), format) != std::end(formats); + return std::find(formats.begin(), formats.end(), format_) != std::end(formats); } /** * @brief Returns true if the attachment is a depth and/or stencil attachment */ - bool - isDepthStencil() + [[nodiscard]] bool + isDepthStencil() const { return (hasDepth() || hasStencil()); } + + public: + VkImage image_ = {}; + VkDeviceMemory memory_ = {}; + VkImageView view_ = {}; + VkFormat format_ = {}; + VkImageSubresourceRange subresourceRange_ = {}; + VkAttachmentDescription description_ = {}; }; /** @@ -62,11 +64,12 @@ struct FramebufferAttachment */ struct AttachmentCreateInfo { - uint32_t width, height; - uint32_t layerCount; - VkFormat format; - VkImageUsageFlags usage; - VkSampleCountFlagBits imageSampleCount = VK_SAMPLE_COUNT_1_BIT; + uint32_t width_ = {}; + uint32_t height_ = {}; + uint32_t layerCount_ = {}; + VkFormat format_ = {}; + VkImageUsageFlags usage_ = {}; + VkSampleCountFlagBits imageSampleCount_ = VK_SAMPLE_COUNT_1_BIT; }; class Framebuffer @@ -78,28 +81,28 @@ class Framebuffer void CreateShadowMap(int32_t width, int32_t height, int32_t numLights); - glm::ivec2 + [[nodiscard]] glm::ivec2 GetSize() const; - VkRenderPass + [[nodiscard]] VkRenderPass GetRenderPass() const; - VkFramebuffer + [[nodiscard]] VkFramebuffer GetFramebuffer() const; - VkImageView + [[nodiscard]] VkImageView GetPositionsImageView() const; - VkImageView + [[nodiscard]] VkImageView GetNormalsImageView() const; - VkImageView + [[nodiscard]] VkImageView GetAlbedoImageView() const; - VkImageView + [[nodiscard]] VkImageView GetShadowMapView() const; - VkSampler + [[nodiscard]] VkSampler GetSampler() const; private: @@ -132,7 +135,7 @@ class Framebuffer * * @return VkResult for the sampler creation */ - VkSampler + static VkSampler CreateSampler(VkFilter magFilter, VkFilter minFilter, VkSamplerAddressMode adressMode); private: @@ -141,8 +144,7 @@ class Framebuffer VkFramebuffer m_framebuffer = {}; std::vector< FramebufferAttachment > m_attachments = {}; VkRenderPass m_renderPass = {}; - VkSampler m_sampler = {}; }; -} // namespace shady::render::vulkan +} // namespace shady::render diff --git a/src/render/helpers.hpp b/src/render/helpers.hpp deleted file mode 100644 index 58e36e2b..00000000 --- a/src/render/helpers.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -#include "renderer_api.hpp" -#include "trace/logger.hpp" -#include "utils/assert.hpp" - -#include -#include - -namespace shady::render { - -template < class OpenGL, class Base, typename... Args > -std::shared_ptr< Base > -CreateSharedWrapper(const Args&... args) -{ - switch (RendererAPI::GetAPI()) - { - case RendererAPI::API::None: { - trace::Logger::Fatal("RendererAPI::None is currently not supported!"); - return nullptr; - } - break; - - case RendererAPI::API::OpenGL: { - return std::make_shared< OpenGL >(args...); - } - break; - } - - utils::Assert(false, fmt::format("API type({}) not supported!", RendererAPI::GetAPI())); - return nullptr; -} - -template < class OpenGL, class Base, typename... Args > -std::unique_ptr< Base > -CreateUniqueWrapper(const Args&... args) -{ - switch (RendererAPI::GetAPI()) - { - case RendererAPI::API::None: { - trace::Logger::Fatal("RendererAPI::None is currently not supported!"); - return nullptr; - } - break; - - case RendererAPI::API::OpenGL: { - return std::make_unique< OpenGL >(args...); - } - break; - } - - utils::Assert(false, fmt::format("API type({}) not supported!", RendererAPI::GetAPI())); - return nullptr; -} - -} // namespace shady::render \ No newline at end of file diff --git a/src/render/renderer.cpp b/src/render/renderer.cpp index f1bfc4c2..8d5ad82d 100644 --- a/src/render/renderer.cpp +++ b/src/render/renderer.cpp @@ -4,6 +4,7 @@ #include "buffer.hpp" #include "command.hpp" #include "common.hpp" +#include "deferred_pipeline.hpp" #include "shader.hpp" #include "texture.hpp" #include "trace/logger.hpp" @@ -106,7 +107,7 @@ Renderer::SetupData() // VkDeviceMemory stagingBufferMemory; //// Commands + draw count - VkDeviceSize bufferSize = commandsSize + sizeof(uint32_t); + const VkDeviceSize bufferSize = commandsSize + sizeof(uint32_t); Buffer::CreateBuffer(bufferSize, VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, @@ -114,7 +115,7 @@ Renderer::SetupData() void* data = nullptr; vkMapMemory(Data::vk_device, Data::m_indirectDrawsBufferMemory, 0, bufferSize, 0, &data); - memcpy(data, Data::m_renderCommands.data(), static_cast< size_t >(bufferSize)); + memcpy(data, Data::m_renderCommands.data(), bufferSize); memcpy(static_cast< uint8_t* >(data) + commandsSize, &Data::m_numMeshes, sizeof(uint32_t)); @@ -135,7 +136,7 @@ struct QueueFamilyIndices std::optional< uint32_t > graphicsFamily; std::optional< uint32_t > presentFamily; - bool + [[nodiscard]] bool isComplete() const { return graphicsFamily.has_value() && presentFamily.has_value(); @@ -182,7 +183,7 @@ checkValidationLayerSupport() for (const auto& extension : availableLayers) { - validationLayers.erase(extension.layerName); + validationLayers.erase(&extension.layerName[0]); } return validationLayers.empty(); @@ -271,6 +272,8 @@ findQueueFamilies(VkPhysicalDevice device, VkSurfaceKHR surface) i++; } + utils::Assert(indices.isComplete(), "Renderer: findQueueFamilies indices are not complete!\n"); + return indices; } @@ -317,7 +320,7 @@ checkDeviceExtensionSupport(VkPhysicalDevice device) for (const auto& extension : availableExtensions) { - requiredExtensions.erase(extension.extensionName); + requiredExtensions.erase(&extension.extensionName[0]); } return requiredExtensions.empty(); @@ -326,23 +329,23 @@ checkDeviceExtensionSupport(VkPhysicalDevice device) bool isDeviceSuitable(VkPhysicalDevice device, VkSurfaceKHR surface) { - QueueFamilyIndices indices = findQueueFamilies(device, surface); + const auto indices = findQueueFamilies(device, surface); - bool extensionsSupported = checkDeviceExtensionSupport(device); + const auto extensionsSupported = checkDeviceExtensionSupport(device); - bool swapChainAdequate = false; + auto swapChainAdequate = false; if (extensionsSupported) { - SwapChainSupportDetails swapChainSupport = querySwapChainSupport(device, surface); + const auto swapChainSupport = querySwapChainSupport(device, surface); swapChainAdequate = !swapChainSupport.formats.empty() && !swapChainSupport.presentModes.empty(); } - VkPhysicalDeviceFeatures supportedFeatures; + VkPhysicalDeviceFeatures supportedFeatures{}; vkGetPhysicalDeviceFeatures(device, &supportedFeatures); // Make sure we use discrete GPU - VkPhysicalDeviceProperties physicalDeviceProperties; + VkPhysicalDeviceProperties physicalDeviceProperties{}; vkGetPhysicalDeviceProperties(device, &physicalDeviceProperties); auto isDiscrete = physicalDeviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU; @@ -353,11 +356,11 @@ isDeviceSuitable(VkPhysicalDevice device, VkSurfaceKHR surface) VkSampleCountFlagBits getMaxUsableSampleCount(VkPhysicalDevice& physicalDevice) { - VkPhysicalDeviceProperties physicalDeviceProperties; + VkPhysicalDeviceProperties physicalDeviceProperties{}; vkGetPhysicalDeviceProperties(physicalDevice, &physicalDeviceProperties); - VkSampleCountFlags counts = physicalDeviceProperties.limits.framebufferColorSampleCounts - & physicalDeviceProperties.limits.framebufferDepthSampleCounts; + const VkSampleCountFlags counts = physicalDeviceProperties.limits.framebufferColorSampleCounts + & physicalDeviceProperties.limits.framebufferDepthSampleCounts; if (counts & VK_SAMPLE_COUNT_64_BIT) { return VK_SAMPLE_COUNT_64_BIT; @@ -407,15 +410,9 @@ chooseSwapPresentMode(const std::vector< VkPresentModeKHR >& availablePresentMod // non-tearing present mode available return availablePresentMode == VK_PRESENT_MODE_MAILBOX_KHR; }); - if (found != availablePresentModes.end()) - { - return *found; - } - else - { - // VK_PRESENT_MODE_FIFO_KHR is v-sync - return VK_PRESENT_MODE_FIFO_KHR; - } + + // VK_PRESENT_MODE_FIFO_KHR is v-sync + return found != availablePresentModes.end() ? *found : VK_PRESENT_MODE_FIFO_KHR; } VkExtent2D @@ -445,7 +442,7 @@ chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities, GLFWwindow* windo void Renderer::CreateVertexBuffer() { - VkDeviceSize bufferSize = sizeof(Data::vertices[0]) * Data::vertices.size(); + const VkDeviceSize bufferSize = sizeof(Data::vertices[0]) * Data::vertices.size(); VkBuffer stagingBuffer = {}; VkDeviceMemory stagingBufferMemory = {}; @@ -455,7 +452,7 @@ Renderer::CreateVertexBuffer() void* data = nullptr; vkMapMemory(Data::vk_device, stagingBufferMemory, 0, bufferSize, 0, &data); - memcpy(data, Data::vertices.data(), static_cast< size_t >(bufferSize)); + memcpy(data, Data::vertices.data(), bufferSize); vkUnmapMemory(Data::vk_device, stagingBufferMemory); Buffer::CreateBuffer( @@ -471,7 +468,7 @@ Renderer::CreateVertexBuffer() void Renderer::CreateIndexBuffer() { - VkDeviceSize bufferSize = sizeof(Data::indices[0]) * Data::indices.size(); + const VkDeviceSize bufferSize = sizeof(Data::indices[0]) * Data::indices.size(); VkBuffer stagingBuffer = {}; VkDeviceMemory stagingBufferMemory = {}; @@ -481,7 +478,7 @@ Renderer::CreateIndexBuffer() void* data = nullptr; vkMapMemory(Data::vk_device, stagingBufferMemory, 0, bufferSize, 0, &data); - memcpy(data, Data::indices.data(), static_cast< size_t >(bufferSize)); + memcpy(data, Data::indices.data(), bufferSize); vkUnmapMemory(Data::vk_device, stagingBufferMemory); Buffer::CreateBuffer( @@ -497,8 +494,8 @@ Renderer::CreateIndexBuffer() void Renderer::CreateUniformBuffers() { - VkDeviceSize bufferSize = sizeof(UniformBufferObject); - VkDeviceSize SSBObufferSize = Data::perInstance.size() * sizeof(PerInstanceBuffer); + const VkDeviceSize bufferSize = sizeof(UniformBufferObject); + const VkDeviceSize SSBObufferSize = Data::perInstance.size() * sizeof(PerInstanceBuffer); const auto swapchainImagesSize = m_swapChainImages.size(); @@ -558,7 +555,7 @@ Renderer::CreateRenderPipeline() CreatePipelineCache(); - m_deferredPipeline.Initialize(Data::m_renderPass, m_swapChainImageViews, Data::m_pipelineCache); + DeferredPipeline::Initialize(Data::m_renderPass, m_swapChainImageViews, Data::m_pipelineCache); app::gui::Gui::Init({Data::m_swapChainExtent.width, Data::m_swapChainExtent.height}); // app::gui::Gui::UpdateUI({Data::m_swapChainExtent.width, Data::m_swapChainExtent.height}); CreateCommandBufferForDeferred(); @@ -587,13 +584,13 @@ Renderer::UpdateUniformBuffer(const scene::Camera* camera, const scene::Light* l memcpy(data2, Data::perInstance.data(), Data::perInstance.size() * sizeof(PerInstanceBuffer)); vkUnmapMemory(Data::vk_device, Data::m_ssboMemory[m_imageIndex]); - m_deferredPipeline.UpdateDeferred(camera, light); + DeferredPipeline::UpdateDeferred(camera, light); } void Renderer::CreateColorResources() { - VkFormat colorFormat = m_swapChainImageFormat; + const VkFormat colorFormat = m_swapChainImageFormat; std::tie(m_colorImage, m_colorImageMemory) = Texture::CreateImage( Data::m_swapChainExtent.width, Data::m_swapChainExtent.height, 1, @@ -607,7 +604,7 @@ Renderer::CreateColorResources() void Renderer::CreateDepthResources() { - VkFormat depthFormat = FindDepthFormat(); + const VkFormat depthFormat = FindDepthFormat(); const auto [depthImage, depthImageMemory] = Texture::CreateImage( Data::m_swapChainExtent.width, Data::m_swapChainExtent.height, 1, @@ -646,7 +643,8 @@ Renderer::Draw() VkSubmitInfo submitInfo{}; submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - std::array waitStages = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT}; + std::array< VkPipelineStageFlags, 1 > waitStages = { + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT}; submitInfo.pWaitDstStageMask = waitStages.data(); // Wait for swap chain presentation to finish @@ -654,12 +652,12 @@ Renderer::Draw() submitInfo.waitSemaphoreCount = 1; // Signal ready with offscreen semaphore - submitInfo.pSignalSemaphores = &m_deferredPipeline.GetOffscreenSemaphore(); + submitInfo.pSignalSemaphores = &DeferredPipeline::GetOffscreenSemaphore(); submitInfo.signalSemaphoreCount = 1; // Submit work submitInfo.commandBufferCount = 1; - submitInfo.pCommandBuffers = &m_deferredPipeline.GetOffscreenCmdBuffer(); + submitInfo.pCommandBuffers = &DeferredPipeline::GetOffscreenCmdBuffer(); VK_CHECK(vkQueueSubmit(Data::vk_graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE), "failed to submit offscreen draw command buffer!"); @@ -668,7 +666,7 @@ Renderer::Draw() // Scene rendering // - submitInfo.pWaitSemaphores = &m_deferredPipeline.GetOffscreenSemaphore(); + submitInfo.pWaitSemaphores = &DeferredPipeline::GetOffscreenSemaphore(); submitInfo.pSignalSemaphores = &m_renderFinishedSemaphores[currentFrame]; @@ -768,13 +766,17 @@ Renderer::CreateDevice() utils::Assert(Data::vk_physicalDevice != VK_NULL_HANDLE, "failed to find a suitable GPU!"); - QueueFamilyIndices indices = findQueueFamilies(Data::vk_physicalDevice, Data::m_surface); + const auto indices = findQueueFamilies(Data::vk_physicalDevice, Data::m_surface); + + std::vector< VkDeviceQueueCreateInfo > queueCreateInfos{}; - std::vector< VkDeviceQueueCreateInfo > queueCreateInfos; - std::set< uint32_t > uniqueQueueFamilies = {indices.graphicsFamily.value(), - indices.presentFamily.value()}; + // indices.isComplete() is called in findQueueFamilies + // NOLINTBEGIN + const std::set< uint32_t > uniqueQueueFamilies = {indices.graphicsFamily.value(), + indices.presentFamily.value()}; + // NOLINTEND - float queuePriority = 1.0f; + const auto queuePriority = 1.0f; for (auto queueFamily : uniqueQueueFamilies) { VkDeviceQueueCreateInfo queueCreateInfo{}; @@ -821,19 +823,22 @@ Renderer::CreateDevice() VK_CHECK(vkCreateDevice(Data::vk_physicalDevice, &createInfo, nullptr, &Data::vk_device), "failed to create logical device!"); + // indices.isComplete() is called in findQueueFamilies + + // NOLINTBEGIN vkGetDeviceQueue(Data::vk_device, indices.graphicsFamily.value(), 0, &Data::vk_graphicsQueue); vkGetDeviceQueue(Data::vk_device, indices.presentFamily.value(), 0, &Data::m_presentQueue); + // NOLINTEND } void Renderer::CreateSwapchain(GLFWwindow* windowHandle) { - SwapChainSupportDetails swapChainSupport = - querySwapChainSupport(Data::vk_physicalDevice, Data::m_surface); + const auto swapChainSupport = querySwapChainSupport(Data::vk_physicalDevice, Data::m_surface); - VkSurfaceFormatKHR surfaceFormat = chooseSwapSurfaceFormat(swapChainSupport.formats); - VkPresentModeKHR presentMode = chooseSwapPresentMode(swapChainSupport.presentModes); - VkExtent2D extent = chooseSwapExtent(swapChainSupport.capabilities, windowHandle); + const auto surfaceFormat = chooseSwapSurfaceFormat(swapChainSupport.formats); + const auto presentMode = chooseSwapPresentMode(swapChainSupport.presentModes); + const auto extent = chooseSwapExtent(swapChainSupport.capabilities, windowHandle); uint32_t imageCount = swapChainSupport.capabilities.minImageCount + 1; if (swapChainSupport.capabilities.maxImageCount > 0 @@ -854,15 +859,19 @@ Renderer::CreateSwapchain(GLFWwindow* windowHandle) swapChainCreateInfo.imageArrayLayers = 1; swapChainCreateInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; - QueueFamilyIndices indicesSecond = findQueueFamilies(Data::vk_physicalDevice, Data::m_surface); - uint32_t queueFamilyIndices[2] = {indicesSecond.graphicsFamily.value(), - indicesSecond.presentFamily.value()}; + const auto indicesSecond = findQueueFamilies(Data::vk_physicalDevice, Data::m_surface); + // indices.isComplete() is called in findQueueFamilies + + // NOLINTBEGIN + const std::array< uint32_t, 2 > queueFamilyIndices = {indicesSecond.graphicsFamily.value(), + indicesSecond.presentFamily.value()}; + // NOLINTEND if (indicesSecond.graphicsFamily != indicesSecond.presentFamily) { swapChainCreateInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT; swapChainCreateInfo.queueFamilyIndexCount = 2; - swapChainCreateInfo.pQueueFamilyIndices = queueFamilyIndices; + swapChainCreateInfo.pQueueFamilyIndices = queueFamilyIndices.data(); } else { @@ -951,7 +960,7 @@ Renderer::CreateRenderPass() subpass.pDepthStencilAttachment = &depthAttachmentRef; // subpass.pResolveAttachments = &colorAttachmentResolveRef; - std::array< VkSubpassDependency, 2 > dependencies; + std::array< VkSubpassDependency, 2 > dependencies{}; dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL; dependencies[0].dstSubpass = 0; @@ -1029,6 +1038,10 @@ Renderer::CreateCommandPool() VkCommandPoolCreateInfo poolInfo{}; poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + + // indices.isComplete() is called in findQueueFamilies + + // NOLINTNEXTLINE poolInfo.queueFamilyIndex = queueFamilyIndicesTwo.graphicsFamily.value(); VK_CHECK(vkCreateCommandPool(Data::vk_device, &poolInfo, nullptr, &Data::vk_commandPool), @@ -1095,11 +1108,11 @@ Renderer::CreateCommandBufferForDeferred() * STAGE 2 - COMPOSITION */ vkCmdBindDescriptorSets(m_commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, - m_deferredPipeline.GetPipelineLayout(), 0, 1, - &m_deferredPipeline.GetDescriptorSet(), 0, nullptr); + DeferredPipeline::GetPipelineLayout(), 0, 1, + &DeferredPipeline::GetDescriptorSet(), 0, nullptr); vkCmdBindPipeline(m_commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, - m_deferredPipeline.GetCompositionPipeline()); + DeferredPipeline::GetCompositionPipeline()); // Final composition as full screen quad vkCmdDraw(m_commandBuffers[i], 3, 1, 0, 0); diff --git a/src/render/shader.hpp b/src/render/shader.hpp index a1212a9c..a1666b37 100644 --- a/src/render/shader.hpp +++ b/src/render/shader.hpp @@ -12,7 +12,7 @@ struct ShaderInfoWrapper * This should be called after the pipeline is created */ void - Destroy() + Destroy() const { vkDestroyShaderModule(device, shaderInfo.module, nullptr); } diff --git a/src/render/texture.cpp b/src/render/texture.cpp index 735bdd00..7903bf6f 100644 --- a/src/render/texture.cpp +++ b/src/render/texture.cpp @@ -66,8 +66,8 @@ Texture::CreateImage(uint32_t width, uint32_t height, uint32_t mipLevels, VkSampleCountFlagBits numSamples, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, bool cubemap) { - VkImage image; - VkDeviceMemory imageMemory; + VkImage image{}; + VkDeviceMemory imageMemory{}; VkImageCreateInfo imageInfo{}; imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; @@ -115,7 +115,7 @@ Texture::CreateImageView(VkImage image, VkFormat format, VkImageAspectFlags aspe viewInfo.subresourceRange.baseArrayLayer = 0; viewInfo.subresourceRange.layerCount = not cubemap ? 1 : 6; - VkImageView imageView; + VkImageView imageView{}; VK_CHECK(vkCreateImageView(Data::vk_device, &viewInfo, nullptr, &imageView), "Failed to create texture image view!"); @@ -125,7 +125,7 @@ Texture::CreateImageView(VkImage image, VkFormat format, VkImageAspectFlags aspe VkSampler Texture::CreateSampler(uint32_t mipLevels) { - VkSampler sampler; + VkSampler sampler{}; VkPhysicalDeviceProperties properties{}; vkGetPhysicalDeviceProperties(Data::vk_physicalDevice, &properties); @@ -221,9 +221,14 @@ Texture::GenerateMipmaps(VkImage image, VkFormat imageFormat, int32_t texWidth, &barrier); if (mipWidth > 1) + { mipWidth /= 2; + } + if (mipHeight > 1) + { mipHeight /= 2; + } } barrier.subresourceRange.baseMipLevel = mipLevels - 1; @@ -297,7 +302,7 @@ Texture::CopyBufferToCubemapImage(VkImage image, uint32_t texWidth, uint32_t tex bufferCopyRegion.imageExtent.width = texWidth; bufferCopyRegion.imageExtent.height = texHeight; bufferCopyRegion.imageExtent.depth = 1; - bufferCopyRegion.bufferOffset = static_cast(face * single_face_size); + bufferCopyRegion.bufferOffset = face * single_face_size; bufferCopyRegions.push_back(bufferCopyRegion); } diff --git a/src/render/texture.hpp b/src/render/texture.hpp index e2036f52..3eca2c9a 100644 --- a/src/render/texture.hpp +++ b/src/render/texture.hpp @@ -47,13 +47,13 @@ class Texture static void CopyBufferToCubemapImage(VkImage image, uint32_t texWidth, uint32_t texHeight, uint8_t* data); - std::pair< VkImageView, VkSampler > + [[nodiscard]] std::pair< VkImageView, VkSampler > GetImageViewAndSampler() const; void CreateTextureSampler(); - TextureType + [[nodiscard]] TextureType GetType() const; private: diff --git a/src/scene/camera.cpp b/src/scene/camera.cpp index ad600d65..eb98ed65 100644 --- a/src/scene/camera.cpp +++ b/src/scene/camera.cpp @@ -6,7 +6,7 @@ namespace shady::scene { Camera::Camera(const glm::mat4& projection, const glm::vec3& position) - : m_projectionMat(projection), m_position(position) + : projectionMat_(projection), position_(position) { UpdateViewMatrix(); } @@ -14,13 +14,13 @@ Camera::Camera(const glm::mat4& projection, const glm::vec3& position) void Camera::SetProjection(const glm::mat4& projection) { - m_projectionMat = projection; + projectionMat_ = projection; } const glm::mat4& Camera::GetProjection() const { - return m_projectionMat; + return projectionMat_; } void @@ -28,12 +28,12 @@ Camera::SetView(const glm::mat4& view) { const auto inversed = glm::inverse(view); - m_rightVector = glm::normalize(inversed[0]); - m_position = inversed[3]; - m_lookAtDirection = glm::vec3(inversed[1]) - m_position; - m_upVector = glm::normalize(glm::cross(m_rightVector, glm::normalize(m_lookAtDirection))); + rightVector_ = glm::normalize(inversed[0]); + position_ = inversed[3]; + lookAtDirection_ = glm::vec3(inversed[1]) - position_; + upVector_ = glm::normalize(glm::cross(rightVector_, glm::normalize(lookAtDirection_))); - m_viewMat = view; + viewMat_ = view; UpdateViewProjection(); } @@ -41,63 +41,63 @@ Camera::SetView(const glm::mat4& view) const glm::mat4& Camera::GetView() const { - return m_viewMat; + return viewMat_; } void Camera::SetViewProjection(const glm::mat4& viewProjection) { - m_viewProjectionMat = viewProjection; + viewProjectionMat_ = viewProjection; } const glm::mat4& Camera::GetViewProjection() const { - return m_viewProjectionMat; + return viewProjectionMat_; } void Camera::SetPosition(const glm::vec3& position) { - m_position = position; + position_ = position; UpdateViewMatrix(); } const glm::vec3& Camera::GetPosition() const { - return m_position; + return position_; } const glm::vec3& Camera::GetLookAtVec() const { - return m_lookAtDirection; + return lookAtDirection_; } const glm::vec3& Camera::GetUpVec() const { - return m_upVector; + return upVector_; } const glm::vec3& Camera::GetRightVec() const { - return m_rightVector; + return rightVector_; } void Camera::UpdateViewMatrix() { - m_viewMat = glm::lookAt(m_position, m_position + m_lookAtDirection, m_upVector); + viewMat_ = glm::lookAt(position_, position_ + lookAtDirection_, upVector_); UpdateViewProjection(); } void Camera::UpdateViewProjection() { - m_viewProjectionMat = m_projectionMat * m_viewMat; + viewProjectionMat_ = projectionMat_ * viewMat_; } } // namespace shady::scene \ No newline at end of file diff --git a/src/scene/camera.hpp b/src/scene/camera.hpp index c48c6682..42e8ca4a 100644 --- a/src/scene/camera.hpp +++ b/src/scene/camera.hpp @@ -4,45 +4,57 @@ namespace shady::scene { -enum class CameraType{ - orthographic, - perspective +enum class CameraType +{ + orthographic, + perspective }; class Camera { public: - Camera() = default; + Camera() = delete; + Camera(const Camera&) = delete; + Camera(Camera&&) = delete; + Camera& + operator=(const Camera&) = delete; + Camera& + operator=(Camera&&) = delete; + Camera(const glm::mat4& projection, const glm::vec3& position); virtual ~Camera() = default; void SetProjection(const glm::mat4&); - const glm::mat4& + + [[nodiscard]] const glm::mat4& GetProjection() const; void SetView(const glm::mat4&); - const glm::mat4& + + [[nodiscard]] const glm::mat4& GetView() const; void SetViewProjection(const glm::mat4&); - const glm::mat4& + + [[nodiscard]] const glm::mat4& GetViewProjection() const; void SetPosition(const glm::vec3&); - const glm::vec3& + + [[nodiscard]] const glm::vec3& GetPosition() const; - const glm::vec3& + [[nodiscard]] const glm::vec3& GetLookAtVec() const; - const glm::vec3& + [[nodiscard]] const glm::vec3& GetUpVec() const; - const glm::vec3& + [[nodiscard]] const glm::vec3& GetRightVec() const; virtual void @@ -62,14 +74,14 @@ class Camera UpdateViewProjection(); protected: - glm::mat4 m_projectionMat = glm::mat4(1.0f); - glm::mat4 m_viewMat = glm::mat4(1.0f); - glm::mat4 m_viewProjectionMat = glm::mat4(1.0f); - - glm::vec3 m_position = glm::vec3(0.0f); - const glm::vec3 m_worldUp = glm::vec3(0.0f, -1.0f, 0.0f); - glm::vec3 m_upVector = m_worldUp; - glm::vec3 m_rightVector = glm::vec3(0.0f, 0.0f, -1.0f); - glm::vec3 m_lookAtDirection = glm::vec3(1.0f, 0.0f, 0.0f); + glm::mat4 projectionMat_ = glm::mat4(1.0f); + glm::mat4 viewMat_ = glm::mat4(1.0f); + glm::mat4 viewProjectionMat_ = glm::mat4(1.0f); + + glm::vec3 position_ = glm::vec3(0.0f); + const glm::vec3 worldUp_ = glm::vec3(0.0f, -1.0f, 0.0f); + glm::vec3 upVector_ = worldUp_; + glm::vec3 rightVector_ = glm::vec3(0.0f, 0.0f, -1.0f); + glm::vec3 lookAtDirection_ = glm::vec3(1.0f, 0.0f, 0.0f); }; -} // namespace shady::render \ No newline at end of file +} // namespace shady::scene \ No newline at end of file diff --git a/src/scene/light.cpp b/src/scene/light.cpp index ea84fbf9..fe1f7095 100644 --- a/src/scene/light.cpp +++ b/src/scene/light.cpp @@ -6,35 +6,31 @@ namespace shady::scene { Light::Light(const glm::vec3& position, const glm::vec3& color, LightType type) - : m_position(position), m_color(color) + : position_(position), color_(color) { // auto buffer_type = render::FrameBufferType::SINGLE; switch (type) { case LightType::DIRECTIONAL_LIGHT: { - m_projectionMatrix = glm::ortho(-200.0f, 200.0f, -200.0f, 200.0f, 1.0f, 500.0f); - // m_projectionMatrix = glm::perspective(70.0f, 16.0f / 9.0f, 0.1f, 500.0f); - } - break; - - case LightType::POINT_LIGHT: { - m_projectionMatrix = glm::perspective(60.0f, 1.0f, 0.1f, 100.0f); - // buffer_type = render::FrameBufferType::CUBE; + projectionMatrix_ = glm::ortho(-200.0f, 200.0f, -200.0f, 200.0f, 1.0f, 500.0f); + // projectionMatrix_ = glm::perspective(70.0f, 16.0f / 9.0f, 0.1f, 500.0f); } break; + case LightType::POINT_LIGHT: case LightType::SPOTLIGHT: { - m_projectionMatrix = glm::perspective(60.0f, 1.0f, 0.1f, 100.0f); + projectionMatrix_ = glm::perspective(60.0f, 1.0f, 0.1f, 100.0f); + // buffer_type = render::FrameBufferType::CUBE; } break; } - // m_shadowBuffer = render::FrameBuffer::Create({m_shadowTextureWidth, m_shadowTextureHeight}, + // m_shadowBuffer = render::FrameBuffer::Create({shadowTextureWidth_, shadowTextureHeight_}, // buffer_type); - m_biasMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.5f)) + biasMatrix_ = glm::translate(glm::mat4(1.0f), glm::vec3(0.5f)) * glm::scale(glm::mat4(1.0f), glm::vec3(0.5f)); - m_lookAt = glm::vec3(0.0f, -1.0f, 0.0f); - m_upVec = glm::vec3(0.0f, 0.0f, 0.5f); + lookAt_ = glm::vec3(0.0f, -1.0f, 0.0f); + upVec_ = glm::vec3(0.0f, 0.0f, 0.5f); // m_shadowBuffer->MakeTextureResident(); UpdateViewProjection(); @@ -43,60 +39,60 @@ Light::Light(const glm::vec3& position, const glm::vec3& color, LightType type) const glm::mat4& Light::GetLightSpaceMat() const { - return m_lightSpaceMatrix; + return lightSpaceMatrix_; } const glm::mat4& Light::GetViewMat() const { - return m_viewMatrix; + return viewMatrix_; } glm::vec3 Light::GetPosition() const { - return m_position; + return position_; } glm::vec3 Light::GetLookAt() const { - return m_lookAt; + return lookAt_; } glm::vec3 Light::GetColor() const { - return m_color; + return color_; } void Light::SetColor(const glm::vec3& new_color) { - m_color = new_color; + color_ = new_color; } glm::tvec2< uint32_t > Light::GetLightmapSize() const { - return {m_shadowTextureWidth, m_shadowTextureHeight}; + return {shadowTextureWidth_, shadowTextureHeight_}; } void Light::MoveBy(const glm::vec3& moveBy) { - m_position += moveBy; + position_ += moveBy; UpdateViewProjection(); - // trace::Logger::Info("Light position {}", m_position); + // trace::Logger::Info("Light position {}", position_); } void Light::UpdateViewProjection() { - m_viewMatrix = glm::lookAt(m_position, m_lookAt, m_upVec); - m_lightSpaceMatrix = m_projectionMatrix * m_viewMatrix; - m_shadowMatrix = m_biasMatrix * m_lightSpaceMatrix; + viewMatrix_ = glm::lookAt(position_, lookAt_, upVec_); + lightSpaceMatrix_ = projectionMatrix_ * viewMatrix_; + shadowMatrix_ = biasMatrix_ * lightSpaceMatrix_; } } // namespace shady::scene diff --git a/src/scene/light.hpp b/src/scene/light.hpp index bf86f81b..e10dedcb 100644 --- a/src/scene/light.hpp +++ b/src/scene/light.hpp @@ -16,25 +16,25 @@ class Light public: Light(const glm::vec3& position, const glm::vec3& color, LightType type); - const glm::mat4& + [[nodiscard]] const glm::mat4& GetLightSpaceMat() const; - const glm::mat4& + [[nodiscard]] const glm::mat4& GetViewMat() const; - glm::vec3 + [[nodiscard]] glm::vec3 GetPosition() const; - glm::vec3 + [[nodiscard]] glm::vec3 GetLookAt() const; - glm::vec3 + [[nodiscard]] glm::vec3 GetColor() const; void SetColor(const glm::vec3& new_color); - glm::tvec2< uint32_t > + [[nodiscard]] glm::tvec2< uint32_t > GetLightmapSize() const; void @@ -45,20 +45,20 @@ class Light UpdateViewProjection(); private: - uint32_t m_shadowTextureWidth = 4096; - uint32_t m_shadowTextureHeight = 4096; + uint32_t shadowTextureWidth_ = 4096; + uint32_t shadowTextureHeight_ = 4096; // std::shared_ptr< render::FrameBuffer > m_shadowBuffer; - glm::vec3 m_position = glm::vec3(0.0f); - glm::vec3 m_lookAt = glm::vec3(0.0f); - glm::vec3 m_upVec = glm::vec3(0.0f); - glm::vec3 m_color = glm::vec3(1.0f); + glm::vec3 position_ = glm::vec3(0.0f); + glm::vec3 lookAt_ = glm::vec3(0.0f); + glm::vec3 upVec_ = glm::vec3(0.0f); + glm::vec3 color_ = glm::vec3(1.0f); - glm::mat4 m_projectionMatrix = glm::mat4(); - glm::mat4 m_viewMatrix = glm::mat4(); - glm::mat4 m_lightSpaceMatrix = glm::mat4(); - glm::mat4 m_biasMatrix = glm::mat4(); - glm::mat4 m_shadowMatrix = glm::mat4(); + glm::mat4 projectionMatrix_ = glm::mat4(); + glm::mat4 viewMatrix_ = glm::mat4(); + glm::mat4 lightSpaceMatrix_ = glm::mat4(); + glm::mat4 biasMatrix_ = glm::mat4(); + glm::mat4 shadowMatrix_ = glm::mat4(); }; } // namespace shady::scene diff --git a/src/scene/mesh.cpp b/src/scene/mesh.cpp index 68ade8c6..47c99e3a 100644 --- a/src/scene/mesh.cpp +++ b/src/scene/mesh.cpp @@ -4,60 +4,61 @@ namespace shady::scene { +//NOLINTNEXTLINE Mesh::Mesh(const std::string& name, std::vector< render::Vertex >&& vertices, std::vector< uint32_t >&& indices, render::TextureMaps&& textures) - : m_vertices(std::move(vertices)), - m_indices(std::move(indices)), - m_textures(std::move(textures)), - m_name(name) + : vertices_(std::move(vertices)), + indices_(std::move(indices)), + textures_(std::move(textures)), + name_(name) { } // void // Mesh::AddTexture(const render::TexturePtr& texture) //{ -// //m_textures.push_back(texture); +// //textures_.push_back(texture); //} void Mesh::Submit() { - render::Renderer::MeshLoaded(m_vertices, m_indices, m_textures, m_modelMat); + render::Renderer::MeshLoaded(vertices_, indices_, textures_, modelMat_); } void Mesh::Draw(const std::string& /*modelName*/, const glm::mat4& /*modelMat*/, const glm::vec4& /*tintColor*/) { - // render::Renderer3D::DrawMesh(m_name, modelMat, m_textures, tintColor); - render::Renderer::MeshLoaded(m_vertices, m_indices, m_textures, m_modelMat); + // render::Renderer3D::DrawMesh(name_, modelMat, textures_, tintColor); + render::Renderer::MeshLoaded(vertices_, indices_, textures_, modelMat_); } void Mesh::Scale(const glm::vec3& scale) { - m_scaleMat = glm::scale(glm::mat4(1.0f), scale); + scaleMat_ = glm::scale(glm::mat4(1.0f), scale); RebuildModelMat(); } void Mesh::Rotate(float roateVal, const glm::vec3& axis) { - m_rotateMat = glm::rotate(glm::mat4(1.0f), roateVal, axis); + rotateMat_ = glm::rotate(glm::mat4(1.0f), roateVal, axis); RebuildModelMat(); } void Mesh::Translate(const glm::vec3& translateVal) { - m_translateMat = glm::translate(glm::mat4(1.0f), translateVal); + translateMat_ = glm::translate(glm::mat4(1.0f), translateVal); RebuildModelMat(); } void Mesh::RebuildModelMat() { - m_modelMat = m_translateMat * m_scaleMat * m_rotateMat; + modelMat_ = translateMat_ * scaleMat_ * rotateMat_; } } // namespace shady::scene diff --git a/src/scene/mesh.hpp b/src/scene/mesh.hpp index 7aa88641..a4a27e9a 100644 --- a/src/scene/mesh.hpp +++ b/src/scene/mesh.hpp @@ -37,17 +37,17 @@ class Mesh RebuildModelMat(); private: - glm::mat4 m_modelMat = glm::mat4(1.0f); + glm::mat4 modelMat_ = glm::mat4(1.0f); - glm::mat4 m_translateMat = glm::mat4(1.0f); - glm::mat4 m_rotateMat = glm::mat4(1.0f); - glm::mat4 m_scaleMat = glm::mat4(1.0f); + glm::mat4 translateMat_ = glm::mat4(1.0f); + glm::mat4 rotateMat_ = glm::mat4(1.0f); + glm::mat4 scaleMat_ = glm::mat4(1.0f); - std::vector< render::Vertex > m_vertices = {}; - std::vector< uint32_t > m_indices = {}; + std::vector< render::Vertex > vertices_ = {}; + std::vector< uint32_t > indices_ = {}; // render::TexturePtrVec m_textures = {}; - render::TextureMaps m_textures; - std::string m_name = "dummyMeshName"; + render::TextureMaps textures_; + std::string name_ = "dummyMeshName"; }; } // namespace shady::scene diff --git a/src/scene/model.cpp b/src/scene/model.cpp index 414a4ecf..08cc142a 100644 --- a/src/scene/model.cpp +++ b/src/scene/model.cpp @@ -1,8 +1,8 @@ #include "model.hpp" +#include "render/texture.hpp" +#include "render/vertex.hpp" #include "trace/logger.hpp" #include "utils/file_manager.hpp" -#include "render/vertex.hpp" -#include "render/texture.hpp" #include #include @@ -26,11 +26,25 @@ GetShadyTexFromAssimpTex(aiTextureType assimpTex) } } +static void +LoadMaterialTextures(aiMaterial* mat, aiTextureType type, render::TextureMaps& textures) +{ + for (uint32_t i = 0; i < mat->GetTextureCount(type); i++) + { + aiString str; + mat->GetTexture(type, i, &str); + + const auto texType = GetShadyTexFromAssimpTex(type); + render::TextureLibrary::CreateTexture(texType, str.C_Str()); + textures[static_cast< uint32_t >(texType)] = str.C_Str(); + } +} + Model::Model(const std::string& path, LoadFlags additionalAssimpFlags) { Assimp::Importer importer; - auto scene = importer.ReadFile( + const auto* scene = importer.ReadFile( path, aiProcess_FlipWindingOrder | aiProcess_GenSmoothNormals | aiProcess_Triangulate | /*aiProcess_CalcTangentSpace |*/ aiProcess_JoinIdenticalVertices | aiProcess_ValidateDataStructure | static_cast< uint32_t >(additionalAssimpFlags)); @@ -48,15 +62,15 @@ Model::Model(const std::string& path, LoadFlags additionalAssimpFlags) // Process ASSIMP's root node recursively ProcessNode(scene->mRootNode, scene); - m_name = scene->mRootNode->mName.C_Str(); - trace::Logger::Info("Loaded model: {} numVertices: {} numIndices: {}", m_name, m_numVertices, - m_numIndices); + name_ = scene->mRootNode->mName.C_Str(); + trace::Logger::Info("Loaded model: {} numVertices: {} numIndices: {}", name_, numVertices_, + numIndices_); } void Model::ScaleModel(const glm::vec3& scale) { - for (auto& mesh : m_meshes) + for (auto& mesh : meshes_) { mesh.Scale(scale); } @@ -65,7 +79,7 @@ Model::ScaleModel(const glm::vec3& scale) void Model::TranslateModel(const glm::vec3& translate) { - for (auto& mesh : m_meshes) + for (auto& mesh : meshes_) { mesh.Translate(translate); } @@ -74,7 +88,7 @@ Model::TranslateModel(const glm::vec3& translate) void Model::RotateModel(const glm::vec3& rotate, float angle) { - for (auto& mesh : m_meshes) + for (auto& mesh : meshes_) { mesh.Rotate(angle, rotate); } @@ -83,7 +97,7 @@ Model::RotateModel(const glm::vec3& rotate, float angle) void Model::Submit() { - for (auto& mesh : m_meshes) + for (auto& mesh : meshes_) { mesh.Submit(); } @@ -92,16 +106,16 @@ Model::Submit() void Model::Draw() { - for (auto& mesh : m_meshes) + for (auto& mesh : meshes_) { - mesh.Draw(m_name, glm::mat4(1.0f), {1.0f, 1.0f, 1.0f, 1.0f}); + mesh.Draw(name_, glm::mat4(1.0f), {1.0f, 1.0f, 1.0f, 1.0f}); } } std::vector< Mesh >& Model::GetMeshes() { - return m_meshes; + return meshes_; } void @@ -112,8 +126,8 @@ Model::ProcessNode(aiNode* node, const aiScene* scene) // The node object only contains indices to index the actual objects in the scene. // The scene contains all the data, node is just to keep stuff organized (like relations // between nodes). - auto mesh = scene->mMeshes[node->mMeshes[i]]; - m_meshes.push_back(ProcessMesh(mesh, scene)); + auto* mesh = scene->mMeshes[node->mMeshes[i]]; + meshes_.push_back(ProcessMesh(mesh, scene)); } trace::Logger::Debug("Processed node: {}", node->mName.C_Str()); @@ -135,8 +149,8 @@ Model::ProcessMesh(aiMesh* mesh, const aiScene* scene) // Walk through each of the mesh's vertices for (uint32_t i = 0; i < mesh->mNumVertices; i++) { - render::Vertex vertex; - glm::vec3 vector; + render::Vertex vertex{}; + glm::vec3 vector{}; // Positions vector.x = mesh->mVertices[i].x; vector.y = mesh->mVertices[i].y; @@ -155,7 +169,7 @@ Model::ProcessMesh(aiMesh* mesh, const aiScene* scene) // Texture Coordinates if (mesh->HasTextureCoords(0)) { - glm::vec2 vec; + glm::vec2 vec{}; // A vertex can contain up to 8 different texture coordinates. We thus make the assumption // that we won't use models where a vertex can have multiple texture coordinates so we // always take the first set (0). @@ -180,12 +194,12 @@ Model::ProcessMesh(aiMesh* mesh, const aiScene* scene) vertices.push_back(vertex); } - std::vector< uint32_t > indices; + std::vector< uint32_t > indices{}; // Now walk through each of the mesh's faces (a face is a mesh its triangle) and retrieve the // corresponding vertex indices. for (uint32_t i = 0; i < mesh->mNumFaces; i++) { - aiFace face = mesh->mFaces[i]; + const auto face = mesh->mFaces[i]; // Retrieve all indices of the face and store them in the indices vector for (uint32_t j = 0; j < face.mNumIndices; j++) { @@ -198,61 +212,47 @@ Model::ProcessMesh(aiMesh* mesh, const aiScene* scene) // Process materials aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex]; - LoadMaterialTextures(material, aiTextureType_DIFFUSE, textures); - // LoadMaterialTextures(material, aiTextureType_SPECULAR, textures); - LoadMaterialTextures(material, aiTextureType_UNKNOWN, textures); - LoadMaterialTextures(material, aiTextureType_NORMALS, textures); - + LoadMaterialTextures(material, aiTextureType_DIFFUSE, textures); + // LoadMaterialTextures(material, aiTextureType_SPECULAR, textures); + LoadMaterialTextures(material, aiTextureType_UNKNOWN, textures); + LoadMaterialTextures(material, aiTextureType_NORMALS, textures); trace::Logger::Debug("Processed mesh: {}", mesh->mName.C_Str()); - m_numVertices += mesh->mNumVertices; - m_numIndices += static_cast< uint32_t >(indices.size()); + numVertices_ += mesh->mNumVertices; + numIndices_ += static_cast< uint32_t >(indices.size()); + // NOLINTNEXTLINE return Mesh(mesh->mName.C_Str(), std::move(vertices), std::move(indices), std::move(textures)); } -void -Model::LoadMaterialTextures(aiMaterial* mat, aiTextureType type, render::TextureMaps& textures) -{ - for (uint32_t i = 0; i < mat->GetTextureCount(type); i++) - { - aiString str; - mat->GetTexture(type, i, &str); - - const auto texType = GetShadyTexFromAssimpTex(type); - render::TextureLibrary::CreateTexture(texType, str.C_Str()); - textures[static_cast< uint32_t >(texType)] = str.C_Str(); - } -} - std::unique_ptr< Model > Model::CreatePlane() { auto model = std::make_unique< Model >(); model->GetMeshes().push_back({"Plane", {{ - {25.0f, -0.5f, 25.0f}, // Position - {0.0f, 1.0f, 0.0f}, // Normal - {25.0f, 0.0f}, // Texcoord - {50.0f, 0.0f, 0.0f} // Tangent + {25.0f, -0.5f, 25.0f}, // Position + {0.0f, 1.0f, 0.0f}, // Normal + {25.0f, 0.0f}, // Texcoord + {50.0f, 0.0f, 0.0f} // Tangent }, { - {-25.0f, -0.5f, 25.0f}, // Position - {0.0f, 1.0f, 0.0f}, // Normal - {0.0f, 0.0f}, // Texcoord + {-25.0f, -0.5f, 25.0f}, // Position + {0.0f, 1.0f, 0.0f}, // Normal + {0.0f, 0.0f}, // Texcoord {50.0f, 0.0f, 0.0f} // Tangent }, { {-25.0f, -0.5f, -25.0f}, // Position {0.0f, 1.0f, 0.0f}, // Normal {0.0f, 25.0f}, // Texcoord - {50.0f, 0.0f, 0.0f} // Tangent + {50.0f, 0.0f, 0.0f} // Tangent }, { - {25.0f, -0.5f, -25.0f}, // Position - {0.0f, 1.0f, 0.0f}, // Normal - {25.0f, 25.0f}, // Texcoord + {25.0f, -0.5f, -25.0f}, // Position + {0.0f, 1.0f, 0.0f}, // Normal + {25.0f, 25.0f}, // Texcoord {50.0f, 0.0f, 0.0f} // Tangent }}, {2, 1, 0, 3, 2, 0}, // Indices diff --git a/src/scene/model.hpp b/src/scene/model.hpp index e2822b0e..0e5526f8 100644 --- a/src/scene/model.hpp +++ b/src/scene/model.hpp @@ -45,10 +45,10 @@ class Model void Draw(); - std::vector< Mesh >& + [[nodiscard]] std::vector< Mesh >& GetMeshes(); - static std::unique_ptr< Model > + [[nodiscard]] static std::unique_ptr< Model > CreatePlane(); // void @@ -58,18 +58,15 @@ class Model void ProcessNode(aiNode* node, const aiScene* scene); - Mesh + [[nodiscard]] Mesh ProcessMesh(aiMesh* mesh, const aiScene* scene); - void - LoadMaterialTextures(aiMaterial* mat, aiTextureType type, render::TextureMaps& textures); - private: - std::vector< Mesh > m_meshes = {}; - uint32_t m_numVertices = 0; - uint32_t m_numIndices = 0; + std::vector< Mesh > meshes_ = {}; + uint32_t numVertices_ = 0; + uint32_t numIndices_ = 0; - std::string m_name = "DefaultName"; + std::string name_ = "DefaultName"; }; } // namespace shady::scene diff --git a/src/scene/orthographic_camera.cpp b/src/scene/orthographic_camera.cpp index 113bae68..0cf880b0 100644 --- a/src/scene/orthographic_camera.cpp +++ b/src/scene/orthographic_camera.cpp @@ -11,6 +11,7 @@ OrthographicCamera::OrthographicCamera(const glm::mat4& projection, const glm::v OrthographicCamera::OrthographicCamera(float left, float right, float top, float bottom, const glm::vec3& position) + //NOLINTNEXTLINE : Camera(glm::ortho(left, right, top, bottom, -1.0f, 10.0f), position) { } diff --git a/src/scene/orthographic_camera.hpp b/src/scene/orthographic_camera.hpp index 3b64b398..429d63cb 100644 --- a/src/scene/orthographic_camera.hpp +++ b/src/scene/orthographic_camera.hpp @@ -7,6 +7,15 @@ namespace shady::scene { class OrthographicCamera : public Camera { public: + OrthographicCamera() = delete; + OrthographicCamera(const OrthographicCamera&) = delete; + OrthographicCamera(OrthographicCamera&&) = delete; + OrthographicCamera& + operator=(const OrthographicCamera&) = delete; + OrthographicCamera& + operator=(OrthographicCamera&&) = delete; + + OrthographicCamera(const glm::mat4& projection, const glm::vec3& position); OrthographicCamera(float left, float right, float top, float bottom, const glm::vec3& position); diff --git a/src/scene/perspective_camera.cpp b/src/scene/perspective_camera.cpp index 2cf74b99..97404c13 100644 --- a/src/scene/perspective_camera.cpp +++ b/src/scene/perspective_camera.cpp @@ -19,21 +19,21 @@ PerspectiveCamera::PerspectiveCamera(float fieldOfView, float aspectRatio, float void PerspectiveCamera::MouseMovement(const glm::vec2& mouseMovement) { - m_yaw += mouseMovement.x; - m_pitch += mouseMovement.y; + yaw_ += mouseMovement.x; + pitch_ += mouseMovement.y; - if (m_constrainPitch) + if (constrainPitch_) { - m_pitch = glm::clamp(m_pitch, -89.0f, 89.0f); + pitch_ = glm::clamp(pitch_, -89.0f, 89.0f); } - m_lookAtDirection.x = -glm::cos(glm::radians(m_yaw)) * glm::cos(glm::radians(m_pitch)); - m_lookAtDirection.y = glm::sin(glm::radians(m_pitch)); - m_lookAtDirection.z = -glm::sin(glm::radians(m_yaw)) * glm::cos(glm::radians(m_pitch)); - m_lookAtDirection = glm::normalize(m_lookAtDirection); + lookAtDirection_.x = -glm::cos(glm::radians(yaw_)) * glm::cos(glm::radians(pitch_)); + lookAtDirection_.y = glm::sin(glm::radians(pitch_)); + lookAtDirection_.z = -glm::sin(glm::radians(yaw_)) * glm::cos(glm::radians(pitch_)); + lookAtDirection_ = glm::normalize(lookAtDirection_); - m_rightVector = glm::normalize(glm::cross(m_lookAtDirection, m_worldUp)); - m_upVector = glm::normalize(glm::cross(m_rightVector, m_lookAtDirection)); + rightVector_ = glm::normalize(glm::cross(lookAtDirection_, worldUp_)); + upVector_ = glm::normalize(glm::cross(rightVector_, lookAtDirection_)); UpdateViewMatrix(); } @@ -43,10 +43,10 @@ PerspectiveCamera::MoveCamera(const glm::vec2& leftRightVec) { constexpr auto cameraSpeed = 0.5f; - trace::Logger::Trace("Camera Pos:{} LookAtDir:{} RightVec:{}", m_position, m_lookAtDirection, - m_rightVector); - m_position += cameraSpeed * (leftRightVec.y * m_lookAtDirection); - m_position += cameraSpeed * (leftRightVec.x * m_rightVector); + trace::Logger::Trace("Camera Pos:{} LookAtDir:{} RightVec:{}", position_, lookAtDirection_, + rightVector_); + position_ += cameraSpeed * (leftRightVec.y * lookAtDirection_); + position_ += cameraSpeed * (leftRightVec.x * rightVector_); UpdateViewMatrix(); } @@ -54,10 +54,10 @@ PerspectiveCamera::MoveCamera(const glm::vec2& leftRightVec) void PerspectiveCamera::RotateCamera(float /*angle*/, const glm::vec3& /*axis*/) { - m_lookAtDirection = glm::normalize(m_lookAtDirection); + lookAtDirection_ = glm::normalize(lookAtDirection_); - m_rightVector = glm::normalize(glm::cross(m_lookAtDirection, m_worldUp)); - m_upVector = glm::normalize(glm::cross(m_rightVector, m_lookAtDirection)); + rightVector_ = glm::normalize(glm::cross(lookAtDirection_, worldUp_)); + upVector_ = glm::normalize(glm::cross(rightVector_, lookAtDirection_)); UpdateViewMatrix(); } diff --git a/src/scene/perspective_camera.hpp b/src/scene/perspective_camera.hpp index 886e81d1..b715915a 100644 --- a/src/scene/perspective_camera.hpp +++ b/src/scene/perspective_camera.hpp @@ -7,6 +7,14 @@ namespace shady::scene { class PerspectiveCamera : public Camera { public: + PerspectiveCamera() = delete; + PerspectiveCamera(const PerspectiveCamera&) = delete; + PerspectiveCamera(PerspectiveCamera&&) = delete; + PerspectiveCamera& + operator=(const PerspectiveCamera&) = delete; + PerspectiveCamera& + operator=(PerspectiveCamera&&) = delete; + PerspectiveCamera(const glm::mat4& projection, const glm::vec3& position); PerspectiveCamera(float fieldOfView, float aspectRatio, float nearClip, float farClip, const glm::vec3& position); @@ -23,9 +31,9 @@ class PerspectiveCamera : public Camera RotateCamera(float angle, const glm::vec3& axis) override; private: - float m_yaw = 0.0f; - float m_pitch = 0.0f; - bool m_constrainPitch = true; + float yaw_ = 0.0f; + float pitch_ = 0.0f; + bool constrainPitch_ = true; }; } // namespace shady::scene diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index bfb365e6..f31d5c8c 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -37,7 +37,7 @@ void Scene::Render(int32_t /*windowWidth*/, int32_t /*windowHeight*/) void Scene::LoadDefault() { - time::ScopedTimer loadScope("Scene::LoadDefault"); + const time::ScopedTimer loadScope("Scene::LoadDefault"); AddModel((utils::FileManager::MODELS_DIR / "sponza" / "glTF" / "Sponza.gltf").string(), scene::LoadFlags::FlipUV); diff --git a/src/scene/skybox.cpp b/src/scene/skybox.cpp index 9c6c119a..89f22cc0 100644 --- a/src/scene/skybox.cpp +++ b/src/scene/skybox.cpp @@ -121,7 +121,7 @@ Skybox::CreateBuffers() void Skybox::UpdateBuffers(const scene::Camera* camera) { - SkyboxUBO buffer; + SkyboxUBO buffer{}; buffer.viewProjection = camera->GetProjection() * glm::mat4(glm::mat3(camera->GetView())); m_uniformBuffer.CopyData(&buffer); @@ -182,7 +182,7 @@ Skybox::CreateDescriptorSet() VkDescriptorBufferInfo bufferInfo{}; - bufferInfo.buffer = m_uniformBuffer.m_buffer; + bufferInfo.buffer = m_uniformBuffer.GetBuffer(); bufferInfo.offset = 0; bufferInfo.range = sizeof(SkyboxUBO); @@ -229,8 +229,8 @@ Skybox::CreatePipeline() auto [vertexInfo, fragmentInfo] = Shader::CreateShader(Data::vk_device, "default/skybox.vert.spv", "default/skybox.frag.spv"); - VkPipelineShaderStageCreateInfo shaderStages[] = {vertexInfo.shaderInfo, - fragmentInfo.shaderInfo}; + std::array< VkPipelineShaderStageCreateInfo, 2 > shaderStages = {vertexInfo.shaderInfo, + fragmentInfo.shaderInfo}; VkPipelineVertexInputStateCreateInfo vertexInputInfo{}; vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; @@ -318,7 +318,7 @@ Skybox::CreatePipeline() VkGraphicsPipelineCreateInfo pipelineInfo{}; pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; pipelineInfo.stageCount = 2; - pipelineInfo.pStages = shaderStages; + pipelineInfo.pStages = shaderStages.data(); pipelineInfo.pVertexInputState = &vertexInputInfo; pipelineInfo.pInputAssemblyState = &inputAssembly; pipelineInfo.pViewportState = &viewportState; @@ -343,9 +343,9 @@ Skybox::Draw(VkCommandBuffer commandBuffer) &m_descriptorSet, 0, nullptr); vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipeline); - VkDeviceSize offsets[1] = {0}; - vkCmdBindVertexBuffers(commandBuffer, 0, 1, &m_vertexBuffer.m_buffer, offsets); - vkCmdBindIndexBuffer(commandBuffer, m_indexBuffer.m_buffer, 0, VK_INDEX_TYPE_UINT32); + std::array offsets = {0}; + vkCmdBindVertexBuffers(commandBuffer, 0, 1, &m_vertexBuffer.GetBuffer(), offsets.data()); + vkCmdBindIndexBuffer(commandBuffer, m_indexBuffer.GetBuffer(), 0, VK_INDEX_TYPE_UINT32); vkCmdDrawIndexed(commandBuffer, 36, 1, 0, 0, 0); } diff --git a/src/time/scoped_timer.cpp b/src/time/scoped_timer.cpp index 2fc995ec..66b4e280 100644 --- a/src/time/scoped_timer.cpp +++ b/src/time/scoped_timer.cpp @@ -5,9 +5,10 @@ namespace shady::time { ScopedTimer::ScopedTimer(std::string&& logMsg) : m_logMsg(std::move(logMsg)) { - m_timer.ToggleTimer(); + static_cast(m_timer.ToggleTimer()); } +//NOLINTNEXTLINE ScopedTimer::~ScopedTimer() { trace::Logger::Debug("{} took {}", m_logMsg, m_timer.ToggleTimer().ToString()); diff --git a/src/time/scoped_timer.hpp b/src/time/scoped_timer.hpp index 4d362010..8b854a7a 100644 --- a/src/time/scoped_timer.hpp +++ b/src/time/scoped_timer.hpp @@ -9,6 +9,11 @@ namespace shady::time { class ScopedTimer { public: + ScopedTimer(const ScopedTimer&) = delete; + ScopedTimer(ScopedTimer&&) = delete; + ScopedTimer& operator=(const ScopedTimer&) = delete; + ScopedTimer& operator=(ScopedTimer&&) = delete; + explicit ScopedTimer(std::string&& logMsg); ~ScopedTimer(); @@ -17,6 +22,7 @@ class ScopedTimer Timer m_timer; }; +//NOLINTNEXTLINE #define SCOPED_TIMER(str) shady::time::ScopedTimer t(std::move(str)); } // namespace shady::time diff --git a/src/time/timer.cpp b/src/time/timer.cpp index 8580ee5e..59179aaa 100644 --- a/src/time/timer.cpp +++ b/src/time/timer.cpp @@ -4,30 +4,30 @@ namespace shady::time { -TimeStep::TimeStep(milliseconds time) : m_time(time) +TimeStep::TimeStep(milliseconds time) : time_(time) { } std::string TimeStep::ToString() const { - return fmt::format("{}ms", m_time.count()); + return fmt::format("{}ms", time_.count()); } seconds TimeStep::GetSeconds() const { - return std::chrono::duration_cast< seconds >(m_time); + return std::chrono::duration_cast< seconds >(time_); } milliseconds TimeStep::GetMilliseconds() const { - return m_time; + return time_; } -Timer::Timer() : m_lastTimeStamp(std::chrono::steady_clock::now()) +Timer::Timer() : lastTimeStamp_(std::chrono::steady_clock::now()) { } @@ -35,9 +35,9 @@ TimeStep Timer::ToggleTimer() { const auto timeNow = std::chrono::steady_clock::now(); - const auto step = std::chrono::duration_cast< milliseconds >(timeNow - m_lastTimeStamp); + const auto step = std::chrono::duration_cast< milliseconds >(timeNow - lastTimeStamp_); - m_lastTimeStamp = timeNow; + lastTimeStamp_ = timeNow; return TimeStep{step}; } diff --git a/src/time/timer.hpp b/src/time/timer.hpp index 64c36cc3..237507ec 100644 --- a/src/time/timer.hpp +++ b/src/time/timer.hpp @@ -13,17 +13,17 @@ struct TimeStep { explicit TimeStep(milliseconds time); - std::string + [[nodiscard]] std::string ToString() const; - seconds + [[nodiscard]] seconds GetSeconds() const; - milliseconds + [[nodiscard]] milliseconds GetMilliseconds() const; private: - milliseconds m_time; + milliseconds time_; }; @@ -32,11 +32,11 @@ class Timer public: Timer(); - TimeStep + [[nodiscard]] TimeStep ToggleTimer(); private: - timeStamp m_lastTimeStamp; + timeStamp lastTimeStamp_; }; } // namespace shady::time \ No newline at end of file diff --git a/src/trace/logger.hpp b/src/trace/logger.hpp index c4061679..b2b8579a 100644 --- a/src/trace/logger.hpp +++ b/src/trace/logger.hpp @@ -76,6 +76,7 @@ class Logger {TYPE::WARNING, FOREGROUND_GREEN | FOREGROUND_RED}, {TYPE::FATAL, FOREGROUND_RED}}; #else + //NOLINTNEXTLINE static const inline std::unordered_map< TYPE, fmt::color, LoggerTypeHash > s_typeStyles = { {TYPE::TRACE, fmt::color::azure}, {TYPE::DEBUG, fmt::color::blanched_almond}, diff --git a/src/utils/file_manager.cpp b/src/utils/file_manager.cpp index 788c4e47..ac94418d 100644 --- a/src/utils/file_manager.cpp +++ b/src/utils/file_manager.cpp @@ -10,7 +10,7 @@ namespace shady::utils { -auto static CreatePath(std::filesystem::path rootPath, std::string_view assetPath) +auto static CreatePath(const std::filesystem::path& rootPath, std::string_view assetPath) { auto new_path = rootPath / ""; new_path += std::filesystem::path(assetPath); @@ -78,8 +78,10 @@ render::ImageData FileManager::ReadTexture(std::string_view fileName, bool flipVertical) { const auto pathToImage = CreatePath(TEXTURES_DIR, fileName); - int force_channels = STBI_rgb_alpha; - int w, h, n; + const int force_channels = STBI_rgb_alpha; + int w{}; + int h{}; + int n{}; stbi_set_flip_vertically_on_load(flipVertical); diff --git a/src/utils/file_manager.hpp b/src/utils/file_manager.hpp index 4b9edb86..87d0614d 100644 --- a/src/utils/file_manager.hpp +++ b/src/utils/file_manager.hpp @@ -8,6 +8,7 @@ namespace shady::render { +//NOLINTNEXTLINE using ImageHandleType = std::unique_ptr< uint8_t[], std::function< void(uint8_t*) > >; struct ImageData @@ -24,6 +25,7 @@ namespace shady::utils { class FileManager { public: + //NOLINTBEGIN static inline const std::filesystem::path ROOT_DIR = std::filesystem::path(std::string(CMAKE_ROOT_DIR)); static inline const std::filesystem::path ASSETS_DIR = ROOT_DIR / "assets"; @@ -31,6 +33,7 @@ class FileManager static inline const std::filesystem::path SHADERS_DIR = ASSETS_DIR / "shaders"; static inline const std::filesystem::path MODELS_DIR = ASSETS_DIR / "models"; static inline const std::filesystem::path FONTS_DIR = ASSETS_DIR / "fonts"; +//NOLINTEND public: static std::string