WebGL Textures & Vertices
Page Sixty Four
Calculate Stride and Offset
The following table demonstrates how to calculate stride and
offsets with data from the
prepared for the
Lighthouse Texture Map project.
stride and offset parameters, based on Byte location within a buffer.
The offset for the first vertex in the buffer, for this book's examples, equals
The offset for the first texel in the buffer, for this book's examples, equals
GLEntity assigns texels to an attribute with
vertexAttribPointer(), therefore the offset value equals
The stride for interleaved vertices and texels always equals
when five floating point values separate entries.
However if we created an array of vertices only, then stride would
0. If we created a non interleaved array with four vertices
at the start,
followed by four texels, then the texel offset
would equal forty eight.
Four vertices times three coordinates per vertex times four Bytes per coordinate
equals forty eight. Stride between texels and vertices would equal zero.
4 * 3 * 4 = 48
WebGL allows the developer
to assign data from different offsets
with more or less stride between entries, for
a range of uses.
This book scratches the surface.
Seven Thunder Software's book
WebGL Textures: Introduction to Mipmaps, Sub Images & Atlases
covers use of stride and offset with a little more detail.
Currently only pirated versions exist on the Web,
please don't download, pay for, or register for
WebGL Textures: Introduction to Mipmaps, Sub Images & Atlases.
Plans are in place to post the official free version here.
Until then, see
projects online and take a look at the source code.
Diagram 20: Calculate Offsets
calls the WebGL method
to activate the texture attribute.
The controller section previously demonstrated
how to activate the attribute which processes vertices.
The following listing activates
the attribute which processes texels.
gl.enableVertexAttribArray ( this.aTexCoord );