GLM : memory alignment, and pointer conversion

Hi,

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*)(&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 ^^

  • Yes (so far, it might evolved in the future with some new unaligned types … not any time soon!)

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

  • my_matrix[0] => first column

Ok, nice, just what I wanted, thanks :slight_smile:

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*