PDA

View Full Version : glUniform: Matrix representation



GreenOwl
08-14-2013, 07:25 AM
Hello,

I'm using OpenGL with C++ through glew. Two simple questions:
1) What format does the matrix (as GLfloat[]) for the function glUniformMatrix__ has to have? I couldn't find any information in the doc nor google.
2) Is the following safe to do:

GLfloat* vertexBuffer = new GLfloat[dynamicSize];
glBufferData(GL_ARRAY_BUFFER, dynamicSize * 4, vertexBuffer, GL_STATIC_DRAW);
delete[] vertexBuffer;
I ask, because I read somewhere, that OpenGL calls aren't necessarily issued instantly and the pointer might be invalid if the "upload into vram" happens to late.

Thanks!

GClements
08-14-2013, 09:25 AM
1) What format does the matrix (as GLfloat[]) for the function glUniformMatrix__ has to have?

It's just MxN floats, e.g. 16 floats for glUniformMatrix4fv(), 6 floats for glUniformMatrix2x3fv(), etc. The elements are in column-major order if the "transpose" argument is false or row-major order if it's true. The interpretation of the matrix is up to the shader.



2) Is the following safe to do:

GLfloat* vertexBuffer = new GLfloat[dynamicSize];
glBufferData(GL_ARRAY_BUFFER, dynamicSize * 4, vertexBuffer, GL_STATIC_DRAW);
delete[] vertexBuffer;

Yes.


I ask, because I read somewhere, that OpenGL calls aren't necessarily issued instantly and the pointer might be invalid if the "upload into vram" happens to late.
Apart from the gl*Pointer functions (glVertexPointer etc), any data referenced by a pointer will be copied before the function returns. In the case of the gl*Pointer functions, the data will be copied before the corresponding draw call (glDrawArrays etc) returns.