1
0
Fork 0

CameraGroup: Add compositor reload callbacks

Add a compositor reload callback object to CameraInfo, with callbacks
for just prior and after the CameraInfo's compositor is reloaded by
reloadCompositors().

This will allow VR cameras to be reconfigured after a reload.
This commit is contained in:
James Hogan 2021-08-02 23:38:56 +01:00
parent 9e430b3fc2
commit e25a560591
No known key found for this signature in database
GPG key ID: 35CEE4862B1023F2
2 changed files with 16 additions and 1 deletions

View file

@ -982,6 +982,9 @@ void reloadCompositors(CameraGroup *cgroup)
SGReaderWriterOptions::fromPath(globals->get_fg_root());
options->setPropertyNode(globals->get_props());
if (info->reloadCompositorCallback.valid())
info->reloadCompositorCallback->preReloadCompositor(cgroup, info);
// Force deletion
info->compositor.reset(nullptr);
// Then replace it with a new instance
@ -993,6 +996,9 @@ void reloadCompositors(CameraGroup *cgroup)
viewport,
compositor_path,
options));
if (info->reloadCompositorCallback.valid())
info->reloadCompositorCallback->postReloadCompositor(cgroup, info);
}
cgroup->_viewer->getViewerBase()->startThreading();

View file

@ -51,6 +51,7 @@ namespace flightgear
class CameraGroupListener;
class GraphicsWindow;
class CameraGroup;
/** A wrapper around osg::Camera that contains some extra information.
*/
@ -76,7 +77,7 @@ struct CameraInfo : public osg::Referenced
flags(flags_),
physicalWidth(0), physicalHeight(0), bezelHeightTop(0),
bezelHeightBottom(0), bezelWidthLeft(0), bezelWidthRight(0),
relativeCameraParent(0) { }
relativeCameraParent(0), reloadCompositorCallback(nullptr) { }
/** The name as given in the config file.
*/
std::string name;
@ -120,6 +121,14 @@ struct CameraInfo : public osg::Referenced
* Compositor path and should use the default one.
*/
std::string compositor_path;
struct ReloadCompositorCallback : public virtual osg::Referenced
{
virtual void preReloadCompositor(CameraGroup *, CameraInfo *) = 0;
virtual void postReloadCompositor(CameraGroup *, CameraInfo *) = 0;
};
osg::ref_ptr<ReloadCompositorCallback> reloadCompositorCallback;
};
class CameraGroup : public osg::Referenced