mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 06:33:35 +00:00
working
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <Core/Graphics.h>
|
||||
#include <Platform/Inputs.h>
|
||||
#include <Core/DriverLoader.h>
|
||||
#include <Core/Fps.h>
|
||||
|
||||
namespace mlx
|
||||
@@ -58,6 +59,7 @@ namespace mlx
|
||||
|
||||
private:
|
||||
FpsManager m_fps;
|
||||
DriverLoader m_driver_loader;
|
||||
std::list<Texture> m_textures;
|
||||
std::vector<std::unique_ptr<GraphicsSupport>> m_graphics;
|
||||
std::function<int(void*)> f_loop_hook;
|
||||
|
||||
39
runtime/Includes/Core/DriverLoader.h
git.filemode.normal_file
39
runtime/Includes/Core/DriverLoader.h
git.filemode.normal_file
@@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* DriverLoader.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <Drivers/DriverInstance.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class DriverLoader
|
||||
{
|
||||
public:
|
||||
DriverLoader() = default;
|
||||
|
||||
template <typename T>
|
||||
inline bool LoadDriver();
|
||||
|
||||
inline void ShutdownAllDrivers();
|
||||
|
||||
~DriverLoader() = default;
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<DriverInstance> > m_instances;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Core/DriverLoader.inl>
|
||||
|
||||
#endif
|
||||
30
runtime/Includes/Core/DriverLoader.inl
git.filemode.normal_file
30
runtime/Includes/Core/DriverLoader.inl
git.filemode.normal_file
@@ -0,0 +1,30 @@
|
||||
/* **************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* DriverLoader.inl :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/03 14:55:01 by maldavid #+# #+# */
|
||||
/* Updated: 2024/04/03 14:55:01 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* **************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
#include <Core/DriverLoader.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
template <typename T>
|
||||
bool DriverLoader::LoadDriver()
|
||||
{
|
||||
m_instances.emplace_back(new T)->InitDriver();
|
||||
}
|
||||
|
||||
void DriverLoader::ShutdownAllDrivers()
|
||||
{
|
||||
for(auto& driver : m_instances)
|
||||
driver->ShutdownDriver();
|
||||
m_instances.clear();
|
||||
}
|
||||
}
|
||||
27
runtime/Includes/Core/ImagesManager.h
git.filemode.normal_file
27
runtime/Includes/Core/ImagesManager.h
git.filemode.normal_file
@@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ImagesManager.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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<Texture*> m_textures_registry;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
35
runtime/Includes/Drivers/DriverInstance.h
git.filemode.normal_file
35
runtime/Includes/Drivers/DriverInstance.h
git.filemode.normal_file
@@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* DriverInstance.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
34
runtime/Includes/Drivers/GLFW/GLFWDriverInstance.h
git.filemode.normal_file
34
runtime/Includes/Drivers/GLFW/GLFWDriverInstance.h
git.filemode.normal_file
@@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* GLFWDriverInstance.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <Drivers/DriverInstance.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class GLFWDriverInstance : public DriverInstance
|
||||
{
|
||||
public:
|
||||
GLFWDriverInstance() = default;
|
||||
|
||||
inline bool InitDriver() override;
|
||||
inline void ShutdownDriver() override;
|
||||
|
||||
~GLFWDriverInstance() override = default;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Drivers/GLFW/GLFWDriverInstance.inl>
|
||||
|
||||
#endif
|
||||
32
runtime/Includes/Drivers/GLFW/GLFWDriverInstance.inl
git.filemode.normal_file
32
runtime/Includes/Drivers/GLFW/GLFWDriverInstance.inl
git.filemode.normal_file
@@ -0,0 +1,32 @@
|
||||
/* **************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* GLFWDriverInstance.inl :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/02 17:04:23 by maldavid #+# #+# */
|
||||
/* Updated: 2024/04/02 17:04:23 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* **************************************************************************** */
|
||||
|
||||
#include <Drivers/GLFW/GLFWDriverInstance.h>
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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); }
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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); }
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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<std::uint32_t> graphics_family;
|
||||
std::optional<std::uint32_t> 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:
|
||||
|
||||
@@ -1,87 +1,83 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vk_image.h :+: :+: :+: */
|
||||
/* Image.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/core/cmd_resource.h>
|
||||
#include <renderer/command/vk_cmd_buffer.h>
|
||||
#include <renderer/command/vk_cmd_pool.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <string>
|
||||
#endif
|
||||
#include <Renderer/Core/CommandResource.h>
|
||||
#include <Renderer/Command/CommandBuffer.h>
|
||||
#include <Renderer/Command/CommandPool.h>
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* texture.h :+: :+: :+: */
|
||||
/* Texture.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/images/vk_image.h>
|
||||
#include <renderer/descriptors/vk_descriptor_set.h>
|
||||
#include <renderer/buffers/vk_ibo.h>
|
||||
#include <renderer/buffers/vk_vbo.h>
|
||||
#include <Renderer/Images/Image.h>
|
||||
#include <Renderer/Descriptors/DescriptorSet.h>
|
||||
#include <Renderer/Buffers/IndexBuffer.h>
|
||||
#include <Renderer/Buffers/VertexBuffer.h>
|
||||
|
||||
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<VkDescriptorSet, 2>& 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<VkDescriptorSet, 2>& 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<std::uint32_t> _cpu_map;
|
||||
std::optional<Buffer> _buf_map = std::nullopt;
|
||||
void* _map = nullptr;
|
||||
bool _has_been_modified = false;
|
||||
bool _has_set_been_updated = false;
|
||||
DescriptorSet m_set;
|
||||
std::vector<std::uint32_t> m_cpu_map;
|
||||
std::optional<Buffer> 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
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* texture_atlas.h :+: :+: :+: */
|
||||
/* TextureAtlas.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/images/texture.h>
|
||||
#include <Renderer/Images/Texture.h>
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* texture_descriptor.h :+: :+: :+: */
|
||||
/* TextureDescriptor.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/images/texture.h>
|
||||
#include <renderer/core/drawable_resource.h>
|
||||
#include <utils/combine_hash.h>
|
||||
#include <Renderer/Images/Texture.h>
|
||||
#include <Renderer/Core/DrawableResource.h>
|
||||
#include <Utils/CombineHash.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
struct TextureRenderDescriptor : public DrawableResource
|
||||
{
|
||||
Texture* texture;
|
||||
NonOwningPtr<Texture> texture;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
TextureRenderDescriptor(Texture* _texture, int _x, int _y) : texture(_texture), x(_x), y(_y) {}
|
||||
TextureRenderDescriptor(NonOwningPtr<Texture> _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<VkDescriptorSet, 2>& sets, class Renderer& renderer) override
|
||||
inline void Render(std::array<VkDescriptorSet, 2>& 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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* texture_manager.h :+: :+: :+: */
|
||||
/* TextureManager.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/images/texture_descriptor.h>
|
||||
#include <core/profiler.h>
|
||||
#include <Renderer/Images/TextureDescriptor.h>
|
||||
|
||||
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<DrawableResource*, bool> registerTexture(Texture* texture, int x, int y)
|
||||
inline std::pair<NonOwningPtr<DrawableResource>, bool> RegisterTexture(NonOwningPtr<Texture> 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<DrawableResource*>(&const_cast<TextureRenderDescriptor&>(*res.first)), res.second);
|
||||
}
|
||||
|
||||
inline bool isTextureKnown(Texture* texture) noexcept
|
||||
inline bool IsTextureKnown(NonOwningPtr<Texture> 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> 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<TextureRenderDescriptor> _texture_descriptors;
|
||||
std::unordered_set<TextureRenderDescriptor> m_texture_descriptors;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* pipeline.h :+: :+: :+: */
|
||||
/* Pipeline.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/command/vk_cmd_buffer.h>
|
||||
#include <Renderer/Command/CommandBuffer.h>
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* pixel_put.h :+: :+: :+: */
|
||||
/* PixelPut.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/images/texture.h>
|
||||
#include <renderer/descriptors/vk_descriptor_set.h>
|
||||
#include <Renderer/Images/Texture.h>
|
||||
#include <Renderer/Descriptors/DescriptorSet.h>
|
||||
|
||||
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<VkDescriptorSet, 2>& sets, class Renderer& renderer) noexcept;
|
||||
void SetPixel(int x, int y, std::uint32_t color) noexcept;
|
||||
void Render(std::array<VkDescriptorSet, 2>& 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<std::uint32_t> _cpu_map;
|
||||
void* _buffer_map = nullptr;
|
||||
std::uint32_t _width = 0;
|
||||
std::uint32_t _height = 0;
|
||||
bool _has_been_modified = true;
|
||||
std::vector<std::uint32_t> 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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* renderer.h :+: :+: :+: */
|
||||
/* Renderer.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/buffers/vk_ubo.h>
|
||||
#include <renderer/core/vk_surface.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <renderer/core/vk_semaphore.h>
|
||||
#include <renderer/pipeline/pipeline.h>
|
||||
#include <renderer/command/cmd_manager.h>
|
||||
#include <renderer/swapchain/vk_swapchain.h>
|
||||
#include <renderer/renderpass/vk_render_pass.h>
|
||||
#include <renderer/renderpass/vk_framebuffer.h>
|
||||
#include <renderer/descriptors/vk_descriptor_set.h>
|
||||
#include <renderer/descriptors/vk_descriptor_pool.h>
|
||||
#include <renderer/descriptors/vk_descriptor_set_layout.h>
|
||||
|
||||
#include <core/errors.h>
|
||||
#include <mlx_profile.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <Renderer/Buffers/UniformBuffer.h>
|
||||
#include <Renderer/Core/Surface.h>
|
||||
#include <Renderer/Core/RenderCore.h>
|
||||
#include <Renderer/Core/Semaphore.h>
|
||||
#include <Renderer/Pipeline/Pipeline.h>
|
||||
#include <Renderer/Command/CommandManager.h>
|
||||
#include <Renderer/Swapchain/Swapchain.h>
|
||||
#include <Renderer/Renderpass/RenderPass.h>
|
||||
#include <Renderer/Renderpass/FrameBuffer.h>
|
||||
#include <Renderer/Descriptors/DescriptorSet.h>
|
||||
#include <Renderer/Descriptors/DescriptorPool.h>
|
||||
#include <Renderer/Descriptors/DescriptorSetLayout.h>
|
||||
|
||||
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<VkVertexInputAttributeDescription, 3> getAttributeDescriptions()
|
||||
static std::array<VkVertexInputAttributeDescription, 3> GetAttributeDescriptions()
|
||||
{
|
||||
std::array<VkVertexInputAttributeDescription, 3> attributeDescriptions;
|
||||
std::array<VkVertexInputAttributeDescription, 3> 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<class Texture> 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<class Window> GetWindow() { return m_window; }
|
||||
inline void SetWindow(NonOwningPtr<class Window> 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<UniformBuffer> 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<Semaphore, MAX_FRAMES_IN_FLIGHT> _semaphores;
|
||||
std::vector<FrameBuffer> _framebuffers;
|
||||
GraphicPipeline m_pipeline;
|
||||
CmdManager m_cmd;
|
||||
RenderPass m_pass;
|
||||
Surface m_surface;
|
||||
SwapChain m_swapchain;
|
||||
std::array<Semaphore, MAX_FRAMES_IN_FLIGHT> m_semaphores;
|
||||
std::vector<FrameBuffer> 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<UBO> _uniform_buffer;
|
||||
std::unique_ptr<UniformBuffer> m_uniform_buffer;
|
||||
|
||||
class Window* _window = nullptr;
|
||||
class Texture* _render_target = nullptr;
|
||||
NonOwningPtr<class Window> m_window;
|
||||
NonOwningPtr<class Texture> 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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vk_framebuffer.h :+: :+: :+: */
|
||||
/* FrameBuffer.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vk_render_pass.h :+: :+: :+: */
|
||||
/* RenderPass.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vk_swapchain.h :+: :+: :+: */
|
||||
/* Swapchain.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/images/vk_image.h>
|
||||
#include <Renderer/Images/Image.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
@@ -34,31 +34,31 @@ namespace mlx
|
||||
public:
|
||||
SwapChain() = default;
|
||||
|
||||
void init(class Renderer* renderer);
|
||||
void recreate();
|
||||
void destroy() noexcept;
|
||||
void Init(NonOwningPtr<class Renderer> renderer);
|
||||
void Recreate();
|
||||
void Destroy() noexcept;
|
||||
|
||||
SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device);
|
||||
VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities);
|
||||
VkPresentModeKHR chooseSwapPresentMode([[maybe_unused]] const std::vector<VkPresentModeKHR> &availablePresentModes);
|
||||
SwapChainSupportDetails QuerySwapChainSupport(VkPhysicalDevice device);
|
||||
VkExtent2D ChooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities);
|
||||
VkPresentModeKHR ChooseSwapPresentMode([[maybe_unused]] const std::vector<VkPresentModeKHR> &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<Image> _images;
|
||||
VkFormat _swapchain_image_format;
|
||||
VkExtent2D _extent;
|
||||
class Renderer* _renderer = nullptr;
|
||||
SwapChainSupportDetails m_swapchain_support;
|
||||
VkSwapchainKHR m_swapchain;
|
||||
std::vector<Image> m_images;
|
||||
VkFormat m_swapchain_image_format;
|
||||
VkExtent2D m_extent;
|
||||
NonOwningPtr<class Renderer> m_renderer;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,52 +1,54 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* font.h :+: :+: :+: */
|
||||
/* Font.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/images/texture_atlas.h>
|
||||
#include <utils/combine_hash.h>
|
||||
#include <Renderer/Images/TextureAtlas.h>
|
||||
#include <Utils/CombineHash.h>
|
||||
|
||||
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<std::uint8_t>& ttf_data, float scale);
|
||||
|
||||
inline const std::string& getName() const { return _name; }
|
||||
inline float getScale() const noexcept { return _scale; }
|
||||
inline const std::array<stbtt_packedchar, 96>& 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<stbtt_packedchar, 96>& 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<stbtt_packedchar, 96> _cdata;
|
||||
TextureAtlas _atlas;
|
||||
std::variant<std::filesystem::path, std::vector<std::uint8_t>> _build_data;
|
||||
std::string _name;
|
||||
class Renderer& _renderer;
|
||||
float _scale = 0;
|
||||
bool _is_init = false;
|
||||
std::array<stbtt_packedchar, 96> m_cdata;
|
||||
TextureAtlas m_atlas;
|
||||
std::variant<std::filesystem::path, std::vector<std::uint8_t>> m_build_data;
|
||||
std::string m_name;
|
||||
class Renderer& m_renderer;
|
||||
float m_scale = 0;
|
||||
bool m_is_init = false;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* font_library.h :+: :+: :+: */
|
||||
/* FontLibrary.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/texts/font.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <utils/singleton.h>
|
||||
#include <Renderer/Texts/Font.h>
|
||||
#include <Renderer/Core/RenderCore.h>
|
||||
#include <Utils/Singleton.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
@@ -27,20 +27,20 @@ namespace mlx
|
||||
friend class Singleton<FontLibrary>;
|
||||
|
||||
public:
|
||||
std::shared_ptr<class Font> getFontData(FontID id);
|
||||
FontID addFontToLibrary(std::shared_ptr<Font> font);
|
||||
void removeFontFromLibrary(FontID id);
|
||||
std::shared_ptr<class Font> GetFontData(FontID id);
|
||||
FontID AddFontToLibrary(std::shared_ptr<Font> font);
|
||||
void RemoveFontFromLibrary(FontID id);
|
||||
|
||||
void clearLibrary();
|
||||
void ClearLibrary();
|
||||
|
||||
private:
|
||||
FontLibrary() = default;
|
||||
~FontLibrary() = default;
|
||||
|
||||
private:
|
||||
std::unordered_map<FontID, std::shared_ptr<class Font>> _cache;
|
||||
std::vector<FontID> _invalid_ids;
|
||||
FontID _current_id = 1;
|
||||
std::unordered_map<FontID, std::shared_ptr<class Font>> m_cache;
|
||||
std::vector<FontID> m_invalid_ids;
|
||||
FontID m_current_id = 1;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* text.h :+: :+: :+: */
|
||||
/* Text.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/texts/font.h>
|
||||
#include <renderer/texts/font_library.h>
|
||||
#include <renderer/buffers/vk_ibo.h>
|
||||
#include <renderer/buffers/vk_vbo.h>
|
||||
#include <Renderer/Texts/Font.h>
|
||||
#include <Renderer/Texts/FontLibrary.h>
|
||||
#include <Renderer/Buffers/IndexBuffer.h>
|
||||
#include <Renderer/Buffers/VertexBuffer.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
@@ -25,24 +25,24 @@ namespace mlx
|
||||
public:
|
||||
Text() = default;
|
||||
|
||||
void init(std::string text, FontID font, std::uint32_t color, std::vector<Vertex> vbo_data, std::vector<std::uint16_t> ibo_data);
|
||||
void bind(class Renderer& renderer) noexcept;
|
||||
inline FontID getFontInUse() const noexcept { return _font; }
|
||||
void updateVertexData(int frame, std::vector<Vertex> 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<Vertex> vbo_data, std::vector<std::uint16_t> ibo_data);
|
||||
void Bind(class Renderer& renderer) noexcept;
|
||||
inline FontID GetFontInUse() const noexcept { return m_font; }
|
||||
void UpdateVertexData(int frame, std::vector<Vertex> 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<D_VBO, MAX_FRAMES_IN_FLIGHT> _vbo;
|
||||
C_IBO _ibo;
|
||||
std::string _text;
|
||||
std::uint32_t _color;
|
||||
FontID _font = nullfont;
|
||||
bool _is_init = false;
|
||||
std::array<DeviceVertexBuffer, MAX_FRAMES_IN_FLIGHT> m_vbo;
|
||||
ConstantIndexBuffer m_ibo;
|
||||
std::string m_text;
|
||||
std::uint32_t m_color;
|
||||
FontID m_font = nullfont;
|
||||
bool m_is_init = false;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* text_descriptor.h :+: :+: :+: */
|
||||
/* TextDescriptor.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <utils/combine_hash.h>
|
||||
#include <renderer/core/drawable_resource.h>
|
||||
#include <renderer/texts/text_library.h>
|
||||
#include <renderer/texts/font_library.h>
|
||||
#include <Utils/CombineHash.h>
|
||||
#include <Renderer/Core/DrawableResource.h>
|
||||
#include <Renderer/Texts/TextLibrary.h>
|
||||
#include <Renderer/Texts/FontLibrary.h>
|
||||
|
||||
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<VkDescriptorSet, 2>& 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<VkDescriptorSet, 2>& 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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* text_library.h :+: :+: :+: */
|
||||
/* TextLibrary.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/buffers/vk_vbo.h>
|
||||
#include <renderer/buffers/vk_ibo.h>
|
||||
#include <renderer/texts/font.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <utils/singleton.h>
|
||||
#include <Renderer/Buffers/VertexBuffer.h>
|
||||
#include <Renderer/Buffers/IndexBuffer.h>
|
||||
#include <Renderer/Texts/Font.h>
|
||||
#include <Renderer/Core/RenderCore.h>
|
||||
#include <Utils/Singleton.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
@@ -29,19 +29,19 @@ namespace mlx
|
||||
friend class Singleton<TextLibrary>;
|
||||
|
||||
public:
|
||||
std::shared_ptr<class Text> getTextData(TextID id);
|
||||
TextID addTextToLibrary(std::shared_ptr<Text> text);
|
||||
void removeTextFromLibrary(TextID id);
|
||||
std::shared_ptr<class Text> GetTextData(TextID id);
|
||||
TextID AddTextToLibrary(std::shared_ptr<Text> text);
|
||||
void RemoveTextFromLibrary(TextID id);
|
||||
|
||||
void clearLibrary();
|
||||
void ClearLibrary();
|
||||
|
||||
private:
|
||||
TextLibrary() = default;
|
||||
~TextLibrary() = default;
|
||||
|
||||
private:
|
||||
std::unordered_map<TextID, std::shared_ptr<class Text>> _cache;
|
||||
TextID _current_id = 1;
|
||||
std::unordered_map<TextID, std::shared_ptr<class Text>> m_cache;
|
||||
TextID m_current_id = 1;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* text_manager.h :+: :+: :+: */
|
||||
/* TextManager.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/renderer.h>
|
||||
#include <renderer/images/texture_atlas.h>
|
||||
#include <renderer/texts/text_descriptor.h>
|
||||
#include <renderer/texts/text_library.h>
|
||||
#include <renderer/texts/font_library.h>
|
||||
#include <Renderer/Renderer.h>
|
||||
#include <Renderer/Images/TextureAtlas.h>
|
||||
#include <Renderer/Texts/TextDescriptor.h>
|
||||
#include <Renderer/Texts/TextLibrary.h>
|
||||
#include <Renderer/Texts/FontLibrary.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
@@ -26,17 +26,17 @@ namespace mlx
|
||||
public:
|
||||
TextManager() = default;
|
||||
|
||||
void init(Renderer& renderer) noexcept;
|
||||
std::pair<DrawableResource*, bool> 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<NonOwningPtr<DrawableResource>, 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<TextDrawDescriptor> _text_descriptors;
|
||||
FontID _font_in_use = nullfont;
|
||||
std::unordered_set<TextDrawDescriptor> m_text_descriptors;
|
||||
FontID m_font_in_use = nullfont;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/texts/font_library.h>
|
||||
#include <renderer/images/texture.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <core/errors.h>
|
||||
#include <mlx_profile.h>
|
||||
#include <core/memory.h>
|
||||
#include <Core/memory.h>
|
||||
#include <Core/EventBus.h>
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user