Skip to content

Commit

Permalink
Added View::share(const View&) method
Browse files Browse the repository at this point in the history
  • Loading branch information
robertosfield committed Sep 6, 2023
1 parent 9fe63f5 commit 85d2982
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 4 additions & 1 deletion include/vsg/app/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Camera> in_camera, ref_ptr<Node> in_scenegraph = {});
Expand All @@ -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> camera;

Expand Down
18 changes: 17 additions & 1 deletion src/vsg/app/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -95,3 +95,19 @@ View::~View()
{
releaseViewID(viewID);
}

void View::share(const View& view)
{
if (viewID != view.viewID)
{
releaseViewID(viewID);
const_cast<uint32_t&>(viewID) = sharedViewID(view.viewID);
}

mask = view.mask;
if (view.camera && view.camera->viewportState)
{
if (!camera) camera = vsg::Camera::create();
camera->viewportState = view.camera->viewportState;
}
}

0 comments on commit 85d2982

Please sign in to comment.