PostProcessing: Move default pixel shader to PostProcessingShaderConfiguration.

Reduces code complexity and fixes a bug where the shader is not properly invalidated.
This commit is contained in:
Jules Blok 2015-01-25 23:08:49 +01:00
parent fc46d460f9
commit 5c4ee2f71e
2 changed files with 19 additions and 18 deletions

View File

@ -36,8 +36,6 @@ static const char s_vertex_shader[] =
" uv0 = rawpos * src_rect.zw + src_rect.xy;\n" " uv0 = rawpos * src_rect.zw + src_rect.xy;\n"
"}\n"; "}\n";
static const char s_default_shader[] = "void main() { SetOutput(Sample()); }\n";
OpenGLPostProcessing::OpenGLPostProcessing() OpenGLPostProcessing::OpenGLPostProcessing()
: m_initialized(false) : m_initialized(false)
{ {
@ -171,13 +169,7 @@ void OpenGLPostProcessing::ApplyShader()
m_uniform_bindings.clear(); m_uniform_bindings.clear();
// load shader code // load shader code
std::string code = ""; std::string code = m_config.LoadShader();
if (g_ActiveConfig.sPostProcessingShader != "")
code = m_config.LoadShader();
if (code == "")
code = s_default_shader;
code = LoadShaderOptions(code); code = LoadShaderOptions(code);
const char* vertex_shader = s_vertex_shader; const char* vertex_shader = s_vertex_shader;
@ -189,8 +181,8 @@ void OpenGLPostProcessing::ApplyShader()
if (!ProgramShaderCache::CompileShader(m_shader, vertex_shader, code.c_str())) if (!ProgramShaderCache::CompileShader(m_shader, vertex_shader, code.c_str()))
{ {
ERROR_LOG(VIDEO, "Failed to compile post-processing shader %s", m_config.GetShader().c_str()); ERROR_LOG(VIDEO, "Failed to compile post-processing shader %s", m_config.GetShader().c_str());
g_ActiveConfig.sPostProcessingShader.clear();
code = LoadShaderOptions(s_default_shader); code = m_config.LoadShader();
ProgramShaderCache::CompileShader(m_shader, vertex_shader, code.c_str()); ProgramShaderCache::CompileShader(m_shader, vertex_shader, code.c_str());
} }

View File

@ -13,6 +13,8 @@
#include "VideoCommon/VideoConfig.h" #include "VideoCommon/VideoConfig.h"
static const char s_default_shader[] = "void main() { SetOutput(Sample()); }\n";
PostProcessingShaderImplementation::PostProcessingShaderImplementation() PostProcessingShaderImplementation::PostProcessingShaderImplementation()
{ {
m_timer.Start(); m_timer.Start();
@ -36,6 +38,12 @@ std::string PostProcessingShaderConfiguration::LoadShader(std::string shader)
std::string code; std::string code;
std::string path = File::GetUserPath(D_SHADERS_IDX) + sub_dir + shader + ".glsl"; std::string path = File::GetUserPath(D_SHADERS_IDX) + sub_dir + shader + ".glsl";
if (shader == "")
{
code = s_default_shader;
}
else
{
if (!File::Exists(path)) if (!File::Exists(path))
{ {
// Fallback to shared user dir // Fallback to shared user dir
@ -45,7 +53,8 @@ std::string PostProcessingShaderConfiguration::LoadShader(std::string shader)
if (!File::ReadFileToString(path, code)) if (!File::ReadFileToString(path, code))
{ {
ERROR_LOG(VIDEO, "Post-processing shader not found: %s", path.c_str()); ERROR_LOG(VIDEO, "Post-processing shader not found: %s", path.c_str());
return ""; code = s_default_shader;
}
} }
LoadOptions(code); LoadOptions(code);