3
0

MeshInstanceManager.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 <Source/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