| 669 | } |
| 670 | |
| 671 | void LevelHandler::OnInitializeViewport(std::int32_t width, std::int32_t height) |
| 672 | { |
| 673 | ZoneScopedC(0x4876AF); |
| 674 | |
| 675 | auto& resolver = ContentResolver::Get(); |
| 676 | if (resolver.IsHeadless()) { |
| 677 | // Use only the main viewport in headless mode |
| 678 | _rootNode->setParent(&theApplication().GetRootNode()); |
| 679 | return; |
| 680 | } |
| 681 | |
| 682 | constexpr float defaultRatio = (float)DefaultWidth / DefaultHeight; |
| 683 | float currentRatio = (float)width / height; |
| 684 | |
| 685 | std::int32_t w, h; |
| 686 | if (currentRatio > defaultRatio) { |
| 687 | w = std::min(DefaultWidth, width); |
| 688 | h = (std::int32_t)roundf(w / currentRatio); |
| 689 | } else if (currentRatio < defaultRatio) { |
| 690 | h = std::min(DefaultHeight, height); |
| 691 | w = (std::int32_t)roundf(h * currentRatio); |
| 692 | } else { |
| 693 | w = std::min(DefaultWidth, width); |
| 694 | h = std::min(DefaultHeight, height); |
| 695 | } |
| 696 | |
| 697 | _viewSize = Vector2i(w, h); |
| 698 | _upscalePass.Initialize(w, h, width, height); |
| 699 | |
| 700 | bool notInitialized = (_combineShader == nullptr); |
| 701 | if (notInitialized) { |
| 702 | LOGI("Acquiring required shaders"); |
| 703 | |
| 704 | _lightingShader = resolver.GetShader(PrecompiledShader::Lighting); |
| 705 | if (_lightingShader == nullptr) { LOGW("PrecompiledShader::Lighting failed"); } |
| 706 | _blurShader = resolver.GetShader(PrecompiledShader::Blur); |
| 707 | if (_blurShader == nullptr) { LOGW("PrecompiledShader::Blur failed"); } |
| 708 | _downsampleShader = resolver.GetShader(PrecompiledShader::Downsample); |
| 709 | if (_downsampleShader == nullptr) { LOGW("PrecompiledShader::Downsample failed"); } |
| 710 | _combineShader = resolver.GetShader(PrecompiledShader::Combine); |
| 711 | if (_combineShader == nullptr) { LOGW("PrecompiledShader::Combine failed"); } |
| 712 | |
| 713 | if (_hud != nullptr) { |
| 714 | _hud->setParent(_upscalePass.GetNode()); |
| 715 | } |
| 716 | if (_console != nullptr) { |
| 717 | _console->setParent(_upscalePass.GetNode()); |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | _combineWithWaterShader = resolver.GetShader(PreferencesCache::LowWaterQuality |
| 722 | ? PrecompiledShader::CombineWithWaterLow |
| 723 | : PrecompiledShader::CombineWithWater); |
| 724 | if (_combineWithWaterShader == nullptr) { |
| 725 | if (PreferencesCache::LowWaterQuality) { |
| 726 | LOGW("PrecompiledShader::CombineWithWaterLow failed"); |
| 727 | } else { |
| 728 | LOGW("PrecompiledShader::CombineWithWater failed"); |
no test coverage detected