[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Public WebGL] Consumed Attribute
I'm not sure about an exact definition - but what it means is that if
(for example) you send a TexCoord2 value to your vertex shader - but it
doesn't use it for anything, or perhaps doesn't even declare it - that's
not an error, the extra data is silently ignored.
There are at least two reasons why that's a good idea:
1) Shader optimization sometimes means that a variable that you declared
and perhaps even used in the shader gets optimized away by the
compiler. You don't want that to cause an error because it's not
obvious to the naive programmer what went wrong or how to fix it.
x = TexCoord2.x * 0.0000001 ;
....on a machine with full 32 bit floating point, this compiles to
actual working code - but on a machine with only 16 bit half-float, that
constant gets truncated to zero - the compiler spots a multiplication by
zero and replaces that line with:
x = 0.0 ;
...and the TexCoord2 value is now "unused" - and in at least some shader
compilers will not appear in the list of attributes if you query them
from the application.
2) Sometimes you want to send the same set of vertex attributes to a
number of different shaders (eg if you have a depth-only pass, a shadow
pass and a beauty pass) - some of which need only a subset of the
attributes. eg When you use an interleaved vertex data format, it could
be inconvenient to have to send only exactly what the shader wanted.
In general, it's very convenient for it not to be illegal to try to pass
things to a shader that it doesn't need.
Erik Möller wrote:
> From WebGL spec 6.2:
> "If a vertex attribute is enabled as an array, a buffer is bound to
> that attribute, but the attribute is not consumed by the current
> program, then regardless of the size of the bound buffer, it will not
> cause any error to be generated during a call to drawArrays or
> What exactly is the definition of an attribute being consumed by a
You are currently subscribed to email@example.com.
To unsubscribe, send an email to firstname.lastname@example.org with
the following command in the body of your email: