Hi all
I want to pass a custom vertex attribute (lets say a material code) to my vertex shader.
For the moment I use BIND_PER_VERTEX:
[code]
int l_SMC = 1027; // some material code
for (unsigned int i=0; i<a_geode.getNumDrawables(); ++i)
{
osg::Geometry* l_Geom = a_geode.getDrawable(i)->asGeometry();
if (l_Geom)
{
osg::Array* l_VertexArray = l_Geom->getVertexArray();
if (l_VertexArray)
{
unsigned int vertex_count = l_VertexArray->getNumElements();
osg::IntArray* l_Array = new osg::IntArray;
for (int v=0; v<vertex_count; v++)
{
l_Array->push_back(l_SMC);
}
l_Geom->setVertexAttribArray(6, l_Array);
l_Geom->setVertexAttribNormalize(6, false);
l_Geom->setVertexAttribBinding(6, osg::Geometry::BIND_PER_VERTEX);
}
}
}
[/code]
,
Since the material code is unique within geometries, so actually I would need to transfer it only once per Geometry. If I change to BIND_OVERALL, the data is no longer transferred, or at least my shader cannot detect it anymore. I thought i should maybe reduce the VertexAttribArray (l_Array) to one single entry, but this doesn't work either.
What is the correct way of passing general or common data, on a per geometry (and not vertex) basis?
"If a generic vertex attribute bound to an attribute variable in a vertex shader is not updated while the vertex shader is executing, the vertex shader will repeatedly use the current value for the generic vertex attribute."So it seems that BIND_OVERALL should be working just fine.