Skip to content

Commit

Permalink
Added View copy constructor that shares viewID and common state.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertosfield committed Sep 4, 2023
1 parent 62b2e8e commit 6bbad2a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
3 changes: 3 additions & 0 deletions include/vsg/app/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace vsg
public:
View();

View(const View& view);

// share the viewID, mask and camera's ViewportState
explicit View(ref_ptr<Camera> in_camera, ref_ptr<Node> in_scenegraph = {});

template<class N, class V>
Expand Down
38 changes: 33 additions & 5 deletions src/vsg/app/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using namespace vsg;

// thread safe container for managing the deviceID for each vsg::View
static std::mutex s_ViewCountMutex;
static std::vector<bool> s_ActiveViews;
static std::vector<uint32_t> s_ActiveViews;

static uint32_t getUniqueViewID()
{
Expand All @@ -27,22 +27,38 @@ static uint32_t getUniqueViewID()
uint32_t viewID = 0;
for (viewID = 0; viewID < static_cast<uint32_t>(s_ActiveViews.size()); ++viewID)
{
if (!s_ActiveViews[viewID])
if (s_ActiveViews[viewID]==0)
{
s_ActiveViews[viewID] = true;
++s_ActiveViews[viewID];
return viewID;
}
}

s_ActiveViews.push_back(true);
s_ActiveViews.push_back(1);

return viewID;
}

static uint32_t sharedViewID(uint32_t viewID)
{
std::scoped_lock<std::mutex> guard(s_ViewCountMutex);

if (viewID < static_cast<uint32_t>(s_ActiveViews.size()))
{
++s_ActiveViews[viewID];
return viewID;
}

viewID = static_cast<uint32_t>(s_ActiveViews.size());
s_ActiveViews.push_back(1);

return viewID;
}

static void releaseViewID(uint32_t viewID)
{
std::scoped_lock<std::mutex> guard(s_ViewCountMutex);
s_ActiveViews[viewID] = false;
--s_ActiveViews[viewID];
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -55,6 +71,18 @@ View::View() :
{
}

View::View(const View& view):
Inherit(view),
viewID(sharedViewID(view.viewID)),
mask(view.mask)
{
if (view.camera)
{
camera = vsg::Camera::create();
camera->viewportState = view.camera->viewportState;
}
}

View::View(ref_ptr<Camera> in_camera, ref_ptr<Node> in_scenegraph) :
camera(in_camera),
viewID(getUniqueViewID()),
Expand Down

0 comments on commit 6bbad2a

Please sign in to comment.