[osg-users] Updating scene properties instead of recreation it each frame.

Robert Osfield robert.osfield at gmail.com
Mon Jul 9 01:52:24 PDT 2018


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 <igwasm at rambler.ru> wrote:
>
> 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
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


More information about the osg-users mailing list