From 85d2982a295d7ff8bfbf931efb0c27bb84b02c8c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 6 Sep 2023 13:04:29 +0100 Subject: [PATCH] Added View::share(const View&) method --- include/vsg/app/View.h | 5 ++++- src/vsg/app/View.cpp | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/vsg/app/View.h b/include/vsg/app/View.h index 72ce9b819..a2393da8d 100644 --- a/include/vsg/app/View.h +++ b/include/vsg/app/View.h @@ -26,7 +26,7 @@ namespace vsg public: View(); - // share the viewID, mask and camera's ViewportState + // share the specified view's children, viewID, mask and camera ViewportState View(const View& view); explicit View(ref_ptr in_camera, ref_ptr in_scenegraph = {}); @@ -49,6 +49,9 @@ namespace vsg void accept(ConstVisitor& visitor) const override { t_accept(*this, visitor); } void accept(RecordTraversal& visitor) const override { t_accept(*this, visitor); } + /// share the specified view's viewID, mask, camera ViewportState, with this View + void share(const View& view); + /// camera controls the viewport state and projection and view matrices ref_ptr camera; diff --git a/src/vsg/app/View.cpp b/src/vsg/app/View.cpp index db2044a74..d54373d73 100644 --- a/src/vsg/app/View.cpp +++ b/src/vsg/app/View.cpp @@ -76,7 +76,7 @@ View::View(const View& view): viewID(sharedViewID(view.viewID)), mask(view.mask) { - if (view.camera) + if (view.camera && view.camera->viewportState) { camera = vsg::Camera::create(); camera->viewportState = view.camera->viewportState; @@ -95,3 +95,19 @@ View::~View() { releaseViewID(viewID); } + +void View::share(const View& view) +{ + if (viewID != view.viewID) + { + releaseViewID(viewID); + const_cast(viewID) = sharedViewID(view.viewID); + } + + mask = view.mask; + if (view.camera && view.camera->viewportState) + { + if (!camera) camera = vsg::Camera::create(); + camera->viewportState = view.camera->viewportState; + } +}