So, a critical requirement for OpenGL programming is that you store your vertices in a fashion that guarantees contiguous memory. I've read a couple decent books lately by professional graphics programmers, and both of them used a variation of the same idea: packaging vertices into a struct
of 3 floats
, x,y,z, and then packaging multiple vertices into either a c-style array or std::vector
of these structs
. And it works.
But I've seen it said time and again on this site that a struct
does not guarantee memory contiguity. It has been said that if your struct contains all floats
then they will probably be contiguous, but it is not guaranteed. The array
and std::vector
do guarantee it, but that's irrelevant if what you are putting into the array or vector is not contiguous.
For production code, I would expect that "probably" doesn't cut it. So despite the suggestion in these two books, which are clearly geared more for learning, I'd like to know what are some other good techniques for easily organizing vertex data in a way that guarantees contiguous memory, or, I'd accept the advice that I shouldn't worry about this, that probably should be good enough.
What are other common and good methods used in the graphics field?