From e663f5c91450ac5b36358195718edddbde25cd75 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 21 Oct 2015 00:04:02 -0400 Subject: gl_shader_gen: Optimize code for AppendAlphaTestCondition. - Also add a comment to AppendColorCombiner. --- src/video_core/renderer_opengl/gl_shader_gen.cpp | 27 ++++++++++-------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 7506cdc08..e456f5847 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp @@ -205,7 +205,7 @@ static void AppendColorCombiner(std::string& out, TevStageConfig::Operation oper LOG_CRITICAL(Render_OpenGL, "Unknown color combiner operation: %u", operation); break; } - out += ", vec3(0.0), vec3(1.0))"; + out += ", vec3(0.0), vec3(1.0))"; // Clamp result to 0.0, 1.0 } /// Writes the combiner function for the alpha component for the specified TEV stage operation @@ -257,23 +257,18 @@ static void AppendAlphaTestCondition(std::string& out, Regs::CompareFunc func) { out += "false"; break; case CompareFunc::Equal: - out += "int(last_tex_env_out.a * 255.0f) != alphatest_ref"; - break; case CompareFunc::NotEqual: - out += "int(last_tex_env_out.a * 255.0f) == alphatest_ref"; - break; case CompareFunc::LessThan: - out += "int(last_tex_env_out.a * 255.0f) >= alphatest_ref"; - break; case CompareFunc::LessThanOrEqual: - out += "int(last_tex_env_out.a * 255.0f) > alphatest_ref"; - break; case CompareFunc::GreaterThan: - out += "int(last_tex_env_out.a * 255.0f) <= alphatest_ref"; - break; case CompareFunc::GreaterThanOrEqual: - out += "int(last_tex_env_out.a * 255.0f) < alphatest_ref"; + { + static const char* op[] = { "!=", "==", ">=", ">", "<=", "<", }; + unsigned index = (unsigned)func - (unsigned)CompareFunc::Equal; + out += "int(last_tex_env_out.a * 255.0f) " + std::string(op[index]) + " alphatest_ref"; break; + } + default: out += "false"; LOG_CRITICAL(Render_OpenGL, "Unknown alpha test condition %u", func); @@ -337,10 +332,10 @@ out vec4 color; )"; using Uniform = RasterizerOpenGL::PicaShader::Uniform; - out += "layout(location = " + std::to_string(Uniform::AlphaTestRef) + ") uniform int alphatest_ref;\n"; - out += "layout(location = " + std::to_string(Uniform::TevConstColors) + ") uniform vec4 const_color[NUM_TEV_STAGES];\n"; - out += "layout(location = " + std::to_string(Uniform::Texture0) + ") uniform sampler2D tex[3];\n"; - out += "layout(location = " + std::to_string(Uniform::TevCombinerBufferColor) + ") uniform vec4 tev_combiner_buffer_color;\n"; + out += "layout(location = " + std::to_string((int)Uniform::AlphaTestRef) + ") uniform int alphatest_ref;\n"; + out += "layout(location = " + std::to_string((int)Uniform::TevConstColors) + ") uniform vec4 const_color[NUM_TEV_STAGES];\n"; + out += "layout(location = " + std::to_string((int)Uniform::Texture0) + ") uniform sampler2D tex[3];\n"; + out += "layout(location = " + std::to_string((int)Uniform::TevCombinerBufferColor) + ") uniform vec4 tev_combiner_buffer_color;\n"; out += "void main() {\n"; out += "vec4 combiner_buffer = tev_combiner_buffer_color;\n"; -- cgit v1.2.3