| 144 | } |
| 145 | |
| 146 | uint32_t MaterialSystem::addTextureSampler(const ref<Sampler>& pSampler) |
| 147 | { |
| 148 | FALCOR_ASSERT(pSampler); |
| 149 | auto isEqual = [&pSampler](const ref<Sampler>& pOther) { |
| 150 | return pSampler->getDesc() == pOther->getDesc(); |
| 151 | }; |
| 152 | |
| 153 | // Reuse previously added samplers. We compare by sampler desc. |
| 154 | if (auto it = std::find_if(mTextureSamplers.begin(), mTextureSamplers.end(), isEqual); it != mTextureSamplers.end()) |
| 155 | { |
| 156 | return (uint32_t)std::distance(mTextureSamplers.begin(), it); |
| 157 | } |
| 158 | |
| 159 | // Add sampler. |
| 160 | if (mTextureSamplers.size() >= kMaxSamplerCount) |
| 161 | { |
| 162 | FALCOR_THROW("Too many samplers"); |
| 163 | } |
| 164 | const uint32_t samplerID = static_cast<uint32_t>(mTextureSamplers.size()); |
| 165 | |
| 166 | mTextureSamplers.push_back(pSampler); |
| 167 | mSamplersChanged = true; |
| 168 | |
| 169 | return samplerID; |
| 170 | } |
| 171 | |
| 172 | uint32_t MaterialSystem::addBuffer(const ref<Buffer>& pBuffer) |
| 173 | { |