can I safely use the glm::* types (e.g. vec4, mat4) to fill a vertex buffer object ?
std::vector<glm::vec3> vertices;
glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * vertices.size(), &vertices[0], GL_STATIC_DRAW);
I'm not quite sure about that since struct padding (member alignment) could cause some trouble in my opinion, though all compilers I've tested returns the expected sizes.
I'm developing for C++11 Compilers (maybe this make a difference).
Define "safe".
C++ gives implementations wide latitude to pad structures as they see fit. So as far as ISO C++ is concerned, whether this "works" is implementation-dependent behavior.
It will work in general across a number of compilers for desktop platforms. I can't speak for ARM CPUs, but generally, glm::vec3
will be 3 floats in size. However, if you want to make sure, you can always perform a simple static_assert
:
static_assert(sizeof(glm::vec3) == sizeof(GLfloat) * 3, "Platform doesn't support this directly.");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With