diff --git a/include/vsg/app/View.h b/include/vsg/app/View.h index d1c4b97a0..f4d06b8c7 100644 --- a/include/vsg/app/View.h +++ b/include/vsg/app/View.h @@ -26,6 +26,9 @@ namespace vsg public: View(); + View(const View& view); + + // share the viewID, mask and camera's ViewportState explicit View(ref_ptr in_camera, ref_ptr in_scenegraph = {}); template diff --git a/src/vsg/app/View.cpp b/src/vsg/app/View.cpp index 6e17e1417..db2044a74 100644 --- a/src/vsg/app/View.cpp +++ b/src/vsg/app/View.cpp @@ -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 s_ActiveViews; +static std::vector s_ActiveViews; static uint32_t getUniqueViewID() { @@ -27,14 +27,30 @@ static uint32_t getUniqueViewID() uint32_t viewID = 0; for (viewID = 0; viewID < static_cast(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 guard(s_ViewCountMutex); + + if (viewID < static_cast(s_ActiveViews.size())) + { + ++s_ActiveViews[viewID]; + return viewID; + } + + viewID = static_cast(s_ActiveViews.size()); + s_ActiveViews.push_back(1); return viewID; } @@ -42,7 +58,7 @@ static uint32_t getUniqueViewID() static void releaseViewID(uint32_t viewID) { std::scoped_lock guard(s_ViewCountMutex); - s_ActiveViews[viewID] = false; + --s_ActiveViews[viewID]; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -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 in_camera, ref_ptr in_scenegraph) : camera(in_camera), viewID(getUniqueViewID()),