PDA

View Full Version : VBO and Normal Array



brtnrdr
04-24-2007, 02:14 PM
Hi,

I have a buffer object filled with vertex data and another buffer object filled with normals. I generate this data using a fragment shader and render them into 32-bit RGBA textures and copy them into buffer objects using PBO's. The vertices render fine, my question regards specifying the normal array.

I make the call:
glNormalPointer(GL_FLOAT,16,0) with the normal buffer object bound and the normals are mostly correct.
What I don't understand is why 16 is the stride. The documentation says it's the byte offset between normals, since I'm using RGBA textures I would think that the stride would be sizeof(float), but the way it is, it seems like there is a whole RGBA set between normals?
Am I mistaken thinking it should be sizeof(float) or do I maybe have a different bug?

Thanks.

Relic
04-25-2007, 12:38 AM
Normals always have three components, with type float that's at least 12 bytes between two normals.
If your data is RGBA32F (you didn't show how you get the data back from the rendering), that's 4 * sizeof(float) per pixel (normal).

Think of it as normal array data with a dummy float, which is a waste, but no problem:
float normal.x
float normal.y
float normal.z
float unused

Different example: If you have a standard vertex array and interleave your normal and color data like this:
float normal.x
float normal.y
float normal.z
unsigned char color.r
unsigned char color.g
unsigned char color.b
unsigned char color.a
that would also be a stride of 16 bytes between two normals. Perfectly ok.

brtnrdr
04-25-2007, 06:48 AM
I see now, if 0 is specified for stride then the data is considered tightly packed, but if it is not tightly packed then you have to take the size of the data into account.

Thanks.