Debian Codegraph @

Source/Core/VideoCommon/PostProcessing.h

raw symbols SCIP
1 // Copyright 2014 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <map>
7 #include <memory>
8 #include <string>
9 #include <vector>
10
11 #include "Common/CommonTypes.h"
12 #include "Common/MathUtil.h"
13 #include "Common/Timer.h"
14 #include "VideoCommon/TextureConfig.h"
15
16 class AbstractPipeline;
17 class AbstractShader;
18 class AbstractTexture;
19 class AbstractFramebuffer;
20
21 namespace VideoCommon
22 {
23 class ShaderIncluder;
24
25 class PostProcessingConfiguration
26 {
27 public:
28 // User defined post process
29 struct ConfigurationOption
30 {
31 enum class OptionType
32 {
33 Bool = 0,
34 Float,
35 Integer,
36 };
37
38 bool m_bool_value = false;
39
40 std::vector<float> m_float_values;
41 std::vector<s32> m_integer_values;
42
43 std::vector<float> m_float_min_values;
44 std::vector<s32> m_integer_min_values;
45
46 std::vector<float> m_float_max_values;
47 std::vector<s32> m_integer_max_values;
48
49 std::vector<float> m_float_step_values;
50 std::vector<s32> m_integer_step_values;
51
52 OptionType m_type = OptionType::Bool;
53
54 std::string m_gui_name;
55 std::string m_option_name;
56 std::string m_dependent_option;
57 bool m_dirty = false;
58 };
59
60 using ConfigMap = std::map<std::string, ConfigurationOption>;
61
62 PostProcessingConfiguration();
63 virtual ~PostProcessingConfiguration();
64
65 // Loads the configuration with a shader
66 // If the argument is "" the class will load the shader from the g_activeConfig option.
67 // Returns the loaded shader source from file
68 void LoadShader(const std::string& shader);
69 void LoadDefaultShader();
70 void SaveOptionsConfiguration();
71 const std::string& GetShader() const { return m_current_shader; }
72 const std::string& GetShaderCode() const { return m_current_shader_code; }
73 ShaderIncluder* GetShaderIncluder() { return m_shader_includer.get(); }
74 bool IsDirty() const { return m_any_options_dirty; }
75 void SetDirty(bool dirty) { m_any_options_dirty = dirty; }
76 bool HasOptions() const { return m_options.size() > 0; }
77 const ConfigMap& GetOptions() const { return m_options; }
78 ConfigMap& GetOptions() { return m_options; }
79 const ConfigurationOption& GetOption(const std::string& option) { return m_options[option]; }
80 // For updating option's values
81 void SetOptionf(const std::string& option, int index, float value);
82 void SetOptioni(const std::string& option, int index, s32 value);
83 void SetOptionb(const std::string& option, bool value);
84
85 private:
86 bool m_any_options_dirty = false;
87 std::unique_ptr<ShaderIncluder> m_shader_includer;
88 std::string m_current_shader;
89 std::string m_current_shader_code;
90 ConfigMap m_options;
91
92 void LoadOptions(const std::string& code);
93 void LoadOptionsConfiguration();
94 };
95
96 class PostProcessing
97 {
98 public:
99 PostProcessing();
100 virtual ~PostProcessing();
101
102 static std::vector<std::string> GetShaderList();
103 static std::vector<std::string> GetPassiveShaderList();
104 static std::vector<std::string> GetAnaglyphShaderList();
105
106 PostProcessingConfiguration* GetConfig() { return &m_config; }
107
108 bool Initialize(AbstractTextureFormat format);
109
110 void RecompileShader();
111 void RecompilePipeline();
112
113 void BlitFromTexture(const MathUtil::Rectangle<int>& dst, const MathUtil::Rectangle<int>& src,
114 const AbstractTexture* src_tex, int src_layer = -1);
115
116 bool IsColorCorrectionActive() const;
117 bool NeedsIntermediaryBuffer() const;
118
119 protected:
120 std::string GetUniformBufferHeader(bool user_post_process) const;
121 std::string GetHeader(bool user_post_process) const;
122 std::string GetFooter() const;
123
124 bool CompileVertexShader();
125 bool CompilePixelShader();
126 bool CompilePipeline();
127
128 size_t CalculateUniformsSize(bool user_post_process) const;
129 void FillUniformBuffer(const MathUtil::Rectangle<int>& src, const AbstractTexture* src_tex,
130 int src_layer, const MathUtil::Rectangle<int>& dst,
131 const MathUtil::Rectangle<int>& wnd, u8* buffer, bool user_post_process,
132 bool intermediary_buffer);
133
134 // Timer for determining our time value
135 Common::Timer m_timer;
136
137 // Dolphin fixed post process:
138 PostProcessingConfiguration::ConfigMap m_default_options;
139 std::unique_ptr<AbstractShader> m_default_vertex_shader;
140 std::unique_ptr<AbstractShader> m_default_pixel_shader;
141 std::unique_ptr<AbstractPipeline> m_default_pipeline;
142 std::unique_ptr<AbstractFramebuffer> m_intermediary_frame_buffer;
143 std::unique_ptr<AbstractTexture> m_intermediary_color_texture;
144 std::vector<u8> m_default_uniform_staging_buffer;
145 // User post process:
146 PostProcessingConfiguration m_config;
147 std::unique_ptr<AbstractShader> m_vertex_shader;
148 std::unique_ptr<AbstractShader> m_pixel_shader;
149 std::unique_ptr<AbstractPipeline> m_pipeline;
150 std::vector<u8> m_uniform_staging_buffer;
151
152 AbstractTextureFormat m_framebuffer_format = AbstractTextureFormat::Undefined;
153 };
154 } // namespace VideoCommon