From df5904605017049fead0de45ad5e1141b5434caf Mon Sep 17 00:00:00 2001 From: jpark37 Date: Tue, 23 Jul 2019 08:31:57 -0700 Subject: [PATCH] libobs-opengl: Support gl_FragCoord and cull unused interpolants --- libobs-opengl/gl-shaderparser.c | 37 +++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/libobs-opengl/gl-shaderparser.c b/libobs-opengl/gl-shaderparser.c index d8d949fbc..5c29517ac 100644 --- a/libobs-opengl/gl-shaderparser.c +++ b/libobs-opengl/gl-shaderparser.c @@ -167,7 +167,16 @@ static void gl_write_storage_var(struct gl_shader_parser *glsp, if (st) { gl_unwrap_storage_struct(glsp, st, var->name, input, prefix); - } else if (!input || strcmp(var->mapping, "VERTEXID")) { + } else { + if (input && (strcmp(var->mapping, "VERTEXID") == 0)) + return; + if (strcmp(var->mapping, "POSITION") == 0) { + if (!input && (glsp->type == GS_SHADER_VERTEX)) + return; + if (input && (glsp->type == GS_SHADER_PIXEL)) + return; + } + struct gl_parser_attrib attrib; gl_parser_attrib_init(&attrib); @@ -555,17 +564,23 @@ static void gl_write_main_storage_assign(struct gl_shader_parser *glsp, dstr_free(&src_copy); } else { - if (!dstr_is_empty(&dst_copy)) - dstr_cat_dstr(&glsp->gl_string, &dst_copy); - dstr_cat(&glsp->gl_string, " = "); - if (input && (strcmp(var->mapping, "VERTEXID") == 0)) - dstr_cat(&glsp->gl_string, "uint(gl_VertexID)"); - else { - if (src) - dstr_cat(&glsp->gl_string, src); - dstr_cat(&glsp->gl_string, var->name); + if (input || (glsp->type != GS_SHADER_VERTEX) || + (strcmp(var->mapping, "POSITION"))) { + if (!dstr_is_empty(&dst_copy)) + dstr_cat_dstr(&glsp->gl_string, &dst_copy); + dstr_cat(&glsp->gl_string, " = "); + if (input && (strcmp(var->mapping, "VERTEXID") == 0)) + dstr_cat(&glsp->gl_string, "uint(gl_VertexID)"); + else if (input && (glsp->type == GS_SHADER_PIXEL) && + (strcmp(var->mapping, "POSITION") == 0)) + dstr_cat(&glsp->gl_string, "gl_FragCoord"); + else { + if (src) + dstr_cat(&glsp->gl_string, src); + dstr_cat(&glsp->gl_string, var->name); + } + dstr_cat(&glsp->gl_string, ";\n"); } - dstr_cat(&glsp->gl_string, ";\n"); if (!input) gl_write_main_interface_assign(glsp, var, src);