Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect parsing behavior in multi-if scrope #311

Open
lemoon opened this issue Jul 12, 2023 · 3 comments
Open

Incorrect parsing behavior in multi-if scrope #311

lemoon opened this issue Jul 12, 2023 · 3 comments

Comments

@lemoon
Copy link

lemoon commented Jul 12, 2023

input shader

varying vec2 v_texcoordOut;
uniform sampler2D s_texture;
uniform float u_degree;
uniform float u_degree2;

void main(void)
{
    vec2 texcoord = v_texcoordOut;
    if(u_degree > 0.001)
    {
        if(u_degree2 > 0.8)
        {
            texcoord.x += 0.1;
        }
        else if(u_degree2 >0.5)
        {
            texcoord.y += 0.1;
        }
    }
    gl_FragColor = texture2D(s_texture, texcoord);
}

after command

mono "$script_dir/shader_minifier.exe" -v --preserve-externals --field-names stpq -o res.h input.frag

// Generated with Shader Minifier 1.3.6 (https://github.com/laurentlb/Shader_Minifier/)
#ifndef RES_H_
# define RES_H_

const char *Basic_frag =
 "precision highp float;varying vec2 v_texcoordOut;"
 "uniform sampler2D s_texture;"
 "uniform float u_degree,u_degree2;"
 "void main()"
 "{"
   "vec2 f=v_texcoordOut;"
   "if(u_degree>.001)"
     "if(u_degree2>.8)"
       "f.s+=.1;"
     "else if(u_degree2>.5)"
       "f.t+=.1;"
   "gl_FragColor=texture2D(s_texture,f);"
 "}";

#endif // RES_H_

missing scrope in ""if(u_degree>.001)""

@lemoon lemoon changed the title Incorrect parsing behavior in multi-if scrop Incorrect parsing behavior in multi-if scrope Jul 12, 2023
@laurentlb
Copy link
Owner

I think the output is correct, the curly braces are not needed here.

@lemoon
Copy link
Author

lemoon commented Jul 12, 2023

Some machines produce compilation errors because of this approach
image

@laurentlb
Copy link
Owner

Can you give more information on your setup? What tool is compiling the code? Have you considered filing a bug against that tool?

As far as I can tell, the syntax is not ambiguous, it's properly defined in the spec (at least for GLSL).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants