1
0
Fork 0

Fix fgviewer for Compositor

This commit is contained in:
Stuart Buchanan 2020-07-01 21:02:16 +01:00
parent c4942eaa69
commit 39cedd1256
2 changed files with 86 additions and 54 deletions

View file

@ -68,12 +68,12 @@ public:
_lodBare(fgGetNode("/sim/rendering/static-lod/bare", true)) _lodBare(fgGetNode("/sim/rendering/static-lod/bare", true))
{ {
_useVBOsProp->addChangeListener(this, true); _useVBOsProp->addChangeListener(this, true);
_enableCacheProp->addChangeListener(this, true); _enableCacheProp->addChangeListener(this, true);
if (_enableCacheProp->getType() == simgear::props::NONE) { if (_enableCacheProp->getType() == simgear::props::NONE) {
_enableCacheProp->setBoolValue(true); _enableCacheProp->setBoolValue(true);
} }
if (_pagedLODMaximumProp->getType() == simgear::props::NONE) { if (_pagedLODMaximumProp->getType() == simgear::props::NONE) {
// not set, use OSG default / environment value variable // not set, use OSG default / environment value variable
osg::ref_ptr<osgViewer::Viewer> viewer(globals->get_renderer()->getViewer()); osg::ref_ptr<osgViewer::Viewer> viewer(globals->get_renderer()->getViewer());
@ -85,7 +85,7 @@ public:
_lodBareDelta->addChangeListener(this, true); _lodBareDelta->addChangeListener(this, true);
_lodRoughDelta->addChangeListener(this, true); _lodRoughDelta->addChangeListener(this, true);
} }
~TileManagerListener() ~TileManagerListener()
{ {
_useVBOsProp->removeChangeListener(this); _useVBOsProp->removeChangeListener(this);
@ -95,7 +95,7 @@ public:
_lodBareDelta->removeChangeListener(this); _lodBareDelta->removeChangeListener(this);
_lodRoughDelta->removeChangeListener(this); _lodRoughDelta->removeChangeListener(this);
} }
virtual void valueChanged(SGPropertyNode* prop) virtual void valueChanged(SGPropertyNode* prop)
{ {
if (prop == _useVBOsProp) { if (prop == _useVBOsProp) {
@ -107,7 +107,10 @@ public:
} else if (prop == _pagedLODMaximumProp) { } else if (prop == _pagedLODMaximumProp) {
int v = prop->getIntValue(); int v = prop->getIntValue();
osg::ref_ptr<osgViewer::Viewer> viewer(globals->get_renderer()->getViewer()); osg::ref_ptr<osgViewer::Viewer> viewer(globals->get_renderer()->getViewer());
viewer->getDatabasePager()->setTargetMaximumNumberOfPageLOD(v); if (viewer) {
osgDB::DatabasePager* pager = viewer->getDatabasePager();
if (pager) pager->setTargetMaximumNumberOfPageLOD(v);
}
} else if (prop == _lodDetailed || prop == _lodBareDelta || prop == _lodRoughDelta) { } else if (prop == _lodDetailed || prop == _lodBareDelta || prop == _lodRoughDelta) {
// compatibility with earlier versions; set the static lod ranges appropriately as otherwise (bad) self managed // compatibility with earlier versions; set the static lod ranges appropriately as otherwise (bad) self managed
// LOD on scenery with range animations doesn't work. // LOD on scenery with range animations doesn't work.
@ -117,7 +120,7 @@ public:
_lodBare->setDoubleValue(_lodRough->getDoubleValue() + _lodBareDelta->getDoubleValue()); _lodBare->setDoubleValue(_lodRough->getDoubleValue() + _lodBareDelta->getDoubleValue());
} }
} }
private: private:
FGTileMgr* _manager; FGTileMgr* _manager;
SGPropertyNode_ptr _useVBOsProp, SGPropertyNode_ptr _useVBOsProp,
@ -183,10 +186,10 @@ void FGTileMgr::reinit()
// drops the previous options reference // drops the previous options reference
_options = new simgear::SGReaderWriterOptions; _options = new simgear::SGReaderWriterOptions;
_listener = new TileManagerListener(this); _listener = new TileManagerListener(this);
materialLibChanged(); materialLibChanged();
_options->setPropertyNode(globals->get_props()); _options->setPropertyNode(globals->get_props());
osgDB::FilePathList &fp = _options->getDatabasePathList(); osgDB::FilePathList &fp = _options->getDatabasePathList();
const PathList &sc = globals->get_fg_scenery(); const PathList &sc = globals->get_fg_scenery();
fp.clear(); fp.clear();
@ -194,18 +197,18 @@ void FGTileMgr::reinit()
fp.push_back(it->utf8Str()); fp.push_back(it->utf8Str());
} }
_options->setPluginStringData("SimGear::FG_ROOT", globals->get_fg_root().utf8Str()); _options->setPluginStringData("SimGear::FG_ROOT", globals->get_fg_root().utf8Str());
if (_terra_sync) { if (_terra_sync) {
_options->setPluginStringData("SimGear::TERRASYNC_ROOT", globals->get_terrasync_dir().utf8Str()); _options->setPluginStringData("SimGear::TERRASYNC_ROOT", globals->get_terrasync_dir().utf8Str());
} }
if (!_disableNasalHooks->getBoolValue()) if (!_disableNasalHooks->getBoolValue())
_options->setModelData(new FGNasalModelDataProxy); _options->setModelData(new FGNasalModelDataProxy);
double detailed = fgGetDouble("/sim/rendering/static-lod/detailed", SG_OBJECT_RANGE_DETAILED); double detailed = fgGetDouble("/sim/rendering/static-lod/detailed", SG_OBJECT_RANGE_DETAILED);
double rough = fgGetDouble("/sim/rendering/static-lod/rough-delta", SG_OBJECT_RANGE_ROUGH) + detailed; double rough = fgGetDouble("/sim/rendering/static-lod/rough-delta", SG_OBJECT_RANGE_ROUGH) + detailed;
double bare = fgGetDouble("/sim/rendering/static-lod/bare", SG_OBJECT_RANGE_BARE) + rough; double bare = fgGetDouble("/sim/rendering/static-lod/bare", SG_OBJECT_RANGE_BARE) + rough;
_options->setPluginStringData("SimGear::LOD_RANGE_BARE", std::to_string(bare)); _options->setPluginStringData("SimGear::LOD_RANGE_BARE", std::to_string(bare));
_options->setPluginStringData("SimGear::LOD_RANGE_ROUGH", std::to_string(rough)); _options->setPluginStringData("SimGear::LOD_RANGE_ROUGH", std::to_string(rough));
_options->setPluginStringData("SimGear::LOD_RANGE_DETAILED", std::to_string(detailed)); _options->setPluginStringData("SimGear::LOD_RANGE_DETAILED", std::to_string(detailed));
@ -223,7 +226,7 @@ void FGTileMgr::reinit()
} }
_options->setSceneryPathSuffixes(scenerySuffixes); _options->setSceneryPathSuffixes(scenerySuffixes);
if (state != Start) if (state != Start)
{ {
// protect against multiple scenery reloads and properly reset flags, // protect against multiple scenery reloads and properly reset flags,
@ -233,25 +236,25 @@ void FGTileMgr::reinit()
return; return;
} }
} }
_scenery_loaded->setBoolValue(false); _scenery_loaded->setBoolValue(false);
fgSetDouble("/sim/startup/splash-alpha", 1.0); fgSetDouble("/sim/startup/splash-alpha", 1.0);
materialLibChanged(); materialLibChanged();
// remove all old scenery nodes from scenegraph and clear cache // remove all old scenery nodes from scenegraph and clear cache
osg::Group* group = globals->get_scenery()->get_terrain_branch(); osg::Group* group = globals->get_scenery()->get_terrain_branch();
group->removeChildren(0, group->getNumChildren()); group->removeChildren(0, group->getNumChildren());
tile_cache.init(); tile_cache.init();
// clear OSG cache, except on initial start-up // clear OSG cache, except on initial start-up
if (state != Start) if (state != Start)
{ {
osgDB::Registry::instance()->clearObjectCache(); osgDB::Registry::instance()->clearObjectCache();
} }
state = Inited; state = Inited;
previous_bucket.make_bad(); previous_bucket.make_bad();
current_bucket.make_bad(); current_bucket.make_bad();
scheduled_visibility = 100.0; scheduled_visibility = 100.0;
@ -319,7 +322,7 @@ void FGTileMgr::schedule_needed(const SGBucket& curr_bucket, double vis)
"scheduling needed tiles for " << curr_bucket "scheduling needed tiles for " << curr_bucket
<< ", tile-width-m:" << tile_width << ", tile-height-m:" << tile_height); << ", tile-width-m:" << tile_width << ", tile-height-m:" << tile_height);
// cout << "tile width = " << tile_width << " tile_height = " // cout << "tile width = " << tile_width << " tile_height = "
// << tile_height << endl; // << tile_height << endl;
// starting with 2018.3 we will use deltas rather than absolutes as it is more intuitive for the user // starting with 2018.3 we will use deltas rather than absolutes as it is more intuitive for the user
@ -339,7 +342,7 @@ void FGTileMgr::schedule_needed(const SGBucket& curr_bucket, double vis)
// cout << "max cache size = " << tile_cache.get_max_cache_size() // cout << "max cache size = " << tile_cache.get_max_cache_size()
// << " current cache size = " << tile_cache.get_size() << endl; // << " current cache size = " << tile_cache.get_size() << endl;
// clear flags of all tiles belonging to the previous view set // clear flags of all tiles belonging to the previous view set
tile_cache.clear_current_view(); tile_cache.clear_current_view();
// update timestamps, so all tiles scheduled now are *newer* than any tile previously loaded // update timestamps, so all tiles scheduled now are *newer* than any tile previously loaded
@ -361,10 +364,10 @@ void FGTileMgr::schedule_needed(const SGBucket& curr_bucket, double vis)
if (!b.isValid()) { if (!b.isValid()) {
continue; continue;
} }
float priority = (-1.0) * (x*x+y*y); float priority = (-1.0) * (x*x+y*y);
sched_tile( b, priority, true, 0.0 ); sched_tile( b, priority, true, 0.0 );
if (_terra_sync) { if (_terra_sync) {
_terra_sync->scheduleTile(b); _terra_sync->scheduleTile(b);
} }
@ -385,7 +388,7 @@ void FGTileMgr::update_queues(bool& isDownloadingScenery)
TileEntry *e; TileEntry *e;
int loading=0; int loading=0;
int sz=0; int sz=0;
tile_cache.set_current_time( current_time ); tile_cache.set_current_time( current_time );
tile_cache.reset_traversal(); tile_cache.reset_traversal();
@ -398,7 +401,7 @@ void FGTileMgr::update_queues(bool& isDownloadingScenery)
// Set the ssg transform and update it's range selector // Set the ssg transform and update it's range selector
// based on current visibilty // based on current visibilty
e->prep_ssg_node(vis); e->prep_ssg_node(vis);
if (!e->is_loaded()) { if (!e->is_loaded()) {
bool nonExpiredOrCurrent = !e->is_expired(current_time) || e->is_current_view(); bool nonExpiredOrCurrent = !e->is_expired(current_time) || e->is_current_view();
bool downloading = isTileDirSyncing(e->tileFileName); bool downloading = isTileDirSyncing(e->tileFileName);
@ -429,7 +432,7 @@ void FGTileMgr::update_queues(bool& isDownloadingScenery)
dropTiles = true; dropTiles = true;
drop_count = sz; // no limit on tiles to drop drop_count = sz; // no limit on tiles to drop
} }
if (dropTiles) if (dropTiles)
{ {
long drop_index = _enableCache ? tile_cache.get_drop_tile() : long drop_index = _enableCache ? tile_cache.get_drop_tile() :
@ -441,14 +444,14 @@ void FGTileMgr::update_queues(bool& isDownloadingScenery)
SG_LOG(SG_TERRAIN, SG_DEBUG, "Dropping:" << old->get_tile_bucket()); SG_LOG(SG_TERRAIN, SG_DEBUG, "Dropping:" << old->get_tile_bucket());
tile_cache.clear_entry(drop_index); tile_cache.clear_entry(drop_index);
osg::ref_ptr<osg::Object> subgraph = old->getNode(); osg::ref_ptr<osg::Object> subgraph = old->getNode();
old->removeFromSceneGraph(); old->removeFromSceneGraph();
delete old; delete old;
// zeros out subgraph ref_ptr, so subgraph is owned by // zeros out subgraph ref_ptr, so subgraph is owned by
// the pager and will be deleted in the pager thread. // the pager and will be deleted in the pager thread.
_pager->queueDeleteRequest(subgraph); _pager->queueDeleteRequest(subgraph);
if (!_enableCache) if (!_enableCache)
drop_index = tile_cache.get_first_expired_tile(); drop_index = tile_cache.get_first_expired_tile();
// limit tiles dropped to drop_count // limit tiles dropped to drop_count
@ -477,8 +480,8 @@ void FGTileMgr::update(double)
bool fdmInited = fgGetBool("sim/fdm-initialized"); bool fdmInited = fgGetBool("sim/fdm-initialized");
bool positionFinalized = fgGetBool("sim/position-finalized"); bool positionFinalized = fgGetBool("sim/position-finalized");
bool sceneryOverride = _scenery_override->getBoolValue(); bool sceneryOverride = _scenery_override->getBoolValue();
// we are done if final position is set and the scenery & FDM are done. // we are done if final position is set and the scenery & FDM are done.
// scenery-override can ignore the last two, but not position finalization. // scenery-override can ignore the last two, but not position finalization.
if (positionFinalized && (sceneryOverride || (isSceneryLoaded() && fdmInited))) if (positionFinalized && (sceneryOverride || (isSceneryLoaded() && fdmInited)))
@ -495,7 +498,7 @@ void FGTileMgr::update(double)
} else { } else {
fgSplashProgress("loading-scenery"); fgSplashProgress("loading-scenery");
} }
// be nice to loader threads while waiting for initial scenery, reduce to 20fps // be nice to loader threads while waiting for initial scenery, reduce to 20fps
SGTimeStamp::sleepForMSec(50); SGTimeStamp::sleepForMSec(50);
} }
@ -535,7 +538,7 @@ void FGTileMgr::schedule_tiles_at(const SGGeod& location, double range_m)
scheduled_visibility = range_m; scheduled_visibility = range_m;
schedule_needed(current_bucket, range_m); schedule_needed(current_bucket, range_m);
} }
// save bucket // save bucket
previous_bucket = current_bucket; previous_bucket = current_bucket;
} else if ( state == Start || state == Inited ) { } else if ( state == Start || state == Inited ) {
@ -562,7 +565,7 @@ bool FGTileMgr::schedule_scenery(const SGGeod& position, double range_m, double
SGBucket bucket(position); SGBucket bucket(position);
available = sched_tile( bucket, priority, false, duration ); available = sched_tile( bucket, priority, false, duration );
if ((!available)&&(duration==0.0)) { if ((!available)&&(duration==0.0)) {
SG_LOG( SG_TERRAIN, SG_DEBUG, "schedule_scenery: Scheduling tile at bucket:" << bucket << " return false" ); SG_LOG( SG_TERRAIN, SG_DEBUG, "schedule_scenery: Scheduling tile at bucket:" << bucket << " return false" );
return false; return false;
@ -576,7 +579,7 @@ bool FGTileMgr::schedule_scenery(const SGGeod& position, double range_m, double
double tile_r = 0.5*sqrt(tile_width*tile_width + tile_height*tile_height); double tile_r = 0.5*sqrt(tile_width*tile_width + tile_height*tile_height);
double max_dist = tile_r + range_m; double max_dist = tile_r + range_m;
double max_dist2 = max_dist*max_dist; double max_dist2 = max_dist*max_dist;
int xrange = (int)fabs(range_m / tile_width) + 1; int xrange = (int)fabs(range_m / tile_width) + 1;
int yrange = (int)fabs(range_m / tile_height) + 1; int yrange = (int)fabs(range_m / tile_height) + 1;
@ -591,7 +594,7 @@ bool FGTileMgr::schedule_scenery(const SGGeod& position, double range_m, double
if (!b.isValid()) { if (!b.isValid()) {
continue; continue;
} }
double distance2 = distSqr(cartPos, SGVec3d::fromGeod(b.get_center())); double distance2 = distSqr(cartPos, SGVec3d::fromGeod(b.get_center()));
// Do not ask if it is just the next tile but way out of range. // Do not ask if it is just the next tile but way out of range.
if (distance2 <= max_dist2) if (distance2 <= max_dist2)
@ -622,11 +625,10 @@ bool FGTileMgr::isTileDirSyncing(const std::string& tileFileName) const
if (!_terra_sync) { if (!_terra_sync) {
return false; return false;
} }
std::string nameWithoutExtension = tileFileName.substr(0, tileFileName.size() - 4); std::string nameWithoutExtension = tileFileName.substr(0, tileFileName.size() - 4);
long int bucketIndex = simgear::strutils::to_int(nameWithoutExtension); long int bucketIndex = simgear::strutils::to_int(nameWithoutExtension);
SGBucket bucket(bucketIndex); SGBucket bucket(bucketIndex);
return _terra_sync->isTileDirPending(bucket.gen_base_path()); return _terra_sync->isTileDirPending(bucket.gen_base_path());
} }

View file

@ -33,6 +33,9 @@
#include <Scenery/scenery.hxx> #include <Scenery/scenery.hxx>
#include <Navaids/NavDataCache.hxx>
#include <Viewer/renderer_compositor.hxx>
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Main/options.hxx> #include <Main/options.hxx>
@ -110,8 +113,10 @@ fgviewerMain(int argc, char** argv)
osg::ArgumentParser arguments(&argc, argv); osg::ArgumentParser arguments(&argc, argv);
// construct the viewer. // construct the viewer.
osgViewer::Viewer viewer(arguments); FGRenderer* fgrenderer = new FGRenderer();
osg::Camera* camera = viewer.getCamera(); osgViewer::Viewer* viewer = new osgViewer::Viewer(arguments);
fgrenderer->setViewer(viewer);
osg::Camera* camera = viewer->getCamera();
osgViewer::Renderer* renderer osgViewer::Renderer* renderer
= static_cast<osgViewer::Renderer*>(camera->getRenderer()); = static_cast<osgViewer::Renderer*>(camera->getRenderer());
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
@ -126,7 +131,7 @@ fgviewerMain(int argc, char** argv)
fog->setDensity(.0000001); fog->setDensity(.0000001);
cameraSS->setAttributeAndModes(fog); cameraSS->setAttributeAndModes(fog);
// ... for some reason, get rid of that FIXME! // ... for some reason, get rid of that FIXME!
viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
// set up the camera manipulators. // set up the camera manipulators.
osgGA::KeySwitchMatrixManipulator* keyswitchManipulator; osgGA::KeySwitchMatrixManipulator* keyswitchManipulator;
@ -140,18 +145,18 @@ fgviewerMain(int argc, char** argv)
new osgGA::DriveManipulator); new osgGA::DriveManipulator);
keyswitchManipulator->addMatrixManipulator('4', "Terrain", keyswitchManipulator->addMatrixManipulator('4', "Terrain",
new osgGA::TerrainManipulator); new osgGA::TerrainManipulator);
viewer.setCameraManipulator(keyswitchManipulator); viewer->setCameraManipulator(keyswitchManipulator);
// Usefull stats // Usefull stats
viewer.addEventHandler(new osgViewer::HelpHandler); viewer->addEventHandler(new osgViewer::HelpHandler);
viewer.addEventHandler(new osgViewer::StatsHandler); viewer->addEventHandler(new osgViewer::StatsHandler);
viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); viewer->addEventHandler( new osgGA::StateSetManipulator(viewer->getCamera()->getOrCreateStateSet()) );
// Same FIXME ... // Same FIXME ...
// viewer.addEventHandler(new osgViewer::ThreadingHandler); // viewer->addEventHandler(new osgViewer::ThreadingHandler);
viewer.addEventHandler(new osgViewer::LODScaleHandler); viewer->addEventHandler(new osgViewer::LODScaleHandler);
viewer.addEventHandler(new osgViewer::ScreenCaptureHandler); viewer->addEventHandler(new osgViewer::ScreenCaptureHandler);
viewer.addEventHandler(new GraphDumpHandler); viewer->addEventHandler(new GraphDumpHandler);
// Extract files to load from arguments now; this way fgInitConfig // Extract files to load from arguments now; this way fgInitConfig
// won't choke on them. // won't choke on them.
@ -168,8 +173,19 @@ fgviewerMain(int argc, char** argv)
// A subset of full flightgear initialization. // A subset of full flightgear initialization.
// Allocate global data structures. This needs to happen before // Allocate global data structures. This needs to happen before
// we parse command line options // we parse command line options
globals = new FGGlobals; globals = new FGGlobals;
globals->set_renderer(fgrenderer);
SGPath dataPath = fgHomePath();
globals->set_fg_home(dataPath);
std::string s;
if (arguments.read("--fg-scenery", s)) {
globals->append_fg_scenery(SGPath::fromLocal8Bit(s.c_str()));
}
if (std::getenv("FG_SCENERY")) {
globals->append_fg_scenery(SGPath::fromEnv("FG_SCENERY"));
}
int configResult = fgInitConfig(arguments.argc(), arguments.argv(), false); int configResult = fgInitConfig(arguments.argc(), arguments.argv(), false);
if (configResult == flightgear::FG_OPTIONS_ERROR) { if (configResult == flightgear::FG_OPTIONS_ERROR) {
@ -209,10 +225,24 @@ fgviewerMain(int argc, char** argv)
options->setPropertyNode(globals->get_props()); options->setPropertyNode(globals->get_props());
options->setPluginStringData("SimGear::PREVIEW", "ON"); options->setPluginStringData("SimGear::PREVIEW", "ON");
FGScenery* scenery = globals->add_new_subsystem<FGScenery>(); // Now init the renderer, as we've got all the options, globals etc.
fgrenderer->init();
FGScenery* scenery = globals->add_new_subsystem<FGScenery>(SGSubsystemMgr::DISPLAY);
scenery->init(); scenery->init();
scenery->bind(); scenery->bind();
if (! flightgear::NavDataCache::instance()) {
flightgear::NavDataCache* cache = flightgear::NavDataCache::createInstance();
cache->updateListsOfDatFiles();
if (cache->isRebuildRequired()) {
while (cache->rebuild() != flightgear::NavDataCache::REBUILD_DONE) {
SGTimeStamp::sleepForMSec(1000);
std::cerr << "." << std::flush;
}
}
}
// read the scene from the list of file specified command line args. // read the scene from the list of file specified command line args.
osg::ref_ptr<osg::Node> loadedModel; osg::ref_ptr<osg::Node> loadedModel;
loadedModel = osgDB::readNodeFiles(dataFiles, options); loadedModel = osgDB::readNodeFiles(dataFiles, options);
@ -224,14 +254,14 @@ fgviewerMain(int argc, char** argv)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
// pass the loaded scene graph to the viewer. // pass the loaded scene graph to the viewer->
viewer.setSceneData(loadedModel.get()); viewer->setSceneData(loadedModel.get());
int result = viewer->run();
int result = viewer.run();
// clear cache now, since it contains SimGear objects. Otherwise SG_LOG // clear cache now, since it contains SimGear objects. Otherwise SG_LOG
// calls during shutdown will cause crashes. // calls during shutdown will cause crashes.
osgDB::Registry::instance()->clearObjectCache(); osgDB::Registry::instance()->clearObjectCache();
return result; return result;
} }