I am currently developing a OpenGL application. So far everything worked well while programming the API.
For the usual datatypes I use structs. For instance:
struct vec3 {
GLfloat x;
GLfloat y;
GLfloat z;
}
But now I considered to use the same datatypes as simple arrays, for instance
typedef GLfloat vec3[3];
I really like to handle the types as simple arrays since it is easier to access them and I can even use loops to modify their values (for instance in GLfloat matrix[16]) However what kind of annoys me is that C does not allow to return arrays, so I have to provide the storage for operations myself mat4_identity(mat4 output) With a structure I could easily say
mat4 m = mat4_identity() clean and nicely.
My question now is: Which one is better performance wise (of course when having many verticies for instance, I can only think of heavy struct pointer dereferences + acesses) and which one should I actually use in the end for my OpenGL API.
struct vec3 { GLfloat vec3[3]; }?struct vec3 { union { struct { float x, y, z; }; float a[3]; };