[osg-users] How to reduce the cache size limit of OSG ?

OpenSceneGraph Users osg-users at lists.openscenegraph.org
Mon Jun 1 00:04:49 PDT 2020

Hi Hui,

On Monday, 1 June 2020 02:28:04 UTC+1, Hui Li wrote:
> Hi Robert,
> Sorry for the late reply. The codes of CreateGeometryNode looks like this: 
> osg::ref_ptr<osg::MatrixTransform> CreateGeometryNode() {
>     std::vector<float> xyzs = RandomPoints(); ///< Create ramdon number of 
> points 
>     osg::Vec3Array vs = new osg::Vec3Array(xyzs.size()/3, (const osg::Vec3 
> *)(xyzs.data()));
>     osg::ref_ptr<osg::Geometry> geo = new osg::Geometry;
>     geo->setVertexArray(vs.get());
>     geo->setColorArray(osg::Vec3(0.5,0.5,0.5));
>     geo->setColorBinding(osg::Geometry::BIND_OVERALL);
>     geo->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, 
> numpt));
>     geo->getOrCreateStateSet()->setMode(GL_LIGHTING, 
> osg::StateAttribute::OFF);
>     geo->getOrCreateStateSet()->setAttribute(new osg::Point(size), 
> osg::StateAttribute::ON);
>     osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
>     osg::ref_ptr<osg::Geode> geode = new osg::Geode;
>     geode->addDrawable(geo.get());
>     mt->addChild(geode);
>     return mt; 
> }
Adding and removing data continuously is least efficient way to implement 
this type of functionality, it's not just an OpenGL/OSG thing, it applies 
pretty well to all computing.

If you have a stream of data coming in then the best way to manage it is to 
allocated fixed size data and then fill it in dynamically.  So no adding 
and removing, no new and delete on every frame.

If you have a really large dataset then chunk the data into blocks, 10,000 
vertices per osg::Gemetry in a good place to start, but make this variable 
so you can figure what is the sweet spot for your system.

To vary th enumber of points draw using single DrawArrays per osg::Geometry 
and simply change the count to match the number of vertices you want to 

If your data stream suddenly needs more points to represent it and your 
don't have enough available in your bricks then that is the time to 
allocate new bricks.

As for the cache, well the OSG does have cache for reusing GL objects but 
it intended to be used for the types of usage you are pushing it through.  
Follow the above steps and your application will work perfectly.


You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osg-users+unsubscribe at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/df2eb7ed-2790-4212-bb25-3935326d8edf%40googlegroups.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20200601/89863d1a/attachment.html>

More information about the osg-users mailing list