12 [[
nodiscard]] std::expected<std::pair<int, int>, std::string>
16 if (
separator == std::string_view::npos ||
18 return std::unexpected(
19 "--resolution expects WIDTHxHEIGHT");
35 return std::unexpected(
36 "--resolution must be between 640x360 and 16384x16384");
53 std::expected<Options, std::string>
65 -> std::expected<void, std::string>
68 return std::unexpected(
69 "window mode was specified more than once");
78 return std::unexpected(changed.error());
84 return std::unexpected(changed.error());
86 else if (
argument ==
"--exclusive-fullscreen")
90 return std::unexpected(changed.error());
96 return std::unexpected(
97 "--resolution requires one WIDTHxHEIGHT value");
100 return std::unexpected(
parsed.error());
105 else if (
argument ==
"--present-mode")
109 return std::unexpected(
110 "--present-mode requires vsync, mailbox or immediate");
113 return std::unexpected(
114 "--present-mode requires vsync, mailbox or immediate");
142 const Options& options)
noexcept
144 return {options.
width, options.height};
148 std::expected<void, std::string>
152 return std::unexpected(
"presentation window is null");
179 return std::unexpected(
"no display is available for fullscreen");
207 std::expected<void, std::string>
213 return std::unexpected(
"presentation window is null");
261 default:
return "vsync";
273 default:
return "borderless-fullscreen";
278 std::expected<SDL_GPUPresentMode, std::string>
285 return std::unexpected(
"GPU presentation owner is missing");
289 device,
window, selected))
297 return std::unexpected(
298 std::string(
"SDL_SetGPUSwapchainParameters: ") +
304 return std::unexpected(
305 std::string(
"SDL_SetGPUAllowedFramesInFlight: ") +
324 if (
elapsed < 1'000'000'000ULL)
327 lastFramesPerSecond_ =
328 static_cast<double>(sampleFrames_) *
342 "Monopoly Modern - %dx%d - %.1f FPS",
345 lastFramesPerSecond_);
351 sampleStartNanoseconds_ =
now;
357 return lastFramesPerSecond_;
double lastFramesPerSecond() const noexcept
FrameTelemetry(SDL_Window *window) noexcept
void framePresented() noexcept
std::expected< Options, std::string > parseArguments(std::span< const std::string_view > arguments)
std::expected< void, std::string > configureWindow(SDL_Window *window, const Options &options)
std::string_view presentModeName(PresentMode mode) noexcept
std::string_view windowModeName(WindowMode mode) noexcept
std::expected< SDL_GPUPresentMode, std::string > configureSwapchain(SDL_GPUDevice *device, SDL_Window *window, PresentMode requested)
std::pair< int, int > initialWindowSize(const Options &options) noexcept
SDL_WindowFlags windowFlags(const Options &options) noexcept
SDL_GPUPresentMode toSDLPresentMode(PresentMode mode) noexcept
std::expected< void, std::string > toggleBorderlessFullscreen(SDL_Window *window, const Options &options)
std::vector< std::string_view > remaining