[osg-users] Bug while updating geometry in Linux

Nikita Petrov nikitapetroff at gmail.com
Thu Jan 26 03:55:24 PST 2017


Thanks, Robert!

Adding vertices->dirty(); worked perfect.
I even removed geometry->dirtyBound(); - I suppose I don't need it? Because my example works without that call.

It is strange why it is only noticable on Linux.

Nikita



robertosfield wrote:
> HI Nikita,
> 
> I don't have time to try and the example problem right now, my best
> guide having had a quick read through is that perhaps you need to a a
> vertices->dirty() after you've done the vertices->push_back().  For a
> straight GL vertex array this won't be required, but if you are using
> VBO's this will be required so the OSG knows to updload the data to
> the GPU.
> 
> Robert.
> 
> On 26 January 2017 at 09:27, Nikita Petrov <> wrote:
> 
> > Hi,
> > 
> > I am trying to port my app from Windows to Linux.
> > I have a ribbon, which is updated dynamically. I add 2 points to vertices and I use GL_TRIANGLE_STRIP to create a ribbon.
> > On Windows everything works fine.
> > But on Linux all new vertices go to coordinates (0,0,0) after calling geometry->dirtyBound();
> > 
> > I even created a small app to test this behaviour on Linux. It should draw sine function ribbon.
> > Here's the code:
> > 
> > osg::ref_ptr<osg::Vec3Array> vertices;
> > osg::ref_ptr<osg::Geometry> geometry;
> > osg::DrawArrays* drawArrays;
> > int count;
> > 
> > class UpdateVertex: public osg::NodeCallback
> > {
> > public:
> > UpdateVertex() {}
> > virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
> > };
> > 
> > void UpdateVertex::operator()(osg::Node* node, osg::NodeVisitor* nv)
> > {
> > OpenThreads::Thread::microSleep(1000);
> > 
> > vertices->push_back(osg::Vec3(1+count/200.0, 1, 1+sin(count*M_PI/180.0)));
> > vertices->push_back(osg::Vec3(1+count/200.0, 2, 1+sin(count*M_PI/180.0)));
> > count++;
> > 
> > drawArrays->setCount(vertices->size());
> > geometry->dirtyBound();
> > 
> > traverse(node, nv);
> > }
> > 
> > int main(int argc, char *argv[])
> > {
> > vertices = new osg::Vec3Array();
> > 
> > count = 120;
> > for (int i=0;i<count;i++)
> > {
> > vertices->push_back(osg::Vec3(1+i/200.0, 1, 1+sin(i*M_PI/180.0)));
> > vertices->push_back(osg::Vec3(1+i/200.0, 2, 1+sin(i*M_PI/180.0)));
> > }
> > 
> > osg::ref_ptr<osg::Vec3Array> normal = new osg::Vec3Array();
> > normal->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));
> > osg::ref_ptr<osg::Vec4Array> color = new osg::Vec4Array();
> > color->push_back(osg::Vec4(0,0,1,0.8f));
> > 
> > geometry = new osg::Geometry;
> > geometry->setDataVariance(osg::Object::DYNAMIC);
> > geometry->setUseDisplayList(false);
> > geometry->setVertexArray(vertices.get());
> > geometry->setNormalArray(normal.get());
> > geometry->setNormalBinding(osg::Geometry::BIND_OVERALL);
> > geometry->setColorArray(color.get());
> > geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
> > 
> > drawArrays = new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, vertices->size());
> > geometry->addPrimitiveSet(drawArrays);
> > 
> > osg::ref_ptr<osg::Geode> geode = new osg::Geode();
> > geode->addDrawable(geometry.get());
> > geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
> > 
> > osg::ref_ptr<osg::Group> root = new osg::Group();
> > 
> > root->addChild(geode.get());
> > 
> > root->addUpdateCallback(new UpdateVertex);
> > 
> > osgViewer::Viewer viewer;
> > viewer.setSceneData(root.get());
> > viewer.getCamera()->setSmallFeatureCullingPixelSize(0);
> > viewer.getCamera()->setClearColor(osg::Vec4(1,1,1,1));
> > viewer.addEventHandler(new osgViewer::StatsHandler);
> > 
> > viewer.realize();
> > 
> > return viewer.run();
> > }
> > 
> > And you can see what I get in the attachements.
> > If I press "S" to see number of vertices (thanks to StatsHandler), it is always increasing. So new vertices are added, but in (0,0,0) coordinates.
> > My guess is that geometry->dirtyBound(); is not working corectly.
> > 
> > I use master build of OSG.
> > On Windows I use x86 build with Visual Studio 2013.
> > On Linux Mint 18 Cinnamon 64-bit, I use x64 build with Qt Creator (GCC 64bit).
> > 
> > Hope that somebody have a clue to that issue.
> > 
> > Best regards,
> > Nikita
> > 
> > ------------------
> > Read this topic online here:
> > http://forum.openscenegraph.org/viewtopic.php?p=70051#70051
> > 
> > 
> > 
> > 
> > Attachments:
> > http://forum.openscenegraph.org//files/2_123.png
> > http://forum.openscenegraph.org//files/1_632.png
> > 
> > 
> > _______________________________________________
> > osg-users mailing list
> > 
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> > 
> _______________________________________________
> osg-users mailing list
> 
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 
>  ------------------
> Post generated by Mail2Forum


------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=70053#70053








More information about the osg-users mailing list