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 

Updating scene properties instead of recreating it each frame


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


Joined: 25 Jun 2018
Posts: 16

PostPosted: Mon Jul 02, 2018 5:34 am    Post subject:
Updating scene properties instead of recreating it each frame
Reply with quote

Hi. I'm wandering if it's ok what i'm doing and how to do it properly.

I have data of primitives which comes from source periodically. These primitives are points, lines, polygons. They have different sizes, colors, vertices, etc. My first approach was to create a new subscene each time i receive new data and replace a current node to a new one. But to create a new scene each frame is not very fast operation(a lot of allocations /deallocations). So instead of that I've decided to update existing scene by changing vertices, primitive types, etc. But I'v noticed that some data somewhat cached. For example.

Code:

osg::Vec3Array& vertices = static_cast<osg::Vec3Array&>(*geometry.getVertexArray());
vertices.clear();
for (int i = 0; i < logPolygon.points.size(); i++)
{
    auto& point = logPolygon.points[i];
    vertices.push_back(osg::Vec3(point.X / 100.f, point.Y / 100.f, 0.f));
}

geometry.setVertexArray(&vertices); // i need to do that otherwise scene is incorrect.


My first question is why do I need to set vertex array again? "geometry.setVertexArray(&vertices);"
Do I need to do it for all properties?

The second question is it ok to do such update of all properties instead of full scene recreation? What other drawbacks can be? Is there a better approach?
Back to top
View user's profile Send private message
mue
Newbie


Joined: 07 Mar 2016
Posts: 3

PostPosted: Mon Jul 02, 2018 7:49 am    Post subject:
Reply with quote

1.) Make sure you have set

Code:
geometry.setDataVariance(osg::Object::DYNAMIC)


2.) To clear the "cached" data if you use display lists:

Code:
geometry.dirtyDisplayList()


or if you use vertex buffer objects:

Code:
vertices.dirty()



Cheers,
Andreas
Back to top
View user's profile Send private message
OmegaDoom
Newbie


Joined: 25 Jun 2018
Posts: 16

PostPosted: Mon Jul 02, 2018 9:50 am    Post subject:
Reply with quote

Thank you.

It's much better with these options but still not the same as with geometry.setVertexArray(&vertices);

With geometry.setVertexArray(&vertices); I get the same picture as when I recreate the whole scene on each frame. I don't get it with options you provided although the picture is closer to it.
Back to top
View user's profile Send private message
dieslower81
User


Joined: 15 Feb 2010
Posts: 38

PostPosted: Mon Jul 02, 2018 1:59 pm    Post subject:
Reply with quote

Hi OmegaDoom,

When you do:
geometry.setVertexArray(&vertices); you are not actually updating anything,
you are replacing the vertex array. So you are still doing deallocation and allocation.

If you want to just update them, I would say do what you were doing, do what Andreas said, and...
osg::Vec3Array& vertices = static_cast<osg::Vec3Array&>(*geometry.getVertexArray());
But instead of clearing them, you need to change the values in the "vertices" to the new values they should be.

_________________
Thank you,
--Maxim
Back to top
View user's profile Send private message
OmegaDoom
Newbie


Joined: 25 Jun 2018
Posts: 16

PostPosted: Mon Jul 02, 2018 3:31 pm    Post subject:
Reply with quote

Hi dieslower81.

I don't think clearing vector is a problem since it's capacity prevents deallocation/allocation.

I can't just update values since i receive polygons with different number of points. I can try to find a geometry with particular number of points but this approach is not general and i'm not sure about its necessity.

I found the problem in suggested approach. I need to call:

Code:

vertices.dirty();
geometry.dirtyDisplayList();
geometry.dirtyBound();


Looks like even geometry.setDataVariance(osg::Object::DYNAMIC) is not necessary. I'm not sure how much performance i will get but I will keep you posted.
Back to top
View user's profile Send private message
dieslower81
User


Joined: 15 Feb 2010
Posts: 38

PostPosted: Mon Jul 02, 2018 6:05 pm    Post subject:
Reply with quote

You definitely need to dirty the list, and you are right, there is no deallocation when you clear the vector, but isn't there allocation when you create a new vertex before you push it to the vector?

Also, the polygons can have a different number of points, as long as say polygon1 always has 6 and polygon2 always has 4. You can update their positions. If that changes also, then that is a different problem all together, and most likely what you are doing is the best solution.

_________________
Thank you,
--Maxim
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12094

PostPosted: Mon Jul 09, 2018 8:53 am    Post subject:
Updating scene properties instead of recreation it each frame.
Reply with quote

Hi Igor,

The OSG uses OpenGL display lists by default, or
VertexBufferObjects/VertexArrayObjects when enabled via
osg::Geometry::setUserVertexBufferObjects(true) +
setUserVertexArrayObject(true). These GL objects cache the vertex
data within GL, so if you want to update the vertex data you need to
call geometry->dirtyGLObjects() to force the objects to update. You
can also call array->dirty() if you are using VBO/VAO.

If the bounding volume of the geometry changes you'll also want to
force the bounding volume to update by calling Geometry::dirtyBound();

Robert.


On Mon, 2 Jul 2018 at 06:44, Igor Spiridonov <> wrote:
Quote:

Hi. I'm wandering if it's ok what i'm doing and how to do it properly.

I have data of primitives which comes from source periodically. These primitives are points, lines, polygons. They have different sizes, colors, vertices, etc. My first approach was to create a new subscene each time i receive new data and replace a current node to a new one. But to create a new scene each frame is not very fast operation(a lot of allocation /deallocation). So instead of that I've decided to update existing scene by changing vertices, primitive types, etc. But I'v noticed that some data somewhat cached. For example.


Code:

osg::Vec3Array& vertices = static_cast<osg::Vec3Array&>(*geometry.getVertexArray());
vertices.clear();
for (int i = 0; i < logPolygon.points.size(); i++)
{
auto& point = logPolygon.points[i];
vertices.push_back(osg::Vec3(point.X / 100.f, point.Y / 100.f, 0.f));
}

geometry.setVertexArray(&vertices); // i need to do that otherwise scene is incorrect.




My first question is why do I need to set vertex array again? "geometry.setVertexArray(&vertices);"

The second question is it ok to do such update of all properties instead of full scene recreation? What other drawbacks can be? Is there a better approach?

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








------------------
Post generated by Mail2Forum
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 Switch call to viewer::frame() betwee... DrPowers General 4 Tue Sep 11, 2018 6:48 am View latest post
No new posts CompositeViewer with multiple view, a... Angel General 3 Tue Aug 28, 2018 1:15 pm View latest post
No new posts Updating VBO's during runtime bcolbert General 4 Fri Jun 01, 2018 2:20 pm View latest post
No new posts Positioning a Camera relative to anot... Takarashy General 0 Thu May 24, 2018 8:27 am View latest post
No new posts render to a texure bound to an FBO an... Julius Ziegler General 4 Tue Apr 10, 2018 6:49 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