MeshInstanceManager.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Mesh/MeshInstanceManager.h>
  9. #include <AzCore/std/parallel/scoped_lock.h>
  10. namespace AZ
  11. {
  12. namespace Render
  13. {
  14. MeshInstanceManager::InsertResult MeshInstanceManager::AddInstance(MeshInstanceGroupKey meshInstanceGroupKey)
  15. {
  16. AZStd::scoped_lock lock(m_instanceDataMutex);
  17. MeshInstanceManager::InsertResult result = m_instanceData.Add(meshInstanceGroupKey);
  18. if (result.m_instanceCount == 1)
  19. {
  20. // The MeshInstanceManager is including the key as part of the data vector,
  21. // so that RemoveInstance can be called via handle instead of key. This allows
  22. // the higher level ModelDataInstance to only have to track the handle,
  23. // not the key, while enabling the underlying MeshInstanceList structure to remove
  24. // by key, without needing to iterate over the entire DataMap
  25. m_instanceData[result.m_handle].m_key = meshInstanceGroupKey;
  26. }
  27. return result;
  28. }
  29. void MeshInstanceManager::RemoveInstance(MeshInstanceGroupKey meshInstanceGroupKey)
  30. {
  31. AZStd::scoped_lock lock(m_instanceDataMutex);
  32. m_instanceData.Remove(meshInstanceGroupKey);
  33. }
  34. void MeshInstanceManager::RemoveInstance(Handle handle)
  35. {
  36. AZStd::scoped_lock lock(m_instanceDataMutex);
  37. m_instanceData.Remove(m_instanceData[handle].m_key);
  38. }
  39. uint32_t MeshInstanceManager::GetInstanceGroupCount() const
  40. {
  41. return m_instanceData.GetInstanceGroupCount();
  42. }
  43. MeshInstanceGroupData& MeshInstanceManager::operator[](Handle handle)
  44. {
  45. return m_instanceData[handle];
  46. }
  47. auto MeshInstanceManager::GetParallelRanges() -> ParallelRanges
  48. {
  49. return m_instanceData.GetParallelRanges();
  50. }
  51. } // namespace Render
  52. } // namespace AZ