From 9671d5e54484b8bce261207d08ff15053ae24e48 Mon Sep 17 00:00:00 2001 From: hachem Date: Thu, 14 Aug 2025 00:28:27 +0200 Subject: feat: ability to switch render API --- src/rendering/renderer.cpp | 6 ++++-- src/rendering/renderer.h | 17 +++++------------ 2 files changed, 9 insertions(+), 14 deletions(-) (limited to 'src/rendering') diff --git a/src/rendering/renderer.cpp b/src/rendering/renderer.cpp index 3343cce..46dd690 100644 --- a/src/rendering/renderer.cpp +++ b/src/rendering/renderer.cpp @@ -1,12 +1,14 @@ #include "renderer.h" + #include "platform/opengl/opengl_renderer_api.h" #include "platform/vulkan/vulkan_renderer_api.h" + #include #include namespace Donut { - Scope RendererAPI::create() + std::unique_ptr RendererAPI::create() { switch (s_api) { @@ -49,7 +51,7 @@ namespace Donut RenderCommand::draw_indexed(vertex_array); } - Scope RenderCommand::s_renderer_api = RendererAPI::create(); + std::unique_ptr 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 c7ace3c..dd4c259 100644 --- a/src/rendering/renderer.h +++ b/src/rendering/renderer.h @@ -2,20 +2,12 @@ #include "vertex_array.h" #include "shader.h" + #include #include namespace Donut { - template - using Scope = std::unique_ptr; - - template - constexpr Scope create_scope(Args&& ... args) - { - return std::make_unique(std::forward(args)...); - } - class RendererAPI { public: @@ -39,8 +31,9 @@ namespace Donut virtual void draw_indexed(const std::shared_ptr& vertex_array, uint32_t index_count = 0) = 0; - inline static API get_api() { return s_api; } - static Scope create(); + inline static API get_api() { return s_api; } + inline static void set_api(API api) { s_api = api; } + static std::unique_ptr create(); private: static API s_api; }; @@ -84,7 +77,7 @@ namespace Donut } private: - static Scope s_renderer_api; + static std::unique_ptr s_renderer_api; }; class Renderer -- cgit v1.3