[osg-users] Why is setTexCoordArray(0, texcoords) needed if array is modified in-place
Florian Castellane
fixed-term.florian.castellane at bosch.com
Thu Jul 7 02:25:05 PDT 2016
Greetings fellow OSG users :)
There is a detail in my code that I found disturbing:
Code:
void applyTextureToCenter( MyNameSpace::SpecificNode* floor )
{
MyNameSpace::MyGeode* center = floor->getCenterGeode() ;
osg::StateSet* stateSet = center->getOrCreateStateSet() ;
MyNameSpace::MyGeometry* geometry = center -> getGeometry() ;
const osg::DrawElementsUShort* indices = geometry -> getIndexArray() ;
const osg::Vec3Array* vtxArray = static_cast<osg::Vec3Array*>( geometry->getVertexArray() ) ;
osg::Vec2Array* texArray = floor ->getTexCoordArray() ;
const unsigned numVertex = geometry->getVertexArray()->getNumElements() ;
const unsigned numIndices = geometry->getIndexArray() ->getNumIndices() ;
for ( unsigned id = 0 ; id < numIndices ; ++id )
{
const unsigned idx = (*indices)[id] ;
osg::Vec2 uv ;
/* *snip*
* some texture coordinates computation
*/
(*texArray)[idx].set( uv.x(), uv.y() ) ;
}
geometry->setTexCoordArray( 0, texArray ) ; //Why is this needed ?
/* *snip*
* Code setting the stateSet parameters (shader program, uniforms...)
*/
return ;
}
I don't understand why the line
Code:
geometry->setTexCoordArray( 0, texArray ) ;
is needed. AFAIK since texArray points to the value given by getTexCoordArray(), we are not actually changing anything... :?
I was thinking that maybe it was because setTexCoordArray() caused dirty() to be called, causing re-evaluation of the texture coordinates, but calling
Code:
geometry->getTexCoordArray(0)->dirty() ;
is not enough for my texture to be displayed.
So I went on and looked at the code for setTexCoordArray:
Code:
openscenegraph/OpenSceneGraph/blob/master/src/osg/Geometry.cpp
I see that it is calling
Code:
geometry->dirtyDisplayList() ;
but since we are using VBOs (Vertex Buffer Objects) and not display lists that should not do anything.
The code is also calling
Code:
geometry->addVertexBufferObjectIfRequired()
, which should itself call
Code:
texArray->setVertexBufferObject(geometry->getOrCreateVertexBufferObject());
, which AFAIK should not be changing anything here either, since it is setting the array to use the existing VBOs (which should already be the case).
What is your take on this? There must be something I'm missing.
Thank you!
Best regards,
Florian.
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=68035#68035
More information about the osg-users
mailing list