2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2014 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-07-29 16:47:56 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
2019-07-17 00:18:48 +00:00
|
|
|
#include <memory>
|
2014-07-29 16:47:56 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2019-07-17 00:18:48 +00:00
|
|
|
#include "Common/MathUtil.h"
|
2014-07-29 16:47:56 +00:00
|
|
|
#include "Common/Timer.h"
|
2019-02-15 01:59:50 +00:00
|
|
|
#include "VideoCommon/TextureConfig.h"
|
2014-10-18 07:32:24 +00:00
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
class AbstractPipeline;
|
|
|
|
class AbstractShader;
|
2019-07-17 00:18:48 +00:00
|
|
|
class AbstractTexture;
|
2019-02-15 01:59:50 +00:00
|
|
|
|
|
|
|
namespace VideoCommon
|
|
|
|
{
|
|
|
|
class PostProcessingConfiguration
|
2014-07-29 16:47:56 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct ConfigurationOption
|
|
|
|
{
|
2022-02-17 17:54:07 +00:00
|
|
|
enum class OptionType
|
2014-07-29 16:47:56 +00:00
|
|
|
{
|
2022-02-17 17:54:07 +00:00
|
|
|
Bool = 0,
|
|
|
|
Float,
|
|
|
|
Integer,
|
2014-07-29 16:47:56 +00:00
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-09-04 04:43:19 +00:00
|
|
|
bool m_bool_value = false;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-07-29 16:47:56 +00:00
|
|
|
std::vector<float> m_float_values;
|
|
|
|
std::vector<s32> m_integer_values;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-07-29 16:47:56 +00:00
|
|
|
std::vector<float> m_float_min_values;
|
|
|
|
std::vector<s32> m_integer_min_values;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-07-29 16:47:56 +00:00
|
|
|
std::vector<float> m_float_max_values;
|
|
|
|
std::vector<s32> m_integer_max_values;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-07-29 16:47:56 +00:00
|
|
|
std::vector<float> m_float_step_values;
|
|
|
|
std::vector<s32> m_integer_step_values;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2022-02-17 17:54:07 +00:00
|
|
|
OptionType m_type = OptionType::Bool;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-07-29 16:47:56 +00:00
|
|
|
std::string m_gui_name;
|
|
|
|
std::string m_option_name;
|
|
|
|
std::string m_dependent_option;
|
2021-09-04 04:43:19 +00:00
|
|
|
bool m_dirty = false;
|
2014-07-29 16:47:56 +00:00
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2018-05-21 15:57:15 +00:00
|
|
|
using ConfigMap = std::map<std::string, ConfigurationOption>;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
PostProcessingConfiguration();
|
|
|
|
virtual ~PostProcessingConfiguration();
|
2018-05-21 15:54:53 +00:00
|
|
|
|
2014-07-29 16:47:56 +00:00
|
|
|
// Loads the configuration with a shader
|
|
|
|
// If the argument is "" the class will load the shader from the g_activeConfig option.
|
|
|
|
// Returns the loaded shader source from file
|
2019-02-15 01:59:50 +00:00
|
|
|
void LoadShader(const std::string& shader);
|
|
|
|
void LoadDefaultShader();
|
2014-07-29 16:47:56 +00:00
|
|
|
void SaveOptionsConfiguration();
|
2018-05-21 16:07:46 +00:00
|
|
|
const std::string& GetShader() const { return m_current_shader; }
|
2019-02-15 01:59:50 +00:00
|
|
|
const std::string& GetShaderCode() const { return m_current_shader_code; }
|
2018-05-21 15:59:04 +00:00
|
|
|
bool IsDirty() const { return m_any_options_dirty; }
|
2014-07-29 16:47:56 +00:00
|
|
|
void SetDirty(bool dirty) { m_any_options_dirty = dirty; }
|
2018-05-21 15:59:04 +00:00
|
|
|
bool HasOptions() const { return m_options.size() > 0; }
|
2017-04-21 13:33:12 +00:00
|
|
|
const ConfigMap& GetOptions() const { return m_options; }
|
2014-07-29 16:47:56 +00:00
|
|
|
ConfigMap& GetOptions() { return m_options; }
|
|
|
|
const ConfigurationOption& GetOption(const std::string& option) { return m_options[option]; }
|
|
|
|
// For updating option's values
|
2015-05-29 00:28:48 +00:00
|
|
|
void SetOptionf(const std::string& option, int index, float value);
|
|
|
|
void SetOptioni(const std::string& option, int index, s32 value);
|
|
|
|
void SetOptionb(const std::string& option, bool value);
|
2014-07-29 16:47:56 +00:00
|
|
|
|
|
|
|
private:
|
2018-05-21 15:54:53 +00:00
|
|
|
bool m_any_options_dirty = false;
|
2014-07-29 16:47:56 +00:00
|
|
|
std::string m_current_shader;
|
2019-02-15 01:59:50 +00:00
|
|
|
std::string m_current_shader_code;
|
2014-07-29 16:47:56 +00:00
|
|
|
ConfigMap m_options;
|
|
|
|
|
|
|
|
void LoadOptions(const std::string& code);
|
|
|
|
void LoadOptionsConfiguration();
|
|
|
|
};
|
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
class PostProcessing
|
2014-07-29 16:47:56 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-02-15 01:59:50 +00:00
|
|
|
PostProcessing();
|
|
|
|
virtual ~PostProcessing();
|
|
|
|
|
|
|
|
static std::vector<std::string> GetShaderList();
|
2019-05-02 02:47:50 +00:00
|
|
|
static std::vector<std::string> GetPassiveShaderList();
|
2019-02-15 01:59:50 +00:00
|
|
|
static std::vector<std::string> GetAnaglyphShaderList();
|
|
|
|
|
|
|
|
PostProcessingConfiguration* GetConfig() { return &m_config; }
|
2014-07-29 16:47:56 +00:00
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
bool Initialize(AbstractTextureFormat format);
|
2017-04-21 13:59:45 +00:00
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
void RecompileShader();
|
|
|
|
void RecompilePipeline();
|
|
|
|
|
|
|
|
void BlitFromTexture(const MathUtil::Rectangle<int>& dst, const MathUtil::Rectangle<int>& src,
|
|
|
|
const AbstractTexture* src_tex, int src_layer);
|
2018-04-12 12:18:04 +00:00
|
|
|
|
2014-07-29 16:47:56 +00:00
|
|
|
protected:
|
2019-02-15 01:59:50 +00:00
|
|
|
std::string GetUniformBufferHeader() const;
|
|
|
|
std::string GetHeader() const;
|
|
|
|
std::string GetFooter() const;
|
|
|
|
|
|
|
|
bool CompileVertexShader();
|
|
|
|
bool CompilePixelShader();
|
|
|
|
bool CompilePipeline();
|
|
|
|
|
|
|
|
size_t CalculateUniformsSize() const;
|
|
|
|
void FillUniformBuffer(const MathUtil::Rectangle<int>& src, const AbstractTexture* src_tex,
|
|
|
|
int src_layer);
|
|
|
|
|
2014-07-29 16:47:56 +00:00
|
|
|
// Timer for determining our time value
|
|
|
|
Common::Timer m_timer;
|
2019-02-15 01:59:50 +00:00
|
|
|
PostProcessingConfiguration m_config;
|
2014-07-29 16:47:56 +00:00
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
std::unique_ptr<AbstractShader> m_vertex_shader;
|
|
|
|
std::unique_ptr<AbstractShader> m_pixel_shader;
|
|
|
|
std::unique_ptr<AbstractPipeline> m_pipeline;
|
|
|
|
AbstractTextureFormat m_framebuffer_format = AbstractTextureFormat::Undefined;
|
|
|
|
std::vector<u8> m_uniform_staging_buffer;
|
2014-07-29 16:47:56 +00:00
|
|
|
};
|
2019-02-15 01:59:50 +00:00
|
|
|
} // namespace VideoCommon
|