View Full Version : GLM : memory alignment, and pointer conversion

01-25-2010, 06:34 AM

I am starting to use GLM, and I have 2 questions :
- is memory alignment always guaranteed ? (I suppose yes, according to some quick tests I did).
What I mean is, are we always sure sizeof(fvec3) == 3*sizeof(float) ? Same for matrices, and any dimension.

- if this is the case (I hope so ^^), how can we convert the
objects to the corresponding pointer ?
In other words : how can I write a clean version of this :
float* p = static_cast<float*>((void*)(&amp;my_matrix));

- is the alignment the same as in OpenGL (i.e., when using a pointer as in my previous question, is p[0] p[1] p[2] p[3] the first column of a mat4 matrix ?)

Sorry for asking basic questions ^^

01-25-2010, 06:50 AM
- Yes (so far, it might evolved in the future with some new unaligned types ... not any time soon!)

- float* p = &amp;my_matrix[0][0];
#include <glm/gtx/type_ptr.hpp>
float* p = glm::value_ptr(my_matrix);

- my_matrix[0] => first column

01-25-2010, 07:32 AM
Ok, nice, just what I wanted, thanks :)

02-12-2010, 04:24 PM
Any chance to change

float* p = glm::value_ptr(my_matrix);

to something easier to write... like

float* p = my_matrix.ptr(); or
float* p = my_matrix.raw();

ptr() will do same thing as value_ptr.. return const T*