aboutsummaryrefslogtreecommitdiff
path: root/src/Rendering/Renderer.h
blob: 61dae82f1a3a360c26557b10d508db3062ab48a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#pragma once

#include "VertexArray.h"
#include "Shader.h"

#include <glm/glm.hpp>
#include <memory>

namespace Donut
{
    class RendererAPI 
    {
    public:
        enum class API 
        {
            None   = 0, 
            OpenGL = 1,
            Vulkan = 2,
        };
    public:
        virtual ~RendererAPI() = default;

        virtual void Init()                                       = 0;
        virtual void SetViewport(uint32_t x, uint32_t y, 
                                 uint32_t width, uint32_t height) = 0;
        virtual void SetClearColor(const glm::vec4& color)        = 0;
        virtual void Clear()                                      = 0;
        virtual void EnableDepthTest()                            = 0;
        virtual void SetFaceCulling(bool enabled)                 = 0;

        virtual void DrawIndexed(const std::shared_ptr<VertexArray>& vertexArray, 
                                 uint32_t indexCount = 0)         = 0;

        inline static API GetAPI()         { return s_API; }
        inline static void SetAPI(API api) { s_API = api;  }
        static std::unique_ptr<RendererAPI> Create();
    private:
        static API s_API;
    };

    class RenderCommand 
    {
    public:
        inline static void Init() 
        {
            s_RendererAPI->Init();
        }

        inline static void SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height)
        {
            s_RendererAPI->SetViewport(x, y, width, height);
        }

        inline static void SetClearColor(const glm::vec4& color)
        {
            s_RendererAPI->SetClearColor(color);
        }

        inline static void Clear()
        {
            s_RendererAPI->Clear();
        }

        inline static void EnableDepthTest()
        {
            s_RendererAPI->EnableDepthTest();
        }

        inline static void SetFaceCulling(bool enabled)
        {
            s_RendererAPI->SetFaceCulling(enabled);
        }

        inline static void DrawIndexed(const std::shared_ptr<VertexArray>& vertexArray, uint32_t indexCount = 0)
        {
            s_RendererAPI->DrawIndexed(vertexArray, indexCount);
        }

    private:
        static std::unique_ptr<RendererAPI> s_RendererAPI;
    };

    class Renderer 
    {
    public:
        static void Init();
        static void Shutdown();

        static void OnWindowResize(uint32_t width, uint32_t height);

        static void Submit(const std::shared_ptr<Shader>& shader, 
                           const std::shared_ptr<VertexArray>& vertexArray,
                           const glm::mat4& transform,
                           const glm::mat4& viewProjection);

        static void SetClearColor(const glm::vec4& color);
        static void Clear();

        inline static RendererAPI::API GetAPI() { return RendererAPI::GetAPI(); }
    };
};