What does stride mean in OpenGL|ES -


i going through signature of method glvertexpointer

void glvertexpointer(glint size, glenum type, glsizei stride, const glvoid * pointer)

can me understand third argument stride do.

i got definition stride after googling it

amount of bytes beginning of 1 element beginning of following element. if pass 0 stride, means tightly packed. if have array of floats, contains vertices this, x1,y1,z1,x2,y2,z2... , on, can set stride either 0 (as tightly packed), or 12 (3 floats*4 bytes each beginning of vertex 1 beginning of vertex two).

i not able mean ? helpful if explains of example.

thanks.

the simple case when array contains vertex coordinate data. have 2 coordinates, hence 6 floats:

{x1,y1,z1, x2,y2,y2} 

the pointer (4th parameter) points beginning of first vertex in array (i.e. zero, pointing x1). stride should 12, meaning move 1 vertex next, opengl needs move along 12 bytes (since each of 3 coordinates in each vertex takes 4 bytes). moving 12 bytes, x2 is, beginning of second vertex.

this example of tightly packed since array contains 1 type of data - can set stride 0 , opengl happily work way through array 1 float @ time. array doesn't have contain coordinate data - store normal , color data alongside coordinates in array well:

{x1,y1,z1,nx1,ny1,nz1,r1,g1,b1,a1, x2,y2,z2,nx2,ny2,nz2,r2,g2,b2,a2} 

this no longer tightly packed - coordinate data no longer contiguous in array (they separated normal , colour values). in case stride 40. beginning of 1 vertex next, opengl needs move along 40 bytes: (3 floats of coordinate data + 3 floats of normal data + 4 floats of colour data) x 4 bytes per float.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -