Hi all,

I am currently trying to pass a matrix array as a VertexAttrib array for a vertex shader.

The first thing I did was to define a MatrixArray type the same way other matrix types are defined:
(in the Array header): typedef TemplateArray<Matrixf,Array::MatrixArrayType,16,GL_FLOAT> MatrixArray;

But then I realized that glVertexAttrib is only able to take Vec4's ... According to the OpenGL ref, the way to pass matrix arrays to a vertex shader is to decompose it into Vec4 columns and to pass them separately:

ref_ptr<Vec4Array> column0Array, column1Array, column2Array, column3Array;
...
geometry->setVertexAttribArray(vaslot, column0Array.get();
geometry->setVertexAttribArray(vaslot+1, column1Array.get();
geometry->setVertexAttribArray(vaslot+2, column2Array.get();
geometry->setVertexAttribArray(vaslot+3, column3Array.get();
...
program->addBindAttribLocation("myMatrix", vaslot);

and then a mat4 can be directly define in the shader: "mat4 myMatrix"....

The problem is that I don't want to maintain separate arrays for separate matrix columns, as it's not very convenient for the calcutations I do. I have no idea how to pass these attribs in another way. Is it possible to specify a "stride" parameter in the glVertexAttribArray function called by OSG for each row and then do a matrix transpose in the shader ??? Maybe I'm trying to do it in a wrong way...

Best regards,

Edmond


_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to