mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 22:53:34 +00:00
working
This commit is contained in:
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user