| 876 | } |
| 877 | |
| 878 | void UpdateFullscreenResolutions() |
| 879 | { |
| 880 | // Query number of display modes |
| 881 | int32_t displayIndex = SDL_GetWindowDisplayIndex(_window); |
| 882 | int32_t numDisplayModes = SDL_GetNumDisplayModes(displayIndex); |
| 883 | |
| 884 | // Get desktop aspect ratio |
| 885 | SDL_DisplayMode mode; |
| 886 | SDL_GetDesktopDisplayMode(displayIndex, &mode); |
| 887 | |
| 888 | // Get resolutions |
| 889 | auto resolutions = std::vector<Resolution>(); |
| 890 | float desktopAspectRatio = static_cast<float>(mode.w) / mode.h; |
| 891 | for (int32_t i = 0; i < numDisplayModes; i++) |
| 892 | { |
| 893 | SDL_GetDisplayMode(displayIndex, i, &mode); |
| 894 | if (mode.w > 0 && mode.h > 0) |
| 895 | { |
| 896 | float aspectRatio = static_cast<float>(mode.w) / mode.h; |
| 897 | if (std::fabs(desktopAspectRatio - aspectRatio) < 0.1f) |
| 898 | { |
| 899 | resolutions.push_back({ mode.w, mode.h }); |
| 900 | } |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | // Sort by area |
| 905 | std::sort(resolutions.begin(), resolutions.end(), [](const Resolution& a, const Resolution& b) -> bool { |
| 906 | int32_t areaA = a.Width * a.Height; |
| 907 | int32_t areaB = b.Width * b.Height; |
| 908 | return areaA < areaB; |
| 909 | }); |
| 910 | |
| 911 | // Remove duplicates |
| 912 | auto last = std::unique(resolutions.begin(), resolutions.end(), [](const Resolution& a, const Resolution& b) -> bool { |
| 913 | return (a.Width == b.Width && a.Height == b.Height); |
| 914 | }); |
| 915 | resolutions.erase(last, resolutions.end()); |
| 916 | |
| 917 | // Update config fullscreen resolution if not set |
| 918 | if (!resolutions.empty() |
| 919 | && (Config::Get().general.fullscreenWidth == -1 || Config::Get().general.fullscreenHeight == -1)) |
| 920 | { |
| 921 | Config::Get().general.fullscreenWidth = resolutions.back().Width; |
| 922 | Config::Get().general.fullscreenHeight = resolutions.back().Height; |
| 923 | } |
| 924 | |
| 925 | _fsResolutions = resolutions; |
| 926 | } |
| 927 | |
| 928 | Resolution GetClosestResolution(int32_t inWidth, int32_t inHeight) |
| 929 | { |
no test coverage detected