somboon

04-09-2011, 04:23 AM

I am in the process of redesign my renderer and has considered using GLM as a math liblary

The question is How should I use the liblary.

Should I declare every matrix/vector in my engine as GLM data type so that the math operation can be done quickly with out having to convert from raw data.

std::vector<glm::vec4> vertexList;

std::vector<glm::vec4> transformdVertexList;

glm::mat4 someMatrix;

//assume initialized of above data

for(unsigned int i=0;i<vertexList.size();i++){

transformdVertexList[i] = someMatrix*vertexList[i];

}

//send transformdVertexList to VBO (dont know the syntax)

which I dont know how to send the array of glm::vec4 to openGL/shader (the sample on site only demonstarte using glm::value_ptr to send individual object but no mention of array)

Or should I keep the data as raw float array like I always do (actually it encapsulate in simple struct...you know what I mean) and only create GLM datatype when doing math operation

typedef struct{

float element[4];

}raw_vec4;

typedef struct{

float element[16];

}raw_mat4;

std::vector<raw_vec4> vertexList;

std::vector<raw_vec4> transformedVertexList;

raw_mat4 someMatrix;

//some calculation

//assume initialized of above data

glm::mat4 someMatrixGLM(someMatrix.element);//is this correct syntax?

for(unsigned int i=0;i<vertexList.size();i++){

vec4 vertexGLM(vertexList[i].element);

vec4 tfVertexGLM = someMatrixGLM*vertexGLM();

memcpy(transformedVertexList[i].element,glm::value_ptr(tfVertexGLM),sizeof(float) *4);

}

//send transform array to VBO/shader as usual

Any suggestion would be appreciate.

somboon

The question is How should I use the liblary.

Should I declare every matrix/vector in my engine as GLM data type so that the math operation can be done quickly with out having to convert from raw data.

std::vector<glm::vec4> vertexList;

std::vector<glm::vec4> transformdVertexList;

glm::mat4 someMatrix;

//assume initialized of above data

for(unsigned int i=0;i<vertexList.size();i++){

transformdVertexList[i] = someMatrix*vertexList[i];

}

//send transformdVertexList to VBO (dont know the syntax)

which I dont know how to send the array of glm::vec4 to openGL/shader (the sample on site only demonstarte using glm::value_ptr to send individual object but no mention of array)

Or should I keep the data as raw float array like I always do (actually it encapsulate in simple struct...you know what I mean) and only create GLM datatype when doing math operation

typedef struct{

float element[4];

}raw_vec4;

typedef struct{

float element[16];

}raw_mat4;

std::vector<raw_vec4> vertexList;

std::vector<raw_vec4> transformedVertexList;

raw_mat4 someMatrix;

//some calculation

//assume initialized of above data

glm::mat4 someMatrixGLM(someMatrix.element);//is this correct syntax?

for(unsigned int i=0;i<vertexList.size();i++){

vec4 vertexGLM(vertexList[i].element);

vec4 tfVertexGLM = someMatrixGLM*vertexGLM();

memcpy(transformedVertexList[i].element,glm::value_ptr(tfVertexGLM),sizeof(float) *4);

}

//send transform array to VBO/shader as usual

Any suggestion would be appreciate.

somboon