Question

In reading the book: OpenGL ES 2.0 Programming Guide (Addison-Wesley). And I have read the following:

"Attribute names that do not exist or are not active in a vertex shader attached to the program object are ignored."

When an attribute is not active?

Thanks.

Was it helpful?

Solution

From the OpenGL specification:

A generic attribute variable is considered active if it is determined by the compiler and linker that the attribute may be accessed when the shader is executed. Attribute variables that are declared in a vertex shader but never used will not count against the limit. In cases where the compiler and linker cannot make a conclusive determination, an attribute will be considered active. A program object will fail to link if the number of active vertex attributes exceeds MAX_VERTEX_ATTRIBS.

OTHER TIPS

Sometimes it's useful to have a vertex shader that provides a bunch of attributes to various fragment shaders without having to worry about whether each specific fragment shader makes use of it. In these cases, it's acceptable for the compiler and linker to remove the attributes which aren't actually being used in the vertex shader's output, and those will be mapped to the no-op handle of -1.

This isn't guaranteed behavior, however - it's just an optimization that the GLSL compiler is free to make, and as such it is a good idea to eventually optimize your shaders such that the vertex shader is only providing the data that the fragment shader needs, as you may get performance improvements on some platforms.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top