| 284 | } |
| 285 | |
| 286 | void ApplyState(ref_ptr<GraphicsContext> context, ref_ptr<GpuProgram> program, RenderState const & state) |
| 287 | { |
| 288 | auto const apiVersion = context->GetApiVersion(); |
| 289 | |
| 290 | TextureState::ApplyTextures(context, state, program); |
| 291 | |
| 292 | // Apply blending state. |
| 293 | if (apiVersion == dp::ApiVersion::Metal) |
| 294 | { |
| 295 | // For Metal rendering blending state is a part of the pipeline state. |
| 296 | #if defined(OMIM_METAL_AVAILABLE) |
| 297 | ApplyPipelineStateForMetal(context, program, state.GetBlending().m_isEnabled); |
| 298 | #endif |
| 299 | } |
| 300 | else if (apiVersion == dp::ApiVersion::Vulkan) |
| 301 | { |
| 302 | ref_ptr<dp::vulkan::VulkanBaseContext> vulkanContext = context; |
| 303 | vulkanContext->SetProgram(program); |
| 304 | vulkanContext->SetBlendingEnabled(state.GetBlending().m_isEnabled); |
| 305 | } |
| 306 | else |
| 307 | { |
| 308 | state.GetBlending().Apply(context, program); |
| 309 | } |
| 310 | |
| 311 | // Apply depth state. |
| 312 | context->SetDepthTestEnabled(state.GetDepthTestEnabled()); |
| 313 | if (state.GetDepthTestEnabled()) |
| 314 | context->SetDepthTestFunction(state.GetDepthFunction()); |
| 315 | if (apiVersion == dp::ApiVersion::Metal) |
| 316 | { |
| 317 | // For Metal rendering we have to apply depth-stencil state after SetX functions calls. |
| 318 | #if defined(OMIM_METAL_AVAILABLE) |
| 319 | ApplyDepthStencilStateForMetal(context); |
| 320 | #endif |
| 321 | } |
| 322 | |
| 323 | if (state.GetDrawAsLine()) |
| 324 | { |
| 325 | if (apiVersion == dp::ApiVersion::OpenGLES3) |
| 326 | { |
| 327 | ASSERT_GREATER_OR_EQUAL(state.GetLineWidth(), 0, ()); |
| 328 | GLFunctions::glLineWidth(static_cast<uint32_t>(state.GetLineWidth())); |
| 329 | } |
| 330 | else if (apiVersion == dp::ApiVersion::Metal) |
| 331 | { |
| 332 | // Do nothing. Metal does not support line width. |
| 333 | } |
| 334 | else if (apiVersion == dp::ApiVersion::Vulkan) |
| 335 | { |
| 336 | ASSERT_GREATER_OR_EQUAL(state.GetLineWidth(), 0, ()); |
| 337 | ref_ptr<dp::vulkan::VulkanBaseContext> vulkanContext = context; |
| 338 | VkCommandBuffer commandBuffer = vulkanContext->GetCurrentRenderingCommandBuffer(); |
| 339 | CHECK(commandBuffer != nullptr, ()); |
| 340 | vkCmdSetLineWidth(commandBuffer, static_cast<float>(state.GetLineWidth())); |
| 341 | } |
| 342 | } |
| 343 | } |
no test coverage detected