aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Common/PostProcesser.h
blob: 966d58bc67f58e7cdc108469365700225ae197c6 (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
#pragma once

#include <d3d11.h>

class PostProcesser
{
public:
    static PostProcesser& GetInstance()
    {
        static PostProcesser instance;
        return instance;
    }

    void Init();
    void Apply() const;
    void SetViewport(const D3D11_VIEWPORT& viewport);
    void ResetViewport();
    void CopyBackbuffer(); // Copy backbuffer once before multi-pass gamma
    void ApplyFromCopied() const; // Apply gamma using already-copied offscreen texture
    void Cleanup();
    void SetGamma(float gamma);
    float GetGamma() const { return m_gamma; }
    PostProcesser(const PostProcesser&) = delete;
    PostProcesser& operator=(const PostProcesser&) = delete;

private:
    PostProcesser();
    ~PostProcesser();

    static bool IsRunningUnderWine();

    ID3D11Texture2D* m_pGammaOffscreenTex = nullptr;
    ID3D11ShaderResourceView* m_pGammaOffscreenSRV = nullptr;
    ID3D11RenderTargetView* m_pGammaOffscreenRTV = nullptr;
    ID3D11VertexShader* m_pGammaVS = nullptr;
    ID3D11PixelShader* m_pGammaPS = nullptr;
    ID3D11Buffer* m_pGammaCB = nullptr;
    ID3D11SamplerState* m_pGammaSampler = nullptr;
    ID3D11RasterizerState* m_pGammaRastState = nullptr;
    ID3D11DepthStencilState* m_pGammaDepthState = nullptr;
    ID3D11BlendState* m_pGammaBlendState = nullptr;

    bool m_initialized = false;
    float m_gamma = 1.0f;
    bool m_wineMode = false;
    D3D11_VIEWPORT m_customViewport;
    bool m_useCustomViewport = false;
    UINT m_gammaTexWidth = 0;
    UINT m_gammaTexHeight = 0;

    struct GammaCBData
    {
        float gamma;
        float pad;
        float uvOffsetX, uvOffsetY;
        float uvScaleX, uvScaleY;
        float pad2[2];
    };

    static const char* g_gammaVSCode;
    static const char* g_gammaPSCode;
};