Hi,
just in the case anybody is interested: I have just converted my
one-file database with LODs into one with PagedLODs and subNodes for
better level of detail stored in separate files. Here I present simple
steps that could help to do the same with your database. I would like
to ask someone more experienced than me to look at these steps if all
is correct.
Preparation of PagedLOD database:
* Create each LOD the same way as before;
* Name with a unique name the every LOD-child-node that should be
written out to a separate file (except the first one for the lowest
level of detail which should stay in the main database file);
* Use the ConvertToPageLODVisitor from from osgPagedLOD example to
convert all LODs into PagedLODs
* Call osg::Optimize to do any optimization you want to apply to your
nodes;
* Use the CompressTexturesVisitor from osgconv application to compress
textures used in LOD children;
* Write your own WriteOutTexturesVisitor to go through all the
PagedLOD children and all of their textures. For each texture write
already compressed image data into a file with ".dds" extension using
osgDB::writeImageFile function and call image->setFilename to change
filename to the one with new extension. This visitor could be derived
from the CompressTexturesVisitor and take advantage of TextureSet to
avoid duplicate processing of the same texture and its image; More
tests could be added to avoid unnecessary overwriting of the same DDS
image file.
* Set osgDB:Registry ReaderWriter options to "noTexturesInIVEFiles";
* Use the WriteOutPagedLODSubgraphsVisitor from osgPagedLOD to save
all the childNodes into separated IVE files.
* Use osgDB::writeNodeFile to save the rootNode with osg::PagedLODs
and their remaining first children for lowest level of detail (which
is not saved into separate file in previous step) into main file that
should be loaded into viewer.
Application for viewing:
Before a call to osgUtil::SceneView::init() function place following
initialization for SharedStateManager/DatabasePager:
* Obtain a pointer to the one and only SharedStateManager by call to
osgDB::Registry::instance()->getOrCreateSharedStateManager();
* Consider call to SharedStateManager->setShareMode and setting it to
SHARE_ALL either to SHARE_TEXTURES only;
* Set osgDB::ReaderWriteOptions cache flag by setObjectCacheHint to
CACHE_IMAGES or event to CACHE_IMAGES | CACHE_OBJECTS;
* Obtain a pointer to the one and only DatabasePager by call to
osgDB::Registry::instance()->getOrCreateDatabasePager();
* Play with several DatabasePager parameters to best suit needs of
your application. Some experiences of mine:
* setUseFrameBlock( true);
* setThreadPriorityOutwithFrame(
OpenThreads::Thread::THREAD_PRIORITY_HIGH) to have faster loading of
detailed PagedLOD child-nodes;
* setDoPreCompile( false) when there is a lot of states to be
later shared in the SharedStateManager::share() function;
* other parameters are: setMaximumNumOfObjectsToCompilePerFrame,
setExpiryDelay
* Let the cull visitor know about the DatabasePager by calling
sceneView->getCullVisitor()->setDatabaseRequestHandler(
databasePager);
* Load your main database file by call to osgDB::readNodeFile;
* Let the DatabasePager know about your PagedLODs by calling
databasePager->registerPagedLODs( rootNode.get());
* Call sharedStateManager->share( rootNode.get()) to share the
stateSet/textures already in main database file;
In the application update frame cycle:
* Somewhere at the beginning:
* databasePager->signalBeginFrame( frameStamp.get());
* databasePager->updateSceneGraph(
frameStamp->getReferenceTime());
* Before the call to SwapBuffers() place:
* databasePager->signalEndFrame();
* At the end of update cycle:
* databasePager->compileGLObjects( *(sceneView->getState()),
availableTime);
* sceneView->flushDeletedGLObjects( availableTime);
* There is a comment in DatabasePager source file for the value
of availableTime suggesting equation:
availableTime= max( 1.0/targetFrameRate-
timeTakenDuringUpdateCullAndDraw,
minimumTimeAvailableForGLCompileAndDeletePerFrame)
Its value can be changed through application running to achieve a
better constant frame-rate.
I hope it could help someone.
Milan
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/