diff --git a/.gitignore b/.gitignore index 1b7975a..27f8f63 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ bin/ .cache libs imgui.ini +Makefile +compile_flags.txt diff --git a/CopiumEngine/makegen.xml b/CopiumEngine/makegen.xml new file mode 100644 index 0000000..565e3c9 --- /dev/null +++ b/CopiumEngine/makegen.xml @@ -0,0 +1,53 @@ + + + MSDF_ATLAS_PUBLIC= + GLM_FORCE_LEFT_HANDED + GLM_FORCE_RADIANS + GLM_FORCE_DEPTH_ZERO_TO_ONE + ../ext/projects/imgui/ + ../ext/projects/msdf-atlas-gen/ + ../ext/projects/msdfgen-core/ + ../ext/projects/msdfgen-ext/ + false + bin/Release/ + libcopium.so + sharedlibrary + Copium Engine + src/ + src/ + ../ext/repos/imgui/ + ../ext/repos/imgui/backends/ + ../ext/repos/freetype/ + ../ext/repos/msdf-atlas-gen/msdfgen/ + ../ext/repos/msdf-atlas-gen/ + ../ext/repos/stb/ + + + -g3 + -w + _DEBUG + MSDF_ATLAS_PUBLIC= + GLM_FORCE_LEFT_HANDED + GLM_FORCE_RADIANS + GLM_FORCE_DEPTH_ZERO_TO_ONE + ../ext/projects/imgui/ + ../ext/projects/msdf-atlas-gen/ + ../ext/projects/msdfgen-core/ + ../ext/projects/msdfgen-ext/ + false + bin/Debug/ + libcopium.so + sharedlibrary + Copium Engine + src/ + src/ + ../ext/repos/imgui/ + ../ext/repos/imgui/backends/ + ../ext/repos/freetype/ + ../ext/repos/msdf-atlas-gen/msdfgen/ + ../ext/repos/msdf-atlas-gen/ + ../ext/repos/stb/ + + Debug + v1.3.4 + diff --git a/CopiumEngine/src/copium/asset/Asset.h b/CopiumEngine/src/copium/asset/Asset.h index 38a5141..bd42544 100644 --- a/CopiumEngine/src/copium/asset/Asset.h +++ b/CopiumEngine/src/copium/asset/Asset.h @@ -1,7 +1,6 @@ #pragma once #include "copium/asset/AssetMeta.h" -#include "copium/util/MetaFile.h" #include "copium/util/Uuid.h" #include diff --git a/CopiumEngine/src/copium/asset/AssetFile.cpp b/CopiumEngine/src/copium/asset/AssetFile.cpp index 6b126b3..10c7cec 100644 --- a/CopiumEngine/src/copium/asset/AssetFile.cpp +++ b/CopiumEngine/src/copium/asset/AssetFile.cpp @@ -17,7 +17,7 @@ namespace Copium return dateModified < FileSystem::DateModified(path); } - void AssetFile::Load() + void AssetFile::Load() { MetaFile metaFile{path}; for (auto&& assetType : assetTypes) @@ -52,4 +52,4 @@ namespace Copium { assetTypes.emplace_back(assetType); } -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/asset/AssetFile.h b/CopiumEngine/src/copium/asset/AssetFile.h index 5506b54..4ffb6e2 100644 --- a/CopiumEngine/src/copium/asset/AssetFile.h +++ b/CopiumEngine/src/copium/asset/AssetFile.h @@ -1,6 +1,5 @@ #pragma once -#include "copium/asset/AssetMeta.h" #include "copium/util/MetaFile.h" #include "copium/util/Uuid.h" @@ -27,4 +26,4 @@ namespace Copium void Load(const MetaFile& metaFile, const std::string& className); static void RegisterAssetType(const std::string& assetType); }; -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/asset/AssetManager.cpp b/CopiumEngine/src/copium/asset/AssetManager.cpp index 8301b8d..d3712f4 100644 --- a/CopiumEngine/src/copium/asset/AssetManager.cpp +++ b/CopiumEngine/src/copium/asset/AssetManager.cpp @@ -1,8 +1,5 @@ #include "copium/asset/AssetManager.h" -#include "copium/buffer/Framebuffer.h" -#include "copium/sampler/ColorAttachment.h" -#include "copium/sampler/Texture2D.h" #include "copium/util/Common.h" #include "copium/util/MetaFile.h" @@ -185,4 +182,4 @@ namespace Copium } CP_ABORT("Unknown Asset type: %s", filepath.c_str()); } -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/buffer/Framebuffer.h b/CopiumEngine/src/copium/buffer/Framebuffer.h index 92cb9b2..c3b874b 100644 --- a/CopiumEngine/src/copium/buffer/Framebuffer.h +++ b/CopiumEngine/src/copium/buffer/Framebuffer.h @@ -1,7 +1,6 @@ #pragma once #include "copium/asset/Asset.h" -#include "copium/asset/AssetMeta.h" #include "copium/asset/AssetRef.h" #include "copium/buffer/CommandBuffer.h" #include "copium/sampler/ColorAttachment.h" @@ -44,4 +43,4 @@ namespace Copium void InitializeRenderPass(); void InitializeFramebuffers(); }; -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/buffer/IndexBuffer.cpp b/CopiumEngine/src/copium/buffer/IndexBuffer.cpp index e65214e..8212837 100644 --- a/CopiumEngine/src/copium/buffer/IndexBuffer.cpp +++ b/CopiumEngine/src/copium/buffer/IndexBuffer.cpp @@ -5,7 +5,9 @@ namespace Copium { IndexBuffer::IndexBuffer(int indexCount) - : Buffer{VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, indexCount * sizeof(uint16_t), 1}, + : Buffer{VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, + indexCount * sizeof(uint16_t), 1}, indexCount{indexCount} {} @@ -24,4 +26,4 @@ namespace Copium CP_ASSERT(indices >= 0 && indices <= indexCount, "amount of indices is out of range"); vkCmdDrawIndexed(commandBuffer, indices, 1, 0, 0, 0); } -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/buffer/UniformBuffer.cpp b/CopiumEngine/src/copium/buffer/UniformBuffer.cpp index c3c47db..f8b869a 100644 --- a/CopiumEngine/src/copium/buffer/UniformBuffer.cpp +++ b/CopiumEngine/src/copium/buffer/UniformBuffer.cpp @@ -84,4 +84,4 @@ namespace Copium Buffer::Update(buffer.data(), i); } } -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/core/DebugMessenger.cpp b/CopiumEngine/src/copium/core/DebugMessenger.cpp index 5d38978..d4c9621 100644 --- a/CopiumEngine/src/copium/core/DebugMessenger.cpp +++ b/CopiumEngine/src/copium/core/DebugMessenger.cpp @@ -53,7 +53,7 @@ namespace Copium VKAPI_ATTR VkBool32 VKAPI_CALL DebugMessenger::DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, - void* pUserData) + void* pUserData) { if (messageSeverity >= VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) { @@ -85,4 +85,4 @@ namespace Copium } } -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/core/Device.cpp b/CopiumEngine/src/copium/core/Device.cpp index b872529..1c13708 100644 --- a/CopiumEngine/src/copium/core/Device.cpp +++ b/CopiumEngine/src/copium/core/Device.cpp @@ -1,5 +1,6 @@ #include "Device.h" +#include "copium/core/QueueFamilies.h" #include "copium/core/Vulkan.h" #include "copium/core/Window.h" diff --git a/CopiumEngine/src/copium/core/Device.h b/CopiumEngine/src/copium/core/Device.h index baab080..8ae9741 100644 --- a/CopiumEngine/src/copium/core/Device.h +++ b/CopiumEngine/src/copium/core/Device.h @@ -1,6 +1,5 @@ #pragma once -#include "copium/core/QueueFamilies.h" #include "copium/util/Common.h" #include @@ -16,7 +15,7 @@ namespace Copium public: Device(); ~Device(); - + uint32_t GetGraphicsQueueFamily() const; uint32_t GetPresentQueueFamily() const; VkQueue GetGraphicsQueue() const; @@ -51,4 +50,4 @@ namespace Copium bool CheckDeviceExtensionSupport(VkPhysicalDevice device); std::vector GetRequiredDeviceExtensions(); }; -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/core/ImGuiInstance.cpp b/CopiumEngine/src/copium/core/ImGuiInstance.cpp index 695ba59..6fa84b6 100644 --- a/CopiumEngine/src/copium/core/ImGuiInstance.cpp +++ b/CopiumEngine/src/copium/core/ImGuiInstance.cpp @@ -10,7 +10,7 @@ namespace Copium { ImGuiInstance::ImGuiInstance() - : descriptorPool{std::make_unique()} + : descriptorPool{std::make_unique(SwapChain::MAX_FRAMES_IN_FLIGHT, 1)} { InitializeImGui(); InitializeDescriptorSetLayout(); @@ -109,4 +109,4 @@ namespace Copium { CP_VK_ASSERT(err, "Failed to initialize ImGui"); } -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/core/Instance.cpp b/CopiumEngine/src/copium/core/Instance.cpp index 2d26755..392cc59 100644 --- a/CopiumEngine/src/copium/core/Instance.cpp +++ b/CopiumEngine/src/copium/core/Instance.cpp @@ -1,8 +1,9 @@ #include "Instance.h" -#include "copium/core/QueueFamilies.h" #include "copium/util/Common.h" +#include + namespace Copium { Instance::Instance(const std::string& applicationName) @@ -107,4 +108,4 @@ namespace Copium } return true; } -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/core/Instance.h b/CopiumEngine/src/copium/core/Instance.h index e004ef1..a177d2d 100644 --- a/CopiumEngine/src/copium/core/Instance.h +++ b/CopiumEngine/src/copium/core/Instance.h @@ -2,9 +2,6 @@ #include "copium/core/DebugMessenger.h" -#include -#include - namespace Copium { class Instance final diff --git a/CopiumEngine/src/copium/core/SwapChain.cpp b/CopiumEngine/src/copium/core/SwapChain.cpp index 63b9053..c68f3bc 100644 --- a/CopiumEngine/src/copium/core/SwapChain.cpp +++ b/CopiumEngine/src/copium/core/SwapChain.cpp @@ -4,10 +4,10 @@ #include "copium/core/Vulkan.h" #include "copium/sampler/Image.h" -#include - namespace Copium { + const int SwapChain::MAX_FRAMES_IN_FLIGHT = 2; + SwapChainSupportDetails::SwapChainSupportDetails(VkSurfaceKHR surface, VkPhysicalDevice physicalDevice) { vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, &capabilities); @@ -35,6 +35,7 @@ namespace Copium } SwapChain::SwapChain() + : flightIndex{0}, resizeFramebuffer{false} { Initialize(); InitializeImageViews(); @@ -49,9 +50,13 @@ namespace Copium for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) { vkDestroyFence(Vulkan::GetDevice(), inFlightFences[i], nullptr); - vkDestroySemaphore(Vulkan::GetDevice(), renderFinishedSemaphores[i], nullptr); vkDestroySemaphore(Vulkan::GetDevice(), imageAvailableSemaphores[i], nullptr); } + for (size_t i = 0; i < images.size(); ++i) + { + vkDestroySemaphore(Vulkan::GetDevice(), renderFinishedSemaphores[i], nullptr); + } + Destroy(); vkDestroyRenderPass(Vulkan::GetDevice(), renderPass, nullptr); } @@ -137,7 +142,7 @@ namespace Copium submitInfo.commandBufferCount = 1; submitInfo.pCommandBuffers = &cmd; submitInfo.signalSemaphoreCount = 1; - submitInfo.pSignalSemaphores = &renderFinishedSemaphores[flightIndex]; + submitInfo.pSignalSemaphores = &renderFinishedSemaphores[imageIndex]; CP_VK_ASSERT(vkQueueSubmit(Vulkan::GetDevice().GetGraphicsQueue(), 1, &submitInfo, inFlightFences[flightIndex]), "Failed to submit command buffer"); } @@ -147,7 +152,7 @@ namespace Copium VkPresentInfoKHR presentInfo{}; presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; presentInfo.waitSemaphoreCount = 1; - presentInfo.pWaitSemaphores = &renderFinishedSemaphores[flightIndex]; + presentInfo.pWaitSemaphores = &renderFinishedSemaphores[imageIndex]; presentInfo.swapchainCount = 1; presentInfo.pSwapchains = &handle; presentInfo.pImageIndices = &imageIndex; @@ -345,14 +350,12 @@ namespace Copium void SwapChain::InitializeSyncObjects() { imageAvailableSemaphores.resize(MAX_FRAMES_IN_FLIGHT); - renderFinishedSemaphores.resize(MAX_FRAMES_IN_FLIGHT); inFlightFences.resize(MAX_FRAMES_IN_FLIGHT); VkSemaphoreCreateInfo semaphoreCreateInfo{}; semaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) { CP_VK_ASSERT(vkCreateSemaphore(Vulkan::GetDevice(), &semaphoreCreateInfo, nullptr, &imageAvailableSemaphores[i]), "Failed to initialize available image semaphore"); - CP_VK_ASSERT(vkCreateSemaphore(Vulkan::GetDevice(), &semaphoreCreateInfo, nullptr, &renderFinishedSemaphores[i]), "Failed to initialize render finished semaphore"); VkFenceCreateInfo fenceCreateInfo{}; fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; @@ -360,6 +363,11 @@ namespace Copium CP_VK_ASSERT(vkCreateFence(Vulkan::GetDevice(), &fenceCreateInfo, nullptr, &inFlightFences[i]), "Failed to initialize in flight fence"); } + renderFinishedSemaphores.resize(images.size()); + for(size_t i = 0; i < renderFinishedSemaphores.size(); i++) + { + CP_VK_ASSERT(vkCreateSemaphore(Vulkan::GetDevice(), &semaphoreCreateInfo, nullptr, &renderFinishedSemaphores[i]), "Failed to initialize render finished semaphore"); + } } void SwapChain::Destroy() diff --git a/CopiumEngine/src/copium/core/SwapChain.h b/CopiumEngine/src/copium/core/SwapChain.h index 3449625..f8e7df1 100644 --- a/CopiumEngine/src/copium/core/SwapChain.h +++ b/CopiumEngine/src/copium/core/SwapChain.h @@ -24,7 +24,7 @@ namespace Copium { CP_DELETE_COPY_AND_MOVE_CTOR(SwapChain); public: - static const int MAX_FRAMES_IN_FLIGHT = 2; + static const int MAX_FRAMES_IN_FLIGHT; private: VkSwapchainKHR handle; VkRenderPass renderPass; @@ -34,7 +34,7 @@ namespace Copium std::vector imageViews; std::vector images; std::vector framebuffers; - uint32_t imageIndex; + uint32_t imageIndex; bool resizeFramebuffer; int flightIndex; diff --git a/CopiumEngine/src/copium/core/Vulkan.cpp b/CopiumEngine/src/copium/core/Vulkan.cpp index dff51b3..172bb4f 100644 --- a/CopiumEngine/src/copium/core/Vulkan.cpp +++ b/CopiumEngine/src/copium/core/Vulkan.cpp @@ -22,6 +22,10 @@ namespace Copium { Timer timer; timer.Start(); + + glfwSetErrorCallback(glfw_error_callback); + CP_ASSERT(glfwInit() == GLFW_TRUE, "Failed to initialize the glfw context"); + instance = std::make_unique("Copium Engine"); window = std::make_unique("Copium Engine", 1440, 810, WindowMode::Windowed); device = std::make_unique(); @@ -97,4 +101,9 @@ namespace Copium { return instance && window && device && swapChain; } -} \ No newline at end of file + + void Vulkan::glfw_error_callback(int error, const char* description) + { + CP_ABORT("GLFW Error %d: %s\n", error, description); + } +} diff --git a/CopiumEngine/src/copium/core/Vulkan.h b/CopiumEngine/src/copium/core/Vulkan.h index a6288a5..de9fde5 100644 --- a/CopiumEngine/src/copium/core/Vulkan.h +++ b/CopiumEngine/src/copium/core/Vulkan.h @@ -36,5 +36,8 @@ namespace Copium static bool Valid(); static AssetHandle GetWhiteTexture2D(); static AssetHandle GetEmptyTexture2D(); + + private: + static void glfw_error_callback(int error, const char* description); }; -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/core/Window.cpp b/CopiumEngine/src/copium/core/Window.cpp index 153e611..64b2d30 100644 --- a/CopiumEngine/src/copium/core/Window.cpp +++ b/CopiumEngine/src/copium/core/Window.cpp @@ -9,8 +9,8 @@ #include "copium/event/MousePressEvent.h" #include "copium/event/MouseReleaseEvent.h" #include "copium/event/MouseScrollEvent.h" -#include "copium/event/WindowResizeEvent.h" #include "copium/event/WindowFocusEvent.h" +#include "copium/event/WindowResizeEvent.h" #include @@ -32,7 +32,6 @@ namespace Copium bool Window::ShouldClose() const { return glfwWindowShouldClose(window); - } int Window::GetWidth() const @@ -72,6 +71,8 @@ namespace Copium { glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + CP_ASSERT(glfwVulkanSupported(), "Vulkan is not supported"); + switch (mode) { case WindowMode::Fullscreen: @@ -187,4 +188,4 @@ namespace Copium { EventDispatcher::QueueEvent(MouseScrollEvent{(int)xoffset, (int)yoffset}); } -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/core/Window.h b/CopiumEngine/src/copium/core/Window.h index dafdcc9..51cc9da 100644 --- a/CopiumEngine/src/copium/core/Window.h +++ b/CopiumEngine/src/copium/core/Window.h @@ -51,4 +51,4 @@ namespace Copium static void WindowFocusCallback(GLFWwindow* window, int focused); static void MouseScrollCallback(GLFWwindow* window, double xoffset, double yoffset); }; -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/ecs/ComponentListener.h b/CopiumEngine/src/copium/ecs/ComponentListener.h index 71087df..c3e5ab7 100644 --- a/CopiumEngine/src/copium/ecs/ComponentListener.h +++ b/CopiumEngine/src/copium/ecs/ComponentListener.h @@ -1,9 +1,11 @@ #pragma once -#include "copium/ecs/ECSManager.h" +#include "copium/ecs/Config.h" namespace Copium { + class ECSManager; + template class ComponentListener { diff --git a/CopiumEngine/src/copium/ecs/ECSManager.h b/CopiumEngine/src/copium/ecs/ECSManager.h index e3cc344..28e38a4 100644 --- a/CopiumEngine/src/copium/ecs/ECSManager.h +++ b/CopiumEngine/src/copium/ecs/ECSManager.h @@ -11,7 +11,6 @@ #include #include #include -#include namespace Copium { @@ -36,7 +35,7 @@ namespace Copium template void RemoveSystem() { - systemPool->MoveSystemBefore(typeid(SystemClass)); + systemPool->RemoveSystem(typeid(SystemClass)); } void UpdateSystems(); diff --git a/CopiumEngine/src/copium/ecs/System.h b/CopiumEngine/src/copium/ecs/System.h index 80483fb..475315b 100644 --- a/CopiumEngine/src/copium/ecs/System.h +++ b/CopiumEngine/src/copium/ecs/System.h @@ -4,6 +4,8 @@ #include "copium/ecs/SystemBase.h" #include "copium/ecs/Entity.h" +#include + namespace Copium { template @@ -26,7 +28,6 @@ namespace Copium // TODO: Not sure if this is the way entities should be validated std::set loggedEntities; - template bool ValidateEntity(Entity entity) { if (entity && entity.HasComponents()) diff --git a/CopiumEngine/src/copium/ecs/SystemBase.h b/CopiumEngine/src/copium/ecs/SystemBase.h index a8d18da..db5a8d7 100644 --- a/CopiumEngine/src/copium/ecs/SystemBase.h +++ b/CopiumEngine/src/copium/ecs/SystemBase.h @@ -13,6 +13,8 @@ namespace Copium ECSManager* manager; public: + virtual ~SystemBase() = default; + virtual void Run() = 0; virtual void Run(const Signal& signal) = 0; }; diff --git a/CopiumEngine/src/copium/ecs/SystemOrderer.h b/CopiumEngine/src/copium/ecs/SystemOrderer.h index d0d1e0e..d2d3028 100644 --- a/CopiumEngine/src/copium/ecs/SystemOrderer.h +++ b/CopiumEngine/src/copium/ecs/SystemOrderer.h @@ -1,7 +1,5 @@ #pragma once -#include -#include #include namespace Copium diff --git a/CopiumEngine/src/copium/ecs/SystemPool.cpp b/CopiumEngine/src/copium/ecs/SystemPool.cpp index 4a2a06e..da054f6 100644 --- a/CopiumEngine/src/copium/ecs/SystemPool.cpp +++ b/CopiumEngine/src/copium/ecs/SystemPool.cpp @@ -1,5 +1,7 @@ #include "copium/ecs/SystemPool.h" +#include + namespace Copium { SystemPool::SystemPool(ECSManager* manager) diff --git a/CopiumEngine/src/copium/event/Event.h b/CopiumEngine/src/copium/event/Event.h index 5638caa..bd2adb9 100644 --- a/CopiumEngine/src/copium/event/Event.h +++ b/CopiumEngine/src/copium/event/Event.h @@ -11,6 +11,8 @@ namespace Copium public: Event(EventType type); + virtual ~Event() = default; + EventType GetType() const; }; } diff --git a/CopiumEngine/src/copium/event/Input.cpp b/CopiumEngine/src/copium/event/Input.cpp index fe27f10..940c4a0 100644 --- a/CopiumEngine/src/copium/event/Input.cpp +++ b/CopiumEngine/src/copium/event/Input.cpp @@ -1,7 +1,8 @@ #include "copium/event/Input.h" -#include "copium/util/Common.h" #include "copium/core/Vulkan.h" +#include "copium/event/InputCode.h" +#include "copium/util/Common.h" #include diff --git a/CopiumEngine/src/copium/event/Input.h b/CopiumEngine/src/copium/event/Input.h index 8dad684..f4c5079 100644 --- a/CopiumEngine/src/copium/event/Input.h +++ b/CopiumEngine/src/copium/event/Input.h @@ -1,11 +1,9 @@ #pragma once -#include - -#include "copium/event/InputCode.h" #include "copium/util/BoundingBox.h" #include +#include namespace Copium { diff --git a/CopiumEngine/src/copium/event/InputCode.h b/CopiumEngine/src/copium/event/InputCode.h index ebbf50e..252338c 100644 --- a/CopiumEngine/src/copium/event/InputCode.h +++ b/CopiumEngine/src/copium/event/InputCode.h @@ -1,7 +1,5 @@ #pragma once -#include "copium/util/Enum.h" - #define CP_MOUSE_LEFT 0 #define CP_MOUSE_RIGHT 1 #define CP_MOUSE_MIDDLE 2 @@ -128,4 +126,4 @@ #define CP_KEY_RIGHT_ALT 346 #define CP_KEY_RIGHT_SUPER 347 #define CP_KEY_MENU 348 -#define CP_KEY_UNBOUND 0xffffffff +#define CP_KEY_UNBOUND 0x0fffffff diff --git a/CopiumEngine/src/copium/event/MousePressEvent.cpp b/CopiumEngine/src/copium/event/MousePressEvent.cpp index 33abb75..de6d5fe 100644 --- a/CopiumEngine/src/copium/event/MousePressEvent.cpp +++ b/CopiumEngine/src/copium/event/MousePressEvent.cpp @@ -6,7 +6,7 @@ namespace Copium : Event{EventType::MousePress}, button{button} {} - int MousePressEvent::GetButton() const + int MousePressEvent::GetButton() const { return button; } diff --git a/CopiumEngine/src/copium/event/MouseReleaseEvent.cpp b/CopiumEngine/src/copium/event/MouseReleaseEvent.cpp index fb628f3..43beb89 100644 --- a/CopiumEngine/src/copium/event/MouseReleaseEvent.cpp +++ b/CopiumEngine/src/copium/event/MouseReleaseEvent.cpp @@ -6,7 +6,7 @@ namespace Copium : Event{EventType::MouseRelease}, button{button} {} - int MouseReleaseEvent::GetButton() const + int MouseReleaseEvent::GetButton() const { return button; } diff --git a/CopiumEngine/src/copium/event/ViewportResize.h b/CopiumEngine/src/copium/event/ViewportResize.h index b4046bd..31f0d54 100644 --- a/CopiumEngine/src/copium/event/ViewportResize.h +++ b/CopiumEngine/src/copium/event/ViewportResize.h @@ -1,7 +1,6 @@ #pragma once #include "copium/event/Event.h" -#include "copium/event/EventType.h" #include "copium/util/BoundingBox.h" namespace Copium diff --git a/CopiumEngine/src/copium/mesh/Vertex.h b/CopiumEngine/src/copium/mesh/Vertex.h index 512c050..d3ca4a4 100644 --- a/CopiumEngine/src/copium/mesh/Vertex.h +++ b/CopiumEngine/src/copium/mesh/Vertex.h @@ -6,7 +6,7 @@ namespace Copium { - struct Vertex + struct Vertex { glm::vec3 pos; glm::vec3 color; diff --git a/CopiumEngine/src/copium/mesh/VertexPassthrough.h b/CopiumEngine/src/copium/mesh/VertexPassthrough.h index d311365..49db4de 100644 --- a/CopiumEngine/src/copium/mesh/VertexPassthrough.h +++ b/CopiumEngine/src/copium/mesh/VertexPassthrough.h @@ -6,7 +6,7 @@ namespace Copium { - struct VertexPassthrough + struct VertexPassthrough { glm::vec2 texCoord; diff --git a/CopiumEngine/src/copium/pipeline/DescriptorPool.cpp b/CopiumEngine/src/copium/pipeline/DescriptorPool.cpp index 8ca9b57..adb20cc 100644 --- a/CopiumEngine/src/copium/pipeline/DescriptorPool.cpp +++ b/CopiumEngine/src/copium/pipeline/DescriptorPool.cpp @@ -4,20 +4,31 @@ namespace Copium { - DescriptorPool::DescriptorPool() + DescriptorPool::DescriptorPool(int uniformDescriptorSets, int imageDescriptorSets) { - std::vector poolSizes{2}; - poolSizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - poolSizes[0].descriptorCount = DESCRIPTOR_SET_COUNT * SwapChain::MAX_FRAMES_IN_FLIGHT; // TODO: how should this actually be determined? + std::vector poolSizes; + if (uniformDescriptorSets != 0) + { + VkDescriptorPoolSize descriptorSetPoolSize; + descriptorSetPoolSize.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + descriptorSetPoolSize.descriptorCount = uniformDescriptorSets; + poolSizes.emplace_back(descriptorSetPoolSize); + } + + if (imageDescriptorSets != 0) + { + VkDescriptorPoolSize descriptorSetPoolSize; + descriptorSetPoolSize.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + descriptorSetPoolSize.descriptorCount = imageDescriptorSets; + poolSizes.emplace_back(descriptorSetPoolSize); + } - poolSizes[1].type = VK_DESCRIPTOR_TYPE_SAMPLER; - poolSizes[1].descriptorCount = DESCRIPTOR_SET_COUNT * SwapChain::MAX_FRAMES_IN_FLIGHT; // TODO: how should this actually be determined? VkDescriptorPoolCreateInfo createInfo{}; createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; createInfo.poolSizeCount = poolSizes.size(); createInfo.pPoolSizes = poolSizes.data(); - createInfo.maxSets = DESCRIPTOR_SET_COUNT * SwapChain::MAX_FRAMES_IN_FLIGHT; + createInfo.maxSets = uniformDescriptorSets + imageDescriptorSets; // I have no actual idea if this is fine createInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT; CP_VK_ASSERT(vkCreateDescriptorPool(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorPool), "Failed to initialize descriptor pool"); @@ -59,4 +70,4 @@ namespace Copium { return descriptorPool; } -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/pipeline/DescriptorPool.h b/CopiumEngine/src/copium/pipeline/DescriptorPool.h index 4df4cc1..a92a813 100644 --- a/CopiumEngine/src/copium/pipeline/DescriptorPool.h +++ b/CopiumEngine/src/copium/pipeline/DescriptorPool.h @@ -11,9 +11,8 @@ namespace Copium CP_DELETE_COPY_AND_MOVE_CTOR(DescriptorPool); private: VkDescriptorPool descriptorPool; - static const int DESCRIPTOR_SET_COUNT = 1000000; public: - DescriptorPool(); + DescriptorPool(int uniformDescriptorSets, int imageDescriptorSets); ~DescriptorPool(); std::vector AllocateDescriptorSets(VkDescriptorSetLayout descriptorSetLayout); diff --git a/CopiumEngine/src/copium/pipeline/DescriptorSet.h b/CopiumEngine/src/copium/pipeline/DescriptorSet.h index 5b29cd1..f86be3a 100644 --- a/CopiumEngine/src/copium/pipeline/DescriptorSet.h +++ b/CopiumEngine/src/copium/pipeline/DescriptorSet.h @@ -3,7 +3,6 @@ #include "copium/buffer/UniformBuffer.h" #include "copium/pipeline/DescriptorPool.h" #include "copium/pipeline/ShaderBinding.h" -#include "copium/pipeline/ShaderReflector.h" #include "copium/sampler/Sampler.h" #include "copium/util/Common.h" @@ -42,4 +41,4 @@ namespace Copium private: void SetUniformBuffer(const UniformBuffer& uniformBuffer, uint32_t binding); }; -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/pipeline/Pipeline.cpp b/CopiumEngine/src/copium/pipeline/Pipeline.cpp index 32e47bd..6d224d0 100644 --- a/CopiumEngine/src/copium/pipeline/Pipeline.cpp +++ b/CopiumEngine/src/copium/pipeline/Pipeline.cpp @@ -1,6 +1,5 @@ #include "copium/pipeline/Pipeline.h" -#include "copium/asset/AssetManager.h" #include "copium/buffer/Framebuffer.h" #include "copium/core/Vulkan.h" #include "copium/pipeline/Shader.h" @@ -8,7 +7,6 @@ #include "copium/mesh/VertexPassthrough.h" #include "copium/mesh/Vertex.h" #include "copium/renderer/LineVertex.h" -#include "copium/util/FileSystem.h" namespace Copium { @@ -121,6 +119,11 @@ namespace Copium return DescriptorSet{descriptorPool, descriptorSetLayouts[setIndex], bindings}; } + int Pipeline::GetDescriptorSetCount() const + { + return boundDescriptorSets.size(); + } + void Pipeline::InitializeDescriptorSetLayout(const PipelineCreator& creator) { boundDescriptorSets.resize(creator.descriptorSetLayouts.size()); @@ -284,4 +287,4 @@ namespace Copium CP_VK_ASSERT(vkCreateGraphicsPipelines(Vulkan::GetDevice(), VK_NULL_HANDLE, 1, &graphicsPipelineCreateInfo, nullptr, &graphicsPipeline), "Failed to initialize graphics pipeline"); } -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/pipeline/Pipeline.h b/CopiumEngine/src/copium/pipeline/Pipeline.h index e588ff2..6fda160 100644 --- a/CopiumEngine/src/copium/pipeline/Pipeline.h +++ b/CopiumEngine/src/copium/pipeline/Pipeline.h @@ -36,8 +36,10 @@ namespace Copium std::unique_ptr CreateDescriptorSet(DescriptorPool& descriptorPool, int setIndex) const; DescriptorSet CreateDescriptorSetRef(DescriptorPool& descriptorPool, int setIndex) const; + int GetDescriptorSetCount() const; + private: void InitializeDescriptorSetLayout(const PipelineCreator& creator); void InitializePipeline(const PipelineCreator& creator); }; -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/pipeline/PipelineCreator.cpp b/CopiumEngine/src/copium/pipeline/PipelineCreator.cpp index 5c3afdb..62952a2 100644 --- a/CopiumEngine/src/copium/pipeline/PipelineCreator.cpp +++ b/CopiumEngine/src/copium/pipeline/PipelineCreator.cpp @@ -76,4 +76,4 @@ namespace Copium CP_ABORT("Unhandled switch case"); } } -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/pipeline/PipelineCreator.h b/CopiumEngine/src/copium/pipeline/PipelineCreator.h index f2a66f9..9ee557d 100644 --- a/CopiumEngine/src/copium/pipeline/PipelineCreator.h +++ b/CopiumEngine/src/copium/pipeline/PipelineCreator.h @@ -7,6 +7,7 @@ #include #include +#include namespace Copium { diff --git a/CopiumEngine/src/copium/pipeline/ShaderBinding.h b/CopiumEngine/src/copium/pipeline/ShaderBinding.h index 0817f0d..d2fe675 100644 --- a/CopiumEngine/src/copium/pipeline/ShaderBinding.h +++ b/CopiumEngine/src/copium/pipeline/ShaderBinding.h @@ -4,6 +4,7 @@ #include #include +#include #define CP_BINDING_TYPE_ENUMS Sampler2D, UniformBuffer diff --git a/CopiumEngine/src/copium/renderer/Batch.cpp b/CopiumEngine/src/copium/renderer/Batch.cpp index 558579c..04b2ab9 100644 --- a/CopiumEngine/src/copium/renderer/Batch.cpp +++ b/CopiumEngine/src/copium/renderer/Batch.cpp @@ -1,12 +1,13 @@ #include "copium/renderer/Batch.h" -#include "copium/asset/AssetManager.h" +#include "copium/core/SwapChain.h" #include "copium/renderer/RendererVertex.h" namespace Copium { - Batch::Batch(AssetRef& pipeline, DescriptorPool& descriptorPool, int vertexCount, const std::vector samplers) + Batch::Batch(AssetRef& pipeline, int vertexCount, const std::vector samplers) : vertexBuffer{RendererVertex::GetDescriptor(), vertexCount}, + descriptorPool{pipeline.GetAsset().GetDescriptorSetCount() * SwapChain::MAX_FRAMES_IN_FLIGHT, 32 * SwapChain::MAX_FRAMES_IN_FLIGHT}, descriptorSet{pipeline.GetAsset().CreateDescriptorSet(descriptorPool, 0)} {} diff --git a/CopiumEngine/src/copium/renderer/Batch.h b/CopiumEngine/src/copium/renderer/Batch.h index a3e87b5..3f8ff44 100644 --- a/CopiumEngine/src/copium/renderer/Batch.h +++ b/CopiumEngine/src/copium/renderer/Batch.h @@ -1,6 +1,5 @@ #pragma once -#include "copium/asset/AssetMeta.h" #include "copium/asset/AssetRef.h" #include "copium/buffer/RendererVertexBuffer.h" #include "copium/pipeline/DescriptorSet.h" @@ -14,9 +13,10 @@ namespace Copium CP_DELETE_COPY_AND_MOVE_CTOR(Batch); private: RendererVertexBuffer vertexBuffer; + DescriptorPool descriptorPool; std::unique_ptr descriptorSet; public: - Batch(AssetRef& pipeline, DescriptorPool& descriptorPool, int vertexCount, const std::vector samplers); + Batch(AssetRef& pipeline, int vertexCount, const std::vector samplers); RendererVertexBuffer& GetVertexBuffer(); DescriptorSet& GetDescriptorSet(); }; diff --git a/CopiumEngine/src/copium/renderer/LineRenderer.cpp b/CopiumEngine/src/copium/renderer/LineRenderer.cpp index f3c3ea2..eb533e2 100644 --- a/CopiumEngine/src/copium/renderer/LineRenderer.cpp +++ b/CopiumEngine/src/copium/renderer/LineRenderer.cpp @@ -1,8 +1,8 @@ #include "copium/renderer/LineRenderer.h" -#include "copium/asset/AssetManager.h" #include "copium/core/Vulkan.h" #include "copium/pipeline/PipelineCreator.h" +#include "copium/renderer/LineVertex.h" namespace Copium { @@ -10,8 +10,8 @@ namespace Copium static constexpr int MAX_NUM_VERTICES = 2 * MAX_NUM_LINES; LineRenderer::LineRenderer(const AssetRef& pipeline) - : descriptorPool{}, - ibo{MAX_NUM_VERTICES}, + : descriptorPool{pipeline.GetAsset().GetDescriptorSetCount() * SwapChain::MAX_FRAMES_IN_FLIGHT, 0}, + ibo{MAX_NUM_VERTICES}, pipeline{pipeline}, vertexBuffer{LineVertex::GetDescriptor(), MAX_NUM_VERTICES} { @@ -60,7 +60,7 @@ namespace Copium pipeline.GetAsset().SetDescriptorSet(descriptorSet); } - void LineRenderer::InitializeIndexBuffer() + void LineRenderer::InitializeIndexBuffer() { CP_ASSERT(MAX_NUM_VERTICES < std::numeric_limits::max(), "Maximum number of indices too big"); @@ -87,4 +87,4 @@ namespace Copium pl.BindDescriptorSets(*currentCommandBuffer); ibo.Draw(*currentCommandBuffer, lineCount * 2); } -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/renderer/LineRenderer.h b/CopiumEngine/src/copium/renderer/LineRenderer.h index b269280..3a80925 100644 --- a/CopiumEngine/src/copium/renderer/LineRenderer.h +++ b/CopiumEngine/src/copium/renderer/LineRenderer.h @@ -3,12 +3,10 @@ #include "copium/buffer/CommandBuffer.h" #include "copium/buffer/IndexBuffer.h" #include "copium/buffer/RendererVertexBuffer.h" -#include "copium/renderer/LineVertex.h" #include "copium/pipeline/Pipeline.h" #include "copium/util/Common.h" #include -#include namespace Copium { diff --git a/CopiumEngine/src/copium/renderer/Renderer.cpp b/CopiumEngine/src/copium/renderer/Renderer.cpp index dbda03b..7d5c534 100644 --- a/CopiumEngine/src/copium/renderer/Renderer.cpp +++ b/CopiumEngine/src/copium/renderer/Renderer.cpp @@ -1,6 +1,5 @@ #include "copium/renderer/Renderer.h" -#include "copium/asset/AssetManager.h" #include "copium/core/Vulkan.h" #include "copium/pipeline/PipelineCreator.h" #include "copium/renderer/RendererVertex.h" @@ -13,18 +12,13 @@ namespace Copium static constexpr int MAX_NUM_TEXTURES = 32; Renderer::Renderer(const AssetRef& pipeline) - : descriptorPool{}, - ibo{MAX_NUM_INDICES}, + : ibo{MAX_NUM_INDICES}, pipeline{pipeline}, samplers{MAX_NUM_TEXTURES, &Vulkan::GetEmptyTexture2D().GetAsset()} { InitializeIndexBuffer(); } - Renderer::~Renderer() - { - } - void Renderer::Quad(const glm::vec2& pos, const glm::vec2& size, const glm::vec3& color) { AllocateQuad(); @@ -71,9 +65,9 @@ namespace Copium const Glyph& glyph = font.GetGlyph(c); AllocateQuad(); int texIndex = AllocateSampler(font); - AddVertex(offset + glm::vec2{glyph.boundingBox.l * size, glyph.boundingBox.b * size}, color, texIndex, glyph.texCoordBoundingBox.lb, RendererVertex::TYPE_TEXT); + AddVertex(offset + glm::vec2{glyph.boundingBox.l * size, glyph.boundingBox.b * size}, color, texIndex, glyph.texCoordBoundingBox.AsLb(), RendererVertex::TYPE_TEXT); AddVertex(offset + glm::vec2{glyph.boundingBox.l * size, glyph.boundingBox.t * size}, color, texIndex, glm::vec2{glyph.texCoordBoundingBox.l, glyph.texCoordBoundingBox.t}, RendererVertex::TYPE_TEXT); - AddVertex(offset + glm::vec2{glyph.boundingBox.r * size, glyph.boundingBox.t * size}, color, texIndex, glyph.texCoordBoundingBox.rt, RendererVertex::TYPE_TEXT); + AddVertex(offset + glm::vec2{glyph.boundingBox.r * size, glyph.boundingBox.t * size}, color, texIndex, glyph.texCoordBoundingBox.AsRt(), RendererVertex::TYPE_TEXT); AddVertex(offset + glm::vec2{glyph.boundingBox.r * size, glyph.boundingBox.b * size}, color, texIndex, glm::vec2{glyph.texCoordBoundingBox.r, glyph.texCoordBoundingBox.b}, RendererVertex::TYPE_TEXT); offset.x += glyph.advance * size; } @@ -115,7 +109,7 @@ namespace Copium pipeline.GetAsset().SetDescriptorSet(descriptorSet); } - void Renderer::InitializeIndexBuffer() + void Renderer::InitializeIndexBuffer() { CP_ASSERT(MAX_NUM_INDICES < std::numeric_limits::max(), "Maximum number of indices too big"); @@ -180,11 +174,11 @@ namespace Copium std::fill(samplers.begin(), samplers.end(), &Vulkan::GetEmptyTexture2D().GetAsset()); if (batchIndex >= batches.size()) { - batches.emplace_back(std::make_unique(pipeline, descriptorPool, MAX_NUM_VERTICES, samplers)); + batches.emplace_back(std::make_unique(pipeline, MAX_NUM_VERTICES, samplers)); } batches[batchIndex]->GetDescriptorSet().SetSamplersDynamic(samplers, 0); mappedVertexBuffer = (char*)batches[batchIndex]->GetVertexBuffer().Map() + batches[batchIndex]->GetVertexBuffer().GetPosition(Vulkan::GetSwapChain().GetFlightIndex()); quadCount = 0; textureCount = 0; } -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/renderer/Renderer.h b/CopiumEngine/src/copium/renderer/Renderer.h index 0c0d798..5b4babc 100644 --- a/CopiumEngine/src/copium/renderer/Renderer.h +++ b/CopiumEngine/src/copium/renderer/Renderer.h @@ -1,13 +1,10 @@ #pragma once -#include "copium/asset/AssetMeta.h" #include "copium/asset/AssetRef.h" #include "copium/buffer/CommandBuffer.h" #include "copium/buffer/IndexBuffer.h" -#include "copium/buffer/RendererVertexBuffer.h" #include "copium/pipeline/Pipeline.h" #include "copium/renderer/Batch.h" -#include "copium/sampler/Texture2D.h" #include "copium/sampler/Font.h" #include "copium/util/Common.h" @@ -16,11 +13,10 @@ namespace Copium { - class Renderer + class Renderer final { CP_DELETE_COPY_AND_MOVE_CTOR(Renderer); private: - DescriptorPool descriptorPool; IndexBuffer ibo; AssetRef pipeline; std::vector> batches; @@ -34,7 +30,6 @@ namespace Copium void* mappedVertexBuffer; public: Renderer(const AssetRef& pipeline); - ~Renderer(); void Quad(const glm::vec2& from, const glm::vec2& to, const glm::vec3& color = glm::vec3{1, 1, 1}); void Quad(const glm::vec2& from, const glm::vec2& to, const Sampler& sampler, const glm::vec2& texCoord1 = glm::vec2{0, 0}, const glm::vec2& texCoord2 = glm::vec2{1, 1}); diff --git a/CopiumEngine/src/copium/sampler/DepthAttachment.h b/CopiumEngine/src/copium/sampler/DepthAttachment.h index 7ddfb39..2595764 100644 --- a/CopiumEngine/src/copium/sampler/DepthAttachment.h +++ b/CopiumEngine/src/copium/sampler/DepthAttachment.h @@ -25,6 +25,5 @@ namespace Copium private: void InitializeDepthAttachment(int width, int height); - }; } diff --git a/CopiumEngine/src/copium/sampler/Font.cpp b/CopiumEngine/src/copium/sampler/Font.cpp index ba2a49e..1ed27fe 100644 --- a/CopiumEngine/src/copium/sampler/Font.cpp +++ b/CopiumEngine/src/copium/sampler/Font.cpp @@ -143,7 +143,10 @@ namespace Copium boundingBox.b = std::min(boundingBox.b, offset.y + glyph.boundingBox.b); } boundingBox.r = std::max(boundingBox.r, offset.x); - boundingBox.lbrt *= size; + boundingBox.l *= size; + boundingBox.b *= size; + boundingBox.r *= size; + boundingBox.t *= size; return boundingBox; } diff --git a/CopiumEngine/src/copium/sampler/SamplerCreator.h b/CopiumEngine/src/copium/sampler/SamplerCreator.h index 932e8a5..d4fc187 100644 --- a/CopiumEngine/src/copium/sampler/SamplerCreator.h +++ b/CopiumEngine/src/copium/sampler/SamplerCreator.h @@ -1,6 +1,7 @@ #pragma once #include "copium/util/MetaFile.h" + #include namespace Copium diff --git a/CopiumEngine/src/copium/sampler/Texture2D.cpp b/CopiumEngine/src/copium/sampler/Texture2D.cpp index 87af066..e46eef5 100644 --- a/CopiumEngine/src/copium/sampler/Texture2D.cpp +++ b/CopiumEngine/src/copium/sampler/Texture2D.cpp @@ -6,8 +6,6 @@ #define STB_IMAGE_IMPLEMENTATION #include -#include - namespace Copium { Texture2D::Texture2D(const MetaFile& metaFile) diff --git a/CopiumEngine/src/copium/util/BoundingBox.cpp b/CopiumEngine/src/copium/util/BoundingBox.cpp index 06d080c..b6b9e16 100644 --- a/CopiumEngine/src/copium/util/BoundingBox.cpp +++ b/CopiumEngine/src/copium/util/BoundingBox.cpp @@ -15,12 +15,12 @@ namespace Copium {} BoundingBox::BoundingBox(glm::vec2 lb, glm::vec2 rt) - : lb{lb}, rt{rt} + : l{lb.x}, b{lb.y}, r{rt.x}, t{rt.y} {} - glm::vec2 BoundingBox::GetSize() const + glm::vec2 BoundingBox::GetSize() const { - return glm::abs(rt - lb); + return glm::abs(AsRt() - AsLb()); } bool BoundingBox::operator==(const BoundingBox& boundingBox) const @@ -32,4 +32,14 @@ namespace Copium { return !(*this == boundingBox); } + + glm::vec2 BoundingBox::AsLb() const + { + return glm::vec2{l, b}; + } + + glm::vec2 BoundingBox::AsRt() const + { + return glm::vec2{r, t}; + } } diff --git a/CopiumEngine/src/copium/util/BoundingBox.h b/CopiumEngine/src/copium/util/BoundingBox.h index 6aacead..28d1bec 100644 --- a/CopiumEngine/src/copium/util/BoundingBox.h +++ b/CopiumEngine/src/copium/util/BoundingBox.h @@ -6,12 +6,10 @@ namespace Copium { struct BoundingBox { - union - { - struct { float l; float b; float r; float t; }; - struct { glm::vec2 lb; glm::vec2 rt; }; - struct { glm::vec4 lbrt; }; - }; + float l; + float b; + float r; + float t; BoundingBox(); BoundingBox(float all); BoundingBox(float l, float b, float r, float t); @@ -21,5 +19,8 @@ namespace Copium bool operator==(const BoundingBox& boundingBox) const; bool operator!=(const BoundingBox& boundingBox) const; + + glm::vec2 AsLb() const; + glm::vec2 AsRt() const; }; } diff --git a/CopiumEngine/src/copium/util/Common.h b/CopiumEngine/src/copium/util/Common.h index ff9a9b5..b7c7897 100644 --- a/CopiumEngine/src/copium/util/Common.h +++ b/CopiumEngine/src/copium/util/Common.h @@ -5,6 +5,7 @@ #include #include +#include #define CP_TERM_RED "\x1B[31m" #define CP_TERM_GREEN "\x1B[32m" @@ -12,42 +13,42 @@ #define CP_TERM_GRAY "\x1B[90m" #define CP_TERM_CLEAR "\033[0m" -#define CP_DEBUG(format, ...) std::cout << CP_TERM_GRAY << "[DBG] " << __func__ << " : " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl -#define CP_INFO(format, ...) std::cout << "[INF] " << __func__ << " : " << Copium::String::Format(format, __VA_ARGS__) << std::endl -#define CP_WARN(format, ...) std::cout << CP_TERM_YELLOW << "[WRN] " << __func__ << " : " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl -#define CP_ERR(format, ...) std::cout << CP_TERM_RED << "[ERR] " << __func__ << " : " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl +#define CP_DEBUG(...) std::cout << CP_TERM_GRAY << "[DBG] " << __func__ << " : " << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR << std::endl +#define CP_INFO(...) std::cout << "[INF] " << __func__ << " : " << Copium::String::Format(__VA_ARGS__) << std::endl +#define CP_WARN(...) std::cout << CP_TERM_YELLOW << "[WRN] " << __func__ << " : " << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR << std::endl +#define CP_ERR(...) std::cout << CP_TERM_RED << "[ERR] " << __func__ << " : " << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR << std::endl // Continue traces, will not print the [XXX] tag before the log -#define CP_DEBUG_CONT(format, ...) std::cout << CP_TERM_GRAY << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl -#define CP_INFO_CONT(format, ...) std::cout << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(format, __VA_ARGS__) << std::endl -#define CP_WARN_CONT(format, ...) std::cout << CP_TERM_YELLOW << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl -#define CP_ERR_CONT(format, ...) std::cout << CP_TERM_RED << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl +#define CP_DEBUG_CONT(...) std::cout << CP_TERM_GRAY << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR << std::endl +#define CP_INFO_CONT(...) std::cout << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(__VA_ARGS__) << std::endl +#define CP_WARN_CONT(...) std::cout << CP_TERM_YELLOW << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR << std::endl +#define CP_ERR_CONT(...) std::cout << CP_TERM_RED << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(__VA_ARGS__) << CP_TERM_CLEAR << std::endl -#define CP_ABORT(format, ...) \ +#define CP_ABORT(...) \ do \ { \ CP_ERR("Aborted at %s:%d", __FILE__, __LINE__); \ - CP_ERR_CONT(format, __VA_ARGS__); \ - throw Copium::RuntimeException(Copium::String::Format(format, __VA_ARGS__)); \ + CP_ERR_CONT(__VA_ARGS__); \ + throw Copium::RuntimeException(Copium::String::Format(__VA_ARGS__)); \ } while(false) -#define CP_ASSERT(Function, format, ...) \ +#define CP_ASSERT(Function, ...) \ do \ { \ if(!(Function)) \ { \ CP_ERR("Assertion failed at %s:%d", __FILE__, __LINE__); \ - CP_ERR_CONT("%s : %s", #Function, Copium::String::Format(format, __VA_ARGS__).c_str()); \ - throw Copium::RuntimeException(Copium::String::Format(format, __VA_ARGS__)); \ + CP_ERR_CONT("%s : %s", #Function, Copium::String::Format(__VA_ARGS__).c_str()); \ + throw Copium::RuntimeException(Copium::String::Format(__VA_ARGS__)); \ } \ } while(false) -#define CP_VK_ASSERT(Function, format, ...) \ +#define CP_VK_ASSERT(Function, ...) \ do \ { \ if(Function != VK_SUCCESS) \ { \ CP_ERR("Assertion failed at %s:%d", __FILE__, __LINE__); \ - CP_ERR_CONT("%s : %s", #Function, Copium::String::Format(format, __VA_ARGS__).c_str()); \ - throw Copium::VulkanException(Copium::String::Format(format, __VA_ARGS__)); \ + CP_ERR_CONT("%s : %s", #Function, Copium::String::Format(__VA_ARGS__).c_str()); \ + throw Copium::VulkanException(Copium::String::Format(__VA_ARGS__)); \ } \ } while(false) @@ -68,6 +69,11 @@ namespace Copium { CP_STATIC_CLASS(String); public: + static std::string Format(const std::string& format) + { + return format; + } + template static std::string Format(const std::string& format, Args... args) { diff --git a/CopiumEngine/src/copium/util/Enum.h b/CopiumEngine/src/copium/util/Enum.h index bccc5bb..1b910bc 100644 --- a/CopiumEngine/src/copium/util/Enum.h +++ b/CopiumEngine/src/copium/util/Enum.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include @@ -15,7 +14,7 @@ namespace NameSpace { \ }; \ static const std::string& ToString(EnumName enumName) \ { \ - static std::vector enumNames = Copium::EnumPrinter::GetEnumNames(CP_TO_STRING(EnumList)); \ + static std::vector enumNames = Copium::EnumPrinter::GetEnumNames(CP_TO_STRING(#EnumList)); \ return enumNames[(int)enumName]; \ } \ \ diff --git a/CopiumEngine/src/copium/util/FileSystem.cpp b/CopiumEngine/src/copium/util/FileSystem.cpp index c3a6d2d..ba46a73 100644 --- a/CopiumEngine/src/copium/util/FileSystem.cpp +++ b/CopiumEngine/src/copium/util/FileSystem.cpp @@ -1,5 +1,10 @@ #include "copium/util/FileSystem.h" +#include +#include +#include +#include + namespace Copium { std::vector FileSystem::ReadFile(const std::string& filename) @@ -78,4 +83,4 @@ namespace Copium CP_ASSERT(stat(filename.c_str(), &result) == 0, "Cannot stat file %s", filename.c_str()); return (int64_t)result.st_mtime; } -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/util/FileSystem.h b/CopiumEngine/src/copium/util/FileSystem.h index 941788c..8773a7b 100644 --- a/CopiumEngine/src/copium/util/FileSystem.h +++ b/CopiumEngine/src/copium/util/FileSystem.h @@ -2,10 +2,8 @@ #include "copium/util/Common.h" -#include -#include -#include -#include +#include +#include namespace Copium { @@ -21,4 +19,4 @@ namespace Copium static bool FileExists(const std::string& filename); static int64_t DateModified(const std::string& filename); }; -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/util/RuntimeException.cpp b/CopiumEngine/src/copium/util/RuntimeException.cpp index 640521a..6c7518a 100644 --- a/CopiumEngine/src/copium/util/RuntimeException.cpp +++ b/CopiumEngine/src/copium/util/RuntimeException.cpp @@ -2,12 +2,12 @@ namespace Copium { - RuntimeException::RuntimeException(const std::string& str) + RuntimeException::RuntimeException(const std::string& str) : errorMessage{str} {} - const std::string& RuntimeException::GetErrorMessage() const + const std::string& RuntimeException::GetErrorMessage() const { return errorMessage; } -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/util/RuntimeException.h b/CopiumEngine/src/copium/util/RuntimeException.h index a9ef0bd..3390f7a 100644 --- a/CopiumEngine/src/copium/util/RuntimeException.h +++ b/CopiumEngine/src/copium/util/RuntimeException.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace Copium { @@ -13,4 +13,4 @@ namespace Copium const std::string& GetErrorMessage() const; }; -} \ No newline at end of file +} diff --git a/CopiumEngine/src/copium/util/StringUtil.h b/CopiumEngine/src/copium/util/StringUtil.h index bc95a73..59612c5 100644 --- a/CopiumEngine/src/copium/util/StringUtil.h +++ b/CopiumEngine/src/copium/util/StringUtil.h @@ -7,7 +7,6 @@ namespace Copium { - class StringUtil { CP_STATIC_CLASS(StringUtil); diff --git a/CopiumEngine/src/copium/util/Timer.cpp b/CopiumEngine/src/copium/util/Timer.cpp index 74ef705..104d44a 100644 --- a/CopiumEngine/src/copium/util/Timer.cpp +++ b/CopiumEngine/src/copium/util/Timer.cpp @@ -13,12 +13,12 @@ namespace Copium double Timer::Elapsed() { - return std::chrono::duration(std::chrono::high_resolution_clock::now() - startTime).count(); + return std::chrono::duration(std::chrono::steady_clock::now() - startTime).count(); } double Timer::ElapsedRestart() { - std::chrono::time_point newTime = std::chrono::high_resolution_clock::now(); + std::chrono::time_point newTime = std::chrono::steady_clock::now(); double elapsedTime = std::chrono::duration(newTime - startTime).count(); startTime = newTime; diff --git a/CopiumEngine/src/copium/util/VulkanException.h b/CopiumEngine/src/copium/util/VulkanException.h index d85e5be..aad0665 100644 --- a/CopiumEngine/src/copium/util/VulkanException.h +++ b/CopiumEngine/src/copium/util/VulkanException.h @@ -2,7 +2,7 @@ #include "copium/util/RuntimeException.h" -#include +#include namespace Copium { diff --git a/ext/projects/imgui/makegen.xml b/ext/projects/imgui/makegen.xml new file mode 100644 index 0000000..e1a452e --- /dev/null +++ b/ext/projects/imgui/makegen.xml @@ -0,0 +1,41 @@ + + + false + bin/Release/ + libimgui.so + sharedlibrary + ImGui + ../../repos/imgui/ + /usr/include/freetype2/ + ../../repos/imgui/imgui.cpp + ../../repos/imgui/imgui_demo.cpp + ../../repos/imgui/imgui_draw.cpp + ../../repos/imgui/imgui_tables.cpp + ../../repos/imgui/imgui_widgets.cpp + ../../repos/imgui/backends/imgui_impl_glfw.cpp + ../../repos/imgui/backends/imgui_impl_vulkan.cpp + + + + -g3 + -w + _DEBUG + false + bin/Debug/ + libimgui.so + sharedlibrary + ImGui + ../../repos/imgui/ + /usr/include/freetype2/ + ../../repos/imgui/imgui.cpp + ../../repos/imgui/imgui_demo.cpp + ../../repos/imgui/imgui_draw.cpp + ../../repos/imgui/imgui_tables.cpp + ../../repos/imgui/imgui_widgets.cpp + ../../repos/imgui/backends/imgui_impl_glfw.cpp + ../../repos/imgui/backends/imgui_impl_vulkan.cpp + + + Debug + v1.3.6 + diff --git a/ext/projects/msdf-atlas-gen/makegen.xml b/ext/projects/msdf-atlas-gen/makegen.xml new file mode 100644 index 0000000..cb597c3 --- /dev/null +++ b/ext/projects/msdf-atlas-gen/makegen.xml @@ -0,0 +1,33 @@ + + + MSDF_ATLAS_PUBLIC= + MSDFGEN_USE_LIBPNG + false + bin/Release/ + libmsdf-atlas-gen.so + sharedlibrary + MsdfAtlasGen + ../../repos/msdf-atlas-gen/msdf-atlas-gen/ + ../../repos/msdf-atlas-gen/msdfgen/ + ../../repos/msdf-atlas-gen/artery-font-format/ + ../../repos/msdf-atlas-gen/msdf-atlas-gen/ + + + -g3 + -w + _DEBUG + MSDF_ATLAS_PUBLIC= + MSDFGEN_USE_LIBPNG + false + bin/Debug/ + libmsdf-atlas-gen.so + sharedlibrary + MsdfAtlasGen + ../../repos/msdf-atlas-gen/msdf-atlas-gen/ + ../../repos/msdf-atlas-gen/msdfgen/ + ../../repos/msdf-atlas-gen/artery-font-format/ + ../../repos/msdf-atlas-gen/msdf-atlas-gen/ + + Debug + v1.3.6 + diff --git a/ext/projects/msdfgen-core/makegen.xml b/ext/projects/msdfgen-core/makegen.xml new file mode 100644 index 0000000..425d73c --- /dev/null +++ b/ext/projects/msdfgen-core/makegen.xml @@ -0,0 +1,31 @@ + + + MSDF_ATLAS_PUBLIC= + false + bin/Release/ + libmsdfgen-core.so + sharedlibrary + MsdfGenCore + ../../repos/msdf-atlas-gen/msdf-atlas-gen/ + ../../repos/msdf-atlas-gen/msdfgen/ + ../../repos/msdf-atlas-gen/artery-font-format/ + ../../repos/msdf-atlas-gen/msdfgen/core/ + + + -g3 + -w + _DEBUG + MSDF_ATLAS_PUBLIC= + false + bin/Debug/ + libmsdfgen-core.so + sharedlibrary + MsdfGenCore + ../../repos/msdf-atlas-gen/msdf-atlas-gen/ + ../../repos/msdf-atlas-gen/msdfgen/ + ../../repos/msdf-atlas-gen/artery-font-format/ + ../../repos/msdf-atlas-gen/msdfgen/core/ + + Debug + v1.3.6 + diff --git a/ext/projects/msdfgen-ext/makegen.xml b/ext/projects/msdfgen-ext/makegen.xml new file mode 100644 index 0000000..542365d --- /dev/null +++ b/ext/projects/msdfgen-ext/makegen.xml @@ -0,0 +1,37 @@ + + + MSDF_ATLAS_PUBLIC= + false + bin/Release/ + libmsdfgen-ext.so + sharedlibrary + MsdfGenExt + ../../repos/msdf-atlas-gen/msdf-atlas-gen/ + ../../repos/msdf-atlas-gen/msdfgen/ + ../../repos/msdf-atlas-gen/artery-font-format/ + ../../repos/freetype/include/ + ../../repos/msdf-atlas-gen/msdfgen/ext/import-font.cpp + ../../repos/msdf-atlas-gen/msdfgen/ext/save-png.cpp + + + + -g3 + -w + _DEBUG + MSDF_ATLAS_PUBLIC= + false + bin/Debug/ + libmsdfgen-ext.so + sharedlibrary + MsdfGenExt + ../../repos/msdf-atlas-gen/msdf-atlas-gen/ + ../../repos/msdf-atlas-gen/msdfgen/ + ../../repos/msdf-atlas-gen/artery-font-format/ + ../../repos/freetype/include/ + ../../repos/msdf-atlas-gen/msdfgen/ext/import-font.cpp + ../../repos/msdf-atlas-gen/msdfgen/ext/save-png.cpp + + + Debug + v1.3.6 +