2022-12-04 11:03:45 +00:00
|
|
|
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
|
|
|
|
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
|
|
|
|
2020-09-12 15:19:57 +00:00
|
|
|
#include "postprocessing_shader.h"
|
2023-08-13 03:42:02 +00:00
|
|
|
|
2020-09-12 15:19:57 +00:00
|
|
|
#include "common/file_system.h"
|
|
|
|
#include "common/log.h"
|
|
|
|
#include "common/string_util.h"
|
2023-08-13 03:42:02 +00:00
|
|
|
|
2020-09-12 15:19:57 +00:00
|
|
|
#include <cctype>
|
|
|
|
#include <cstring>
|
|
|
|
#include <sstream>
|
|
|
|
|
2023-08-27 12:48:40 +00:00
|
|
|
Log_SetChannel(PostProcessing);
|
2020-09-12 15:19:57 +00:00
|
|
|
|
2024-05-05 10:21:54 +00:00
|
|
|
void PostProcessing::Shader::ParseKeyValue(std::string_view line, std::string_view* key, std::string_view* value)
|
2020-09-12 15:19:57 +00:00
|
|
|
{
|
|
|
|
size_t key_start = 0;
|
|
|
|
while (key_start < line.size() && std::isspace(line[key_start]))
|
|
|
|
key_start++;
|
|
|
|
|
|
|
|
size_t key_end = key_start;
|
|
|
|
while (key_end < line.size() && (!std::isspace(line[key_end]) && line[key_end] != '='))
|
|
|
|
key_end++;
|
|
|
|
|
|
|
|
if (key_start == key_end || key_end == line.size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
size_t value_start = key_end;
|
|
|
|
while (value_start < line.size() && std::isspace(line[value_start]))
|
|
|
|
value_start++;
|
|
|
|
|
|
|
|
if (value_start == line.size() || line[value_start] != '=')
|
|
|
|
return;
|
|
|
|
|
|
|
|
value_start++;
|
|
|
|
while (value_start < line.size() && std::isspace(line[value_start]))
|
|
|
|
value_start++;
|
|
|
|
|
2020-09-13 08:39:40 +00:00
|
|
|
size_t value_end = line.size();
|
|
|
|
while (value_end > value_start && std::isspace(line[value_end - 1]))
|
|
|
|
value_end--;
|
2020-09-12 15:19:57 +00:00
|
|
|
|
|
|
|
if (value_start == value_end)
|
|
|
|
return;
|
|
|
|
|
|
|
|
*key = line.substr(key_start, key_end - key_start);
|
|
|
|
*value = line.substr(value_start, value_end - value_start);
|
|
|
|
}
|
|
|
|
|
2023-08-27 12:48:40 +00:00
|
|
|
PostProcessing::Shader::Shader() = default;
|
2020-09-12 15:19:57 +00:00
|
|
|
|
2023-08-27 12:48:40 +00:00
|
|
|
PostProcessing::Shader::Shader(std::string name) : m_name(std::move(name))
|
|
|
|
{
|
2020-09-12 15:19:57 +00:00
|
|
|
}
|
|
|
|
|
2023-08-27 12:48:40 +00:00
|
|
|
PostProcessing::Shader::~Shader() = default;
|
2020-09-12 15:19:57 +00:00
|
|
|
|
2023-08-27 12:48:40 +00:00
|
|
|
bool PostProcessing::Shader::IsValid() const
|
2020-09-12 15:19:57 +00:00
|
|
|
{
|
2023-08-27 12:48:40 +00:00
|
|
|
return false;
|
2020-09-12 15:19:57 +00:00
|
|
|
}
|
|
|
|
|
2023-08-27 12:48:40 +00:00
|
|
|
std::vector<PostProcessing::ShaderOption> PostProcessing::Shader::TakeOptions()
|
2020-09-12 15:19:57 +00:00
|
|
|
{
|
2023-08-27 12:48:40 +00:00
|
|
|
return std::move(m_options);
|
2020-09-12 15:19:57 +00:00
|
|
|
}
|
|
|
|
|
2023-10-15 15:00:43 +00:00
|
|
|
void PostProcessing::Shader::LoadOptions(const SettingsInterface& si, const char* section)
|
2020-09-12 15:19:57 +00:00
|
|
|
{
|
2023-08-27 12:48:40 +00:00
|
|
|
for (ShaderOption& option : m_options)
|
2020-09-12 15:19:57 +00:00
|
|
|
{
|
2023-08-27 12:48:40 +00:00
|
|
|
if (option.type == ShaderOption::Type::Bool)
|
|
|
|
{
|
|
|
|
const bool new_value = si.GetBoolValue(section, option.name.c_str(), option.default_value[0].int_value != 0);
|
|
|
|
if ((option.value[0].int_value != 0) != new_value)
|
|
|
|
{
|
|
|
|
option.value[0].int_value = new_value ? 1 : 0;
|
|
|
|
OnOptionChanged(option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ShaderOption::ValueVector value = option.default_value;
|
2020-09-12 15:19:57 +00:00
|
|
|
|
2023-08-27 12:48:40 +00:00
|
|
|
std::string config_value;
|
|
|
|
if (si.GetStringValue(section, option.name.c_str(), &config_value))
|
|
|
|
{
|
|
|
|
const u32 value_vector_size = (option.type == ShaderOption::Type::Int) ?
|
|
|
|
ShaderOption::ParseIntVector(config_value, &value) :
|
|
|
|
ShaderOption::ParseFloatVector(config_value, &value);
|
|
|
|
if (value_vector_size != option.vector_size)
|
|
|
|
{
|
2024-05-25 05:45:17 +00:00
|
|
|
WARNING_LOG("Only got {} of {} elements for '{}' in config section {}.", value_vector_size,
|
2024-05-23 10:55:28 +00:00
|
|
|
option.vector_size, option.name, section);
|
2023-08-27 12:48:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (std::memcmp(&option.value, &value, sizeof(value)) != 0)
|
|
|
|
{
|
|
|
|
option.value = value;
|
|
|
|
OnOptionChanged(option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-12 15:19:57 +00:00
|
|
|
}
|
|
|
|
|
2024-05-05 10:21:54 +00:00
|
|
|
const PostProcessing::ShaderOption* PostProcessing::Shader::GetOptionByName(std::string_view name) const
|
2020-09-12 15:19:57 +00:00
|
|
|
{
|
2023-08-27 12:48:40 +00:00
|
|
|
for (const ShaderOption& option : m_options)
|
2020-09-12 15:19:57 +00:00
|
|
|
{
|
|
|
|
if (option.name == name)
|
|
|
|
return &option;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2024-05-05 10:21:54 +00:00
|
|
|
PostProcessing::ShaderOption* PostProcessing::Shader::GetOptionByName(std::string_view name)
|
2020-09-12 15:19:57 +00:00
|
|
|
{
|
2023-08-27 12:48:40 +00:00
|
|
|
for (ShaderOption& option : m_options)
|
2020-09-12 15:19:57 +00:00
|
|
|
{
|
2023-08-27 12:48:40 +00:00
|
|
|
if (option.name == name)
|
|
|
|
return &option;
|
2020-09-12 15:19:57 +00:00
|
|
|
}
|
|
|
|
|
2023-08-27 12:48:40 +00:00
|
|
|
return nullptr;
|
2020-09-12 15:19:57 +00:00
|
|
|
}
|
|
|
|
|
2023-08-27 12:48:40 +00:00
|
|
|
void PostProcessing::Shader::OnOptionChanged(const ShaderOption& option)
|
2020-09-12 15:19:57 +00:00
|
|
|
{
|
|
|
|
}
|