OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

ViewerBase::frame() method slow after changing the color of a geometry


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
gambr
Appreciator


Joined: 22 Jun 2010
Posts: 350

PostPosted: Fri Jul 21, 2017 9:11 am    Post subject:
ViewerBase::frame() method slow after changing the color of a geometry
Reply with quote

Hi All,
I build a huge geometry (27 milion vertices, 9 milion triangles) as follows:

osg::Geometry* geometry = new osg::Geometry;
geometry->setDataVariance(osg::Object::DYNAMIC);
geometry->setVertexArray(buildVertices(count));
geometry->setColorArray(buildColors(count), osg::Array::BIND_PER_VERTEX);
geometry->addPrimitiveSet(buildElements(count));

On mouse event, after getting an intersection with the graphics, I do:

osg::Geometry* geom = dynamic_cast<osg::Geometry*>(intersection.drawable.get());
osg::Vec4Array& color = dynamic_cast<osg::Vec4Array&>(*geom->getColorArray());
color[intersection.indexList[0]] = selectedColor;
color[intersection.indexList[1]] = selectedColor;
color[intersection.indexList[2]] = selectedColor;
geom->dirtyDisplayList();
color.dirty();

The problem is that after these lines there is a delay of at least one second before seeing the triangle with the updated color on my 3D viewer.
Debugging OSG code I found that "ViewerBase::frame()" is called twice before seeing the new color. Moreover the first time "frame()" is called "renderingTraversals()" takes a lot.

I will debug the OSG code deeper but is there a way to prevent the delay I see in my application?
You can find the full example in attachment.

Thanks for your help,
Gianni
Back to top
View user's profile Send private message
errno (Lionel Lagarde)
User


Joined: 10 Mar 2009
Posts: 54
Location: Toulouse, France

PostPosted: Fri Jul 21, 2017 9:25 am    Post subject:
ViewerBase::frame() method slow after changing the color of a geometry
Reply with quote

I don't know about the double frame but the default for geometries (drawables in fact) is to use OpenGL display lists (depending on the OSG compilation).
OpenGL display lists creation takes time. The dirtyDisplayList method forces OSG to re-create the OpenGL display list.



The solution is to force the geometry to use vertex arrays:
geometry->setUseDisplayLists(false);

On 21/07/2017 11:11, Gianni Ambrosio wrote:
Quote:
Quote:
Hi All,
I build a huge geometry (27 milion vertices, 9 milion triangles) as follows:

osg::Geometry* geometry = new osg::Geometry;
geometry->setDataVariance(osg::Object::DYNAMIC);
geometry->setVertexArray(buildVertices(count));
geometry->setColorArray(buildColors(count), osg::Array::BIND_PER_VERTEX);
geometry->addPrimitiveSet(buildElements(count));

On mouse event, after getting an intersection with the graphics, I do:

osg::Geometry* geom = dynamic_cast<osg::Geometry*>(intersection.drawable.get());
osg::Vec4Array& color = dynamic_cast<osg::Vec4Array&>(*geom->getColorArray());
color[intersection.indexList[0]] = selectedColor;
color[intersection.indexList[1]] = selectedColor;
color[intersection.indexList[2]] = selectedColor;
geom->dirtyDisplayList();
color.dirty();

The problem is that after these lines there is a delay of at least one second before seeing the triangle with the updated color on my 3D viewer.
Debugging OSG code I found that "ViewerBase::frame()" is called twice before seeing the new color. Moreover the first time "frame()" is called "renderingTraversals()" takes a lot.

I will debug the OSG code deeper but is there a way to prevent the delay I see in my application?
You can find the full example in attachment.

Thanks for your help,
Gianni

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





Quote:
_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message Send e-mail
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11021

PostPosted: Fri Jul 21, 2017 9:33 am    Post subject:
ViewerBase::frame() method slow after changing the color of a geometry
Reply with quote

Hi Gianni,


As Lionel explains if you have display lists enabled (they are by default) then rebuilding the display list will create a big cost.  Not using display lists will avoid this one off cost, but it will increase the cost of rendering on some drivers.


However, I would recommend you take a step back and learn a bit more what you are expecting your computer to do with your dataset and how the drivers/hardware will be handle the type of dataset you are working with.  From what you describe of your data and how you are doing things you should absolutely expect things to crawl along.  When you are dealling with big data you need to be smarter how you deal with your data.


Your dataset is very heavy on vertices and triangles. The 3:1 ratio between vertices and triangles suggest that no vertices are shared.  This itself suggests that the dataset may well be poorly optimized as well - with this size of dataset you should be doing everything you can to remove duplicates vertices.


The second observation I'd make is that with huge datasets modern hardware/drivers perform far better when you break them down into small chunks, so rather than a very small number of very large osg::Geometry, you have a moderate number of moderately size osg::Geometry.  This will help the OSG with culling and will help the graphics hardware handle this amount of data far better.  Using VBO's instead of Display Lists will also provide a big improvement.



Robert.




On 21 July 2017 at 10:11, Gianni Ambrosio <g.ambrosio+ ([email]g.ambrosio+[/email])> wrote:
Quote:
Hi All,
I build a huge geometry (27 milion vertices, 9 milion triangles) as follows:

        osg::Geometry* geometry = new osg::Geometry;
        geometry->setDataVariance(osg::Object::DYNAMIC);
        geometry->setVertexArray(buildVertices(count));
        geometry->setColorArray(buildColors(count), osg::Array::BIND_PER_VERTEX);
        geometry->addPrimitiveSet(buildElements(count));

