still working on code refactoring

This commit is contained in:
Kbz-8
2024-04-23 22:59:33 +02:00
parent f8a856db1c
commit be19b71c55
16 changed files with 560 additions and 518 deletions

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/04/23 19:49:02 by maldavid ### ########.fr */
/* Updated: 2024/04/23 22:14:48 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -30,11 +30,15 @@ namespace mlx
inline bool IsInit() const noexcept { return m_pool != nullptr && m_renderer != nullptr; }
void Bind() noexcept;
DescriptorSet Duplicate();
VkDescriptorSet& operator()() noexcept;
VkDescriptorSet& Get() noexcept;
inline const DescriptorSetLayout& GetLayout() const noexcept { return m_layout; }
inline const std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT>& GetAllFramesDescriptorSets() const { return m_desc_set; }
void Destroy() noexcept;
@@ -42,7 +46,7 @@ namespace mlx
~DescriptorSet() = default;
private:
DescriptorSetLayout p_layout;
DescriptorSetLayout m_layout;
std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT> m_desc_set;
NonOwningPtr<class DescriptorPool> p_pool;
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/04/23 19:50:50 by maldavid ### ########.fr */
/* Updated: 2024/04/23 22:15:01 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,8 +23,8 @@ namespace mlx
void Init(std::vector<std::pair<int, VkDescriptorType>> binds, VkShaderStageFlagBits stage);
void Destroy() noexcept;
inline VkDescriptorSetLayout& operator()() noexcept { return m_layout; }
inline VkDescriptorSetLayout& Get() noexcept { return m_layout; }
inline VkDescriptorSetLayout operator()() const noexcept { return m_layout; }
inline VkDescriptorSetLayout Get() const noexcept { return m_layout; }
inline const std::vector<std::pair<int, VkDescriptorType>>& GetBindings() const noexcept { return m_bindings; }
~DescriptorSetLayout() = default;

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 01:00:13 by maldavid #+# #+# */
/* Updated: 2024/03/28 22:13:23 by maldavid ### ########.fr */
/* Updated: 2024/04/23 22:08:02 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -27,11 +27,11 @@ namespace mlx
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(class Renderer& renderer) override
{
if(!texture->IsInit())
return;
texture->Render(sets, renderer, x, y);
texture->Render(renderer, x, y);
}
inline void ResetUpdate() override
{

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* TextureManager.h :+: :+: :+: */
/* TextureRegistry.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 00:56:15 by maldavid #+# #+# */
/* Updated: 2024/04/03 16:24:51 by maldavid ### ########.fr */
/* Updated: 2024/04/23 22:10:08 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,48 +17,23 @@
namespace mlx
{
class TextureManager
class TextureRegistry
{
public:
TextureManager() = default;
TextureRegistry() = default;
inline void Clear() { m_texture_descriptors.clear(); }
inline void Clear();
inline std::pair<NonOwningPtr<DrawableResource>, bool> RegisterTexture(NonOwningPtr<Texture> texture, int x, int y);
inline bool IsTextureKnown(NonOwningPtr<Texture> texture) noexcept;
inline void EraseTextures(NonOwningPtr<Texture> texture);
inline std::pair<NonOwningPtr<DrawableResource>, bool> RegisterTexture(NonOwningPtr<Texture> texture, int x, int y)
{
MLX_PROFILE_FUNCTION();
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(NonOwningPtr<Texture> texture) noexcept
{
MLX_PROFILE_FUNCTION();
for(const auto& desc : m_texture_descriptors)
{
if(desc.texture == texture)
return true;
}
return false;
}
inline void EraseTextures(NonOwningPtr<Texture> texture)
{
MLX_PROFILE_FUNCTION();
for(auto it = m_texture_descriptors.begin(); it != m_texture_descriptors.end();)
{
if(it->texture == texture)
it = m_texture_descriptors.erase(it);
else
++it;
}
}
~TextureManager() = default;
~TextureRegistry() = default;
private:
std::unordered_set<TextureRenderDescriptor> m_texture_descriptors;
};
}
#include <Renderer/Image/TextureRegistry.inl>
#endif

View File

@@ -0,0 +1,52 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* TextureRegistry.inl :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/23 22:08:46 by maldavid #+# #+# */
/* Updated: 2024/04/23 22:11:09 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include <Renderer/Images/TextureRegistry.h>
namespace mlx
{
void TextureRegistry::Clear()
{
m_texture_descriptors.clear();
}
std::pair<NonOwningPtr<DrawableResource>, bool> TextureRegistry::RegisterTexture(NonOwningPtr<Texture> texture, int x, int y)
{
MLX_PROFILE_FUNCTION();
auto res = m_texture_descriptors.emplace(texture, x, y);
return std::make_pair(static_cast<DrawableResource*>(&const_cast<TextureRenderDescriptor&>(*res.first)), res.second);
}
bool TextureRegistry::IsTextureKnown(NonOwningPtr<Texture> texture) noexcept
{
MLX_PROFILE_FUNCTION();
for(const auto& desc : m_texture_descriptors)
{
if(desc.texture == texture)
return true;
}
return false;
}
void TextureRegistry::EraseTextures(NonOwningPtr<Texture> texture)
{
MLX_PROFILE_FUNCTION();
for(auto it = m_texture_descriptors.begin(); it != m_texture_descriptors.end();)
{
if(it->texture == texture)
it = m_texture_descriptors.erase(it);
else
++it;
}
}
}

View File

@@ -6,13 +6,14 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 17:14:45 by maldavid #+# #+# */
/* Updated: 2024/03/28 22:36:05 by maldavid ### ########.fr */
/* Updated: 2024/04/23 22:25:13 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __RENDERER__
#define __RENDERER__
#include <Renderer/Vertex.h>
#include <Renderer/Buffers/UniformBuffer.h>
#include <Renderer/Core/Surface.h>
#include <Renderer/Core/RenderCore.h>
@@ -28,47 +29,6 @@
namespace mlx
{
struct Vertex
{
glm::vec2 pos;
glm::vec4 color;
glm::vec2 uv;
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()
{
VkVertexInputBindingDescription binding_description{};
binding_description.binding = 0;
binding_description.stride = sizeof(Vertex);
binding_description.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
return binding_description;
}
static std::array<VkVertexInputAttributeDescription, 3> GetAttributeDescriptions()
{
std::array<VkVertexInputAttributeDescription, 3> attribute_descriptions;
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);
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);
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 attribute_descriptions;
}
};
class Renderer
{
public:
@@ -96,8 +56,6 @@ namespace mlx
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; }
@@ -117,9 +75,6 @@ namespace mlx
std::array<Semaphore, MAX_FRAMES_IN_FLIGHT> m_semaphores;
std::vector<FrameBuffer> m_framebuffers;
DescriptorSetLayout m_vert_layout;
DescriptorSetLayout m_frag_layout;
DescriptorSet m_vert_set;
DescriptorSet m_frag_set;

60
runtime/Includes/Renderer/Vertex.h git.filemode.normal_file
View File

@@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Vertex.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/23 22:24:33 by maldavid #+# #+# */
/* Updated: 2024/04/23 22:25:01 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_RENDERER_VERTEX__
#define __MLX_RENDERER_VERTEX__
namespace mlx
{
struct Vertex
{
glm::vec2 pos;
glm::vec4 color;
glm::vec2 uv;
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()
{
VkVertexInputBindingDescription binding_description{};
binding_description.binding = 0;
binding_description.stride = sizeof(Vertex);
binding_description.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
return binding_description;
}
static std::array<VkVertexInputAttributeDescription, 3> GetAttributeDescriptions()
{
std::array<VkVertexInputAttributeDescription, 3> attribute_descriptions;
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);
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);
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 attribute_descriptions;
}
};
}
#endif