| 222 | } |
| 223 | |
| 224 | MaterialID MaterialSystem::addMaterial(const ref<Material>& pMaterial) |
| 225 | { |
| 226 | FALCOR_CHECK(pMaterial != nullptr, "'pMaterial' is missing"); |
| 227 | |
| 228 | // Reuse previously added materials. |
| 229 | if (auto it = std::find(mMaterials.begin(), mMaterials.end(), pMaterial); it != mMaterials.end()) |
| 230 | { |
| 231 | return MaterialID{(size_t)std::distance(mMaterials.begin(), it) }; |
| 232 | } |
| 233 | |
| 234 | // Add material. |
| 235 | if (mMaterials.size() >= std::numeric_limits<uint32_t>::max()) |
| 236 | { |
| 237 | FALCOR_THROW("Too many materials"); |
| 238 | } |
| 239 | const MaterialID materialID{ mMaterials.size() }; |
| 240 | |
| 241 | if (pMaterial->getDefaultTextureSampler() == nullptr) |
| 242 | { |
| 243 | pMaterial->setDefaultTextureSampler(mpDefaultTextureSampler); |
| 244 | } |
| 245 | |
| 246 | pMaterial->registerUpdateCallback([this](auto flags) { mMaterialUpdates |= flags; }); |
| 247 | mMaterials.push_back(pMaterial); |
| 248 | mMaterialsChanged = true; |
| 249 | |
| 250 | return materialID; |
| 251 | } |
| 252 | |
| 253 | void MaterialSystem::removeMaterial(const MaterialID materialID) |
| 254 | { |