From 0d8b874c0048ca088bb9e353a5f7c62e1f8cd0e8 Mon Sep 17 00:00:00 2001 From: hachem Date: Thu, 14 Aug 2025 00:42:05 +0200 Subject: feat: custom memory managers and fix includes --- src/rendering/renderer.cpp | 13 ++++++------- src/rendering/renderer.h | 14 +++++++------- src/rendering/shader.cpp | 16 ++++++++-------- src/rendering/shader.h | 15 ++++++++------- src/rendering/texture.cpp | 17 +++++++++-------- src/rendering/texture.h | 7 ++++--- src/rendering/vertex_array.cpp | 1 + src/rendering/vertex_array.h | 12 +++++++----- src/rendering/vertex_buffer.cpp | 1 + 9 files changed, 51 insertions(+), 45 deletions(-) (limited to 'src/rendering') diff --git a/src/rendering/renderer.cpp b/src/rendering/renderer.cpp index 46dd690..5e4682c 100644 --- a/src/rendering/renderer.cpp +++ b/src/rendering/renderer.cpp @@ -3,19 +3,18 @@ #include "platform/opengl/opengl_renderer_api.h" #include "platform/vulkan/vulkan_renderer_api.h" -#include #include namespace Donut { - std::unique_ptr RendererAPI::create() + Scope RendererAPI::create() { switch (s_api) { case API::OpenGL: - return std::make_unique(); + return create_scope(); case API::Vulkan: - return std::make_unique(); + return create_scope(); default: return nullptr; } @@ -38,8 +37,8 @@ namespace Donut RenderCommand::set_viewport(0, 0, width, height); } - void Renderer::submit(const std::shared_ptr& shader, - const std::shared_ptr& vertex_array, + void Renderer::submit(const Ref& shader, + const Ref& vertex_array, const glm::mat4& transform, const glm::mat4& view_projection) { @@ -51,7 +50,7 @@ namespace Donut RenderCommand::draw_indexed(vertex_array); } - std::unique_ptr RenderCommand::s_renderer_api = RendererAPI::create(); + Scope RenderCommand::s_renderer_api = RendererAPI::create(); void Renderer::set_clear_color(const glm::vec4& color) { diff --git a/src/rendering/renderer.h b/src/rendering/renderer.h index dd4c259..6212b21 100644 --- a/src/rendering/renderer.h +++ b/src/rendering/renderer.h @@ -1,10 +1,10 @@ #pragma once +#include "core/memory.h" #include "vertex_array.h" #include "shader.h" #include -#include namespace Donut { @@ -28,12 +28,12 @@ namespace Donut virtual void enable_depth_test() = 0; virtual void set_face_culling(bool enabled) = 0; - virtual void draw_indexed(const std::shared_ptr& vertex_array, + virtual void draw_indexed(const Ref& vertex_array, uint32_t index_count = 0) = 0; inline static API get_api() { return s_api; } inline static void set_api(API api) { s_api = api; } - static std::unique_ptr create(); + static Scope create(); private: static API s_api; }; @@ -71,13 +71,13 @@ namespace Donut s_renderer_api->set_face_culling(enabled); } - inline static void draw_indexed(const std::shared_ptr& vertex_array, uint32_t index_count = 0) + inline static void draw_indexed(const Ref& vertex_array, uint32_t index_count = 0) { s_renderer_api->draw_indexed(vertex_array, index_count); } private: - static std::unique_ptr s_renderer_api; + static Scope s_renderer_api; }; class Renderer @@ -88,8 +88,8 @@ namespace Donut static void on_window_resize(uint32_t width, uint32_t height); - static void submit(const std::shared_ptr& shader, - const std::shared_ptr& vertex_array, + static void submit(const Ref& shader, + const Ref& vertex_array, const glm::mat4& transform, const glm::mat4& view_projection); diff --git a/src/rendering/shader.cpp b/src/rendering/shader.cpp index 1e84125..1bbd0fc 100644 --- a/src/rendering/shader.cpp +++ b/src/rendering/shader.cpp @@ -1,8 +1,8 @@ #include "shader.h" #include "renderer.h" + #include "platform/opengl/opengl_shader.h" #include "platform/vulkan/vulkan_shader.h" -#include namespace Donut { @@ -45,32 +45,32 @@ namespace Donut } } - void ShaderLibrary::add(const std::shared_ptr& shader) + void ShaderLibrary::add(const Ref& shader) { auto& name = shader->get_name(); add(name, shader); } - void ShaderLibrary::add(const std::string& name, const std::shared_ptr& shader) + void ShaderLibrary::add(const std::string& name, const Ref& shader) { m_shaders[name] = shader; } - std::shared_ptr ShaderLibrary::load(const std::string& filepath) + Ref ShaderLibrary::load(const std::string& filepath) { - auto shader = std::shared_ptr(Shader::create(filepath)); + auto shader = Ref(Shader::create(filepath)); add(shader); return shader; } - std::shared_ptr ShaderLibrary::load(const std::string& name, const std::string& filepath) + Ref ShaderLibrary::load(const std::string& name, const std::string& filepath) { - auto shader = std::shared_ptr(Shader::create(filepath)); + auto shader = Ref(Shader::create(filepath)); add(name, shader); return shader; } - std::shared_ptr ShaderLibrary::get(const std::string& name) + Ref ShaderLibrary::get(const std::string& name) { if (exists(name)) return m_shaders[name]; diff --git a/src/rendering/shader.h b/src/rendering/shader.h index f490f3c..814f0cf 100644 --- a/src/rendering/shader.h +++ b/src/rendering/shader.h @@ -1,8 +1,9 @@ #pragma once +#include "core/memory.h" + #include #include -#include #include #define SHADER_STORAGE_BARRIER_BIT 0x00002000 @@ -42,15 +43,15 @@ namespace Donut class ShaderLibrary { public: - void add(const std::shared_ptr& shader); - void add(const std::string& name, const std::shared_ptr& shader); - std::shared_ptr load(const std::string& filepath); - std::shared_ptr load(const std::string& name, const std::string& filepath); + void add(const Ref& shader); + void add(const std::string& name, const Ref& shader); + Ref load(const std::string& filepath); + Ref load(const std::string& name, const std::string& filepath); - std::shared_ptr get(const std::string& name); + Ref get(const std::string& name); bool exists(const std::string& name) const; private: - std::unordered_map> m_shaders; + std::unordered_map> m_shaders; }; }; diff --git a/src/rendering/texture.cpp b/src/rendering/texture.cpp index 36189a3..e14c09c 100644 --- a/src/rendering/texture.cpp +++ b/src/rendering/texture.cpp @@ -1,18 +1,19 @@ #include "texture.h" #include "renderer.h" -#include "../platform/opengl/opengl_texture.h" -#include "../platform/vulkan/vulkan_texture.h" + +#include "platform/opengl/opengl_texture.h" +#include "platform/vulkan/vulkan_texture.h" namespace Donut { - std::shared_ptr Texture2D::create(uint32_t width, uint32_t height) + Ref Texture2D::create(uint32_t width, uint32_t height) { switch (Renderer::get_api()) { case RendererAPI::API::OpenGL: - return std::make_shared(width, height); + return create_ref(width, height); case RendererAPI::API::Vulkan: - return std::make_shared(width, height); + return create_ref(width, height); case RendererAPI::API::None: return nullptr; default: @@ -20,14 +21,14 @@ namespace Donut } } - std::shared_ptr Texture2D::create(const std::string& path) + Ref Texture2D::create(const std::string& path) { switch (Renderer::get_api()) { case RendererAPI::API::OpenGL: - return std::make_shared(path); + return create_ref(path); case RendererAPI::API::Vulkan: - return std::make_shared(path); + return create_ref(path); case RendererAPI::API::None: return nullptr; default: diff --git a/src/rendering/texture.h b/src/rendering/texture.h index e9f369f..cc5c59e 100644 --- a/src/rendering/texture.h +++ b/src/rendering/texture.h @@ -1,6 +1,7 @@ #pragma once -#include +#include "core/memory.h" + #include #include @@ -27,7 +28,7 @@ namespace Donut : public Texture { public: - static std::shared_ptr create(uint32_t width, uint32_t height); - static std::shared_ptr create(const std::string& path); + static Ref create(uint32_t width, uint32_t height); + static Ref create(const std::string& path); }; }; diff --git a/src/rendering/vertex_array.cpp b/src/rendering/vertex_array.cpp index 8057a3e..bb92ff3 100644 --- a/src/rendering/vertex_array.cpp +++ b/src/rendering/vertex_array.cpp @@ -1,5 +1,6 @@ #include "vertex_array.h" #include "renderer.h" + #include "platform/opengl/opengl_vertex_array.h" #include "platform/vulkan/vulkan_vertex_array.h" diff --git a/src/rendering/vertex_array.h b/src/rendering/vertex_array.h index 946f273..a39849f 100644 --- a/src/rendering/vertex_array.h +++ b/src/rendering/vertex_array.h @@ -1,8 +1,10 @@ #pragma once +#include "core/memory.h" + #include "vertex_buffer.h" #include "index_buffer.h" -#include + #include namespace Donut @@ -15,11 +17,11 @@ namespace Donut virtual void bind() const = 0; virtual void unbind() const = 0; - virtual void add_vertex_buffer(const std::shared_ptr& vertex_buffer) = 0; - virtual void set_index_buffer(const std::shared_ptr& index_buffer) = 0; + virtual void add_vertex_buffer(const Ref& vertex_buffer) = 0; + virtual void set_index_buffer(const Ref& index_buffer) = 0; - virtual const std::vector>& get_vertex_buffers() const = 0; - virtual const std::shared_ptr& get_index_buffer() const = 0; + virtual const std::vector>& get_vertex_buffers() const = 0; + virtual const Ref& get_index_buffer() const = 0; static VertexArray* create(); }; diff --git a/src/rendering/vertex_buffer.cpp b/src/rendering/vertex_buffer.cpp index 32ae10a..4929711 100644 --- a/src/rendering/vertex_buffer.cpp +++ b/src/rendering/vertex_buffer.cpp @@ -1,5 +1,6 @@ #include "vertex_buffer.h" #include "renderer.h" + #include "platform/opengl/opengl_vertex_buffer.h" #include "platform/vulkan/vulkan_vertex_buffer.h" -- cgit v1.3