Hi Aitor,
I need to pass an array of matrix to a vertex program. I do as follow:
Code:
osg::Matrixf boneMatrices[MAX_BONES];
Uniform *g_boneMatrixUniform = new Uniform("boneMatrices",*boneMatrices);
cylinderStateSet->addUniform(g_boneMatrixUniform);
//update
cylinderStateSet->getUniform("boneMatrices")->set(*boneMatrices);
Code:
//vertex program
uniform mat4 boneMatrices[3];
The code complie and runs ok, but in the vertex program only pick up right the
first matrix.
What´s the problem?!
You need to pass the number of elements to the osg::Uniform constructor,
or else it defaults to 1 which explains the behavior you're seeing. The
constructor's signature is:
Uniform (Type type, const std::string &name, int numElements=1);
The convenience constructors (that take the name and value) are only for
single element uniforms, not arrays.
So change that initialization code to:
osg::Matrixf boneMatrices[MAX_BONES];
Uniform *g_boneMatrixUniform =
new Uniform(osg::Uniform::FLOAT_MAT4, "boneMatrices", MAX_BONES);
cylinderStateSet->addUniform(g_boneMatrixUniform);
for (unsigned int i = 0; i < MAX_BONES; ++i)
boneMatrixUniform->setElement(i, boneMatrices[i]);
And also change the update code to look like the above loop.
That should work.
Hope this helps,
J-S
--
______________________________________________________
Jean-Sebastien Guay [email protected]
http://www.cm-labs.com/
http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org