views:

74

answers:

1

Hello,

I am writing my first shader in WebGL. I was wondering if the GLSL language has any way to evaluate if an attribute or a uniform is null. According to the specs it does not support to do something like

if (attributeX) {
dothis();
}  
else{ 
dothat():
}

And I think it would be a waste to write a bool attribute for each of these cases would be a waste.

Another question: what happen during rendering when you don't pass along the uniforms or attribs to the shader?

Thanks!

+2  A: 

GLSL has no concept of null, using a bool uniform for that case is fine.

If you don't pass uniforms, they get zero-initialized, for attribs, i think you get garbage out of them.

Matias Valdenegro
no, you don't get garbage. You get the constant value of the attribute (you can set it with glVertexAttrib http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttrib.xml)
Bahbar
Right, if you don't set it, you get the default zero intialized, but still, i've seen implementations crash or give garbage.
Matias Valdenegro