@@ -48,22 +48,7 @@ namespace MauRen
4848 return { false , INVALID_MATERIAL_ID };
4949 }
5050
51- return { true , it->second };
52- }
53-
54- bool VulkanMaterialManager::Exists (uint32_t ID ) const noexcept
55- {
56- if (ID == INVALID_MATERIAL_ID )
57- {
58- return false ;
59- }
60-
61- if (ID < m_Materials.size ())
62- {
63- return true ;
64- }
65-
66- return false ;
51+ return { true , it->second .materialID };
6752 }
6853
6954 uint32_t VulkanMaterialManager::LoadOrGetMaterial (VulkanCommandPoolManager& cmdPoolManager, VulkanDescriptorContext& descriptorContext, Material const & material)
@@ -80,7 +65,8 @@ namespace MauRen
8065 auto const it{ m_MaterialIDMap.find (material.name ) };
8166 if (it != end (m_MaterialIDMap))
8267 {
83- return it->second ;
68+ m_MaterialIDMap[material.name ].useCount ++;
69+ return it->second .materialID ;
8470 }
8571
8672 MaterialData vkMat{};
@@ -112,7 +98,11 @@ namespace MauRen
11298 vkMat.metallicTextureID = m_TextureManager->LoadOrGetTexture (cmdPoolManager, descriptorContext, material.metalnessRoughnessTexture , true );
11399 }
114100
101+ vkMat.materialID = m_NextMaterialID;
102+
115103 m_Materials.emplace_back (vkMat);
104+ m_MaterialIDMap[material.name ] = { static_cast <uint32_t >(m_Materials.size () - 1 ), 1 };
105+ m_NextMaterialID++;
116106
117107 // Upload the material id if new
118108 {
@@ -129,7 +119,6 @@ namespace MauRen
129119 bufferInfo.buffer = m_MaterialDataBuffers[i].buffer .buffer ;
130120 bufferInfo.range = sizeof (MaterialData) * MAX_MATERIALS ;
131121
132- // TODO simply do this once per frame, if buffer has changed
133122 descriptorContext.BindMaterialBuffer (bufferInfo, i);
134123 }
135124 }
@@ -138,11 +127,6 @@ namespace MauRen
138127 return static_cast <uint32_t >(m_Materials.size () - 1 );
139128 }
140129
141- MaterialData const & VulkanMaterialManager::GetMaterial (uint32_t ID ) const noexcept
142- {
143- return m_Materials[ID ];
144- }
145-
146130 void VulkanMaterialManager::InitMaterialBuffers ()
147131 {
148132 auto deviceContext{ VulkanDeviceContextManager::GetInstance ().GetDeviceContext () };
@@ -168,6 +152,6 @@ namespace MauRen
168152 Material const defaultMat{};
169153 auto const id{ LoadOrGetMaterial (cmdPoolManager, descContext, defaultMat) };
170154
171- ME_ASSERT (id == INVALID_MATERIAL_ID );
155+ ME_ASSERT (id == DEFAULT_MATERIAL_ID );
172156 }
173157}
0 commit comments