Add Linux support

- Add linux build system using MakeGen
- Fix a swapchain validation error, likelydue to my linux system using a
  different vulkan version
- Make DescriptorPool take in amount of descriptors it needs, instead of
  allocating a mass amount for every pool, causing loads of RAM/VRAM usage
This commit is contained in:
Tim Håkansson
2025-08-09 21:42:15 +02:00
committed by GitHub
parent ecc11f07db
commit 4d2dfce31c
69 changed files with 389 additions and 152 deletions
+2
View File
@@ -9,3 +9,5 @@ bin/
.cache .cache
libs libs
imgui.ini imgui.ini
Makefile
compile_flags.txt
+53
View File
@@ -0,0 +1,53 @@
<makegen>
<configuration name="Release">
<define>MSDF_ATLAS_PUBLIC=</define>
<define>GLM_FORCE_LEFT_HANDED</define>
<define>GLM_FORCE_RADIANS</define>
<define>GLM_FORCE_DEPTH_ZERO_TO_ONE</define>
<dependency>../ext/projects/imgui/</dependency>
<dependency>../ext/projects/msdf-atlas-gen/</dependency>
<dependency>../ext/projects/msdfgen-core/</dependency>
<dependency>../ext/projects/msdfgen-ext/</dependency>
<generatehfile>false</generatehfile>
<outputdir>bin/Release/</outputdir>
<outputname>libcopium.so</outputname>
<outputtype>sharedlibrary</outputtype>
<projectname>Copium Engine</projectname>
<srcdir>src/</srcdir>
<includedir>src/</includedir>
<includedir>../ext/repos/imgui/</includedir>
<includedir>../ext/repos/imgui/backends/</includedir>
<includedir>../ext/repos/freetype/</includedir>
<includedir>../ext/repos/msdf-atlas-gen/msdfgen/</includedir>
<includedir>../ext/repos/msdf-atlas-gen/</includedir>
<includedir>../ext/repos/stb/</includedir>
</configuration>
<configuration name="Debug">
<cflag>-g3</cflag>
<cflag>-w</cflag>
<define>_DEBUG</define>
<define>MSDF_ATLAS_PUBLIC=</define>
<define>GLM_FORCE_LEFT_HANDED</define>
<define>GLM_FORCE_RADIANS</define>
<define>GLM_FORCE_DEPTH_ZERO_TO_ONE</define>
<dependency>../ext/projects/imgui/</dependency>
<dependency>../ext/projects/msdf-atlas-gen/</dependency>
<dependency>../ext/projects/msdfgen-core/</dependency>
<dependency>../ext/projects/msdfgen-ext/</dependency>
<generatehfile>false</generatehfile>
<outputdir>bin/Debug/</outputdir>
<outputname>libcopium.so</outputname>
<outputtype>sharedlibrary</outputtype>
<projectname>Copium Engine</projectname>
<srcdir>src/</srcdir>
<includedir>src/</includedir>
<includedir>../ext/repos/imgui/</includedir>
<includedir>../ext/repos/imgui/backends/</includedir>
<includedir>../ext/repos/freetype/</includedir>
<includedir>../ext/repos/msdf-atlas-gen/msdfgen/</includedir>
<includedir>../ext/repos/msdf-atlas-gen/</includedir>
<includedir>../ext/repos/stb/</includedir>
</configuration>
<target>Debug</target>
<version>v1.3.4</version>
</makegen>
-1
View File
@@ -1,7 +1,6 @@
#pragma once #pragma once
#include "copium/asset/AssetMeta.h" #include "copium/asset/AssetMeta.h"
#include "copium/util/MetaFile.h"
#include "copium/util/Uuid.h" #include "copium/util/Uuid.h"
#include <stdint.h> #include <stdint.h>
+2 -2
View File
@@ -17,7 +17,7 @@ namespace Copium
return dateModified < FileSystem::DateModified(path); return dateModified < FileSystem::DateModified(path);
} }
void AssetFile::Load() void AssetFile::Load()
{ {
MetaFile metaFile{path}; MetaFile metaFile{path};
for (auto&& assetType : assetTypes) for (auto&& assetType : assetTypes)
@@ -52,4 +52,4 @@ namespace Copium
{ {
assetTypes.emplace_back(assetType); assetTypes.emplace_back(assetType);
} }
} }
+1 -2
View File
@@ -1,6 +1,5 @@
#pragma once #pragma once
#include "copium/asset/AssetMeta.h"
#include "copium/util/MetaFile.h" #include "copium/util/MetaFile.h"
#include "copium/util/Uuid.h" #include "copium/util/Uuid.h"
@@ -27,4 +26,4 @@ namespace Copium
void Load(const MetaFile& metaFile, const std::string& className); void Load(const MetaFile& metaFile, const std::string& className);
static void RegisterAssetType(const std::string& assetType); static void RegisterAssetType(const std::string& assetType);
}; };
} }
@@ -1,8 +1,5 @@
#include "copium/asset/AssetManager.h" #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/Common.h"
#include "copium/util/MetaFile.h" #include "copium/util/MetaFile.h"
@@ -185,4 +182,4 @@ namespace Copium
} }
CP_ABORT("Unknown Asset type: %s", filepath.c_str()); CP_ABORT("Unknown Asset type: %s", filepath.c_str());
} }
} }
+1 -2
View File
@@ -1,7 +1,6 @@
#pragma once #pragma once
#include "copium/asset/Asset.h" #include "copium/asset/Asset.h"
#include "copium/asset/AssetMeta.h"
#include "copium/asset/AssetRef.h" #include "copium/asset/AssetRef.h"
#include "copium/buffer/CommandBuffer.h" #include "copium/buffer/CommandBuffer.h"
#include "copium/sampler/ColorAttachment.h" #include "copium/sampler/ColorAttachment.h"
@@ -44,4 +43,4 @@ namespace Copium
void InitializeRenderPass(); void InitializeRenderPass();
void InitializeFramebuffers(); void InitializeFramebuffers();
}; };
} }
@@ -5,7 +5,9 @@
namespace Copium namespace Copium
{ {
IndexBuffer::IndexBuffer(int indexCount) 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} indexCount{indexCount}
{} {}
@@ -24,4 +26,4 @@ namespace Copium
CP_ASSERT(indices >= 0 && indices <= indexCount, "amount of indices is out of range"); CP_ASSERT(indices >= 0 && indices <= indexCount, "amount of indices is out of range");
vkCmdDrawIndexed(commandBuffer, indices, 1, 0, 0, 0); vkCmdDrawIndexed(commandBuffer, indices, 1, 0, 0, 0);
} }
} }
@@ -84,4 +84,4 @@ namespace Copium
Buffer::Update(buffer.data(), i); Buffer::Update(buffer.data(), i);
} }
} }
} }
@@ -53,7 +53,7 @@ namespace Copium
VKAPI_ATTR VkBool32 VKAPI_CALL DebugMessenger::DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VKAPI_ATTR VkBool32 VKAPI_CALL DebugMessenger::DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
VkDebugUtilsMessageTypeFlagsEXT messageType, VkDebugUtilsMessageTypeFlagsEXT messageType,
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
void* pUserData) void* pUserData)
{ {
if (messageSeverity >= VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) if (messageSeverity >= VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT)
{ {
@@ -85,4 +85,4 @@ namespace Copium
} }
} }
} }
+1
View File
@@ -1,5 +1,6 @@
#include "Device.h" #include "Device.h"
#include "copium/core/QueueFamilies.h"
#include "copium/core/Vulkan.h" #include "copium/core/Vulkan.h"
#include "copium/core/Window.h" #include "copium/core/Window.h"
+2 -3
View File
@@ -1,6 +1,5 @@
#pragma once #pragma once
#include "copium/core/QueueFamilies.h"
#include "copium/util/Common.h" #include "copium/util/Common.h"
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
@@ -16,7 +15,7 @@ namespace Copium
public: public:
Device(); Device();
~Device(); ~Device();
uint32_t GetGraphicsQueueFamily() const; uint32_t GetGraphicsQueueFamily() const;
uint32_t GetPresentQueueFamily() const; uint32_t GetPresentQueueFamily() const;
VkQueue GetGraphicsQueue() const; VkQueue GetGraphicsQueue() const;
@@ -51,4 +50,4 @@ namespace Copium
bool CheckDeviceExtensionSupport(VkPhysicalDevice device); bool CheckDeviceExtensionSupport(VkPhysicalDevice device);
std::vector<const char*> GetRequiredDeviceExtensions(); std::vector<const char*> GetRequiredDeviceExtensions();
}; };
} }
@@ -10,7 +10,7 @@
namespace Copium namespace Copium
{ {
ImGuiInstance::ImGuiInstance() ImGuiInstance::ImGuiInstance()
: descriptorPool{std::make_unique<DescriptorPool>()} : descriptorPool{std::make_unique<DescriptorPool>(SwapChain::MAX_FRAMES_IN_FLIGHT, 1)}
{ {
InitializeImGui(); InitializeImGui();
InitializeDescriptorSetLayout(); InitializeDescriptorSetLayout();
@@ -109,4 +109,4 @@ namespace Copium
{ {
CP_VK_ASSERT(err, "Failed to initialize ImGui"); CP_VK_ASSERT(err, "Failed to initialize ImGui");
} }
} }
+3 -2
View File
@@ -1,8 +1,9 @@
#include "Instance.h" #include "Instance.h"
#include "copium/core/QueueFamilies.h"
#include "copium/util/Common.h" #include "copium/util/Common.h"
#include <GLFW/glfw3.h>
namespace Copium namespace Copium
{ {
Instance::Instance(const std::string& applicationName) Instance::Instance(const std::string& applicationName)
@@ -107,4 +108,4 @@ namespace Copium
} }
return true; return true;
} }
} }
-3
View File
@@ -2,9 +2,6 @@
#include "copium/core/DebugMessenger.h" #include "copium/core/DebugMessenger.h"
#include <GLFW/glfw3.h>
#include <set>
namespace Copium namespace Copium
{ {
class Instance final class Instance final
+15 -7
View File
@@ -4,10 +4,10 @@
#include "copium/core/Vulkan.h" #include "copium/core/Vulkan.h"
#include "copium/sampler/Image.h" #include "copium/sampler/Image.h"
#include <GLFW/glfw3.h>
namespace Copium namespace Copium
{ {
const int SwapChain::MAX_FRAMES_IN_FLIGHT = 2;
SwapChainSupportDetails::SwapChainSupportDetails(VkSurfaceKHR surface, VkPhysicalDevice physicalDevice) SwapChainSupportDetails::SwapChainSupportDetails(VkSurfaceKHR surface, VkPhysicalDevice physicalDevice)
{ {
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, &capabilities); vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, &capabilities);
@@ -35,6 +35,7 @@ namespace Copium
} }
SwapChain::SwapChain() SwapChain::SwapChain()
: flightIndex{0}, resizeFramebuffer{false}
{ {
Initialize(); Initialize();
InitializeImageViews(); InitializeImageViews();
@@ -49,9 +50,13 @@ namespace Copium
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i)
{ {
vkDestroyFence(Vulkan::GetDevice(), inFlightFences[i], nullptr); vkDestroyFence(Vulkan::GetDevice(), inFlightFences[i], nullptr);
vkDestroySemaphore(Vulkan::GetDevice(), renderFinishedSemaphores[i], nullptr);
vkDestroySemaphore(Vulkan::GetDevice(), imageAvailableSemaphores[i], nullptr); vkDestroySemaphore(Vulkan::GetDevice(), imageAvailableSemaphores[i], nullptr);
} }
for (size_t i = 0; i < images.size(); ++i)
{
vkDestroySemaphore(Vulkan::GetDevice(), renderFinishedSemaphores[i], nullptr);
}
Destroy(); Destroy();
vkDestroyRenderPass(Vulkan::GetDevice(), renderPass, nullptr); vkDestroyRenderPass(Vulkan::GetDevice(), renderPass, nullptr);
} }
@@ -137,7 +142,7 @@ namespace Copium
submitInfo.commandBufferCount = 1; submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &cmd; submitInfo.pCommandBuffers = &cmd;
submitInfo.signalSemaphoreCount = 1; 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"); CP_VK_ASSERT(vkQueueSubmit(Vulkan::GetDevice().GetGraphicsQueue(), 1, &submitInfo, inFlightFences[flightIndex]), "Failed to submit command buffer");
} }
@@ -147,7 +152,7 @@ namespace Copium
VkPresentInfoKHR presentInfo{}; VkPresentInfoKHR presentInfo{};
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
presentInfo.waitSemaphoreCount = 1; presentInfo.waitSemaphoreCount = 1;
presentInfo.pWaitSemaphores = &renderFinishedSemaphores[flightIndex]; presentInfo.pWaitSemaphores = &renderFinishedSemaphores[imageIndex];
presentInfo.swapchainCount = 1; presentInfo.swapchainCount = 1;
presentInfo.pSwapchains = &handle; presentInfo.pSwapchains = &handle;
presentInfo.pImageIndices = &imageIndex; presentInfo.pImageIndices = &imageIndex;
@@ -345,14 +350,12 @@ namespace Copium
void SwapChain::InitializeSyncObjects() void SwapChain::InitializeSyncObjects()
{ {
imageAvailableSemaphores.resize(MAX_FRAMES_IN_FLIGHT); imageAvailableSemaphores.resize(MAX_FRAMES_IN_FLIGHT);
renderFinishedSemaphores.resize(MAX_FRAMES_IN_FLIGHT);
inFlightFences.resize(MAX_FRAMES_IN_FLIGHT); inFlightFences.resize(MAX_FRAMES_IN_FLIGHT);
VkSemaphoreCreateInfo semaphoreCreateInfo{}; VkSemaphoreCreateInfo semaphoreCreateInfo{};
semaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; semaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) 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, &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{}; VkFenceCreateInfo fenceCreateInfo{};
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; 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"); 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() void SwapChain::Destroy()
+2 -2
View File
@@ -24,7 +24,7 @@ namespace Copium
{ {
CP_DELETE_COPY_AND_MOVE_CTOR(SwapChain); CP_DELETE_COPY_AND_MOVE_CTOR(SwapChain);
public: public:
static const int MAX_FRAMES_IN_FLIGHT = 2; static const int MAX_FRAMES_IN_FLIGHT;
private: private:
VkSwapchainKHR handle; VkSwapchainKHR handle;
VkRenderPass renderPass; VkRenderPass renderPass;
@@ -34,7 +34,7 @@ namespace Copium
std::vector<VkImageView> imageViews; std::vector<VkImageView> imageViews;
std::vector<VkImage> images; std::vector<VkImage> images;
std::vector<VkFramebuffer> framebuffers; std::vector<VkFramebuffer> framebuffers;
uint32_t imageIndex; uint32_t imageIndex;
bool resizeFramebuffer; bool resizeFramebuffer;
int flightIndex; int flightIndex;
+10 -1
View File
@@ -22,6 +22,10 @@ namespace Copium
{ {
Timer timer; Timer timer;
timer.Start(); timer.Start();
glfwSetErrorCallback(glfw_error_callback);
CP_ASSERT(glfwInit() == GLFW_TRUE, "Failed to initialize the glfw context");
instance = std::make_unique<Instance>("Copium Engine"); instance = std::make_unique<Instance>("Copium Engine");
window = std::make_unique<Window>("Copium Engine", 1440, 810, WindowMode::Windowed); window = std::make_unique<Window>("Copium Engine", 1440, 810, WindowMode::Windowed);
device = std::make_unique<Device>(); device = std::make_unique<Device>();
@@ -97,4 +101,9 @@ namespace Copium
{ {
return instance && window && device && swapChain; return instance && window && device && swapChain;
} }
}
void Vulkan::glfw_error_callback(int error, const char* description)
{
CP_ABORT("GLFW Error %d: %s\n", error, description);
}
}
+4 -1
View File
@@ -36,5 +36,8 @@ namespace Copium
static bool Valid(); static bool Valid();
static AssetHandle<Texture2D> GetWhiteTexture2D(); static AssetHandle<Texture2D> GetWhiteTexture2D();
static AssetHandle<Texture2D> GetEmptyTexture2D(); static AssetHandle<Texture2D> GetEmptyTexture2D();
private:
static void glfw_error_callback(int error, const char* description);
}; };
} }
+4 -3
View File
@@ -9,8 +9,8 @@
#include "copium/event/MousePressEvent.h" #include "copium/event/MousePressEvent.h"
#include "copium/event/MouseReleaseEvent.h" #include "copium/event/MouseReleaseEvent.h"
#include "copium/event/MouseScrollEvent.h" #include "copium/event/MouseScrollEvent.h"
#include "copium/event/WindowResizeEvent.h"
#include "copium/event/WindowFocusEvent.h" #include "copium/event/WindowFocusEvent.h"
#include "copium/event/WindowResizeEvent.h"
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
@@ -32,7 +32,6 @@ namespace Copium
bool Window::ShouldClose() const bool Window::ShouldClose() const
{ {
return glfwWindowShouldClose(window); return glfwWindowShouldClose(window);
} }
int Window::GetWidth() const int Window::GetWidth() const
@@ -72,6 +71,8 @@ namespace Copium
{ {
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
CP_ASSERT(glfwVulkanSupported(), "Vulkan is not supported");
switch (mode) switch (mode)
{ {
case WindowMode::Fullscreen: case WindowMode::Fullscreen:
@@ -187,4 +188,4 @@ namespace Copium
{ {
EventDispatcher::QueueEvent(MouseScrollEvent{(int)xoffset, (int)yoffset}); EventDispatcher::QueueEvent(MouseScrollEvent{(int)xoffset, (int)yoffset});
} }
} }
+1 -1
View File
@@ -51,4 +51,4 @@ namespace Copium
static void WindowFocusCallback(GLFWwindow* window, int focused); static void WindowFocusCallback(GLFWwindow* window, int focused);
static void MouseScrollCallback(GLFWwindow* window, double xoffset, double yoffset); static void MouseScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
}; };
} }
@@ -1,9 +1,11 @@
#pragma once #pragma once
#include "copium/ecs/ECSManager.h" #include "copium/ecs/Config.h"
namespace Copium namespace Copium
{ {
class ECSManager;
template <typename Component> template <typename Component>
class ComponentListener class ComponentListener
{ {
+1 -2
View File
@@ -11,7 +11,6 @@
#include <map> #include <map>
#include <typeindex> #include <typeindex>
#include <unordered_set> #include <unordered_set>
#include <vector>
namespace Copium namespace Copium
{ {
@@ -36,7 +35,7 @@ namespace Copium
template <typename SystemClass> template <typename SystemClass>
void RemoveSystem() void RemoveSystem()
{ {
systemPool->MoveSystemBefore(typeid(SystemClass)); systemPool->RemoveSystem(typeid(SystemClass));
} }
void UpdateSystems(); void UpdateSystems();
+2 -1
View File
@@ -4,6 +4,8 @@
#include "copium/ecs/SystemBase.h" #include "copium/ecs/SystemBase.h"
#include "copium/ecs/Entity.h" #include "copium/ecs/Entity.h"
#include <set>
namespace Copium namespace Copium
{ {
template <typename... Components> template <typename... Components>
@@ -26,7 +28,6 @@ namespace Copium
// TODO: Not sure if this is the way entities should be validated // TODO: Not sure if this is the way entities should be validated
std::set<EntityId> loggedEntities; std::set<EntityId> loggedEntities;
template <typename... Components>
bool ValidateEntity(Entity entity) bool ValidateEntity(Entity entity)
{ {
if (entity && entity.HasComponents<Components...>()) if (entity && entity.HasComponents<Components...>())
+2
View File
@@ -13,6 +13,8 @@ namespace Copium
ECSManager* manager; ECSManager* manager;
public: public:
virtual ~SystemBase() = default;
virtual void Run() = 0; virtual void Run() = 0;
virtual void Run(const Signal& signal) = 0; virtual void Run(const Signal& signal) = 0;
}; };
@@ -1,7 +1,5 @@
#pragma once #pragma once
#include <vector>
#include <map>
#include <typeindex> #include <typeindex>
namespace Copium namespace Copium
@@ -1,5 +1,7 @@
#include "copium/ecs/SystemPool.h" #include "copium/ecs/SystemPool.h"
#include <algorithm>
namespace Copium namespace Copium
{ {
SystemPool::SystemPool(ECSManager* manager) SystemPool::SystemPool(ECSManager* manager)
+2
View File
@@ -11,6 +11,8 @@ namespace Copium
public: public:
Event(EventType type); Event(EventType type);
virtual ~Event() = default;
EventType GetType() const; EventType GetType() const;
}; };
} }
+2 -1
View File
@@ -1,7 +1,8 @@
#include "copium/event/Input.h" #include "copium/event/Input.h"
#include "copium/util/Common.h"
#include "copium/core/Vulkan.h" #include "copium/core/Vulkan.h"
#include "copium/event/InputCode.h"
#include "copium/util/Common.h"
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
+1 -3
View File
@@ -1,11 +1,9 @@
#pragma once #pragma once
#include <vector>
#include "copium/event/InputCode.h"
#include "copium/util/BoundingBox.h" #include "copium/util/BoundingBox.h"
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <string>
namespace Copium namespace Copium
{ {
+1 -3
View File
@@ -1,7 +1,5 @@
#pragma once #pragma once
#include "copium/util/Enum.h"
#define CP_MOUSE_LEFT 0 #define CP_MOUSE_LEFT 0
#define CP_MOUSE_RIGHT 1 #define CP_MOUSE_RIGHT 1
#define CP_MOUSE_MIDDLE 2 #define CP_MOUSE_MIDDLE 2
@@ -128,4 +126,4 @@
#define CP_KEY_RIGHT_ALT 346 #define CP_KEY_RIGHT_ALT 346
#define CP_KEY_RIGHT_SUPER 347 #define CP_KEY_RIGHT_SUPER 347
#define CP_KEY_MENU 348 #define CP_KEY_MENU 348
#define CP_KEY_UNBOUND 0xffffffff #define CP_KEY_UNBOUND 0x0fffffff
@@ -6,7 +6,7 @@ namespace Copium
: Event{EventType::MousePress}, button{button} : Event{EventType::MousePress}, button{button}
{} {}
int MousePressEvent::GetButton() const int MousePressEvent::GetButton() const
{ {
return button; return button;
} }
@@ -6,7 +6,7 @@ namespace Copium
: Event{EventType::MouseRelease}, button{button} : Event{EventType::MouseRelease}, button{button}
{} {}
int MouseReleaseEvent::GetButton() const int MouseReleaseEvent::GetButton() const
{ {
return button; return button;
} }
@@ -1,7 +1,6 @@
#pragma once #pragma once
#include "copium/event/Event.h" #include "copium/event/Event.h"
#include "copium/event/EventType.h"
#include "copium/util/BoundingBox.h" #include "copium/util/BoundingBox.h"
namespace Copium namespace Copium
+1 -1
View File
@@ -6,7 +6,7 @@
namespace Copium namespace Copium
{ {
struct Vertex struct Vertex
{ {
glm::vec3 pos; glm::vec3 pos;
glm::vec3 color; glm::vec3 color;
@@ -6,7 +6,7 @@
namespace Copium namespace Copium
{ {
struct VertexPassthrough struct VertexPassthrough
{ {
glm::vec2 texCoord; glm::vec2 texCoord;
@@ -4,20 +4,31 @@
namespace Copium namespace Copium
{ {
DescriptorPool::DescriptorPool() DescriptorPool::DescriptorPool(int uniformDescriptorSets, int imageDescriptorSets)
{ {
std::vector<VkDescriptorPoolSize> poolSizes{2}; std::vector<VkDescriptorPoolSize> poolSizes;
poolSizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; if (uniformDescriptorSets != 0)
poolSizes[0].descriptorCount = DESCRIPTOR_SET_COUNT * SwapChain::MAX_FRAMES_IN_FLIGHT; // TODO: how should this actually be determined? {
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{}; VkDescriptorPoolCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
createInfo.poolSizeCount = poolSizes.size(); createInfo.poolSizeCount = poolSizes.size();
createInfo.pPoolSizes = poolSizes.data(); 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; createInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
CP_VK_ASSERT(vkCreateDescriptorPool(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorPool), "Failed to initialize descriptor pool"); CP_VK_ASSERT(vkCreateDescriptorPool(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorPool), "Failed to initialize descriptor pool");
@@ -59,4 +70,4 @@ namespace Copium
{ {
return descriptorPool; return descriptorPool;
} }
} }
@@ -11,9 +11,8 @@ namespace Copium
CP_DELETE_COPY_AND_MOVE_CTOR(DescriptorPool); CP_DELETE_COPY_AND_MOVE_CTOR(DescriptorPool);
private: private:
VkDescriptorPool descriptorPool; VkDescriptorPool descriptorPool;
static const int DESCRIPTOR_SET_COUNT = 1000000;
public: public:
DescriptorPool(); DescriptorPool(int uniformDescriptorSets, int imageDescriptorSets);
~DescriptorPool(); ~DescriptorPool();
std::vector<VkDescriptorSet> AllocateDescriptorSets(VkDescriptorSetLayout descriptorSetLayout); std::vector<VkDescriptorSet> AllocateDescriptorSets(VkDescriptorSetLayout descriptorSetLayout);
@@ -3,7 +3,6 @@
#include "copium/buffer/UniformBuffer.h" #include "copium/buffer/UniformBuffer.h"
#include "copium/pipeline/DescriptorPool.h" #include "copium/pipeline/DescriptorPool.h"
#include "copium/pipeline/ShaderBinding.h" #include "copium/pipeline/ShaderBinding.h"
#include "copium/pipeline/ShaderReflector.h"
#include "copium/sampler/Sampler.h" #include "copium/sampler/Sampler.h"
#include "copium/util/Common.h" #include "copium/util/Common.h"
@@ -42,4 +41,4 @@ namespace Copium
private: private:
void SetUniformBuffer(const UniformBuffer& uniformBuffer, uint32_t binding); void SetUniformBuffer(const UniformBuffer& uniformBuffer, uint32_t binding);
}; };
} }
@@ -1,6 +1,5 @@
#include "copium/pipeline/Pipeline.h" #include "copium/pipeline/Pipeline.h"
#include "copium/asset/AssetManager.h"
#include "copium/buffer/Framebuffer.h" #include "copium/buffer/Framebuffer.h"
#include "copium/core/Vulkan.h" #include "copium/core/Vulkan.h"
#include "copium/pipeline/Shader.h" #include "copium/pipeline/Shader.h"
@@ -8,7 +7,6 @@
#include "copium/mesh/VertexPassthrough.h" #include "copium/mesh/VertexPassthrough.h"
#include "copium/mesh/Vertex.h" #include "copium/mesh/Vertex.h"
#include "copium/renderer/LineVertex.h" #include "copium/renderer/LineVertex.h"
#include "copium/util/FileSystem.h"
namespace Copium namespace Copium
{ {
@@ -121,6 +119,11 @@ namespace Copium
return DescriptorSet{descriptorPool, descriptorSetLayouts[setIndex], bindings}; return DescriptorSet{descriptorPool, descriptorSetLayouts[setIndex], bindings};
} }
int Pipeline::GetDescriptorSetCount() const
{
return boundDescriptorSets.size();
}
void Pipeline::InitializeDescriptorSetLayout(const PipelineCreator& creator) void Pipeline::InitializeDescriptorSetLayout(const PipelineCreator& creator)
{ {
boundDescriptorSets.resize(creator.descriptorSetLayouts.size()); 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"); CP_VK_ASSERT(vkCreateGraphicsPipelines(Vulkan::GetDevice(), VK_NULL_HANDLE, 1, &graphicsPipelineCreateInfo, nullptr, &graphicsPipeline), "Failed to initialize graphics pipeline");
} }
} }
+3 -1
View File
@@ -36,8 +36,10 @@ namespace Copium
std::unique_ptr<DescriptorSet> CreateDescriptorSet(DescriptorPool& descriptorPool, int setIndex) const; std::unique_ptr<DescriptorSet> CreateDescriptorSet(DescriptorPool& descriptorPool, int setIndex) const;
DescriptorSet CreateDescriptorSetRef(DescriptorPool& descriptorPool, int setIndex) const; DescriptorSet CreateDescriptorSetRef(DescriptorPool& descriptorPool, int setIndex) const;
int GetDescriptorSetCount() const;
private: private:
void InitializeDescriptorSetLayout(const PipelineCreator& creator); void InitializeDescriptorSetLayout(const PipelineCreator& creator);
void InitializePipeline(const PipelineCreator& creator); void InitializePipeline(const PipelineCreator& creator);
}; };
} }
@@ -76,4 +76,4 @@ namespace Copium
CP_ABORT("Unhandled switch case"); CP_ABORT("Unhandled switch case");
} }
} }
} }
@@ -7,6 +7,7 @@
#include <map> #include <map>
#include <string> #include <string>
#include <cstdint>
namespace Copium namespace Copium
{ {
@@ -4,6 +4,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <cstdint>
#define CP_BINDING_TYPE_ENUMS Sampler2D, UniformBuffer #define CP_BINDING_TYPE_ENUMS Sampler2D, UniformBuffer
+3 -2
View File
@@ -1,12 +1,13 @@
#include "copium/renderer/Batch.h" #include "copium/renderer/Batch.h"
#include "copium/asset/AssetManager.h" #include "copium/core/SwapChain.h"
#include "copium/renderer/RendererVertex.h" #include "copium/renderer/RendererVertex.h"
namespace Copium namespace Copium
{ {
Batch::Batch(AssetRef<Pipeline>& pipeline, DescriptorPool& descriptorPool, int vertexCount, const std::vector<const Sampler*> samplers) Batch::Batch(AssetRef<Pipeline>& pipeline, int vertexCount, const std::vector<const Sampler*> samplers)
: vertexBuffer{RendererVertex::GetDescriptor(), vertexCount}, : 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)} descriptorSet{pipeline.GetAsset().CreateDescriptorSet(descriptorPool, 0)}
{} {}
+2 -2
View File
@@ -1,6 +1,5 @@
#pragma once #pragma once
#include "copium/asset/AssetMeta.h"
#include "copium/asset/AssetRef.h" #include "copium/asset/AssetRef.h"
#include "copium/buffer/RendererVertexBuffer.h" #include "copium/buffer/RendererVertexBuffer.h"
#include "copium/pipeline/DescriptorSet.h" #include "copium/pipeline/DescriptorSet.h"
@@ -14,9 +13,10 @@ namespace Copium
CP_DELETE_COPY_AND_MOVE_CTOR(Batch); CP_DELETE_COPY_AND_MOVE_CTOR(Batch);
private: private:
RendererVertexBuffer vertexBuffer; RendererVertexBuffer vertexBuffer;
DescriptorPool descriptorPool;
std::unique_ptr<DescriptorSet> descriptorSet; std::unique_ptr<DescriptorSet> descriptorSet;
public: public:
Batch(AssetRef<Pipeline>& pipeline, DescriptorPool& descriptorPool, int vertexCount, const std::vector<const Sampler*> samplers); Batch(AssetRef<Pipeline>& pipeline, int vertexCount, const std::vector<const Sampler*> samplers);
RendererVertexBuffer& GetVertexBuffer(); RendererVertexBuffer& GetVertexBuffer();
DescriptorSet& GetDescriptorSet(); DescriptorSet& GetDescriptorSet();
}; };
@@ -1,8 +1,8 @@
#include "copium/renderer/LineRenderer.h" #include "copium/renderer/LineRenderer.h"
#include "copium/asset/AssetManager.h"
#include "copium/core/Vulkan.h" #include "copium/core/Vulkan.h"
#include "copium/pipeline/PipelineCreator.h" #include "copium/pipeline/PipelineCreator.h"
#include "copium/renderer/LineVertex.h"
namespace Copium namespace Copium
{ {
@@ -10,8 +10,8 @@ namespace Copium
static constexpr int MAX_NUM_VERTICES = 2 * MAX_NUM_LINES; static constexpr int MAX_NUM_VERTICES = 2 * MAX_NUM_LINES;
LineRenderer::LineRenderer(const AssetRef<Pipeline>& pipeline) LineRenderer::LineRenderer(const AssetRef<Pipeline>& pipeline)
: descriptorPool{}, : descriptorPool{pipeline.GetAsset().GetDescriptorSetCount() * SwapChain::MAX_FRAMES_IN_FLIGHT, 0},
ibo{MAX_NUM_VERTICES}, ibo{MAX_NUM_VERTICES},
pipeline{pipeline}, pipeline{pipeline},
vertexBuffer{LineVertex::GetDescriptor(), MAX_NUM_VERTICES} vertexBuffer{LineVertex::GetDescriptor(), MAX_NUM_VERTICES}
{ {
@@ -60,7 +60,7 @@ namespace Copium
pipeline.GetAsset().SetDescriptorSet(descriptorSet); pipeline.GetAsset().SetDescriptorSet(descriptorSet);
} }
void LineRenderer::InitializeIndexBuffer() void LineRenderer::InitializeIndexBuffer()
{ {
CP_ASSERT(MAX_NUM_VERTICES < std::numeric_limits<uint16_t>::max(), "Maximum number of indices too big"); CP_ASSERT(MAX_NUM_VERTICES < std::numeric_limits<uint16_t>::max(), "Maximum number of indices too big");
@@ -87,4 +87,4 @@ namespace Copium
pl.BindDescriptorSets(*currentCommandBuffer); pl.BindDescriptorSets(*currentCommandBuffer);
ibo.Draw(*currentCommandBuffer, lineCount * 2); ibo.Draw(*currentCommandBuffer, lineCount * 2);
} }
} }
@@ -3,12 +3,10 @@
#include "copium/buffer/CommandBuffer.h" #include "copium/buffer/CommandBuffer.h"
#include "copium/buffer/IndexBuffer.h" #include "copium/buffer/IndexBuffer.h"
#include "copium/buffer/RendererVertexBuffer.h" #include "copium/buffer/RendererVertexBuffer.h"
#include "copium/renderer/LineVertex.h"
#include "copium/pipeline/Pipeline.h" #include "copium/pipeline/Pipeline.h"
#include "copium/util/Common.h" #include "copium/util/Common.h"
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <vector>
namespace Copium namespace Copium
{ {
+6 -12
View File
@@ -1,6 +1,5 @@
#include "copium/renderer/Renderer.h" #include "copium/renderer/Renderer.h"
#include "copium/asset/AssetManager.h"
#include "copium/core/Vulkan.h" #include "copium/core/Vulkan.h"
#include "copium/pipeline/PipelineCreator.h" #include "copium/pipeline/PipelineCreator.h"
#include "copium/renderer/RendererVertex.h" #include "copium/renderer/RendererVertex.h"
@@ -13,18 +12,13 @@ namespace Copium
static constexpr int MAX_NUM_TEXTURES = 32; static constexpr int MAX_NUM_TEXTURES = 32;
Renderer::Renderer(const AssetRef<Pipeline>& pipeline) Renderer::Renderer(const AssetRef<Pipeline>& pipeline)
: descriptorPool{}, : ibo{MAX_NUM_INDICES},
ibo{MAX_NUM_INDICES},
pipeline{pipeline}, pipeline{pipeline},
samplers{MAX_NUM_TEXTURES, &Vulkan::GetEmptyTexture2D().GetAsset()} samplers{MAX_NUM_TEXTURES, &Vulkan::GetEmptyTexture2D().GetAsset()}
{ {
InitializeIndexBuffer(); InitializeIndexBuffer();
} }
Renderer::~Renderer()
{
}
void Renderer::Quad(const glm::vec2& pos, const glm::vec2& size, const glm::vec3& color) void Renderer::Quad(const glm::vec2& pos, const glm::vec2& size, const glm::vec3& color)
{ {
AllocateQuad(); AllocateQuad();
@@ -71,9 +65,9 @@ namespace Copium
const Glyph& glyph = font.GetGlyph(c); const Glyph& glyph = font.GetGlyph(c);
AllocateQuad(); AllocateQuad();
int texIndex = AllocateSampler(font); 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.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); 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; offset.x += glyph.advance * size;
} }
@@ -115,7 +109,7 @@ namespace Copium
pipeline.GetAsset().SetDescriptorSet(descriptorSet); pipeline.GetAsset().SetDescriptorSet(descriptorSet);
} }
void Renderer::InitializeIndexBuffer() void Renderer::InitializeIndexBuffer()
{ {
CP_ASSERT(MAX_NUM_INDICES < std::numeric_limits<uint16_t>::max(), "Maximum number of indices too big"); CP_ASSERT(MAX_NUM_INDICES < std::numeric_limits<uint16_t>::max(), "Maximum number of indices too big");
@@ -180,11 +174,11 @@ namespace Copium
std::fill(samplers.begin(), samplers.end(), &Vulkan::GetEmptyTexture2D().GetAsset()); std::fill(samplers.begin(), samplers.end(), &Vulkan::GetEmptyTexture2D().GetAsset());
if (batchIndex >= batches.size()) if (batchIndex >= batches.size())
{ {
batches.emplace_back(std::make_unique<Batch>(pipeline, descriptorPool, MAX_NUM_VERTICES, samplers)); batches.emplace_back(std::make_unique<Batch>(pipeline, MAX_NUM_VERTICES, samplers));
} }
batches[batchIndex]->GetDescriptorSet().SetSamplersDynamic(samplers, 0); batches[batchIndex]->GetDescriptorSet().SetSamplersDynamic(samplers, 0);
mappedVertexBuffer = (char*)batches[batchIndex]->GetVertexBuffer().Map() + batches[batchIndex]->GetVertexBuffer().GetPosition(Vulkan::GetSwapChain().GetFlightIndex()); mappedVertexBuffer = (char*)batches[batchIndex]->GetVertexBuffer().Map() + batches[batchIndex]->GetVertexBuffer().GetPosition(Vulkan::GetSwapChain().GetFlightIndex());
quadCount = 0; quadCount = 0;
textureCount = 0; textureCount = 0;
} }
} }
+1 -6
View File
@@ -1,13 +1,10 @@
#pragma once #pragma once
#include "copium/asset/AssetMeta.h"
#include "copium/asset/AssetRef.h" #include "copium/asset/AssetRef.h"
#include "copium/buffer/CommandBuffer.h" #include "copium/buffer/CommandBuffer.h"
#include "copium/buffer/IndexBuffer.h" #include "copium/buffer/IndexBuffer.h"
#include "copium/buffer/RendererVertexBuffer.h"
#include "copium/pipeline/Pipeline.h" #include "copium/pipeline/Pipeline.h"
#include "copium/renderer/Batch.h" #include "copium/renderer/Batch.h"
#include "copium/sampler/Texture2D.h"
#include "copium/sampler/Font.h" #include "copium/sampler/Font.h"
#include "copium/util/Common.h" #include "copium/util/Common.h"
@@ -16,11 +13,10 @@
namespace Copium namespace Copium
{ {
class Renderer class Renderer final
{ {
CP_DELETE_COPY_AND_MOVE_CTOR(Renderer); CP_DELETE_COPY_AND_MOVE_CTOR(Renderer);
private: private:
DescriptorPool descriptorPool;
IndexBuffer ibo; IndexBuffer ibo;
AssetRef<Pipeline> pipeline; AssetRef<Pipeline> pipeline;
std::vector<std::unique_ptr<Batch>> batches; std::vector<std::unique_ptr<Batch>> batches;
@@ -34,7 +30,6 @@ namespace Copium
void* mappedVertexBuffer; void* mappedVertexBuffer;
public: public:
Renderer(const AssetRef<Pipeline>& pipeline); Renderer(const AssetRef<Pipeline>& 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 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}); 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});
@@ -25,6 +25,5 @@ namespace Copium
private: private:
void InitializeDepthAttachment(int width, int height); void InitializeDepthAttachment(int width, int height);
}; };
} }
+4 -1
View File
@@ -143,7 +143,10 @@ namespace Copium
boundingBox.b = std::min(boundingBox.b, offset.y + glyph.boundingBox.b); boundingBox.b = std::min(boundingBox.b, offset.y + glyph.boundingBox.b);
} }
boundingBox.r = std::max(boundingBox.r, offset.x); 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; return boundingBox;
} }
@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "copium/util/MetaFile.h" #include "copium/util/MetaFile.h"
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
namespace Copium namespace Copium
@@ -6,8 +6,6 @@
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h> #include <stb_image.h>
#include <fstream>
namespace Copium namespace Copium
{ {
Texture2D::Texture2D(const MetaFile& metaFile) Texture2D::Texture2D(const MetaFile& metaFile)
+13 -3
View File
@@ -15,12 +15,12 @@ namespace Copium
{} {}
BoundingBox::BoundingBox(glm::vec2 lb, glm::vec2 rt) 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 bool BoundingBox::operator==(const BoundingBox& boundingBox) const
@@ -32,4 +32,14 @@ namespace Copium
{ {
return !(*this == boundingBox); return !(*this == boundingBox);
} }
glm::vec2 BoundingBox::AsLb() const
{
return glm::vec2{l, b};
}
glm::vec2 BoundingBox::AsRt() const
{
return glm::vec2{r, t};
}
} }
+7 -6
View File
@@ -6,12 +6,10 @@ namespace Copium
{ {
struct BoundingBox struct BoundingBox
{ {
union float l;
{ float b;
struct { float l; float b; float r; float t; }; float r;
struct { glm::vec2 lb; glm::vec2 rt; }; float t;
struct { glm::vec4 lbrt; };
};
BoundingBox(); BoundingBox();
BoundingBox(float all); BoundingBox(float all);
BoundingBox(float l, float b, float r, float t); 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;
bool operator!=(const BoundingBox& boundingBox) const; bool operator!=(const BoundingBox& boundingBox) const;
glm::vec2 AsLb() const;
glm::vec2 AsRt() const;
}; };
} }
+23 -17
View File
@@ -5,6 +5,7 @@
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <memory>
#define CP_TERM_RED "\x1B[31m" #define CP_TERM_RED "\x1B[31m"
#define CP_TERM_GREEN "\x1B[32m" #define CP_TERM_GREEN "\x1B[32m"
@@ -12,42 +13,42 @@
#define CP_TERM_GRAY "\x1B[90m" #define CP_TERM_GRAY "\x1B[90m"
#define CP_TERM_CLEAR "\033[0m" #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_DEBUG(...) std::cout << CP_TERM_GRAY << "[DBG] " << __func__ << " : " << Copium::String::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_INFO(...) std::cout << "[INF] " << __func__ << " : " << Copium::String::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_WARN(...) std::cout << CP_TERM_YELLOW << "[WRN] " << __func__ << " : " << Copium::String::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_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 // 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_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(format, ...) std::cout << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(format, __VA_ARGS__) << 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(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_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(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_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 \ do \
{ \ { \
CP_ERR("Aborted at %s:%d", __FILE__, __LINE__); \ CP_ERR("Aborted at %s:%d", __FILE__, __LINE__); \
CP_ERR_CONT(format, __VA_ARGS__); \ CP_ERR_CONT(__VA_ARGS__); \
throw Copium::RuntimeException(Copium::String::Format(format, __VA_ARGS__)); \ throw Copium::RuntimeException(Copium::String::Format(__VA_ARGS__)); \
} while(false) } while(false)
#define CP_ASSERT(Function, format, ...) \ #define CP_ASSERT(Function, ...) \
do \ do \
{ \ { \
if(!(Function)) \ if(!(Function)) \
{ \ { \
CP_ERR("Assertion failed at %s:%d", __FILE__, __LINE__); \ CP_ERR("Assertion failed at %s:%d", __FILE__, __LINE__); \
CP_ERR_CONT("%s : %s", #Function, Copium::String::Format(format, __VA_ARGS__).c_str()); \ CP_ERR_CONT("%s : %s", #Function, Copium::String::Format(__VA_ARGS__).c_str()); \
throw Copium::RuntimeException(Copium::String::Format(format, __VA_ARGS__)); \ throw Copium::RuntimeException(Copium::String::Format(__VA_ARGS__)); \
} \ } \
} while(false) } while(false)
#define CP_VK_ASSERT(Function, format, ...) \ #define CP_VK_ASSERT(Function, ...) \
do \ do \
{ \ { \
if(Function != VK_SUCCESS) \ if(Function != VK_SUCCESS) \
{ \ { \
CP_ERR("Assertion failed at %s:%d", __FILE__, __LINE__); \ CP_ERR("Assertion failed at %s:%d", __FILE__, __LINE__); \
CP_ERR_CONT("%s : %s", #Function, Copium::String::Format(format, __VA_ARGS__).c_str()); \ CP_ERR_CONT("%s : %s", #Function, Copium::String::Format(__VA_ARGS__).c_str()); \
throw Copium::VulkanException(Copium::String::Format(format, __VA_ARGS__)); \ throw Copium::VulkanException(Copium::String::Format(__VA_ARGS__)); \
} \ } \
} while(false) } while(false)
@@ -68,6 +69,11 @@ namespace Copium
{ {
CP_STATIC_CLASS(String); CP_STATIC_CLASS(String);
public: public:
static std::string Format(const std::string& format)
{
return format;
}
template<typename ... Args> template<typename ... Args>
static std::string Format(const std::string& format, Args... args) static std::string Format(const std::string& format, Args... args)
{ {
+1 -2
View File
@@ -1,6 +1,5 @@
#pragma once #pragma once
#include <ostream>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -15,7 +14,7 @@ namespace NameSpace { \
}; \ }; \
static const std::string& ToString(EnumName enumName) \ static const std::string& ToString(EnumName enumName) \
{ \ { \
static std::vector<std::string> enumNames = Copium::EnumPrinter::GetEnumNames(CP_TO_STRING(EnumList)); \ static std::vector<std::string> enumNames = Copium::EnumPrinter::GetEnumNames(CP_TO_STRING(#EnumList)); \
return enumNames[(int)enumName]; \ return enumNames[(int)enumName]; \
} \ } \
\ \
+6 -1
View File
@@ -1,5 +1,10 @@
#include "copium/util/FileSystem.h" #include "copium/util/FileSystem.h"
#include <filesystem>
#include <fstream>
#include <sys/stat.h>
#include <sys/types.h>
namespace Copium namespace Copium
{ {
std::vector<char> FileSystem::ReadFile(const std::string& filename) std::vector<char> 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()); CP_ASSERT(stat(filename.c_str(), &result) == 0, "Cannot stat file %s", filename.c_str());
return (int64_t)result.st_mtime; return (int64_t)result.st_mtime;
} }
} }
+3 -5
View File
@@ -2,10 +2,8 @@
#include "copium/util/Common.h" #include "copium/util/Common.h"
#include <filesystem> #include <cstdint>
#include <fstream> #include <vector>
#include <sys/stat.h>
#include <sys/types.h>
namespace Copium namespace Copium
{ {
@@ -21,4 +19,4 @@ namespace Copium
static bool FileExists(const std::string& filename); static bool FileExists(const std::string& filename);
static int64_t DateModified(const std::string& filename); static int64_t DateModified(const std::string& filename);
}; };
} }
@@ -2,12 +2,12 @@
namespace Copium namespace Copium
{ {
RuntimeException::RuntimeException(const std::string& str) RuntimeException::RuntimeException(const std::string& str)
: errorMessage{str} : errorMessage{str}
{} {}
const std::string& RuntimeException::GetErrorMessage() const const std::string& RuntimeException::GetErrorMessage() const
{ {
return errorMessage; return errorMessage;
} }
} }
@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <stdexcept> #include <string>
namespace Copium namespace Copium
{ {
@@ -13,4 +13,4 @@ namespace Copium
const std::string& GetErrorMessage() const; const std::string& GetErrorMessage() const;
}; };
} }
@@ -7,7 +7,6 @@
namespace Copium namespace Copium
{ {
class StringUtil class StringUtil
{ {
CP_STATIC_CLASS(StringUtil); CP_STATIC_CLASS(StringUtil);
+2 -2
View File
@@ -13,12 +13,12 @@ namespace Copium
double Timer::Elapsed() double Timer::Elapsed()
{ {
return std::chrono::duration<double>(std::chrono::high_resolution_clock::now() - startTime).count(); return std::chrono::duration<double>(std::chrono::steady_clock::now() - startTime).count();
} }
double Timer::ElapsedRestart() double Timer::ElapsedRestart()
{ {
std::chrono::time_point<std::chrono::steady_clock> newTime = std::chrono::high_resolution_clock::now(); std::chrono::time_point<std::chrono::steady_clock> newTime = std::chrono::steady_clock::now();
double elapsedTime = std::chrono::duration<double>(newTime - startTime).count(); double elapsedTime = std::chrono::duration<double>(newTime - startTime).count();
startTime = newTime; startTime = newTime;
@@ -2,7 +2,7 @@
#include "copium/util/RuntimeException.h" #include "copium/util/RuntimeException.h"
#include <stdexcept> #include <string>
namespace Copium namespace Copium
{ {
+41
View File
@@ -0,0 +1,41 @@
<makegen>
<configuration name="Release">
<generatehfile>false</generatehfile>
<outputdir>bin/Release/</outputdir>
<outputname>libimgui.so</outputname>
<outputtype>sharedlibrary</outputtype>
<projectname>ImGui</projectname>
<includedir>../../repos/imgui/</includedir>
<includedir>/usr/include/freetype2/</includedir>
<sourcefile>../../repos/imgui/imgui.cpp</sourcefile>
<sourcefile>../../repos/imgui/imgui_demo.cpp</sourcefile>
<sourcefile>../../repos/imgui/imgui_draw.cpp</sourcefile>
<sourcefile>../../repos/imgui/imgui_tables.cpp</sourcefile>
<sourcefile>../../repos/imgui/imgui_widgets.cpp</sourcefile>
<sourcefile>../../repos/imgui/backends/imgui_impl_glfw.cpp</sourcefile>
<sourcefile>../../repos/imgui/backends/imgui_impl_vulkan.cpp</sourcefile>
<srcdir></srcdir>
</configuration>
<configuration name="Debug">
<cflag>-g3</cflag>
<cflag>-w</cflag>
<define>_DEBUG</define>
<generatehfile>false</generatehfile>
<outputdir>bin/Debug/</outputdir>
<outputname>libimgui.so</outputname>
<outputtype>sharedlibrary</outputtype>
<projectname>ImGui</projectname>
<includedir>../../repos/imgui/</includedir>
<includedir>/usr/include/freetype2/</includedir>
<sourcefile>../../repos/imgui/imgui.cpp</sourcefile>
<sourcefile>../../repos/imgui/imgui_demo.cpp</sourcefile>
<sourcefile>../../repos/imgui/imgui_draw.cpp</sourcefile>
<sourcefile>../../repos/imgui/imgui_tables.cpp</sourcefile>
<sourcefile>../../repos/imgui/imgui_widgets.cpp</sourcefile>
<sourcefile>../../repos/imgui/backends/imgui_impl_glfw.cpp</sourcefile>
<sourcefile>../../repos/imgui/backends/imgui_impl_vulkan.cpp</sourcefile>
<srcdir></srcdir>
</configuration>
<target>Debug</target>
<version>v1.3.6</version>
</makegen>
+33
View File
@@ -0,0 +1,33 @@
<makegen>
<configuration name="Release">
<define>MSDF_ATLAS_PUBLIC=</define>
<define>MSDFGEN_USE_LIBPNG</define>
<generatehfile>false</generatehfile>
<outputdir>bin/Release/</outputdir>
<outputname>libmsdf-atlas-gen.so</outputname>
<outputtype>sharedlibrary</outputtype>
<projectname>MsdfAtlasGen</projectname>
<includedir>../../repos/msdf-atlas-gen/msdf-atlas-gen/</includedir>
<includedir>../../repos/msdf-atlas-gen/msdfgen/</includedir>
<includedir>../../repos/msdf-atlas-gen/artery-font-format/</includedir>
<srcdir>../../repos/msdf-atlas-gen/msdf-atlas-gen/</srcdir>
</configuration>
<configuration name="Debug">
<cflag>-g3</cflag>
<cflag>-w</cflag>
<define>_DEBUG</define>
<define>MSDF_ATLAS_PUBLIC=</define>
<define>MSDFGEN_USE_LIBPNG</define>
<generatehfile>false</generatehfile>
<outputdir>bin/Debug/</outputdir>
<outputname>libmsdf-atlas-gen.so</outputname>
<outputtype>sharedlibrary</outputtype>
<projectname>MsdfAtlasGen</projectname>
<includedir>../../repos/msdf-atlas-gen/msdf-atlas-gen/</includedir>
<includedir>../../repos/msdf-atlas-gen/msdfgen/</includedir>
<includedir>../../repos/msdf-atlas-gen/artery-font-format/</includedir>
<srcdir>../../repos/msdf-atlas-gen/msdf-atlas-gen/</srcdir>
</configuration>
<target>Debug</target>
<version>v1.3.6</version>
</makegen>
+31
View File
@@ -0,0 +1,31 @@
<makegen>
<configuration name="Release">
<define>MSDF_ATLAS_PUBLIC=</define>
<generatehfile>false</generatehfile>
<outputdir>bin/Release/</outputdir>
<outputname>libmsdfgen-core.so</outputname>
<outputtype>sharedlibrary</outputtype>
<projectname>MsdfGenCore</projectname>
<includedir>../../repos/msdf-atlas-gen/msdf-atlas-gen/</includedir>
<includedir>../../repos/msdf-atlas-gen/msdfgen/</includedir>
<includedir>../../repos/msdf-atlas-gen/artery-font-format/</includedir>
<srcdir>../../repos/msdf-atlas-gen/msdfgen/core/</srcdir>
</configuration>
<configuration name="Debug">
<cflag>-g3</cflag>
<cflag>-w</cflag>
<define>_DEBUG</define>
<define>MSDF_ATLAS_PUBLIC=</define>
<generatehfile>false</generatehfile>
<outputdir>bin/Debug/</outputdir>
<outputname>libmsdfgen-core.so</outputname>
<outputtype>sharedlibrary</outputtype>
<projectname>MsdfGenCore</projectname>
<includedir>../../repos/msdf-atlas-gen/msdf-atlas-gen/</includedir>
<includedir>../../repos/msdf-atlas-gen/msdfgen/</includedir>
<includedir>../../repos/msdf-atlas-gen/artery-font-format/</includedir>
<srcdir>../../repos/msdf-atlas-gen/msdfgen/core/</srcdir>
</configuration>
<target>Debug</target>
<version>v1.3.6</version>
</makegen>
+37
View File
@@ -0,0 +1,37 @@
<makegen>
<configuration name="Release">
<define>MSDF_ATLAS_PUBLIC=</define>
<generatehfile>false</generatehfile>
<outputdir>bin/Release/</outputdir>
<outputname>libmsdfgen-ext.so</outputname>
<outputtype>sharedlibrary</outputtype>
<projectname>MsdfGenExt</projectname>
<includedir>../../repos/msdf-atlas-gen/msdf-atlas-gen/</includedir>
<includedir>../../repos/msdf-atlas-gen/msdfgen/</includedir>
<includedir>../../repos/msdf-atlas-gen/artery-font-format/</includedir>
<includedir>../../repos/freetype/include/</includedir>
<sourcefile>../../repos/msdf-atlas-gen/msdfgen/ext/import-font.cpp</sourcefile>
<sourcefile>../../repos/msdf-atlas-gen/msdfgen/ext/save-png.cpp</sourcefile>
<srcdir></srcdir>
</configuration>
<configuration name="Debug">
<cflag>-g3</cflag>
<cflag>-w</cflag>
<define>_DEBUG</define>
<define>MSDF_ATLAS_PUBLIC=</define>
<generatehfile>false</generatehfile>
<outputdir>bin/Debug/</outputdir>
<outputname>libmsdfgen-ext.so</outputname>
<outputtype>sharedlibrary</outputtype>
<projectname>MsdfGenExt</projectname>
<includedir>../../repos/msdf-atlas-gen/msdf-atlas-gen/</includedir>
<includedir>../../repos/msdf-atlas-gen/msdfgen/</includedir>
<includedir>../../repos/msdf-atlas-gen/artery-font-format/</includedir>
<includedir>../../repos/freetype/include/</includedir>
<sourcefile>../../repos/msdf-atlas-gen/msdfgen/ext/import-font.cpp</sourcefile>
<sourcefile>../../repos/msdf-atlas-gen/msdfgen/ext/save-png.cpp</sourcefile>
<srcdir></srcdir>
</configuration>
<target>Debug</target>
<version>v1.3.6</version>
</makegen>