[Switch][osg] About PagedLOD loading and unloading mechanism

Reprinted from: http://bbs.osgchina.org/forum.php?mod=viewthread&tid=7612&highlight=PagedLOD&_dsign=ed8fb143

 

Paging is an essential scheduling rendering technique for large scenes. When you find that osg itself has the PagedLOD function, why not use it immediately. However, when I was using it, I suddenly found that there was only loading but not unloading, and the memory continued to climb with the operation. The expired PagedLOD nodes were not kicked out of memory by osg? Troubled, troubled? Is it a bug? In fact, the PagedLOD technology of osg is very mature, so what is the reason? If you are anxious, please be patient and read
1. The first reason that PagedLOD is not uninstalled
Before using osgViewr::Viewer::setSceneData to set the scene to Viewr, you did not add your PagedLOD node to the scene root node. Consider the following two cases:

osg::Group * root=new osg::Group;
osg::PagedLOD * lod1=new osg::PagedLOD;
lod1->setFileName(0,"cow.osg");
lod1->setRange(0,0,10);

root->addChild(lod1);
viewer->setSceneData(root /*createTeapot()*/ );
osg::Group * root=new osg::Group;
osg::PagedLOD * lod1=new osg::PagedLOD;
lod1->setFileName(0,"cow.osg");
lod1->setRange(0,0,10);

viewer->setSceneData(root /*createTeapot()*/ );
root->addChild(lod1);

Will the lod1 node be deleted when it expires in both cases?

no!

Only the PagedLOD in the first case is unloaded from memory when it expires.

Speaking of the reason, I have to tell you a little secret of the setSceneData function. See the code below:

void Scene::setSceneData(osg::Node* node)
{
_sceneData = node;

if (_databasePager.valid())
{
// register any PagedLOD that need to be tracked in the scene graph
if (node) _databasePager->registerPagedLODs(node);
}
}

All PagedLOD nodes in the scene are registered with DatabasePagerr when setSceneDAta.

If the PagedLOD node has not been set in the scene at this time, then I am sorry, even if you set it later, the PagedLOD nodes registered in the DatabasePager are still those registered at that time, and you can only set the unplanned population later, black households, sorry DatabasePager It doesn't matter whether these black PagedLODs live or die.

Since DatabasePager doesn't care whether these PagedLOD nodes are alive or dead, why can these PagedLOD nodes be dynamically loaded?

Because the dynamic load request of the PagedLOD node is issued by the PagedLOD node itself, and the unloading is managed by the DatabasePager! Check out PagedLOD's traverse function, it will tell you everything.
At this point, maybe you already know that, when using the PagedLOD node, you should pre-set and then setSceneData.

What if I want to add a PagedLOD node during runtime but also want it to be unloadable?

The answer is to call the DatabasePager::registerPagedLODs(node); function to register the account when changing.

 

2. The second reason that the PagedLOD node cannot be uninstalled:

If you use the PagedLOD node to completely avoid the problem mentioned in 1, but your PagedLOD node is still stubbornly stuck in memory, then please take a look here.

We know that the function of paging is related to memory, so when the memory is not enough, the PagedLOD node should automatically exit the memory. Why is it still there?

The answer is that he doesn't know that the memory is not enough and needs you to tell him! The DatabasePager::setTargetMaximumNumberOfPageLOD function or the environment variable OSG_MAX_PAGEDLOD does this. He told DatabasePager that my computer's memory is limited and can only hold a specified number of PagedLODs, and if the expired PagedLODs exceed this number, let him go.

Maybe you will ask if there is a gross relationship between the number of PagedLODs and memory usage?

It does matter, each level of your PagedLOD node has a certain size when you perform PagedLOD paging planning, then the multiplication of this size and the number is the total memory to be occupied.

It is worth mentioning that the default number of this number in osg is 300, osg thinks that your computer configuration is very high!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325213068&siteId=291194637