[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Public WebGL] Consumed Attribute
- To: Steve Baker <email@example.com>
- Subject: Re: [Public WebGL] Consumed Attribute
- From: "Gregg Tavares (wrk)" <firstname.lastname@example.org>
- Date: Fri, 17 Sep 2010 10:30:27 -0700
- Cc: Erik Möller <email@example.com>, "firstname.lastname@example.org" <email@example.com>
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1284744630; bh=AjJkVJyCSZubMAojq5cM9tm0t48=; h=MIME-Version:In-Reply-To:References:Date:Message-ID:Subject:From: To:Cc:Content-Type; b=GLj3w1ek+iVTTuu8iAfNrZV7bV8vcv23qDtpWZIBhVu5CjjujBrOYGXZmt/SDXQW/ wDFAKy7Fl00FEvr5xhs/A==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=beta; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=xTXXnWag8ePfjvpFW9OaDBoVxwHg9Puum/dgDqLLLaQ=; b=n2vm0C1gIsT0tfb2832i4rYZCx6rBT2cU4YsLEHjeKqa4UaCFZfO9kJ7F8lutBah4B pqK9pgWQGS/VTXlJj4DA==
- Domainkey-signature: a=rsa-sha1; c=nofws; d=google.com; s=beta; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=WFgqZ5jk+XlbIi+w6NM0IDfVn/ODj2bn2/6EC1Yk5eTibRNMNnukaCyDiF+9+eXTlS 0E6CwCS+nahJu6qm0TRg==
- In-reply-to: <4C9353B9.firstname.lastname@example.org>
- References: <email@example.com> <4C9353B9.firstname.lastname@example.org>
- Sender: email@example.com
What Steve said.
It's for the case of you turn on 3 attributes with 3 vertices each (drawing a triangle with a shader that uses positions, texcoords and normals). You call drawArrays with a count of 3. Next you draw 2 triangles, 6 vertices and use a shader that only uses positions. You call gl.vertexAttribPointer to setup your position vertex attrib to point to 6 position values but there are still 2 other vertex attribs setup from the previous draw call each with only 3 vertices available. You call drawArrays with a count of 6.
Since WebGL enforces that you don't try to access out of bounds values you have 2 options
1) fail the draw. You asked to draw 6 but 2 of your attribs only reference buffers that have 3 vertices each
2) You pass the draw because you know the shader is not going to access those 2 other vertex attribs.
The spec says do #2.
On Fri, Sep 17, 2010 at 4:40 AM, Steve Baker <firstname.lastname@example.org>
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
the following command in the body of your email: