adding graphics support class, refactoring the code

This commit is contained in:
2023-04-02 17:37:38 +02:00
parent 7eea6ea1d5
commit aaf7e861d5
14 changed files with 318 additions and 148 deletions

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/31 18:03:35 by maldavid #+# #+# */
/* Updated: 2023/04/01 15:39:59 by maldavid ### ########.fr */
/* Updated: 2023/04/02 15:47:49 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -55,9 +55,9 @@ namespace mlx
void Texture::render(Renderer& renderer, int x, int y)
{
auto cmd = renderer.getActiveCmdBuffer().get();
_vbo.bind(renderer);
_ibo.bind(renderer);
auto cmd = renderer.getActiveCmdBuffer().get();
glm::vec2 translate(x, y);
vkCmdPushConstants(cmd, renderer.getPipeline().getPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(translate), &translate);
vkCmdDrawIndexed(cmd, static_cast<uint32_t>(_ibo.getSize() / sizeof(uint16_t)), 1, 0, 0, 0);
@@ -70,7 +70,7 @@ namespace mlx
_ibo.destroy();
}
Texture stb_texture_load(std::filesystem::path file, int* w, int* h)
Texture stbTextureLoad(std::filesystem::path file, int* w, int* h)
{
Texture texture;
int channels;

View File

@@ -6,7 +6,7 @@
/* By: maldavid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */
/* Updated: 2023/04/01 15:31:26 by maldavid ### ########.fr */
/* Updated: 2023/04/02 17:33:26 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,6 +14,8 @@
#define __MLX_TEXTURE__
#include <filesystem>
#include <memory>
#include <functional>
#include <renderer/images/vk_image.h>
#include <renderer/descriptors/vk_descriptor_set.h>
#include <renderer/buffers/vk_ibo.h>
@@ -32,7 +34,9 @@ namespace mlx
inline void setDescriptor(DescriptorSet set) noexcept { _set = std::move(set); }
inline VkDescriptorSet getSet() noexcept { return _set.isInit() ? _set.get() : VK_NULL_HANDLE; }
inline void updateSet(int binding) noexcept { _set.writeDescriptor(binding, getImageView(), getSampler());}
inline void updateSet(int binding) noexcept { _set.writeDescriptor(binding, getImageView(), getSampler()); _has_been_updated = true; }
inline bool hasBeenUpdated() const noexcept { return _has_been_updated; }
inline constexpr void resetUpdate() noexcept { _has_been_updated = false; }
~Texture() = default;
@@ -40,9 +44,32 @@ namespace mlx
C_VBO _vbo;
C_IBO _ibo;
DescriptorSet _set;
bool _has_been_updated = false;
};
Texture stb_texture_load(std::filesystem::path file, int* w, int* h);
Texture stbTextureLoad(std::filesystem::path file, int* w, int* h);
struct TextureRenderData
{
std::shared_ptr<Texture> texture;
int x;
int y;
TextureRenderData(std::shared_ptr<Texture> _texture, int _x, int _y) : texture(_texture), x(_x), y(_y) {}
bool operator==(const TextureRenderData& rhs) const { return texture == rhs.texture && x == rhs.x && y == rhs.y; }
};
}
namespace std
{
template <>
struct hash<mlx::TextureRenderData>
{
size_t operator()(const mlx::TextureRenderData& td) const noexcept
{
return std::hash<std::shared_ptr<mlx::Texture>>()(td.texture) + std::hash<int>()(td.x) + std::hash<int>()(td.y);
}
};
}
#endif

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 17:25:16 by maldavid #+# #+# */
/* Updated: 2023/04/01 17:50:28 by maldavid ### ########.fr */
/* Updated: 2023/04/02 15:24:40 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -153,7 +153,6 @@ namespace mlx
for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
_cmd_buffers[i].destroy();
_pixel_put_pipeline.destroy();
_pipeline.destroy();
_uniform_buffer->destroy();
_vert_layout.destroy();

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 17:14:45 by maldavid #+# #+# */
/* Updated: 2023/04/01 15:37:40 by maldavid ### ########.fr */
/* Updated: 2023/04/02 15:26:59 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -104,7 +104,6 @@ namespace mlx
inline DescriptorSet& getFragDescriptorSet() noexcept { return _frag_set; }
inline DescriptorSetLayout& getVertDescriptorSetLayout() noexcept { return _vert_layout; }
inline DescriptorSetLayout& getFragDescriptorSetLayout() noexcept { return _frag_layout; }
inline PixelPutPipeline& getPixelPutPipeline() noexcept { return _pixel_put_pipeline; }
inline uint32_t getActiveImageIndex() noexcept { return _active_image_index; }
inline uint32_t getImageIndex() noexcept { return _image_index; }
@@ -113,7 +112,6 @@ namespace mlx
~Renderer() = default;
private:
PixelPutPipeline _pixel_put_pipeline;
GraphicPipeline _pipeline;
RenderPass _pass;
Surface _surface;
@@ -130,7 +128,7 @@ namespace mlx
DescriptorSet _frag_set;
std::array<CmdBuffer, MAX_FRAMES_IN_FLIGHT> _cmd_buffers;
std::unique_ptr<UBO> _uniform_buffer = nullptr;
std::unique_ptr<UBO> _uniform_buffer;
class MLX_Window* _window = nullptr;