diff options
| author | hachem <im@hachem.wtf> | 2025-08-14 00:42:05 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2025-08-14 00:42:05 +0200 |
| commit | 0d8b874c0048ca088bb9e353a5f7c62e1f8cd0e8 (patch) | |
| tree | 2c0f3b13161489e4e91994882f8f2ed67a20bc0e /src/rendering | |
| parent | 9671d5e54484b8bce261207d08ff15053ae24e48 (diff) | |
feat: custom memory managers and fix includes
Diffstat (limited to 'src/rendering')
| -rw-r--r-- | src/rendering/renderer.cpp | 13 | ||||
| -rw-r--r-- | src/rendering/renderer.h | 14 | ||||
| -rw-r--r-- | src/rendering/shader.cpp | 16 | ||||
| -rw-r--r-- | src/rendering/shader.h | 15 | ||||
| -rw-r--r-- | src/rendering/texture.cpp | 17 | ||||
| -rw-r--r-- | src/rendering/texture.h | 7 | ||||
| -rw-r--r-- | src/rendering/vertex_array.cpp | 1 | ||||
| -rw-r--r-- | src/rendering/vertex_array.h | 12 | ||||
| -rw-r--r-- | src/rendering/vertex_buffer.cpp | 1 |
9 files changed, 51 insertions, 45 deletions
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 <memory> #include <glm/gtc/matrix_transform.hpp> namespace Donut { - std::unique_ptr<RendererAPI> RendererAPI::create() + Scope<RendererAPI> RendererAPI::create() { switch (s_api) { case API::OpenGL: - return std::make_unique<OpenGLRendererAPI>(); + return create_scope<OpenGLRendererAPI>(); case API::Vulkan: - return std::make_unique<VulkanRendererAPI>(); + return create_scope<VulkanRendererAPI>(); default: return nullptr; } @@ -38,8 +37,8 @@ namespace Donut RenderCommand::set_viewport(0, 0, width, height); } - void Renderer::submit(const std::shared_ptr<Shader>& shader, - const std::shared_ptr<VertexArray>& vertex_array, + void Renderer::submit(const Ref<Shader>& shader, + const Ref<VertexArray>& 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<RendererAPI> RenderCommand::s_renderer_api = RendererAPI::create(); + Scope<RendererAPI> 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 <glm/glm.hpp> -#include <memory> 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<VertexArray>& vertex_array, + virtual void draw_indexed(const Ref<VertexArray>& 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<RendererAPI> create(); + static Scope<RendererAPI> 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<VertexArray>& vertex_array, uint32_t index_count = 0) + inline static void draw_indexed(const Ref<VertexArray>& vertex_array, uint32_t index_count = 0) { s_renderer_api->draw_indexed(vertex_array, index_count); } private: - static std::unique_ptr<RendererAPI> s_renderer_api; + static Scope<RendererAPI> 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>& shader, - const std::shared_ptr<VertexArray>& vertex_array, + static void submit(const Ref<Shader>& shader, + const Ref<VertexArray>& 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 <memory> namespace Donut { @@ -45,32 +45,32 @@ namespace Donut } } - void ShaderLibrary::add(const std::shared_ptr<Shader>& shader) + void ShaderLibrary::add(const Ref<Shader>& shader) { auto& name = shader->get_name(); add(name, shader); } - void ShaderLibrary::add(const std::string& name, const std::shared_ptr<Shader>& shader) + void ShaderLibrary::add(const std::string& name, const Ref<Shader>& shader) { m_shaders[name] = shader; } - std::shared_ptr<Shader> ShaderLibrary::load(const std::string& filepath) + Ref<Shader> ShaderLibrary::load(const std::string& filepath) { - auto shader = std::shared_ptr<Shader>(Shader::create(filepath)); + auto shader = Ref<Shader>(Shader::create(filepath)); add(shader); return shader; } - std::shared_ptr<Shader> ShaderLibrary::load(const std::string& name, const std::string& filepath) + Ref<Shader> ShaderLibrary::load(const std::string& name, const std::string& filepath) { - auto shader = std::shared_ptr<Shader>(Shader::create(filepath)); + auto shader = Ref<Shader>(Shader::create(filepath)); add(name, shader); return shader; } - std::shared_ptr<Shader> ShaderLibrary::get(const std::string& name) + Ref<Shader> 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 <string> #include <unordered_map> -#include <memory> #include <glm/glm.hpp> #define SHADER_STORAGE_BARRIER_BIT 0x00002000 @@ -42,15 +43,15 @@ namespace Donut class ShaderLibrary { public: - void add(const std::shared_ptr<Shader>& shader); - void add(const std::string& name, const std::shared_ptr<Shader>& shader); - std::shared_ptr<Shader> load(const std::string& filepath); - std::shared_ptr<Shader> load(const std::string& name, const std::string& filepath); + void add(const Ref<Shader>& shader); + void add(const std::string& name, const Ref<Shader>& shader); + Ref<Shader> load(const std::string& filepath); + Ref<Shader> load(const std::string& name, const std::string& filepath); - std::shared_ptr<Shader> get(const std::string& name); + Ref<Shader> get(const std::string& name); bool exists(const std::string& name) const; private: - std::unordered_map<std::string, std::shared_ptr<Shader>> m_shaders; + std::unordered_map<std::string, Ref<Shader>> 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> Texture2D::create(uint32_t width, uint32_t height) + Ref<Texture2D> Texture2D::create(uint32_t width, uint32_t height) { switch (Renderer::get_api()) { case RendererAPI::API::OpenGL: - return std::make_shared<OpenGLTexture2D>(width, height); + return create_ref<OpenGLTexture2D>(width, height); case RendererAPI::API::Vulkan: - return std::make_shared<VulkanTexture2D>(width, height); + return create_ref<VulkanTexture2D>(width, height); case RendererAPI::API::None: return nullptr; default: @@ -20,14 +21,14 @@ namespace Donut } } - std::shared_ptr<Texture2D> Texture2D::create(const std::string& path) + Ref<Texture2D> Texture2D::create(const std::string& path) { switch (Renderer::get_api()) { case RendererAPI::API::OpenGL: - return std::make_shared<OpenGLTexture2D>(path); + return create_ref<OpenGLTexture2D>(path); case RendererAPI::API::Vulkan: - return std::make_shared<VulkanTexture2D>(path); + return create_ref<VulkanTexture2D>(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 <memory> +#include "core/memory.h" + #include <string> #include <glm/glm.hpp> @@ -27,7 +28,7 @@ namespace Donut : public Texture { public: - static std::shared_ptr<Texture2D> create(uint32_t width, uint32_t height); - static std::shared_ptr<Texture2D> create(const std::string& path); + static Ref<Texture2D> create(uint32_t width, uint32_t height); + static Ref<Texture2D> 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 <memory> + #include <vector> 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<VertexBuffer>& vertex_buffer) = 0; - virtual void set_index_buffer(const std::shared_ptr<IndexBuffer>& index_buffer) = 0; + virtual void add_vertex_buffer(const Ref<VertexBuffer>& vertex_buffer) = 0; + virtual void set_index_buffer(const Ref<IndexBuffer>& index_buffer) = 0; - virtual const std::vector<std::shared_ptr<VertexBuffer>>& get_vertex_buffers() const = 0; - virtual const std::shared_ptr<IndexBuffer>& get_index_buffer() const = 0; + virtual const std::vector<Ref<VertexBuffer>>& get_vertex_buffers() const = 0; + virtual const Ref<IndexBuffer>& 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" |
