| 210 | uint8_t TextureState::m_usedSlots = 0; |
| 211 | |
| 212 | void TextureState::ApplyTextures(ref_ptr<GraphicsContext> context, RenderState const & state, |
| 213 | ref_ptr<GpuProgram> program) |
| 214 | { |
| 215 | m_usedSlots = 0; |
| 216 | auto const apiVersion = context->GetApiVersion(); |
| 217 | if (apiVersion == dp::ApiVersion::OpenGLES3) |
| 218 | { |
| 219 | ref_ptr<dp::GLGpuProgram> p = program; |
| 220 | for (auto const & texture : state.GetTextures()) |
| 221 | { |
| 222 | auto const tex = texture.second; |
| 223 | int8_t texLoc = -1; |
| 224 | if (tex != nullptr && (texLoc = p->GetUniformLocation(texture.first)) >= 0) |
| 225 | { |
| 226 | GLFunctions::glActiveTexture(gl_const::GLTexture0 + m_usedSlots); |
| 227 | tex->Bind(context); |
| 228 | GLFunctions::glUniformValuei(texLoc, m_usedSlots); |
| 229 | tex->SetFilter(state.GetTextureFilter()); |
| 230 | m_usedSlots++; |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | else if (apiVersion == dp::ApiVersion::Metal) |
| 235 | { |
| 236 | #if defined(OMIM_METAL_AVAILABLE) |
| 237 | ApplyTexturesForMetal(context, program, state); |
| 238 | #endif |
| 239 | } |
| 240 | else if (apiVersion == dp::ApiVersion::Vulkan) |
| 241 | { |
| 242 | ref_ptr<dp::vulkan::VulkanBaseContext> vulkanContext = context; |
| 243 | vulkanContext->ClearParamDescriptors(); |
| 244 | ref_ptr<dp::vulkan::VulkanGpuProgram> p = program; |
| 245 | auto const & bindings = p->GetTextureBindings(); |
| 246 | for (auto const & texture : state.GetTextures()) |
| 247 | { |
| 248 | if (texture.second == nullptr) |
| 249 | continue; |
| 250 | |
| 251 | ref_ptr<dp::vulkan::VulkanTexture> t = texture.second->GetHardwareTexture(); |
| 252 | if (t == nullptr) |
| 253 | { |
| 254 | texture.second->UpdateState(context); |
| 255 | t = texture.second->GetHardwareTexture(); |
| 256 | CHECK(t != nullptr, ()); |
| 257 | } |
| 258 | t->Bind(context); |
| 259 | t->SetFilter(state.GetTextureFilter()); |
| 260 | |
| 261 | dp::vulkan::ParamDescriptor descriptor; |
| 262 | descriptor.m_type = dp::vulkan::ParamDescriptor::Type::Texture; |
| 263 | descriptor.m_imageDescriptor.imageView = t->GetTextureView(); |
| 264 | descriptor.m_imageDescriptor.sampler = vulkanContext->GetSampler(t->GetSamplerKey()); |
| 265 | descriptor.m_imageDescriptor.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 266 | |
| 267 | auto const it = bindings.find(texture.first); |
| 268 | CHECK(it != bindings.end(), (texture.first, " is not found in the program", p->GetName())); |
| 269 | descriptor.m_textureSlot = it->second; |
nothing calls this directly
no test coverage detected