PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
gpu_preference_tokens_internal.h
1#pragma once
2
3#include "pixelbullet/graphics/gpu_selection.h"
4
5#include <optional>
6#include <string_view>
7
8namespace pixelbullet::application_internal
9{
10inline constexpr std::string_view k_graphics_device_preference_token_values = "auto|discrete|integrated|virtual|cpu";
11
12[[nodiscard]] inline std::optional<GraphicsDevicePreference> parse_graphics_device_preference_token(const std::string_view value) noexcept
13{
14 if (value == "auto")
15 {
16 return GraphicsDevicePreference::Auto;
17 }
18 if (value == "discrete")
19 {
20 return GraphicsDevicePreference::Discrete;
21 }
22 if (value == "integrated")
23 {
24 return GraphicsDevicePreference::Integrated;
25 }
26 if (value == "virtual")
27 {
28 return GraphicsDevicePreference::Virtual;
29 }
30 if (value == "cpu")
31 {
32 return GraphicsDevicePreference::Cpu;
33 }
34
35 return std::nullopt;
36}
37
38[[nodiscard]] inline std::optional<std::string_view> graphics_device_preference_token(const GraphicsDevicePreference preference) noexcept
39{
40 switch (preference)
41 {
42 case GraphicsDevicePreference::Auto:
43 return "auto";
44 case GraphicsDevicePreference::Discrete:
45 return "discrete";
46 case GraphicsDevicePreference::Integrated:
47 return "integrated";
48 case GraphicsDevicePreference::Virtual:
49 return "virtual";
50 case GraphicsDevicePreference::Cpu:
51 return "cpu";
52 }
53
54 return std::nullopt;
55}
56
57[[nodiscard]] inline std::string_view graphics_device_preference_token_or_unknown(const GraphicsDevicePreference preference) noexcept
58{
59 if (const auto token = graphics_device_preference_token(preference); token.has_value())
60 {
61 return *token;
62 }
63
64 return "unknown";
65}
66} // namespace pixelbullet::application_internal