| 256 | } |
| 257 | |
| 258 | bool PostprocessRenderer::EndFrame(ref_ptr<dp::GraphicsContext> context, ref_ptr<gpu::ProgramManager> gpuProgramManager, |
| 259 | dp::Viewport const & viewport) |
| 260 | { |
| 261 | TRACE_SECTION("[drape] PostprocessRenderer::EndFrame"); |
| 262 | if (!IsEnabled()) |
| 263 | return true; |
| 264 | |
| 265 | // Subpixel Morphological Antialiasing (SMAA). |
| 266 | if (m_frameStarted && CanRenderAntialiasing()) |
| 267 | { |
| 268 | ASSERT(m_staticTextures->m_smaaAreaTexture != nullptr, ()); |
| 269 | ASSERT(m_staticTextures->m_smaaSearchTexture != nullptr, ()); |
| 270 | |
| 271 | if (m_apiVersion == dp::ApiVersion::OpenGLES3) |
| 272 | { |
| 273 | ASSERT_GREATER(m_staticTextures->m_smaaAreaTexture->GetID(), 0, ()); |
| 274 | ASSERT_GREATER(m_staticTextures->m_smaaSearchTexture->GetID(), 0, ()); |
| 275 | } |
| 276 | |
| 277 | context->SetClearColor(dp::Color::Transparent()); |
| 278 | context->SetStencilTestEnabled(true); |
| 279 | |
| 280 | // Render edges to texture. |
| 281 | { |
| 282 | TRACE_SECTION("[drape][SMAA] Edges rendering"); |
| 283 | context->SetFramebuffer(make_ref(m_edgesFramebuffer)); |
| 284 | context->Clear(dp::ClearBits::ColorBit, dp::ClearBits::ColorBit | dp::ClearBits::StencilBit /* storeBits */); |
| 285 | if (m_apiVersion == dp::ApiVersion::Metal || m_apiVersion == dp::ApiVersion::Vulkan) |
| 286 | context->SetStencilFunction(dp::StencilFace::FrontAndBack, dp::TestFunction::Greater); |
| 287 | else |
| 288 | context->SetStencilFunction(dp::StencilFace::FrontAndBack, dp::TestFunction::NotEqual); |
| 289 | context->SetStencilActions(dp::StencilFace::FrontAndBack, dp::StencilAction::Zero, dp::StencilAction::Zero, |
| 290 | dp::StencilAction::Replace); |
| 291 | context->SetStencilReferenceValue(1); |
| 292 | context->ApplyFramebuffer("SMAA edges"); |
| 293 | viewport.Apply(context); |
| 294 | |
| 295 | EdgesRenderParams params; |
| 296 | params.SetParams(m_mainFramebuffer->GetTexture(), m_width, m_height); |
| 297 | |
| 298 | auto program = gpuProgramManager->GetProgram(params.GetRenderState().GetProgram<gpu::Program>()); |
| 299 | m_screenQuadRenderer->Render(context, program, params.GetRenderState(), gpuProgramManager->GetParamsSetter(), |
| 300 | params.GetProgramParams()); |
| 301 | } |
| 302 | |
| 303 | // Render blending weight to texture. |
| 304 | { |
| 305 | TRACE_SECTION("[drape][SMAA] Blending weight rendering"); |
| 306 | context->SetFramebuffer(make_ref(m_blendingWeightFramebuffer)); |
| 307 | context->Clear(dp::ClearBits::ColorBit, dp::ClearBits::ColorBit | dp::ClearBits::StencilBit /* storeBits */); |
| 308 | context->SetStencilFunction(dp::StencilFace::FrontAndBack, dp::TestFunction::Equal); |
| 309 | context->SetStencilActions(dp::StencilFace::FrontAndBack, dp::StencilAction::Keep, dp::StencilAction::Keep, |
| 310 | dp::StencilAction::Keep); |
| 311 | context->ApplyFramebuffer("SMAA blending"); |
| 312 | viewport.Apply(context); |
| 313 | |
| 314 | BlendingWeightRenderParams params; |
| 315 | params.SetParams(m_edgesFramebuffer->GetTexture(), m_staticTextures->m_smaaAreaTexture, |
no test coverage detected