diff options
| author | Markus Wick <degasus@users.noreply.github.com> | 2017-04-18 09:37:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-04-18 09:37:34 +0200 |
| commit | f3f9489852bfcb1f7744ec3ff3108270b0070ea1 (patch) | |
| tree | 88a19a7acef120623703ffee275b616d9f1d5320 /Source/Core/VideoBackends/OGL/PostProcessing.cpp | |
| parent | e0c489d80cbd512cff50328d77aa93d5c3600f84 (diff) | |
| parent | e370f6a82aafd94334c99b2547f3c90c6a12e014 (diff) | |
Merge pull request #5277 from stenzek/glsl-token-pasting
OGL: Use struct for post-processing shader options
Diffstat (limited to 'Source/Core/VideoBackends/OGL/PostProcessing.cpp')
| -rw-r--r-- | Source/Core/VideoBackends/OGL/PostProcessing.cpp | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/Source/Core/VideoBackends/OGL/PostProcessing.cpp b/Source/Core/VideoBackends/OGL/PostProcessing.cpp index 177a6ae4d8..928480567b 100644 --- a/Source/Core/VideoBackends/OGL/PostProcessing.cpp +++ b/Source/Core/VideoBackends/OGL/PostProcessing.cpp @@ -131,8 +131,9 @@ void OpenGLPostProcessing::ApplyShader() m_uniform_bindings.clear(); // load shader code - std::string code = m_config.LoadShader(); - code = LoadShaderOptions(code); + std::string main_code = m_config.LoadShader(); + std::string options_code = LoadShaderOptions(); + std::string code = m_glsl_header + options_code + main_code; // and compile it if (!ProgramShaderCache::CompileShader(m_shader, s_vertex_shader, code)) @@ -151,7 +152,7 @@ void OpenGLPostProcessing::ApplyShader() for (const auto& it : m_config.GetOptions()) { - std::string glsl_name = "option_" + it.first; + std::string glsl_name = "options." + it.first; m_uniform_bindings[it.first] = glGetUniformLocation(m_shader.glprogid, glsl_name.c_str()); } m_initialized = true; @@ -225,45 +226,51 @@ void OpenGLPostProcessing::CreateHeader() "\tocol0 = color;\n" "}\n" - "#define GetOption(x) (option_##x)\n" - "#define OptionEnabled(x) (option_##x != 0)\n"; + "#define GetOption(x) (options.x)\n" + "#define OptionEnabled(x) (options.x != 0)\n"; } -std::string OpenGLPostProcessing::LoadShaderOptions(const std::string& code) +std::string OpenGLPostProcessing::LoadShaderOptions() { - std::string glsl_options = ""; m_uniform_bindings.clear(); + if (m_config.GetOptions().empty()) + return ""; + + std::string glsl_options = "struct Options\n{\n"; for (const auto& it : m_config.GetOptions()) { if (it.second.m_type == PostProcessingShaderConfiguration::ConfigurationOption::OptionType::OPTION_BOOL) { - glsl_options += StringFromFormat("uniform int option_%s;\n", it.first.c_str()); + glsl_options += StringFromFormat("int %s;\n", it.first.c_str()); } else if (it.second.m_type == PostProcessingShaderConfiguration::ConfigurationOption::OptionType::OPTION_INTEGER) { u32 count = static_cast<u32>(it.second.m_integer_values.size()); if (count == 1) - glsl_options += StringFromFormat("uniform int option_%s;\n", it.first.c_str()); + glsl_options += StringFromFormat("int %s;\n", it.first.c_str()); else - glsl_options += StringFromFormat("uniform int%d option_%s;\n", count, it.first.c_str()); + glsl_options += StringFromFormat("int%d %s;\n", count, it.first.c_str()); } else if (it.second.m_type == PostProcessingShaderConfiguration::ConfigurationOption::OptionType::OPTION_FLOAT) { u32 count = static_cast<u32>(it.second.m_float_values.size()); if (count == 1) - glsl_options += StringFromFormat("uniform float option_%s;\n", it.first.c_str()); + glsl_options += StringFromFormat("float %s;\n", it.first.c_str()); else - glsl_options += StringFromFormat("uniform float%d option_%s;\n", count, it.first.c_str()); + glsl_options += StringFromFormat("float%d %s;\n", count, it.first.c_str()); } m_uniform_bindings[it.first] = 0; } - return m_glsl_header + glsl_options + code; + glsl_options += "};\n"; + glsl_options += "uniform Options options;\n"; + + return glsl_options; } } // namespace OGL |
