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

Multiple require problems #116

Open
Eronana opened this issue Sep 7, 2018 · 2 comments
Open

Multiple require problems #116

Eronana opened this issue Sep 7, 2018 · 2 comments

Comments

@Eronana
Copy link
Contributor

Eronana commented Sep 7, 2018

a.glsl

#ifdef HELLO
#pragma glslify: b = require('./b.glsl')
float a(float x) {
	return b(x);
}
#else
float a(float x) {
	return x * 10.0;
}
#endif

#pragma glslify:export(a)

b.glsl

float b(float x) {
	return x * 11.11;
}

#pragma glslify:export(b)

c.glsl

#pragma glslify: a = require('./a.glsl')
#pragma glslify: b = require('./b.glsl')

void main() {
	gl_FragColor = vec4(a(1.0), b(1.0), 0.0, 0.0);
}

glslify < c.glsl

#define GLSLIFY 1
#ifdef HELLO
float b(float x) {
	return x * 11.11;
}

float a(float x) {
	return b(x);
}
#else
float a(float x) {
	return x * 10.0;
}
#endif

void main() {
	gl_FragColor = vec4(a(1.0), b(1.0), 0.0, 0.0);
}

the problem is, no function b when HELLO is undefined, it will caused some issue.
so maybe glslify shouldn't do too much processing, user could use macros to avoid multiple require like C/C++.

@Eronana
Copy link
Contributor Author

Eronana commented Sep 10, 2018

fixed here glslify/glslify-bundle#7
please update dependencies when it is published.

@hughsk
Copy link
Member

hughsk commented Sep 10, 2018

A temporary workaround for this issue is to require b before a. I believe it's possible to do this in all cases where a module is required between preprocessor conditionals like that, even if you're not using b in the file where you're requiring it.

#pragma glslify: b = require('./b.glsl')
#pragma glslify: a = require('./a.glsl')

void main() {
	gl_FragColor = vec4(a(1.0), b(1.0), 0.0, 0.0);
}
#define GLSLIFY 1
float b(float x) {
        return x * 11.11;
}

#ifdef HELLO

float a(float x) {
        return b(x);
}
#else
float a(float x) {
        return x * 10.0;
}
#endif

void main() {
        gl_FragColor = vec4(a(1.0), b(1.0), 0.0, 0.0);
}

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