Hello,
I've been playing with multi-texturing and have encountered a situation where I
get a vector subscript out of range error. Typically, it's easy to spot the
cause of this, but this one has me a bit stumped.
I've boiled down the problem to what appears to be an issue with converting
geometry tex coord arrays to vertex attributes using the osgBuiltIn code. That
is, if I specify more than five tex coord arrays for a geometry object, the osg
built-in vertex attribute conversion code seems to have issues.
For reference, here's the function to enable osg built-in's:
Code:
void enableOsgBuiltIns( osgViewer::Viewer viewer )
{
// switch on the FnUniforms that track the modelview and projection
matrices
osgViewer::Viewer::Windows windows;
viewer.getWindows(windows);
for(osgViewer::Viewer::Windows::iterator itr = windows.begin(); itr !=
windows.end(); ++itr)
{
(*itr)-getState()-setUseModelViewAndProjectionUniforms(true);
(*itr)-getState()-setUseVertexAttributeAliasing(true);
}
};
Next is my code which adds textures to an existing geometry object:
Code:
void RenderStage::addInputTexture ( osg::Texture2D* tex, const std::string
texName = )
{
osg::StateSet* ss = this-getOrCreateStateSet();
int textureCount = ss-getNumTextureAttributeLists();
ss-setTextureAttributeAndModes( textureCount, tex );
if( usingRttQuad_ )
{
osg::Geometry* geom =
geometry_-asGeode()-getDrawable(0)-asGeometry();
geom-setTexCoordArray( textureCount, geom-getTexCoordArray(0)
);
}
};
The quad code is:
Code:
osg::Geode* RenderStage::createRttQuad()
{
osg::ref_ptrosg::Vec3Array quad_coords = new osg::Vec3Array; // vertex
coords
// counter-clockwise
quad_coords-push_back(osg::Vec3d(0, 0, -1));
quad_coords-push_back(osg::Vec3d(1, 0, -1));
quad_coords-push_back(osg::Vec3d(1, 1, -1));
quad_coords-push_back(osg::Vec3d(0, 1, -1));
osg::ref_ptrosg::Vec2Array quad_tcoords = new osg::Vec2Array; // texture
coords
quad_tcoords-push_back(osg::Vec2(0, 0));
quad_tcoords-push_back(osg::Vec2(1, 0));
quad_tcoords-push_back(osg::Vec2(1, 1));
quad_tcoords-push_back(osg::Vec2(0, 1));
osg::Geometry* quad_geom = new osg::Geometry;
quad_geom-setVertexArray(quad_coords.get());
osg::ref_ptrosg::DrawArrays quad_da = new
osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4);
quad_geom-setTexCoordArray(0, quad_tcoords.get());
quad_geom-addPrimitiveSet(quad_da.get());
osg::Geode* node = new osg::Geode;
node-addDrawable( quad_geom) ;
return node;
};
So here's what I've observed:
1. If I do not enable OSG builtin's, I have no error.
2. With built-in's enabled, I can eliminate the error if I comment out the
following line in my addInputTexture() fuunction:
Code:
geom-setTexCoordArray( textureCount, geom-getTexCoordArray(0) );
The reason this line is there is because I'm using an RTT camera and,
naturally, wish to use the same quad geometry for multiple textures. Of
course, for each new texture, I also assign texture coordinates to the
corresponding unit, which is just a copy of the original texture coordinate
array pointer. Perhaps that approach is wrong, but it escapes me as to why it
appears to work fine up to tex unit four.
Granted, I could just reference the unit 0 tex coord array for all textures,
but now that this inexplicable error has appeared, I am worried there may be
more going on that I need to understand. Given that the gl_MultiTexCoord
built-in has indices ranging from 0 to 8, I am confused as to why the
osgBuiltIn's code appears to choke on texture coords assigned to units over 4...
--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=48461#48461
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org