Skip to content

Commit

Permalink
osgearth_windows: force SingleThreaded mode when sharing an OSG graph…
Browse files Browse the repository at this point in the history
…ics context across multiple windows
  • Loading branch information
gwaldron committed Feb 5, 2024
1 parent 8c95efb commit a02c7db
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/applications/osgearth_windows/osgearth_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ usage(const char* name)
OE_NOTICE
<< "\nUsage: " << name << " file.earth"
<< "\n --views [num] : Number of windows to open"
<< "\n --shared : Use a shared graphics context"
<< "\n --shared : Share a single OSG graphics context across all windows (forces SingleThreaded mode)"
<< "\n --updates [num] : Number of update traversals"
<< "\n"
<< MapNodeHelper().usage() << std::endl;
Expand All @@ -61,7 +61,6 @@ struct App
_viewer(args),
_size(800)
{
//_viewer.setThreadingModel(_viewer.SingleThreaded);
_sharedGC = args.read("--shared");
}

Expand Down Expand Up @@ -101,7 +100,6 @@ struct App

osgViewer::View* view = new osgViewer::View();
view->getCamera()->setGraphicsContext(gc);
//osg::GraphicsContext::incrementContextIDUsageCount(gc->getState()->getContextID());

view->getCamera()->setViewport(0, 0, width, height);
view->getCamera()->setProjectionMatrixAsPerspective(45, 1, 1, 10);
Expand Down Expand Up @@ -248,6 +246,16 @@ main(int argc, char** argv)
// Setup the viewer for imgui
app._viewer.setRealizeOperation(new GUI::ApplicationGUI::RealizeOperation);

// Force SingleThreaded mode if we are sharing a GC and have more than one view.
// OSG cannot share a GC across multiple draw threads.
// https://groups.google.com/g/osg-users/c/hZEOr-Hb2kM/m/AiYZvRDLCAAJ
if (app._sharedGC)
{
app._viewer.setThreadingModel(osgViewer::ViewerBase::SingleThreaded);
OE_WARN << "Forcing --SingleThreaded mode because we are sharing an OSG Graphics Context (GC), "
"and OSG does not support multi-threading of a shared GC" << std::endl;
}

app._node = MapNodeHelper().loadWithoutControls(arguments, &app._viewer);
if (!app._node.get())
return usage(argv[0]);
Expand Down

0 comments on commit a02c7db

Please sign in to comment.