On mouse event, after getting an intersection with the graphics, I do:

        osg::Geometry* geom = dynamic_cast<osg::Geometry*>(intersection.drawable.get());
        osg::Vec4Array& color = dynamic_cast<osg::Vec4Array&>(*geom->getColorArray());
        color[intersection.indexList[0]] = selectedColor;
        color[intersection.indexList[1]] = selectedColor;
        color[intersection.indexList[2]] = selectedColor;
        geom->dirtyDisplayList();
        color.dirty();

The problem is that after these lines there is a delay of at least one second before seeing the triangle with the updated color on my 3D viewer.
Debugging OSG code I found that "ViewerBase::frame()" is called twice before seeing the new color. Moreover the first time "frame()" is called "renderingTraversals()" takes a lot.

I will debug the OSG code deeper but is there a way to prevent the delay I see in my application?
You can find the full example in attachment.

Thanks for your help,
Gianni

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




_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
gambr
Appreciator


Joined: 22 Jun 2010
Posts: 350

PostPosted: Fri Jul 21, 2017 10:32 am    Post subject:
Reply with quote

Thanks Lionel and Robert for the quick reply.

I tried what Lionel suggested but in fact the geometry generation is much more slow now.
Anyway, since I suspected that "dirtyDisplayList()" is the cause of the delay, I tried to remove that line but without it I cannot see the new color.
Now, is "dirtyDisplayList()" really required for what I need or is there a different call should I use just to see the triangle with the updated color?

Thanks,
Gianni
Back to top
View user's profile Send private message
errno (Lionel Lagarde)
User


Joined: 10 Mar 2009
Posts: 54
Location: Toulouse, France

PostPosted: Fri Jul 21, 2017 10:58 am    Post subject:
ViewerBase::frame() method slow after changing the color of a geometry
Reply with quote

If you use display lists, you have to tell OSG that it has to re-build it.

If you use vertex arrays, colors->dirty() should be enough.



On 21/07/2017 12:32, Gianni Ambrosio wrote:
Quote:
Thanks Lionel and Robert for the quick reply.

I tried what Lionel suggested but in fact the geometry generation is much more slow now.
Anyway, since I suspected that "dirtyDisplayList()" is the cause of the delay, I tried to remove that line but without it I cannot see the new color.
Now, is "dirtyDisplayList()" really required for what I need or is there a different call should I use just to see the triangle with the updated color?

Thanks,
Gianni

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










------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message Send e-mail
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11021

PostPosted: Fri Jul 21, 2017 12:57 pm    Post subject:
ViewerBase::frame() method slow after changing the color of a geometry
Reply with quote

Hi Gianni,

On 21 July 2017 at 11:32, Gianni Ambrosio <g.ambrosio+ ([email]g.ambrosio+[/email])> wrote:
Quote:
I tried what Lionel suggested but in fact the geometry generation is much more slow now.
Anyway, since I suspected that "dirtyDisplayList()" is the cause of the delay, I tried to remove that line but without it I cannot see the new color.
Now, is "dirtyDisplayList()" really required for what I need or is there a different call should I use just to see the triangle with the updated color?


If you use display lists and you modify the osg::Geometry you need to call dirtyDislplayList() to force OSG to recompile.


What you need to do is to break your dataset into smaller chunks, 10,000 vertices per osg::Geometry is a reasonable level of granularity.  Using VertexBufferObjects rather than DisplayLists is also something you should do.  Finally optimize the dataset so you don't have some many vertices by making sure the triangle share vertices where possible - you'll need to use osg::DrawElementsUInt/UShort to use indices.


Doing these above steps will resolve most of the problems you have been presenting recently.  If want to handle big datasets these are the steps you absolutely need to do.



Robert.








 

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
gambr
Appreciator


Joined: 22 Jun 2010
Posts: 350

PostPosted: Fri Jul 21, 2017 1:17 pm    Post subject:
Reply with quote

Hi Lionel,
thanks for the explanation. So, that information is stored into the DL.

On the other side I can confirm that the color is updated correcly without "geometry->dirtyDisplayList()" if DL is not used. But unfortunately, for huge a geometry, creation is extremely slow (the example application hangs for about 4 minutes at startup).

Thanks for the support,
Gianni
Back to top
View user's profile Send private message
gambr
Appreciator


Joined: 22 Jun 2010
Posts: 350

PostPosted: Fri Jul 21, 2017 1:17 pm    Post subject:
Reply with quote

Thank you very much Robert,
I will do as you suggested.

Gianni
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts osgUtil::IntersectionVisitor slow wit... gambr General 4 Tue Jul 18, 2017 10:17 am View latest post
No new posts How to color each character of an osg... lq37 General 0 Thu Jun 22, 2017 1:31 pm View latest post
No new posts background color for osgWidget::Input Meldryt General 0 Tue Jun 20, 2017 12:36 pm View latest post
No new posts changing dimensions of a box matthias_os General 4 Tue May 30, 2017 1:06 pm View latest post
No new posts draw primitive sets and geometry shad... wernerM General 0 Wed May 24, 2017 3:20 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP