View Full Version : vertex VBO + color VBO with different sizes=crash?
11-27-2011, 02:57 AM
Hi OpenGL community.
Hope you can help on this. :)
I have two VBO:
- one of N vertex
- one of less that N color
On linux, it work "well". The color is "nothing" (random value depending of the memory I suppose but it work, OpenGL can draw).
On Mac, this seems to be a problem. It segfault on glDrawElement.
My question is pretty simple for an advanced OpenGL user:
Is it normal it crash if VBOs doesn't have a coherent size?
If so, I suppose I have to manually feed the rest of the color VBO with empty color. Am I right?
Thanks in advance! :)
11-27-2011, 10:06 AM
All of the vertex attribute arrays will need to be the same length - the length specified by glDrawElements.
11-27-2011, 11:46 AM
So if you have a vertex VBO of 3*N elements, you need a color VBO of 4*N elements (I use Alpha).
Thanks for the answer! :)
11-28-2011, 02:48 AM
You're confusing the size of the array with the number of elements of the vertex attribute.
Whatever vertex attributes you are enabling (vertex/position/normal/color), they must all have the same number of elements (number of elements != array size).
Vertex color array can have 4 components (RGBA) per vertex, whereas normals always have 3 (XYZ). So the normal array must be (numVerts*3) and color array (numVerts*4). The array sizes differ, but they have the same number of vertices (elements).
If the attribute arrays do not have the same number of elements, it may result in undefined behavior according to the GL specification. On most decent GL implementations, you might get zeroes (the black you describe) or garbage (essentially zero or non-zero random values as the driver/hardware is accesing memory outside where it should not be allowed). If the graphics drivers are crappy, they may crash the application as happens for you on Mac. On many platforms, this undefined behavior is generally forgiving for backwards compatibility. There are a lot of legacy games/applications out there that would otherwise be unusable.
11-28-2011, 04:15 AM
No no! Really! I think I understand the difference between number of elements and array size (even if I wasn't clear). :(
On most decent GL implementations, you might get [...] garbage (essentially zero or non-zero random values as the driver/hardware is accesing memory outside where it should not be allowed).
This is what I have on Linux.
So I suppose I just have to garbage the color VBO and this should solve the problem.
Thanks again. :)
PS: Very nice and interesting web site @remdul. :) Keep the good work!
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.