summaryrefslogtreecommitdiffstats
path: root/src/RenderConfigs.hpp
blob: da7fd962a54d7af4a0e4aa6bec689ac37cdf8073 (plain) (blame)
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
#pragma once

#include "Gal.hpp"

struct GlobalShaderParameters {
    glm::mat4 projView;
    glm::uvec2 viewportSize;
    float globalTime;
    float dayTime;
};

std::shared_ptr<Gal::Shader> LoadVertexShader(std::string_view assetPath);

std::shared_ptr<Gal::Shader> LoadPixelShader(std::string_view assetPath);

class PostProcess {
    std::shared_ptr<Gal::Framebuffer> framebuffer;
    std::shared_ptr<Gal::Buffer> fbBuffer;
    std::shared_ptr<Gal::Pipeline> pipeline;
    std::shared_ptr<Gal::PipelineInstance> pipelineInstance;
    std::shared_ptr<Gal::Texture> result;
public:

    PostProcess(
        std::shared_ptr<Gal::Shader> pixelShader,
        std::vector<std::pair<std::string_view, std::shared_ptr<Gal::Texture>>> inputTextures,
        std::vector<std::pair<std::string_view, Gal::Type>> inputParameters,
        size_t width,
        size_t height,
        Gal::Format format,
        Gal::Filtering filtering);

    void Clear() {
        framebuffer->Clear();
    }

    void Render() {
        pipeline->Activate();
        pipelineInstance->Activate();
        pipelineInstance->Render(0, 6);
    }

    template<typename T>
    void SetShaderParameter(std::string_view name, T value) {
        pipeline->SetShaderParameter(name, value);
    }

    std::shared_ptr<Gal::Texture> GetResultTexture() {
        return result;
    }
};

class Gbuffer {
    std::unique_ptr<PostProcess> lightingPass;
    std::shared_ptr<Gal::Texture> color; //RGB - color
    std::shared_ptr<Gal::Texture> normal; //RGB - normal
    std::shared_ptr<Gal::Texture> addColor; //RGB - addColor
    std::shared_ptr<Gal::Texture> light; //R - faceLight, G - skyLight, B - unused
    std::shared_ptr<Gal::Texture> depthStencil;
    std::shared_ptr<Gal::Framebuffer> geomFramebuffer;

public:
    Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH);

    std::shared_ptr<Gal::Framebuffer> GetGeometryTarget() {
        return geomFramebuffer;
    }

    std::shared_ptr<Gal::Texture> GetFinalTexture() {
        return lightingPass->GetResultTexture();
    }

    void Render() {
        lightingPass->Render();
    }

    void Clear() {
        geomFramebuffer->Clear();
        lightingPass->Clear();
    }

    int GetMaxRenderBuffers() {
        return 5;
    }

    void SetRenderBuff(int renderBuff) {
        lightingPass->SetShaderParameter("renderBuff", renderBuff);
    }
};