working on code refactor

This commit is contained in:
Kbz-8
2024-04-23 20:59:50 +02:00
parent 810417a251
commit f8a856db1c
53 changed files with 1378 additions and 1403 deletions

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
/* Updated: 2024/04/03 15:05:24 by maldavid ### ########.fr */
/* Updated: 2024/04/21 20:39:33 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,6 +16,7 @@
#include <Core/Graphics.h>
#include <Platform/Inputs.h>
#include <Core/DriverLoader.h>
#include <Core/ImagesRegistry.h>
#include <Core/Fps.h>
namespace mlx
@@ -59,11 +60,11 @@ namespace mlx
private:
FpsManager m_fps;
Input m_in;
DriverLoader m_driver_loader;
std::list<Texture> m_textures;
ImageRegistry m_image_registry;
std::vector<std::unique_ptr<GraphicsSupport>> m_graphics;
std::function<int(void*)> f_loop_hook;
std::unique_ptr<Input> p_in;
void* p_param = nullptr;
};
}

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* application.inl :+: :+: :+: */
/* Application.inl :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
/* Updated: 2023/04/02 14:56:27 by maldavid ### ########.fr */
/* Updated: 2024/04/23 14:45:07 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -30,12 +30,9 @@
Error("invalid image ptr (NULL)"); \
retval; \
} \
else if(std::find_if(_textures.begin(), _textures.end(), [=](const Texture& texture) \
{ \
return &texture == img; \
}) == _textures.end()) \
else if(m_image_registry.Find(img)) \
{ \
Error(e_kind::error, "invalid image ptr"); \
Error("invalid image ptr"); \
retval; \
} else {}
@@ -65,7 +62,7 @@ namespace mlx
Warning("trying to add event hook for a window that is targeting an image and not a real window, this is not allowed (hook ignored)");
return;
}
p_in->OnEvent(m_graphics[*static_cast<int*>(win)]->GetWindow()->GetID(), event, funct_ptr, param);
m_in.OnEvent(m_graphics[*static_cast<int*>(win)]->GetWindow()->GetID(), event, funct_ptr, param);
}
void Application::GetScreenSize(void* win, int* w, int* h) noexcept
@@ -97,7 +94,7 @@ namespace mlx
return nullptr;
}
m_graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, title, m_graphics.size()));
p_in->RegisterWindow(m_graphics.back()->GetWindow());
m_in.RegisterWindow(m_graphics.back()->GetWindow());
}
return static_cast<void*>(&m_graphics.back()->GetID());
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
/* Updated: 2024/03/27 21:16:11 by maldavid ### ########.fr */
/* Updated: 2024/04/23 14:02:48 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -42,13 +42,14 @@ namespace mlx
inline void LoadFont(const std::filesystem::path& filepath, float scale);
inline void TryEraseTextureFromManager(NonOwningPtr<Texture> texture) noexcept;
inline bool HasWindow() const noexcept { return _has_window; }
inline bool HasWindow() const noexcept { return m_has_window; }
inline Renderer& GetRenderer() { return *_renderer; }
inline Renderer& GetRenderer() { return m_renderer; }
~GraphicsSupport();
private:
Renderer m_renderer;
PixelPutPipeline m_pixel_put_pipeline;
std::vector<NonOwningPtr<DrawableResource>> m_drawlist;
@@ -59,7 +60,6 @@ namespace mlx
glm::mat4 m_proj = glm::mat4(1.0);
std::shared_ptr<Window> p_window;
std::unique_ptr<Renderer> p_renderer;
std::size_t m_width = 0;
std::size_t m_height = 0;

View File

@@ -1,27 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ImagesManager.h :+: :+: :+: */
/* ImagesRegistry.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 */
/* Updated: 2024/04/21 20:31:00 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_CORE_IMAGES_MANAGER__
#define __MLX_CORE_IMAGES_MANAGER__
#ifndef __MLX_CORE_IMAGES_REGISTRY__
#define __MLX_CORE_IMAGES_REGISTRY__
namespace mlx
{
class ImagesManager
class ImageRegistry
{
public:
ImageRegistry() = default;
inline void RegisterTexture(NonOwningPtr<class Texture> texture);
inline void UnregisterTexture(NonOwningPtr<class Texture> texture);
inline bool IsTextureKnown(NonOwningPtr<class Texture> texture);
~ImageRegistry() = default;
private:
std::unordered_set<Texture*> m_textures_registry;
std::unordered_set<NonOwningPtr<class Texture>> m_textures_registry;
};
}
#include <Core/ImagesRegistry.inl>
#endif

25
runtime/Includes/Core/ImagesRegistry.inl git.filemode.normal_file
View File

@@ -0,0 +1,25 @@
// This file is a part of Akel
// Authors : @kbz_8
// Created : 21/04/2024
// Updated : 21/04/2024
#pragma once
#include <Core/ImagesRegistry.h>
namespace mlx
{
void ImageRegistry::RegisterTexture(NonOwningPtr<class Texture> texture)
{
m_textures_registry.insert(texture);
}
void ImageRegistry::UnregisterTexture(NonOwningPtr<class Texture> texture)
{
m_textures_registry.erase(texture);
}
bool ImageRegistry::IsTextureKnown(NonOwningPtr<class Texture> texture)
{
return m_textures_registry.find(texture) != m_textures_registry.end();
}
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/25 17:37:23 by maldavid #+# #+# */
/* Updated: 2024/03/27 21:33:47 by maldavid ### ########.fr */
/* Updated: 2024/04/23 13:49:52 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,7 +23,7 @@
#include <iostream>
#include <volk.h>
#ifdef LEGACY
#ifdef MLX_LEGACY
#include <SDL2/SDL.h>
#include <SDL2/SDL_vulkan.h>
#else
@@ -84,6 +84,6 @@
#include <Core/Logs.h>
#include <EventBus.h>
#include <Core/Profiler.h>
#include <?Utils/NonOwningPtr.h>
#include <Utils/NonOwningPtr.h>
#endif

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 23:18:52 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:09:07 by maldavid ### ########.fr */
/* Updated: 2024/04/23 14:20:49 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -27,9 +27,9 @@ namespace mlx
void Create(BufferType type, VkDeviceSize size, VkBufferUsageFlags usage, const char* name, const void* data = nullptr);
void Destroy() noexcept;
inline void MapMem(void** data) noexcept { Render_Core::get().getAllocator().mapMemory(m_allocation, data); m_is_mapped = true; }
inline void MapMem(void** data) noexcept { RenderCore::Get().GetAllocator().MapMemory(m_allocation, data); m_is_mapped = true; }
inline bool IsMapped() const noexcept { return m_is_mapped; }
inline void UnmapMem() noexcept { Render_Core::get().getAllocator().unmapMemory(m_allocation); m_is_mapped = false; }
inline void UnmapMem() noexcept { RenderCore::Get().GetAllocator().UnmapMemory(m_allocation); m_is_mapped = false; }
void Flush(VkDeviceSize size = VK_WHOLE_SIZE, VkDeviceSize offset = 0);
bool CopyFromBuffer(const Buffer& buffer) noexcept;

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:45:29 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:15:23 by maldavid ### ########.fr */
/* Updated: 2024/04/23 14:23:56 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -43,7 +43,7 @@ namespace mlx
private:
std::array<Buffer, MAX_FRAMES_IN_FLIGHT> m_buffers;
std::array<void*, MAX_FRAMES_IN_FLIGHT> m_maps;
NonOwningPtr<class Renderer> m_renderer;
NonOwningPtr<class Renderer> p_renderer;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:25:42 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:44:58 by maldavid ### ########.fr */
/* Updated: 2024/04/23 17:59:50 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -29,7 +29,7 @@ namespace mlx
void Destroy() noexcept;
void BeginRecord(VkCommandBufferUsageFlags usage = 0);
void Submit(class Semaphore* semaphores) noexcept;
void Submit(NonOwningPtr<class Semaphore> signal, NonOwningPtr<class Semaphore> wait) noexcept;
void SubmitIdle(bool shouldWaitForExecution = true) noexcept; // TODO : handle `shouldWaitForExecution` as false by default (needs to modify CmdResources lifetimes to do so)
void UpdateSubmitState() noexcept;
inline void WaitForExecution() noexcept { m_fence.wait(); UpdateSubmitState(); m_state = CommandBufferState::Ready; }
@@ -58,7 +58,7 @@ namespace mlx
void PostTransferBarrier() noexcept;
private:
std::vector<class CmdResource*> m_cmd_resources;
std::vector<NonOwningPtr<class CommandResource>> m_cmd_resources;
Fence m_fence;
VkCommandBuffer m_cmd_buffer = VK_NULL_HANDLE;
NonOwningPtr<class CmdPool> m_pool;

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/10 21:00:37 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:47:32 by maldavid ### ########.fr */
/* Updated: 2024/04/23 18:10:56 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,7 +19,7 @@ namespace mlx
{
public:
DrawableResource() = default;
virtual void Render(std::array<VkDescriptorSet, 2>& sets, class Renderer& renderer) = 0;
virtual void Render(class Renderer& renderer) = 0;
virtual void ResetUpdate() {}
virtual ~DrawableResource() = default;
};

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:03:04 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:48:55 by maldavid ### ########.fr */
/* Updated: 2024/04/23 18:44:02 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,6 +21,8 @@ namespace mlx
void Init();
void Destroy() noexcept;
inline std::uint32_t GetInstanceVersion() const noexcept { return m_instance_version; }
inline VkInstance& operator()() noexcept { return m_instance; }
inline VkInstance& Get() noexcept { return m_instance; }
@@ -29,6 +31,7 @@ namespace mlx
private:
VkInstance m_instance = VK_NULL_HANDLE;
std::uint32_t m_instance_version = 0;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/19 14:04:25 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:59:00 by maldavid ### ########.fr */
/* Updated: 2024/04/23 19:16:25 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,10 +22,10 @@ namespace mlx
void Init();
void Destroy();
bool CheckValidationLayerSupport();
void PopulateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& create_info);
VkResult SetDebugUtilsObjectNameEXT(VkObjectType object_type, std::uint64_t object_handle, const char* object_name);
~ValidationLayers() = default;

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/23 18:32:43 by maldavid #+# #+# */
/* Updated: 2024/03/27 23:00:29 by maldavid ### ########.fr */
/* Updated: 2024/04/23 19:36:03 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,8 +20,9 @@ namespace mlx
public:
DescriptorPool() = default;
void Init(std::size_t n, NonOwningPtr<VkDescriptorPoolSize> size);
void FreeDescriptor(const class DescriptorSet& set);
void Init(std::vector<VkDescriptorPoolSize> sizes);
VkDescriptorSet AllocateDescriptorSet(class DescriptorSetLayout& layout);
void FreeDescriptor(VkDescriptorSet set);
void Destroy() noexcept;
inline VkDescriptorPool& operator()() noexcept { return m_pool; }

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/20 06:26:26 by maldavid #+# #+# */
/* Updated: 2024/03/27 23:00:56 by maldavid ### ########.fr */
/* Updated: 2024/04/23 19:40:22 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,7 +22,7 @@ namespace mlx
public:
DescriptorPoolManager() = default;
DescriptorPool& GetAvailablePool(); // assumes the pool is for only one set allocation, may cause some issues if this is for more than one
DescriptorPool& GetAvailablePool();
void DestroyAllPools();
~DescriptorPoolManager() = default;

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/23 18:39:36 by maldavid #+# #+# */
/* Updated: 2024/03/27 23:02:38 by maldavid ### ########.fr */
/* Updated: 2024/04/23 19:49:02 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,6 +14,7 @@
#define __VK_DESCRIPTOR_SET__
#include <Renderer/Core/RenderCore.h>
#include <Renderer/Descriptors/DescriptorSetLayout.h>
namespace mlx
{
@@ -22,7 +23,7 @@ namespace mlx
public:
DescriptorSet() = default;
void Init(class Renderer* renderer, class DescriptorPool* pool, class DescriptorSetLayout* layout);
void Init(NonOwningPtr<class Renderer> renderer, NonOwningPtr<class DescriptorPool> pool, DescriptorSetLayout layout);
void WriteDescriptor(int binding, NonOwningPtr<class UniformBuffer> ubo) const noexcept;
void WriteDescriptor(int binding, const class Image& image) const noexcept;
@@ -41,9 +42,9 @@ namespace mlx
~DescriptorSet() = default;
private:
DescriptorSetLayout p_layout;
std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT> m_desc_set;
NonOwningPtr<class DescriptorPool> p_pool;
NonOwningPtr<class DescriptorSetLayout> p_layout;
NonOwningPtr<class Renderer> p_renderer;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/23 18:36:22 by maldavid #+# #+# */
/* Updated: 2024/03/27 23:03:04 by maldavid ### ########.fr */
/* Updated: 2024/04/23 19:50:50 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/25 11:54:21 by maldavid #+# #+# */
/* Updated: 2024/03/28 22:08:35 by maldavid ### ########.fr */
/* Updated: 2024/04/23 20:00:53 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -45,7 +45,7 @@ namespace mlx
void CreateSampler() noexcept;
void CopyFromBuffer(class Buffer& buffer);
void CopyToBuffer(class Buffer& buffer);
void TransitionLayout(VkImageLayout new_layout, CmdBuffer* cmd = nullptr);
void TransitionLayout(VkImageLayout new_layout, NonOwningPtr<CommandBuffer> cmd = nullptr);
virtual void Destroy() noexcept;
inline VkImage Get() noexcept { return m_image; }

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */
/* Updated: 2024/03/28 22:11:21 by maldavid ### ########.fr */
/* Updated: 2024/04/23 20:03:59 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -26,15 +26,15 @@ namespace mlx
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 Render(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;
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 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; }
@@ -57,7 +57,7 @@ namespace mlx
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

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 21:03:37 by maldavid #+# #+# */
/* Updated: 2024/03/27 21:05:05 by maldavid ### ########.fr */
/* Updated: 2024/04/21 20:21:56 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -42,4 +42,16 @@ namespace mlx
#include <Utils/NonOwningPtr.inl>
namespace std
{
template <typename T>
struct hash<mlx::NonOwningPtr<T>>
{
std::size_t operator()(const mlx::NonOwningPtr<T>& ptr) const noexcept
{
return std::hash<T*>{}(ptr.Get());
}
};
}
#endif