This is both a very simple and very complex question. So I'll start from the simple way first.
If you're looking to build some struct
out of GLM types, upload them to a buffer, and access them via glVertexAttribPointer
, you can probably get away with it on most C++98/03 compilers. Assuming you get offsets properly. It won't be "portable C++"; as far as the standard is concerned, it will be implementation-defined behavior (or undefined behavior if you try to use the offsetof
macro. Granted, anything you might use in place of offsetof
will be no less well defined by the standard).
But it will generally work.
In a conforming C++11 compiler, the GLM types will be considered standard layout types, and therefore offsetof
has well-defined behavior. And as long as your Vertex
structure is also standard layout, offsetof
will work.
However, that doesn't mean that the internal structure of any of these types will not have arbitrary padding. A glm::vec3
is not required to be layout-compatible with a float[3]
, which is what OpenGL would expect. The C++ standard won't protect you.
That being said, it's pretty safe to assume for most compilers you will encounter that GLM's types will be equivalent to arrays. GLM even provides the type_ptr
function to get a pointer to the contents of one of its types as an array, under the expectation that the compiler will make them compatible.
Similarly, the C++ standard provides no guarantees that a float[16*n]
will be layout-compatible with an array of glm::mat4[n]
. But again, it's fairly safe to assume that it will just work.