hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src/rendering/renderer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/rendering/renderer.h')
-rw-r--r--src/rendering/renderer.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/rendering/renderer.h b/src/rendering/renderer.h
new file mode 100644
index 0000000..fd61914
--- /dev/null
+++ b/src/rendering/renderer.h
@@ -0,0 +1,100 @@
+#pragma once
+
+#include "vertex_array.h"
+#include "shader.h"
+#include <glm/glm.hpp>
+#include <memory>
+
+namespace Donut
+{
+ template<typename T>
+ using Scope = std::unique_ptr<T>;
+
+ template<typename T, typename ... Args>
+ constexpr Scope<T> create_scope(Args&& ... args)
+ {
+ return std::make_unique<T>(std::forward<Args>(args)...);
+ }
+
+ class RendererAPI
+ {
+ public:
+ enum class API
+ {
+ None = 0,
+ OpenGL = 1,
+ Vulkan = 2,
+ };
+
+ public:
+ virtual ~RendererAPI() = default;
+
+ virtual void init() = 0;
+ virtual void set_viewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) = 0;
+ virtual void set_clear_color(const glm::vec4& color) = 0;
+ virtual void clear() = 0;
+
+ virtual void draw_indexed(const std::shared_ptr<VertexArray>& vertex_array, uint32_t index_count = 0) = 0;
+
+ inline static API get_api() { return s_api; }
+ static Scope<RendererAPI> create();
+
+ private:
+ static API s_api;
+ };
+
+ class RenderCommand
+ {
+ public:
+ inline static void init() {
+ s_renderer_api->init();
+ }
+
+ inline static void set_viewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) {
+ s_renderer_api->set_viewport(x, y, width, height);
+ }
+
+ inline static void set_clear_color(const glm::vec4& color) {
+ s_renderer_api->set_clear_color(color);
+ }
+
+ inline static void clear() {
+ s_renderer_api->clear();
+ }
+
+ inline static void draw_indexed(const std::shared_ptr<VertexArray>& vertex_array, uint32_t index_count = 0) {
+ s_renderer_api->draw_indexed(vertex_array, index_count);
+ }
+
+ private:
+ static Scope<RendererAPI> s_renderer_api;
+ };
+
+ class Renderer
+ {
+ public:
+ static void init();
+ static void shutdown();
+
+ static void on_window_resize(uint32_t width, uint32_t height);
+
+ static void begin_scene();
+ static void end_scene();
+
+ static void submit(const std::shared_ptr<Shader>& shader,
+ const std::shared_ptr<VertexArray>& vertex_array,
+ const glm::mat4& transform = glm::mat4(1.0f));
+
+ static void set_clear_color(const glm::vec4& color);
+ static void clear();
+
+ inline static RendererAPI::API get_api() { return RendererAPI::get_api(); }
+ private:
+ struct SceneData
+ {
+ glm::mat4 ViewProjectionMatrix;
+ };
+
+ static SceneData* s_scene_data;
+ };
+};