if I remember correctly.
I’ve just been reading the ATi R500 full hardware whitepaper (http://www.x.org/docs/AMD/) and there’s no way to directly specify a matrix as an attribute on their Shader3 gpus.
P.S when you specify
attribute mat4 MyMat; , it probably automatically generates 4 vertex attributes (vec4 each), with consecutive Index.
So, you’ll use this to set matrices:
glVertexAttribPointer(MyMatID+0, …);
glVertexAttribPointer(MyMatID+1, …);
glVertexAttribPointer(MyMatID+2, …);
glVertexAttribPointer(MyMatID+3, …);
I’ve only verified this with looking at the assembly code, generated by the compiler.
Thank you guys I know that I can “emulate” a matrix just sending four vectors, what I am trying to understand is: what is the “official way” of doing it given the fact that according to the documentation there should be a way to do it.
Mine is actually more and intellectual challenge than a real need, but since I am writing some wrapper functions around GLSL I would like to know how to deal, in a clean way, with this feature.
I tryed to put the whole matrix as a vertex attribute giving 4 GL_FLOAT components to glVertexAttribPointer but if for example I read the first column of the matrix from the vertex shader, (using nVidia 8600GT) I get the first row of the first matrix when processing the first vertex, the second row of the first matrix when processing the second vertex and so on. I know I probably did’t explain in the best way…
But the interesting thing is that the matrix attribute eats up 4 indices! If anyone knows a possible usage of this feature I would like to hear it, otherwise I will probably just skip the support for it.
Thank you HexCat,
it actually turned out also for me that you have to specify each column of the matrix on a different vertex attribute, which as you showed are allocated consecutively, finally everything is clear!
… now we just have to invent a useful way to use this feature
Personally, I use this feature to consolidate three vertex attributes (Tangent, Bitangent, and gl_Normal) into one mat3 attribute for transforming normal map normals into eye space for reflective bumpmapping.
Thank you very much HexCat, this usage is a text-book level one! this moves this feature from my “almost deprecated wish list” to the “must have features list”
Thank you guys I know that I can “emulate” a matrix just sending four vectors, what I am trying to understand is: what is the “official way” of doing it given the fact that according to the documentation there should be a way to do it.
This is the official way to do it. An attribute in OpenGL is defined as a vector, not a matrix. So the only way to actually send a matrix attribute is to send it as multiple vectors.
But the interesting thing is that the matrix attribute eats up 4 indices!
Got it,
maybe is useful to recap then, taking Ilian example, he wasn’t sure about it but it seems that we can “officialize” it:
attribute mat4 MyMat;
generates 4 vertex attributes (vec4 each), with consecutive indices: this is why a mat4 eats up 4 indices. Infact if you try to bind a matrix to index 14 for example, the GLSL linker it will give you an error if your GLSL implemententation supports maximum 16 indices like on my Geforce 8600 GT.
Of course that it doesn’t work. Do you know the meaning of the last two parameters? If you are referring to the same VBO, offsets cannot be 0 for all attributes, as well as stride.