Renderer.hpp 2.19 KB
Newer Older
Shu's avatar
Shu committed
1
2
3
4
5
#pragma once
#include "../Renderer.hpp"
#include "forward.hpp"

namespace render::vk {
Shu's avatar
Shu committed
6
class Allocator;
Shu's avatar
Shu committed
7
8
class SwapChain;
class Pipeline;
Shu's avatar
Shu committed
9
class CommandCenter;
Shu's avatar
Shu committed
10
11
12
13
14
15

/// Vulkan rendering
class Renderer final: public render::Renderer {
public:
    virtual ~Renderer();

Shu's avatar
Shu committed
16
    static bool Load(Window& window, const renderOptions& options, int samples);
Shu's avatar
Shu committed
17
18
19
20
21
22

    void loadUI(Window &) override;

    static _FORCE_INLINE_ Renderer *Get() { return static_cast<Renderer*>(render::Renderer::Get()); }

    void beginFrame() override;
23
    std::function<size_t(render::LodModel *const, glm::mat4, glm::vec4, float)> beginWorldPass() override;
Shu's avatar
Shu committed
24
    std::function<size_t(render::Model *const, const std::vector<glm::mat4> &)> beginEntityPass() override;
Shu's avatar
Shu committed
25
    std::function<size_t(glm::mat4)> beginIndicatorPass() override;
26
27
28
    void postProcess() override;
    void endFrame() override;
    void swapBuffer(Window &) override;
Shu's avatar
Shu committed
29
30
31
32
33
34
35
36

    void setClearColor(glm::vec4) override;

    /// Apply camera matrices
    void lookFrom(const Camera &) override;
    void reloadShaders(const passOptions &) override;
    void reloadTextures(const std::string &, float mipMapLOD, float anisotropy) override;

Shu's avatar
Shu committed
37
38
    Allocator* getAllocator() const { return allocator.get(); }

Shu's avatar
Shu committed
39
40
41
42
43
    void setResized() { framebufferResized = true; }

private:
    Renderer(VkInstance, VkDevice, const PhysicalDeviceInfo &, const renderOptions &);

Shu's avatar
Shu committed
44
45
    const PhysicalDeviceInfo &getInfos() const { return *physicalInfo.get(); }

Shu's avatar
Shu committed
46
47
48
    renderOptions options;

    VkInstance instance;
Shu's avatar
Shu committed
49
    VkDebugUtilsMessengerEXT debugMessenger;
Shu's avatar
Shu committed
50
51
52
53
    VkSurfaceKHR surface;
    VkDevice device;

    std::unique_ptr<PhysicalDeviceInfo> physicalInfo;
Shu's avatar
Shu committed
54
    std::unique_ptr<Allocator> allocator;
Shu's avatar
Shu committed
55
56
    std::unique_ptr<SwapChain> swapChain;
    std::unique_ptr<Pipeline> pipeline;
Shu's avatar
Shu committed
57
    std::unique_ptr<CommandCenter> commandCenter;
Shu's avatar
Shu committed
58
59
60
61
62
63
64
65
66
67

    size_t currentFrame = 0;
    uint32_t currentImage = UINT32_MAX;
    std::vector<VkSemaphore> imageAvailableSemaphores;
    std::vector<VkSemaphore> renderFinishedSemaphores;
    std::vector<VkFence> inFlightFences;

    bool framebufferResized = false;
    void recreateSwapChain();
    void destroySwapChain();
68
69
70
71

    glm::mat4 ProjectionMatrix;
    glm::mat4 ViewMatrix;
    float FogDepth;
Shu's avatar
Shu committed
72
73
};
}