From 810417a251b942c5b722932bed69ef29d95a4322 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Sun, 21 Apr 2024 18:10:36 +0200 Subject: [PATCH] working --- runtime/Includes/Core/Application.h | 4 +- runtime/Includes/Core/DriverLoader.h | 39 +++++ runtime/Includes/Core/DriverLoader.inl | 30 ++++ runtime/Includes/Core/ImagesManager.h | 27 +++ runtime/Includes/Drivers/DriverInstance.h | 35 ++++ .../Drivers/GLFW/GLFWDriverInstance.h | 34 ++++ .../Drivers/GLFW/GLFWDriverInstance.inl | 32 ++++ .../Includes/Renderer/Buffers/IndexBuffer.h | 4 +- .../Includes/Renderer/Buffers/VertexBuffer.h | 4 +- runtime/Includes/Renderer/Core/Queues.h | 4 +- runtime/Includes/Renderer/Images/Image.h | 98 ++++++----- runtime/Includes/Renderer/Images/Texture.h | 54 +++--- .../Includes/Renderer/Images/TextureAtlas.h | 28 ++-- .../Renderer/Images/TextureDescriptor.h | 28 ++-- .../Includes/Renderer/Images/TextureManager.h | 25 ++- .../Includes/Renderer/Pipelines/Pipeline.h | 18 +- runtime/Includes/Renderer/PixelPut.h | 32 ++-- runtime/Includes/Renderer/Renderer.h | 157 +++++++++--------- .../Renderer/Renderpass/FrameBuffer.h | 22 +-- .../Includes/Renderer/Renderpass/RenderPass.h | 20 +-- .../Includes/Renderer/Renderpass/Swapchain.h | 44 ++--- runtime/Includes/Renderer/Texts/Font.h | 40 ++--- runtime/Includes/Renderer/Texts/FontLibrary.h | 24 +-- runtime/Includes/Renderer/Texts/Text.h | 40 ++--- .../Includes/Renderer/Texts/TextDescriptor.h | 24 +-- runtime/Includes/Renderer/Texts/TextLibrary.h | 26 +-- runtime/Includes/Renderer/Texts/TextManager.h | 28 ++-- runtime/Sources/Core/Application.cpp | 12 +- 28 files changed, 558 insertions(+), 375 deletions(-) create mode 100644 runtime/Includes/Core/DriverLoader.h create mode 100644 runtime/Includes/Core/DriverLoader.inl create mode 100644 runtime/Includes/Core/ImagesManager.h create mode 100644 runtime/Includes/Drivers/DriverInstance.h create mode 100644 runtime/Includes/Drivers/GLFW/GLFWDriverInstance.h create mode 100644 runtime/Includes/Drivers/GLFW/GLFWDriverInstance.inl diff --git a/runtime/Includes/Core/Application.h b/runtime/Includes/Core/Application.h index cceb2db..25d369e 100644 --- a/runtime/Includes/Core/Application.h +++ b/runtime/Includes/Core/Application.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */ -/* Updated: 2024/03/27 21:00:53 by maldavid ### ########.fr */ +/* Updated: 2024/04/03 15:05:24 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ #include #include +#include #include namespace mlx @@ -58,6 +59,7 @@ namespace mlx private: FpsManager m_fps; + DriverLoader m_driver_loader; std::list m_textures; std::vector> m_graphics; std::function f_loop_hook; diff --git a/runtime/Includes/Core/DriverLoader.h b/runtime/Includes/Core/DriverLoader.h new file mode 100644 index 0000000..18e5695 --- /dev/null +++ b/runtime/Includes/Core/DriverLoader.h @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* DriverLoader.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maldavid +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/02 16:56:10 by maldavid #+# #+# */ +/* Updated: 2024/04/03 15:02:44 by maldavid ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef __MLX_CORE_DRIVER_LOADER__ +#define __MLX_CORE_DRIVER_LOADER__ + +#include + +namespace mlx +{ + class DriverLoader + { + public: + DriverLoader() = default; + + template + inline bool LoadDriver(); + + inline void ShutdownAllDrivers(); + + ~DriverLoader() = default; + + private: + std::vector > m_instances; + }; +} + +#include + +#endif diff --git a/runtime/Includes/Core/DriverLoader.inl b/runtime/Includes/Core/DriverLoader.inl new file mode 100644 index 0000000..6104d76 --- /dev/null +++ b/runtime/Includes/Core/DriverLoader.inl @@ -0,0 +1,30 @@ +/* **************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* DriverLoader.inl :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maldavid +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/03 14:55:01 by maldavid #+# #+# */ +/* Updated: 2024/04/03 14:55:01 by maldavid ### ########.fr */ +/* */ +/* **************************************************************************** */ + +#pragma once +#include + +namespace mlx +{ + template + bool DriverLoader::LoadDriver() + { + m_instances.emplace_back(new T)->InitDriver(); + } + + void DriverLoader::ShutdownAllDrivers() + { + for(auto& driver : m_instances) + driver->ShutdownDriver(); + m_instances.clear(); + } +} diff --git a/runtime/Includes/Core/ImagesManager.h b/runtime/Includes/Core/ImagesManager.h new file mode 100644 index 0000000..46e223d --- /dev/null +++ b/runtime/Includes/Core/ImagesManager.h @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ImagesManager.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maldavid +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/03 15:11:47 by maldavid #+# #+# */ +/* Updated: 2024/04/21 15:13:43 by maldavid ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef __MLX_CORE_IMAGES_MANAGER__ +#define __MLX_CORE_IMAGES_MANAGER__ + +namespace mlx +{ + class ImagesManager + { + public: + + private: + std::unordered_set m_textures_registry; + }; +} + +#endif diff --git a/runtime/Includes/Drivers/DriverInstance.h b/runtime/Includes/Drivers/DriverInstance.h new file mode 100644 index 0000000..c72cf97 --- /dev/null +++ b/runtime/Includes/Drivers/DriverInstance.h @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* DriverInstance.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maldavid +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/02 16:57:20 by maldavid #+# #+# */ +/* Updated: 2024/04/02 17:01:03 by maldavid ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef __MLX_DRIVER_INSTANCE__ +#define __MLX_DRIVER_INSTANCE__ + +namespace mlx +{ + class DriverInstance + { + public: + DriverInstance() = default; + + virtual bool InitDriver() { m_is_up = true; return true; } + virtual void ShutdownDriver() { m_is_up = false; } + + inline bool IsRunning() const noexcept { return m_is_up; } + + virtual ~DriverInstance() = default; + + private: + bool m_is_up = false; + }; +} + +#endif diff --git a/runtime/Includes/Drivers/GLFW/GLFWDriverInstance.h b/runtime/Includes/Drivers/GLFW/GLFWDriverInstance.h new file mode 100644 index 0000000..fe1d124 --- /dev/null +++ b/runtime/Includes/Drivers/GLFW/GLFWDriverInstance.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* GLFWDriverInstance.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maldavid +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/02 17:01:51 by maldavid #+# #+# */ +/* Updated: 2024/04/02 17:04:12 by maldavid ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef __MLX_GLFW_DRIVER_INSTANCE__ +#define __MLX_GLFW_DRIVER_INSTANCE__ + +#include + +namespace mlx +{ + class GLFWDriverInstance : public DriverInstance + { + public: + GLFWDriverInstance() = default; + + inline bool InitDriver() override; + inline void ShutdownDriver() override; + + ~GLFWDriverInstance() override = default; + }; +} + +#include + +#endif diff --git a/runtime/Includes/Drivers/GLFW/GLFWDriverInstance.inl b/runtime/Includes/Drivers/GLFW/GLFWDriverInstance.inl new file mode 100644 index 0000000..b96b66d --- /dev/null +++ b/runtime/Includes/Drivers/GLFW/GLFWDriverInstance.inl @@ -0,0 +1,32 @@ +/* **************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* GLFWDriverInstance.inl :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maldavid +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/02 17:04:23 by maldavid #+# #+# */ +/* Updated: 2024/04/02 17:04:23 by maldavid ### ########.fr */ +/* */ +/* **************************************************************************** */ + +#include + +namespace mlx +{ + bool GLFWDriverInstance::InitDriver() + { + glfwSetErrorCallback([]([[maybe_unused]] int code, const char* desc) + { + FatalError("GLFW Driver Error : %", desc); + }); + glfwInit(); + DebugLog("GLFW Driver loaded"); + } + + void GLFWDriverInstance::ShutdownDriver() + { + glfwTerminate(); + DebugLog("GLFW Driver shutted down"); + } +} diff --git a/runtime/Includes/Renderer/Buffers/IndexBuffer.h b/runtime/Includes/Renderer/Buffers/IndexBuffer.h index 20b6132..4a8f4d8 100644 --- a/runtime/Includes/Renderer/Buffers/IndexBuffer.h +++ b/runtime/Includes/Renderer/Buffers/IndexBuffer.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/01/25 15:05:05 by maldavid #+# #+# */ -/* Updated: 2024/03/27 22:11:57 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:11:05 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ namespace mlx { - class C_IBO : public Buffer + class ConstantIndexBuffer : public Buffer { public: inline void Create(std::uint32_t size, const std::uint16_t* data, const char* name) { Buffer::Create(BufferType::Constant, size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, name, data); } diff --git a/runtime/Includes/Renderer/Buffers/VertexBuffer.h b/runtime/Includes/Renderer/Buffers/VertexBuffer.h index 10d7c07..ec193b7 100644 --- a/runtime/Includes/Renderer/Buffers/VertexBuffer.h +++ b/runtime/Includes/Renderer/Buffers/VertexBuffer.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/06 18:27:38 by maldavid #+# #+# */ -/* Updated: 2024/03/27 22:18:23 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:23:32 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ namespace mlx { - class VertexBuffer : public Buffer + class RAMVertexBuffer : public Buffer { public: inline void Create(std::uint32_t size, const void* data, const char* name) { Buffer::Create(BufferType::HighDynamic, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, name, data); } diff --git a/runtime/Includes/Renderer/Core/Queues.h b/runtime/Includes/Renderer/Core/Queues.h index 4230e25..3986e17 100644 --- a/runtime/Includes/Renderer/Core/Queues.h +++ b/runtime/Includes/Renderer/Core/Queues.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/08 19:01:49 by maldavid #+# #+# */ -/* Updated: 2024/03/27 22:50:52 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:05:15 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ namespace mlx std::optional graphics_family; std::optional present_family; - inline bool isComplete() { return graphics_family.has_value() && present_family.has_value(); } + inline bool IsComplete() { return graphics_family.has_value() && present_family.has_value(); } }; public: diff --git a/runtime/Includes/Renderer/Images/Image.h b/runtime/Includes/Renderer/Images/Image.h index 7319917..6f93bed 100644 --- a/runtime/Includes/Renderer/Images/Image.h +++ b/runtime/Includes/Renderer/Images/Image.h @@ -1,87 +1,83 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* vk_image.h :+: :+: :+: */ +/* Image.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/01/25 11:54:21 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:09:40 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:08:35 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef __MLX_VK_IMAGE__ #define __MLX_VK_IMAGE__ -#include -#include -#include - -#ifdef DEBUG - #include -#endif +#include +#include +#include namespace mlx { - std::uint32_t formatSize(VkFormat format); - bool isStencilFormat(VkFormat format); - bool isDepthFormat(VkFormat format); - VkFormat bitsToFormat(std::uint32_t bits); - VkPipelineStageFlags layoutToAccessMask(VkImageLayout layout, bool isDestination); + std::uint32_t FormatSize(VkFormat format); + bool IsStencilFormat(VkFormat format); + bool IsDepthFormat(VkFormat format); + VkFormat BitsToFormat(std::uint32_t bits); + VkPipelineStageFlags LayoutToAccessMask(VkImageLayout layout, bool is_destination); - class Image : public CmdResource + class Image : public CommandResource { - friend class SwapChain; + friend class Swapchain; public: Image() = default; - inline void create(VkImage image, VkFormat format, std::uint32_t width, std::uint32_t height, VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED) noexcept + inline void Create(VkImage image, VkFormat format, std::uint32_t width, std::uint32_t height, VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED) noexcept { - _image = image; - _format = format; - _width = width; - _height = height; - _layout = layout; + m_image = image; + m_format = format; + m_width = width; + m_height = height; + m_layout = layout; } - void create(std::uint32_t width, std::uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, const char* name, bool decated_memory = false); - void createImageView(VkImageViewType type, VkImageAspectFlags aspectFlags) noexcept; - void createSampler() noexcept; - void copyFromBuffer(class Buffer& buffer); - void copyToBuffer(class Buffer& buffer); - void transitionLayout(VkImageLayout new_layout, CmdBuffer* cmd = nullptr); - virtual void destroy() noexcept; + void Create(std::uint32_t width, std::uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, const char* name, bool decated_memory = false); + void CreateImageView(VkImageViewType type, VkImageAspectFlags aspect_flags) noexcept; + void CreateSampler() noexcept; + void CopyFromBuffer(class Buffer& buffer); + void CopyToBuffer(class Buffer& buffer); + void TransitionLayout(VkImageLayout new_layout, CmdBuffer* cmd = nullptr); + virtual void Destroy() noexcept; - inline VkImage get() noexcept { return _image; } - inline VkImage operator()() noexcept { return _image; } - inline VkImageView getImageView() const noexcept { return _image_view; } - inline VkFormat getFormat() const noexcept { return _format; } - inline VkImageTiling getTiling() const noexcept { return _tiling; } - inline VkImageLayout getLayout() const noexcept { return _layout; } - inline VkSampler getSampler() const noexcept { return _sampler; } - inline std::uint32_t getWidth() const noexcept { return _width; } - inline std::uint32_t getHeight() const noexcept { return _height; } - inline bool isInit() const noexcept { return _image != VK_NULL_HANDLE; } + inline VkImage Get() noexcept { return m_image; } + inline VkImage operator()() noexcept { return m_image; } + inline VkImageView GetImageView() const noexcept { return m_image_view; } + inline VkFormat GetFormat() const noexcept { return m_format; } + inline VkImageTiling GetTiling() const noexcept { return m_tiling; } + inline VkImageLayout GetLayout() const noexcept { return m_layout; } + inline VkSampler GetSampler() const noexcept { return m_sampler; } + inline std::uint32_t GetWidth() const noexcept { return m_width; } + inline std::uint32_t GetHeight() const noexcept { return m_height; } + inline bool IsInit() const noexcept { return m_image != VK_NULL_HANDLE; } virtual ~Image() = default; private: - void destroySampler() noexcept; - void destroyImageView() noexcept; + void DestroySampler() noexcept; + void DestroyImageView() noexcept; private: - VmaAllocation _allocation; - VkImage _image = VK_NULL_HANDLE; - VkImageView _image_view = VK_NULL_HANDLE; - VkSampler _sampler = VK_NULL_HANDLE; + VmaAllocation m_allocation; + VkImage m_image = VK_NULL_HANDLE; + VkImageView m_image_view = VK_NULL_HANDLE; + VkSampler m_sampler = VK_NULL_HANDLE; #ifdef DEBUG - std::string _name; + std::string m_name; #endif - VkFormat _format; - VkImageTiling _tiling; - VkImageLayout _layout = VK_IMAGE_LAYOUT_UNDEFINED; - std::uint32_t _width = 0; - std::uint32_t _height = 0; + VkFormat m_format; + VkImageTiling m_tiling; + VkImageLayout m_layout = VK_IMAGE_LAYOUT_UNDEFINED; + std::uint32_t m_width = 0; + std::uint32_t m_height = 0; }; } diff --git a/runtime/Includes/Renderer/Images/Texture.h b/runtime/Includes/Renderer/Images/Texture.h index 8d497db..7c88e17 100644 --- a/runtime/Includes/Renderer/Images/Texture.h +++ b/runtime/Includes/Renderer/Images/Texture.h @@ -1,22 +1,22 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* texture.h :+: :+: :+: */ +/* Texture.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:09:56 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:11:21 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef __MLX_TEXTURE__ #define __MLX_TEXTURE__ -#include -#include -#include -#include +#include +#include +#include +#include namespace mlx { @@ -25,39 +25,39 @@ namespace mlx public: Texture() = default; - void create(std::uint8_t* pixels, std::uint32_t width, std::uint32_t height, VkFormat format, const char* name, bool dedicated_memory = false); - void render(std::array& sets, class Renderer& renderer, int x, int y); - void destroy() noexcept override; + void Create(std::uint8_t* pixels, std::uint32_t width, std::uint32_t height, VkFormat format, const char* name, bool dedicated_memory = false); + void Render(std::array& sets, class Renderer& renderer, int x, int y); + void Destroy() noexcept override; - void setPixel(int x, int y, std::uint32_t color) noexcept; - int getPixel(int x, int y) noexcept; + void SetPixel(int x, int y, std::uint32_t color) noexcept; + int GetPixel(int x, int y) noexcept; - inline void setDescriptor(DescriptorSet&& set) noexcept { _set = set; } - inline VkDescriptorSet getSet() noexcept { return _set.isInit() ? _set.get() : VK_NULL_HANDLE; } - inline void updateSet(int binding) noexcept { _set.writeDescriptor(binding, *this); _has_set_been_updated = true; } - inline bool hasBeenUpdated() const noexcept { return _has_set_been_updated; } - inline constexpr void resetUpdate() noexcept { _has_set_been_updated = false; } + inline void SetDescriptor(DescriptorSet&& set) noexcept { m_set = set; } + inline VkDescriptorSet GetSet() noexcept { return m_set.isInit() ? m_set.get() : VK_NULL_HANDLE; } + inline void UpdateSet(int binding) noexcept { m_set.writeDescriptor(binding, *this); m_has_set_been_updated = true; } + inline bool HasBeenUpdated() const noexcept { return m_has_set_been_updated; } + inline constexpr void ResetUpdate() noexcept { m_has_set_been_updated = false; } ~Texture() = default; private: - void openCPUmap(); + void OpenCPUmap(); private: - C_VBO _vbo; - C_IBO _ibo; + ConstantVertexBuffer m_vbo; + ConstantIndexBuffer m_ibo; #ifdef DEBUG - std::string _name; + std::string m_name; #endif - DescriptorSet _set; - std::vector _cpu_map; - std::optional _buf_map = std::nullopt; - void* _map = nullptr; - bool _has_been_modified = false; - bool _has_set_been_updated = false; + DescriptorSet m_set; + std::vector m_cpu_map; + std::optional m_buf_map = std::nullopt; + void* m_map = nullptr; + bool m_has_been_modified = false; + bool m_has_set_been_updated = false; }; - Texture stbTextureLoad(std::filesystem::path file, int* w, int* h); + Texture StbTextureLoad(std::filesystem::path file, int* w, int* h); } #endif diff --git a/runtime/Includes/Renderer/Images/TextureAtlas.h b/runtime/Includes/Renderer/Images/TextureAtlas.h index e2e310b..dc53e3c 100644 --- a/runtime/Includes/Renderer/Images/TextureAtlas.h +++ b/runtime/Includes/Renderer/Images/TextureAtlas.h @@ -1,19 +1,19 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* texture_atlas.h :+: :+: :+: */ +/* TextureAtlas.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/07 16:36:33 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:09:50 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:12:13 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef __MLX_TEXTURE_ATLAS__ #define __MLX_TEXTURE_ATLAS__ -#include +#include namespace mlx { @@ -22,22 +22,22 @@ namespace mlx public: TextureAtlas() = default; - void create(std::uint8_t* pixels, std::uint32_t width, std::uint32_t height, VkFormat format, const char* name, bool dedicated_memory = false); - void render(class Renderer& renderer, int x, int y, std::uint32_t ibo_size) const; - void destroy() noexcept override; + void Create(std::uint8_t* pixels, std::uint32_t width, std::uint32_t height, VkFormat format, const char* name, bool dedicated_memory = false); + void Render(class Renderer& renderer, int x, int y, std::uint32_t ibo_size) const; + void Destroy() noexcept override; - inline void setDescriptor(DescriptorSet&& set) noexcept { _set = set; } - inline VkDescriptorSet getVkSet() noexcept { return _set.isInit() ? _set.get() : VK_NULL_HANDLE; } - inline DescriptorSet getSet() noexcept { return _set; } - inline void updateSet(int binding) noexcept { _set.writeDescriptor(binding, *this); _has_been_updated = true; } - inline bool hasBeenUpdated() const noexcept { return _has_been_updated; } - inline constexpr void resetUpdate() noexcept { _has_been_updated = false; } + inline void SetDescriptor(DescriptorSet&& set) noexcept { m_set = set; } + inline VkDescriptorSet GetVkSet() noexcept { return m_set.isInit() ? m_set.get() : VK_NULL_HANDLE; } + inline DescriptorSet GetSet() noexcept { return m_set; } + inline void UpdateSet(int binding) noexcept { m_set.writeDescriptor(binding, *this); m_has_been_updated = true; } + inline bool HasBeenUpdated() const noexcept { return m_has_been_updated; } + inline constexpr void ResetUpdate() noexcept { m_has_been_updated = false; } ~TextureAtlas() = default; private: - DescriptorSet _set; - bool _has_been_updated = false; + DescriptorSet m_set; + bool m_has_been_updated = false; }; } diff --git a/runtime/Includes/Renderer/Images/TextureDescriptor.h b/runtime/Includes/Renderer/Images/TextureDescriptor.h index f3a2663..56683a9 100644 --- a/runtime/Includes/Renderer/Images/TextureDescriptor.h +++ b/runtime/Includes/Renderer/Images/TextureDescriptor.h @@ -1,43 +1,43 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* texture_descriptor.h :+: :+: :+: */ +/* TextureDescriptor.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 01:00:13 by maldavid #+# #+# */ -/* Updated: 2024/01/11 01:21:52 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:13:23 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef __MLX_TEXTURE_DESCRIPTOR__ #define __MLX_TEXTURE_DESCRIPTOR__ -#include -#include -#include +#include +#include +#include namespace mlx { struct TextureRenderDescriptor : public DrawableResource { - Texture* texture; + NonOwningPtr texture; int x; int y; - TextureRenderDescriptor(Texture* _texture, int _x, int _y) : texture(_texture), x(_x), y(_y) {} + TextureRenderDescriptor(NonOwningPtr _texture, int _x, int _y) : texture(_texture), x(_x), y(_y) {} inline bool operator==(const TextureRenderDescriptor& rhs) const { return texture == rhs.texture && x == rhs.x && y == rhs.y; } - inline void render(std::array& sets, class Renderer& renderer) override + inline void Render(std::array& sets, class Renderer& renderer) override { - if(!texture->isInit()) + if(!texture->IsInit()) return; - texture->render(sets, renderer, x, y); + texture->Render(sets, renderer, x, y); } - inline void resetUpdate() override + inline void ResetUpdate() override { - if(!texture->isInit()) + if(!texture->IsInit()) return; - texture->resetUpdate(); + texture->ResetUpdate(); } }; } @@ -50,7 +50,7 @@ namespace std std::size_t operator()(const mlx::TextureRenderDescriptor& d) const noexcept { std::size_t hash = 0; - mlx::hashCombine(hash, d.texture, d.x, d.y); + mlx::HashCombine(hash, d.texture, d.x, d.y); return hash; } }; diff --git a/runtime/Includes/Renderer/Images/TextureManager.h b/runtime/Includes/Renderer/Images/TextureManager.h index c667cbd..e9f655d 100644 --- a/runtime/Includes/Renderer/Images/TextureManager.h +++ b/runtime/Includes/Renderer/Images/TextureManager.h @@ -1,20 +1,19 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* texture_manager.h :+: :+: :+: */ +/* TextureManager.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 00:56:15 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:09:45 by maldavid ### ########.fr */ +/* Updated: 2024/04/03 16:24:51 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef __MLX_TEXTURE_MANAGER__ #define __MLX_TEXTURE_MANAGER__ -#include -#include +#include namespace mlx { @@ -23,19 +22,19 @@ namespace mlx public: TextureManager() = default; - inline void clear() { _texture_descriptors.clear(); } + inline void Clear() { m_texture_descriptors.clear(); } - inline std::pair registerTexture(Texture* texture, int x, int y) + inline std::pair, bool> RegisterTexture(NonOwningPtr texture, int x, int y) { MLX_PROFILE_FUNCTION(); - auto res = _texture_descriptors.emplace(texture, x, y); + auto res = m_texture_descriptors.emplace(texture, x, y); return std::make_pair(static_cast(&const_cast(*res.first)), res.second); } - inline bool isTextureKnown(Texture* texture) noexcept + inline bool IsTextureKnown(NonOwningPtr texture) noexcept { MLX_PROFILE_FUNCTION(); - for(const auto& desc : _texture_descriptors) + for(const auto& desc : m_texture_descriptors) { if(desc.texture == texture) return true; @@ -43,13 +42,13 @@ namespace mlx return false; } - inline void eraseTextures(Texture* texture) + inline void EraseTextures(NonOwningPtr texture) { MLX_PROFILE_FUNCTION(); - for(auto it = _texture_descriptors.begin(); it != _texture_descriptors.end();) + for(auto it = m_texture_descriptors.begin(); it != m_texture_descriptors.end();) { if(it->texture == texture) - it = _texture_descriptors.erase(it); + it = m_texture_descriptors.erase(it); else ++it; } @@ -58,7 +57,7 @@ namespace mlx ~TextureManager() = default; private: - std::unordered_set _texture_descriptors; + std::unordered_set m_texture_descriptors; }; } diff --git a/runtime/Includes/Renderer/Pipelines/Pipeline.h b/runtime/Includes/Renderer/Pipelines/Pipeline.h index 304a58d..7cd8ffd 100644 --- a/runtime/Includes/Renderer/Pipelines/Pipeline.h +++ b/runtime/Includes/Renderer/Pipelines/Pipeline.h @@ -1,19 +1,19 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pipeline.h :+: :+: :+: */ +/* Pipeline.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/12/18 21:23:52 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:09:01 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:15:38 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef __PIPELINE__ #define __PIPELINE__ -#include +#include namespace mlx { @@ -21,16 +21,16 @@ namespace mlx { public: void init(class Renderer& renderer); - void destroy() noexcept; + void Destroy() noexcept; - inline void bindPipeline(CmdBuffer& command_buffer) noexcept { vkCmdBindPipeline(command_buffer.get(), VK_PIPELINE_BIND_POINT_GRAPHICS, _graphics_pipeline); } + inline void BindPipeline(CommandBuffer& command_buffer) noexcept { vkCmdBindPipeline(command_buffer.Get(), VK_PIPELINE_BIND_POINT_GRAPHICS, m_graphics_pipeline); } - inline const VkPipeline& getPipeline() const noexcept { return _graphics_pipeline; } - inline const VkPipelineLayout& getPipelineLayout() const noexcept { return _pipeline_layout; } + inline const VkPipeline& GetPipeline() const noexcept { return m_graphics_pipeline; } + inline const VkPipelineLayout& GetPipelineLayout() const noexcept { return m_pipeline_layout; } private: - VkPipeline _graphics_pipeline = VK_NULL_HANDLE; - VkPipelineLayout _pipeline_layout = VK_NULL_HANDLE; + VkPipeline m_graphics_pipeline = VK_NULL_HANDLE; + VkPipelineLayout m_pipeline_layout = VK_NULL_HANDLE; }; } diff --git a/runtime/Includes/Renderer/PixelPut.h b/runtime/Includes/Renderer/PixelPut.h index b084d82..9101643 100644 --- a/runtime/Includes/Renderer/PixelPut.h +++ b/runtime/Includes/Renderer/PixelPut.h @@ -1,20 +1,20 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pixel_put.h :+: :+: :+: */ +/* PixelPut.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/31 13:18:50 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:07:56 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:28:46 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef __MLX_PIXEL_PUT__ #define __MLX_PIXEL_PUT__ -#include -#include +#include +#include namespace mlx { @@ -23,25 +23,25 @@ namespace mlx public: PixelPutPipeline() = default; - void init(std::uint32_t width, std::uint32_t height, class Renderer& renderer) noexcept; + void Init(std::uint32_t width, std::uint32_t height, class Renderer& renderer) noexcept; - void setPixel(int x, int y, std::uint32_t color) noexcept; - void render(std::array& sets, class Renderer& renderer) noexcept; + void SetPixel(int x, int y, std::uint32_t color) noexcept; + void Render(std::array& sets, class Renderer& renderer) noexcept; - void clear(); - void destroy() noexcept; + void Clear(); + void Destroy() noexcept; ~PixelPutPipeline(); private: - Texture _texture; - Buffer _buffer; + Texture m_texture; + Buffer m_buffer; // using vector as CPU map and not directly writting to mapped buffer to improve performances - std::vector _cpu_map; - void* _buffer_map = nullptr; - std::uint32_t _width = 0; - std::uint32_t _height = 0; - bool _has_been_modified = true; + std::vector m_cpu_map; + void* m_buffer_map = nullptr; + std::uint32_t m_width = 0; + std::uint32_t m_height = 0; + bool m_has_been_modified = true; }; } diff --git a/runtime/Includes/Renderer/Renderer.h b/runtime/Includes/Renderer/Renderer.h index bd347d2..4003a3e 100644 --- a/runtime/Includes/Renderer/Renderer.h +++ b/runtime/Includes/Renderer/Renderer.h @@ -1,35 +1,30 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* renderer.h :+: :+: :+: */ +/* Renderer.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/12/18 17:14:45 by maldavid #+# #+# */ -/* Updated: 2024/03/27 00:31:28 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:36:05 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef __RENDERER__ #define __RENDERER__ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace mlx { @@ -41,36 +36,36 @@ namespace mlx Vertex(glm::vec2 _pos, glm::vec4 _color, glm::vec2 _uv) : pos(std::move(_pos)), color(std::move(_color)), uv(std::move(_uv)) {} - static VkVertexInputBindingDescription getBindingDescription() + static VkVertexInputBindingDescription GetBindingDescription() { - VkVertexInputBindingDescription bindingDescription{}; - bindingDescription.binding = 0; - bindingDescription.stride = sizeof(Vertex); - bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; + VkVertexInputBindingDescription binding_description{}; + binding_description.binding = 0; + binding_description.stride = sizeof(Vertex); + binding_description.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; - return bindingDescription; + return binding_description; } - static std::array getAttributeDescriptions() + static std::array GetAttributeDescriptions() { - std::array attributeDescriptions; + std::array attribute_descriptions; - attributeDescriptions[0].binding = 0; - attributeDescriptions[0].location = 0; - attributeDescriptions[0].format = VK_FORMAT_R32G32_SFLOAT; - attributeDescriptions[0].offset = offsetof(Vertex, pos); + attribute_descriptions[0].binding = 0; + attribute_descriptions[0].location = 0; + attribute_descriptions[0].format = VK_FORMAT_R32G32_SFLOAT; + attribute_descriptions[0].offset = offsetof(Vertex, pos); - attributeDescriptions[1].binding = 0; - attributeDescriptions[1].location = 1; - attributeDescriptions[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; - attributeDescriptions[1].offset = offsetof(Vertex, color); + attribute_descriptions[1].binding = 0; + attribute_descriptions[1].location = 1; + attribute_descriptions[1].format = VK_FORMAT_R32G32B32A32_SFLOAT; + attribute_descriptions[1].offset = offsetof(Vertex, color); - attributeDescriptions[2].binding = 0; - attributeDescriptions[2].location = 2; - attributeDescriptions[2].format = VK_FORMAT_R32G32_SFLOAT; - attributeDescriptions[2].offset = offsetof(Vertex, uv); + attribute_descriptions[2].binding = 0; + attribute_descriptions[2].location = 2; + attribute_descriptions[2].format = VK_FORMAT_R32G32_SFLOAT; + attribute_descriptions[2].offset = offsetof(Vertex, uv); - return attributeDescriptions; + return attribute_descriptions; } }; @@ -79,63 +74,63 @@ namespace mlx public: Renderer() = default; - void init(class Texture* render_target); + void Init(NonOwningPtr render_target); - bool beginFrame(); - void endFrame(); + bool BeginFrame(); + void EndFrame(); - void destroy(); + void Destroy(); - inline class Window* getWindow() { return _window; } - inline void setWindow(class Window* window) { _window = window; } + inline NonOwningPtr GetWindow() { return m_window; } + inline void SetWindow(NonOwningPtr window) { m_window = window; } - inline Surface& getSurface() noexcept { return _surface; } - inline CmdPool& getCmdPool() noexcept { return _cmd.getCmdPool(); } - inline UBO* getUniformBuffer() noexcept { return _uniform_buffer.get(); } - inline SwapChain& getSwapChain() noexcept { return _swapchain; } - inline Semaphore& getSemaphore(int i) noexcept { return _semaphores[i]; } - inline RenderPass& getRenderPass() noexcept { return _pass; } - inline GraphicPipeline& getPipeline() noexcept { return _pipeline; } - inline CmdBuffer& getCmdBuffer(int i) noexcept { return _cmd.getCmdBuffer(i); } - inline CmdBuffer& getActiveCmdBuffer() noexcept { return _cmd.getCmdBuffer(_current_frame_index); } - inline FrameBuffer& getFrameBuffer(int i) noexcept { return _framebuffers[i]; } - inline DescriptorSet& getVertDescriptorSet() noexcept { return _vert_set; } - inline DescriptorSet& getFragDescriptorSet() noexcept { return _frag_set; } - inline DescriptorSetLayout& getVertDescriptorSetLayout() noexcept { return _vert_layout; } - inline DescriptorSetLayout& getFragDescriptorSetLayout() noexcept { return _frag_layout; } - inline std::uint32_t getActiveImageIndex() noexcept { return _current_frame_index; } - inline std::uint32_t getImageIndex() noexcept { return _image_index; } + inline Surface& GetSurface() noexcept { return m_surface; } + inline CmdPool& GetCmdPool() noexcept { return m_cmd.GetCmdPool(); } + inline NonOwningPtr GetUniformBuffer() noexcept { return m_uniform_buffer.get(); } + inline SwapChain& GetSwapChain() noexcept { return m_swapchain; } + inline Semaphore& GetSemaphore(int i) noexcept { return m_semaphores[i]; } + inline RenderPass& GetRenderPass() noexcept { return m_pass; } + inline GraphicPipeline& GetPipeline() noexcept { return m_pipeline; } + inline CmdBuffer& GetCmdBuffer(int i) noexcept { return m_cmd.GetCmdBuffer(i); } + inline CmdBuffer& GetActiveCmdBuffer() noexcept { return m_cmd.GetCmdBuffer(m_current_frame_index); } + inline FrameBuffer& GetFrameBuffer(int i) noexcept { return m_framebuffers[i]; } + inline DescriptorSet& GetVertDescriptorSet() noexcept { return m_vert_set; } + inline DescriptorSet& GetFragDescriptorSet() noexcept { return m_frag_set; } + inline DescriptorSetLayout& GetVertDescriptorSetLayout() noexcept { return m_vert_layout; } + inline DescriptorSetLayout& GetFragDescriptorSetLayout() noexcept { return m_frag_layout; } + inline std::uint32_t GetActiveImageIndex() noexcept { return m_current_frame_index; } + inline std::uint32_t GetImageIndex() noexcept { return m_image_index; } - constexpr inline void requireFrameBufferResize() noexcept { _framebuffer_resized = true; } + constexpr inline void RequireFrameBufferResize() noexcept { m_framebuffer_resized = true; } ~Renderer() = default; private: - void recreateRenderData(); + void RecreateRenderData(); private: - GraphicPipeline _pipeline; - CmdManager _cmd; - RenderPass _pass; - Surface _surface; - SwapChain _swapchain; - std::array _semaphores; - std::vector _framebuffers; + GraphicPipeline m_pipeline; + CmdManager m_cmd; + RenderPass m_pass; + Surface m_surface; + SwapChain m_swapchain; + std::array m_semaphores; + std::vector m_framebuffers; - DescriptorSetLayout _vert_layout; - DescriptorSetLayout _frag_layout; + DescriptorSetLayout m_vert_layout; + DescriptorSetLayout m_frag_layout; - DescriptorSet _vert_set; - DescriptorSet _frag_set; + DescriptorSet m_vert_set; + DescriptorSet m_frag_set; - std::unique_ptr _uniform_buffer; + std::unique_ptr m_uniform_buffer; - class Window* _window = nullptr; - class Texture* _render_target = nullptr; + NonOwningPtr m_window; + NonOwningPtr m_render_target; - std::uint32_t _current_frame_index = 0; - std::uint32_t _image_index = 0; - bool _framebuffer_resized = false; + std::uint32_t m_current_frame_index = 0; + std::uint32_t m_image_index = 0; + bool m_framebuffer_resized = false; }; } diff --git a/runtime/Includes/Renderer/Renderpass/FrameBuffer.h b/runtime/Includes/Renderer/Renderpass/FrameBuffer.h index e12be0d..ec6abe5 100644 --- a/runtime/Includes/Renderer/Renderpass/FrameBuffer.h +++ b/runtime/Includes/Renderer/Renderpass/FrameBuffer.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* vk_framebuffer.h :+: :+: :+: */ +/* FrameBuffer.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/06 18:19:44 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:08:37 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:16:02 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,18 +18,18 @@ namespace mlx class FrameBuffer { public: - void init(class RenderPass& renderpass, class Image& image); - void destroy() noexcept; + void Init(class RenderPass& renderpass, class Image& image); + void Destroy() noexcept; - inline VkFramebuffer& operator()() noexcept { return _framebuffer; } - inline VkFramebuffer& get() noexcept { return _framebuffer; } - inline std::uint32_t getWidth() const noexcept { return _width; } - inline std::uint32_t getHeight() const noexcept { return _height; } + inline VkFramebuffer& operator()() noexcept { return m_framebuffer; } + inline VkFramebuffer& Get() noexcept { return m_framebuffer; } + inline std::uint32_t GetWidth() const noexcept { return m_width; } + inline std::uint32_t GetHeight() const noexcept { return m_height; } private: - VkFramebuffer _framebuffer = VK_NULL_HANDLE; - std::uint32_t _width = 0; - std::uint32_t _height = 0; + VkFramebuffer m_framebuffer = VK_NULL_HANDLE; + std::uint32_t m_width = 0; + std::uint32_t m_height = 0; }; } diff --git a/runtime/Includes/Renderer/Renderpass/RenderPass.h b/runtime/Includes/Renderer/Renderpass/RenderPass.h index 724c920..18c6c03 100644 --- a/runtime/Includes/Renderer/Renderpass/RenderPass.h +++ b/runtime/Includes/Renderer/Renderpass/RenderPass.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* vk_render_pass.h :+: :+: :+: */ +/* RenderPass.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/06 18:22:00 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:08:30 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:16:44 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,18 +18,18 @@ namespace mlx class RenderPass { public: - void init(VkFormat attachement_format, VkImageLayout layout); - void destroy() noexcept; + void Init(VkFormat attachement_format, VkImageLayout layout); + void Destroy() noexcept; - void begin(class CmdBuffer& cmd, class FrameBuffer& fb); - void end(class CmdBuffer& cmd); + void Begin(class CmommandBuffer& cmd, class FrameBuffer& fb); + void End(class CommandBuffer& cmd); - inline VkRenderPass& operator()() noexcept { return _render_pass; } - inline VkRenderPass& get() noexcept { return _render_pass; } + inline VkRenderPass& operator()() noexcept { return m_render_pass; } + inline VkRenderPass& Get() noexcept { return m_render_pass; } private: - VkRenderPass _render_pass = VK_NULL_HANDLE; - bool _is_running = false; + VkRenderPass m_render_pass = VK_NULL_HANDLE; + bool m_is_running = false; }; } diff --git a/runtime/Includes/Renderer/Renderpass/Swapchain.h b/runtime/Includes/Renderer/Renderpass/Swapchain.h index d68072e..f9c8054 100644 --- a/runtime/Includes/Renderer/Renderpass/Swapchain.h +++ b/runtime/Includes/Renderer/Renderpass/Swapchain.h @@ -1,19 +1,19 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* vk_swapchain.h :+: :+: :+: */ +/* Swapchain.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/06 18:23:27 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:08:26 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:18:15 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef __MLX_VK_SWAPCHAIN__ #define __MLX_VK_SWAPCHAIN__ -#include +#include namespace mlx { @@ -34,31 +34,31 @@ namespace mlx public: SwapChain() = default; - void init(class Renderer* renderer); - void recreate(); - void destroy() noexcept; + void Init(NonOwningPtr renderer); + void Recreate(); + void Destroy() noexcept; - SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device); - VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities); - VkPresentModeKHR chooseSwapPresentMode([[maybe_unused]] const std::vector &availablePresentModes); + SwapChainSupportDetails QuerySwapChainSupport(VkPhysicalDevice device); + VkExtent2D ChooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities); + VkPresentModeKHR ChooseSwapPresentMode([[maybe_unused]] const std::vector &available_present_modes); - inline VkSwapchainKHR get() noexcept { return _swapchain; } - inline VkSwapchainKHR operator()() noexcept { return _swapchain; } - inline std::size_t getImagesNumber() const noexcept { return _images.size(); } - inline Image& getImage(std::size_t i) noexcept { return _images[i]; } - inline SwapChainSupportDetails getSupport() noexcept { return _swapchain_support; } - inline VkExtent2D getExtent() noexcept { return _extent; } - inline VkFormat getImagesFormat() const noexcept { return _swapchain_image_format; } + inline VkSwapchainKHR Get() noexcept { return m_swapchain; } + inline VkSwapchainKHR operator()() noexcept { return m_swapchain; } + inline std::size_t GetImagesNumber() const noexcept { return m_images.size(); } + inline Image& GetImage(std::size_t i) noexcept { return m_images[i]; } + inline SwapChainSupportDetails GetSupport() noexcept { return m_swapchain_support; } + inline VkExtent2D GetExtent() noexcept { return m_extent; } + inline VkFormat GetImagesFormat() const noexcept { return m_swapchain_image_format; } ~SwapChain() = default; private: - SwapChainSupportDetails _swapchain_support; - VkSwapchainKHR _swapchain; - std::vector _images; - VkFormat _swapchain_image_format; - VkExtent2D _extent; - class Renderer* _renderer = nullptr; + SwapChainSupportDetails m_swapchain_support; + VkSwapchainKHR m_swapchain; + std::vector m_images; + VkFormat m_swapchain_image_format; + VkExtent2D m_extent; + NonOwningPtr m_renderer; }; } diff --git a/runtime/Includes/Renderer/Texts/Font.h b/runtime/Includes/Renderer/Texts/Font.h index c1c48df..ebf873f 100644 --- a/runtime/Includes/Renderer/Texts/Font.h +++ b/runtime/Includes/Renderer/Texts/Font.h @@ -1,52 +1,54 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* font.h :+: :+: :+: */ +/* Font.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/11 21:17:04 by kbz_8 #+# #+# */ -/* Updated: 2024/03/25 19:08:21 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:19:39 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef __MLX_FONT__ #define __MLX_FONT__ -#include -#include +#include +#include namespace mlx { class Font { friend class FontLibrary; + public: Font() = delete; Font(class Renderer& renderer, const std::filesystem::path& path, float scale); Font(class Renderer& renderer, const std::string& name, const std::vector& ttf_data, float scale); - inline const std::string& getName() const { return _name; } - inline float getScale() const noexcept { return _scale; } - inline const std::array& getCharData() const { return _cdata; } - inline const TextureAtlas& getAtlas() const noexcept { return _atlas; } - inline bool operator==(const Font& rhs) const { return rhs._name == _name && rhs._scale == _scale; } - inline bool operator!=(const Font& rhs) const { return rhs._name != _name || rhs._scale != _scale; } - void destroy(); + inline const std::string& GetName() const { return m_name; } + inline float GetScale() const noexcept { return m_scale; } + inline const std::array& GetCharData() const { return m_cdata; } + inline const TextureAtlas& GetAtlas() const noexcept { return m_atlas; } + inline bool operator==(const Font& rhs) const { return rhs._name == m_name && rhs._scale == m_scale; } + inline bool operator!=(const Font& rhs) const { return rhs._name != m_name || rhs._scale != m_scale; } + + void Destroy(); ~Font(); private: - void buildFont(); + void BuildFont(); private: - std::array _cdata; - TextureAtlas _atlas; - std::variant> _build_data; - std::string _name; - class Renderer& _renderer; - float _scale = 0; - bool _is_init = false; + std::array m_cdata; + TextureAtlas m_atlas; + std::variant> m_build_data; + std::string m_name; + class Renderer& m_renderer; + float m_scale = 0; + bool m_is_init = false; }; } diff --git a/runtime/Includes/Renderer/Texts/FontLibrary.h b/runtime/Includes/Renderer/Texts/FontLibrary.h index ddd15ad..433c5f5 100644 --- a/runtime/Includes/Renderer/Texts/FontLibrary.h +++ b/runtime/Includes/Renderer/Texts/FontLibrary.h @@ -1,21 +1,21 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* font_library.h :+: :+: :+: */ +/* FontLibrary.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/18 09:26:03 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:08:18 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:21:53 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef __MLX_FONT_LIBRARY__ #define __MLX_FONT_LIBRARY__ -#include -#include -#include +#include +#include +#include namespace mlx { @@ -27,20 +27,20 @@ namespace mlx friend class Singleton; public: - std::shared_ptr getFontData(FontID id); - FontID addFontToLibrary(std::shared_ptr font); - void removeFontFromLibrary(FontID id); + std::shared_ptr GetFontData(FontID id); + FontID AddFontToLibrary(std::shared_ptr font); + void RemoveFontFromLibrary(FontID id); - void clearLibrary(); + void ClearLibrary(); private: FontLibrary() = default; ~FontLibrary() = default; private: - std::unordered_map> _cache; - std::vector _invalid_ids; - FontID _current_id = 1; + std::unordered_map> m_cache; + std::vector m_invalid_ids; + FontID m_current_id = 1; }; } diff --git a/runtime/Includes/Renderer/Texts/Text.h b/runtime/Includes/Renderer/Texts/Text.h index c30bbb9..07b6d10 100644 --- a/runtime/Includes/Renderer/Texts/Text.h +++ b/runtime/Includes/Renderer/Texts/Text.h @@ -1,22 +1,22 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* text.h :+: :+: :+: */ +/* Text.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 00:09:04 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:08:15 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:23:50 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef __MLX_TEXT__ #define __MLX_TEXT__ -#include -#include -#include -#include +#include +#include +#include +#include namespace mlx { @@ -25,24 +25,24 @@ namespace mlx public: Text() = default; - void init(std::string text, FontID font, std::uint32_t color, std::vector vbo_data, std::vector ibo_data); - void bind(class Renderer& renderer) noexcept; - inline FontID getFontInUse() const noexcept { return _font; } - void updateVertexData(int frame, std::vector vbo_data); - inline std::uint32_t getIBOsize() noexcept { return _ibo.getSize(); } - inline const std::string& getText() const { return _text; } - inline std::uint32_t getColor() const noexcept { return _color; } - void destroy() noexcept; + void Init(std::string text, FontID font, std::uint32_t color, std::vector vbo_data, std::vector ibo_data); + void Bind(class Renderer& renderer) noexcept; + inline FontID GetFontInUse() const noexcept { return m_font; } + void UpdateVertexData(int frame, std::vector vbo_data); + inline std::uint32_t GetIBOsize() noexcept { return m_ibo.GetSize(); } + inline const std::string& GetText() const { return m_text; } + inline std::uint32_t GetColor() const noexcept { return m_color; } + void Destroy() noexcept; ~Text(); private: - std::array _vbo; - C_IBO _ibo; - std::string _text; - std::uint32_t _color; - FontID _font = nullfont; - bool _is_init = false; + std::array m_vbo; + ConstantIndexBuffer m_ibo; + std::string m_text; + std::uint32_t m_color; + FontID m_font = nullfont; + bool m_is_init = false; }; } diff --git a/runtime/Includes/Renderer/Texts/TextDescriptor.h b/runtime/Includes/Renderer/Texts/TextDescriptor.h index 25a4335..87496ec 100644 --- a/runtime/Includes/Renderer/Texts/TextDescriptor.h +++ b/runtime/Includes/Renderer/Texts/TextDescriptor.h @@ -1,22 +1,22 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* text_descriptor.h :+: :+: :+: */ +/* TextDescriptor.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/11 00:13:34 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:08:11 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:25:09 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef __MLX_TEXT_DESCRIPTOR__ #define __MLX_TEXT_DESCRIPTOR__ -#include -#include -#include -#include +#include +#include +#include +#include namespace mlx { @@ -33,15 +33,15 @@ namespace mlx public: TextDrawDescriptor(std::string text, std::uint32_t _color, int _x, int _y); - void init(FontID font) noexcept; - bool operator==(const TextDrawDescriptor& rhs) const { return _text == rhs._text && x == rhs.x && y == rhs.y && color == rhs.color; } - void render(std::array& sets, Renderer& renderer) override; - void resetUpdate() override; + void Init(FontID font) noexcept; + bool operator==(const TextDrawDescriptor& rhs) const { return m_text == rhs.m_text && x == rhs.x && y == rhs.y && color == rhs.color; } + void Render(std::array& sets, Renderer& renderer) override; + void ResetUpdate() override; TextDrawDescriptor() = default; private: - std::string _text; + std::string m_text; }; } @@ -53,7 +53,7 @@ namespace std std::size_t operator()(const mlx::TextDrawDescriptor& d) const noexcept { std::size_t hash = 0; - mlx::hashCombine(hash, d.x, d.y, d.color, d._text); + mlx::HashCombine(hash, d.x, d.y, d.color, d.m_text); return hash; } }; diff --git a/runtime/Includes/Renderer/Texts/TextLibrary.h b/runtime/Includes/Renderer/Texts/TextLibrary.h index 598cef9..63385ea 100644 --- a/runtime/Includes/Renderer/Texts/TextLibrary.h +++ b/runtime/Includes/Renderer/Texts/TextLibrary.h @@ -1,23 +1,23 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* text_library.h :+: :+: :+: */ +/* TextLibrary.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/10 11:52:30 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:08:03 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:26:10 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef __MLX_TEXT_LIBRARY__ #define __MLX_TEXT_LIBRARY__ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include namespace mlx { @@ -29,19 +29,19 @@ namespace mlx friend class Singleton; public: - std::shared_ptr getTextData(TextID id); - TextID addTextToLibrary(std::shared_ptr text); - void removeTextFromLibrary(TextID id); + std::shared_ptr GetTextData(TextID id); + TextID AddTextToLibrary(std::shared_ptr text); + void RemoveTextFromLibrary(TextID id); - void clearLibrary(); + void ClearLibrary(); private: TextLibrary() = default; ~TextLibrary() = default; private: - std::unordered_map> _cache; - TextID _current_id = 1; + std::unordered_map> m_cache; + TextID m_current_id = 1; }; } diff --git a/runtime/Includes/Renderer/Texts/TextManager.h b/runtime/Includes/Renderer/Texts/TextManager.h index 1c4cec0..a2d57db 100644 --- a/runtime/Includes/Renderer/Texts/TextManager.h +++ b/runtime/Includes/Renderer/Texts/TextManager.h @@ -1,23 +1,23 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* text_manager.h :+: :+: :+: */ +/* TextManager.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/06 16:24:11 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:08:00 by maldavid ### ########.fr */ +/* Updated: 2024/03/28 22:27:32 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef __MLX_TEXT_MANAGER__ #define __MLX_TEXT_MANAGER__ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include namespace mlx { @@ -26,17 +26,17 @@ namespace mlx public: TextManager() = default; - void init(Renderer& renderer) noexcept; - std::pair registerText(int x, int y, std::uint32_t color, std::string str); - inline void clear() { _text_descriptors.clear(); } - void loadFont(Renderer& renderer, const std::filesystem::path& filepath, float scale); - void destroy() noexcept; + void Init(Renderer& renderer) noexcept; + std::pair, bool> RegisterText(int x, int y, std::uint32_t color, std::string str); + inline void Clear() { m_text_descriptors.clear(); } + void LoadFont(Renderer& renderer, const std::filesystem::path& filepath, float scale); + void Destroy() noexcept; ~TextManager() = default; private: - std::unordered_set _text_descriptors; - FontID _font_in_use = nullfont; + std::unordered_set m_text_descriptors; + FontID m_font_in_use = nullfont; }; } diff --git a/runtime/Sources/Core/Application.cpp b/runtime/Sources/Core/Application.cpp index 8e22407..ab2a4aa 100644 --- a/runtime/Sources/Core/Application.cpp +++ b/runtime/Sources/Core/Application.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */ -/* Updated: 2024/03/27 17:43:18 by maldavid ### ########.fr */ +/* Updated: 2024/04/02 17:06:34 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,9 +17,7 @@ #include #include #include -#include -#include -#include +#include #include namespace mlx::core @@ -32,11 +30,6 @@ namespace mlx::core }, "__internal_application" }); _fps.init(); - glfwSetErrorCallback([]([[maybe_unused]] int code, const char* desc) - { - error::report(e_kind::fatal_error, "GLFW error : %s", desc); - }); - glfwInit(); } void Application::run() noexcept @@ -111,6 +104,5 @@ namespace mlx::core { TextLibrary::get().clearLibrary(); FontLibrary::get().clearLibrary(); - glfwTerminate(); } }