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

struct and array support? #12

Open
bhouston opened this issue Oct 13, 2015 · 2 comments
Open

struct and array support? #12

bhouston opened this issue Oct 13, 2015 · 2 comments

Comments

@bhouston
Copy link

I was chatting with @unconed about using glsl-parser to handle the new structs and arrays that I using in a refactor of ThreeJS's lighting BRDFs. He said it wasn't supported by glsl-parser. Is that the case?

@heisters
Copy link

I am seeing some issues with structs, and would be interested to hear about support for them.

For instance, this parses:

struct Foo {
};

void main() {
  Bar baz;
}

And this parses:

struct Bar {
};

void main() {
  Bar baz = foo();
}

But this throws

Error: did not use all tokens
    at module.exports (/Users/iheisters/code/glslpreprec/node_modules/glsl-parser/lib/expr.js:121:11)
struct Foo {
};

void main() {
  Bar baz = foo();
}

@weiwen1990
Copy link

weiwen1990 commented May 29, 2020

precision mediump float;
uniform sampler2D Texture;

vec4 test1()
{
    vec2 p1 = vec2(0.0);
    vec2 p2 = vec2(1.0);
    mediump vec4 rgba = vec4(0.0);

    int m[3];
    m[0] = 1;
    m[1] = 2;
    m[2] = 3;

    vec4 d[6];

    int offset = 0;
    for (int i = 0; i < 3; i ++) {
        for (int j = 0; j < m[i]; j ++) {
            vec2 pos = p1 + float(j + 1)/float(m[i] + 1) * (p2 - p1);
            vec4 color = texture2D(Texture, pos);
            d[offset + j] = color;
        }
        offset += m[i];
    }

    for (int i = 0; i < 6; i ++) {
        rgba += d[i];
    }
    rgba /= float(6);
    return rgba;
}

Error: did not use all tokens
at module.exports (/usr/local/lib/node_modules/glsl-minifier/node_modules/glsl-parser/lib/expr.js:121:11)
at parseexpr (/usr/local/lib/node_modules/glsl-minifier/node_modules/glsl-parser/lib/index.js:605:9)
at parse_expr (/usr/local/lib/node_modules/glsl-minifier/node_modules/glsl-parser/lib/index.js:582:14)
at write (/usr/local/lib/node_modules/glsl-minifier/node_modules/glsl-parser/lib/index.js:192:18)
at reader (/usr/local/lib/node_modules/glsl-minifier/node_modules/glsl-parser/lib/index.js:166:5)
at DestroyableTransform.write [as _transform] (/usr/local/lib/node_modules/glsl-minifier/node_modules/glsl-parser/stream.js:16:17)
at DestroyableTransform.Transform._read (/usr/local/lib/node_modules/glsl-minifier/node_modules/readable-stream/lib/_stream_transform.js:184:10)
at DestroyableTransform.Transform._write (/usr/local/lib/node_modules/glsl-minifier/node_modules/readable-stream/lib/_stream_transform.js:172:12)
at doWrite (/usr/local/lib/node_modules/glsl-minifier/node_modules/readable-stream/lib/_stream_writable.js:237:10)
at writeOrBuffer (/usr/local/lib/node_modules/glsl-minifier/node_modules/readable-stream/lib/_stream_writable.js:227:5)

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

3 participants