18 SDL_GetWindowSizeInPixels(m_p_window, &width, &height);
20 static constexpr uint32_t MIN_DIMENSION = 64;
21 static constexpr uint32_t MAX_DIMENSION = 32768;
23 if (width <= 0 || height <= 0) {
24 log(LogLevel::WARNING,
"ResolutionManager::update() called with invalid window dimensions: %dx%d. Skipping update.",
29 if (width < MIN_DIMENSION || height < MIN_DIMENSION) {
30 log(LogLevel::WARNING,
"Window resolution %dx%d is below minimum %u. Clamping.",
31 width, height, MIN_DIMENSION);
32 width = std::max(width, (
int)MIN_DIMENSION);
33 height = std::max(height, (
int)MIN_DIMENSION);
36 if (width > MAX_DIMENSION || height > MAX_DIMENSION) {
37 log(LogLevel::WARNING,
"Window resolution %dx%d exceeds maximum %u. Clamping.",
38 width, height, MAX_DIMENSION);
39 width = std::min(width, (
int)MAX_DIMENSION);
40 height = std::min(height, (
int)MAX_DIMENSION);
43 m_windowResolution = {
static_cast<uint32_t
>(width),
static_cast<uint32_t
>(height)};
45 switch(m_currentMode) {
47 m_renderResolution = m_windowResolution;
48 m_upscaleRatio = 1.0f;
53 log(LogLevel::ERROR,
"Invalid height for RES_240P calculation: %d", height);
54 m_renderResolution = m_windowResolution;
55 m_upscaleRatio = 1.0f;
58 float aspect = width /
static_cast<float>(height);
59 m_renderResolution.y = 240;
60 uint32_t calculatedWidth =
static_cast<uint32_t
>(240 * aspect);
61 m_renderResolution.x = std::clamp(calculatedWidth, 64u, 32768u);
62 m_upscaleRatio = std::clamp(height / 240.0f, 0.5f, 136.5f);
68 log(LogLevel::ERROR,
"Invalid height for RES_480P calculation: %d", height);
69 m_renderResolution = m_windowResolution;
70 m_upscaleRatio = 1.0f;
73 float aspect = width /
static_cast<float>(height);
74 m_renderResolution.y = 480;
75 uint32_t calculatedWidth =
static_cast<uint32_t
>(480 * aspect);
76 m_renderResolution.x = std::clamp(calculatedWidth, 64u, 32768u);
77 m_upscaleRatio = std::clamp(height / 480.0f, 0.25f, 68.27f);
86 log(
"Resolution mode updated: %dx%d (render) -> %dx%d (window), scale: %.2f",
87 m_renderResolution.x, m_renderResolution.y,
88 m_windowResolution.x, m_windowResolution.y,
93 if (m_windowResolution.x == 0 || m_windowResolution.y == 0) {
94 log(LogLevel::ERROR,
"getPotencialUpscaleRatio() called with invalid window resolution: %ux%u",
95 m_windowResolution.x, m_windowResolution.y);
96 m_renderResolution = m_windowResolution;
97 m_upscaleRatio = 1.0f;
101 int yscale =
static_cast<int>(floor(m_windowResolution.y / 240.0f));
102 int maxScale = std::max(1, yscale);
104 return std::floor(maxScale);
108 if (m_windowResolution.x == 0 || m_windowResolution.y == 0) {
109 log(LogLevel::ERROR,
"calculatePS1SharpResolution() called with invalid window resolution: %ux%u. Using native resolution.",
110 m_windowResolution.x, m_windowResolution.y);
111 m_renderResolution = m_windowResolution;
112 m_upscaleRatio = 1.0f;
118 m_renderResolution = m_windowResolution /
static_cast<unsigned int>(maxScale);
119 m_upscaleRatio = maxScale;
121 if (m_renderResolution.y < 240) {
122 if (m_windowResolution.y <= 0) {
123 log(LogLevel::ERROR,
"Invalid window height for PS1_SHARP aspect calculation: %u", m_windowResolution.y);
124 m_renderResolution = m_windowResolution;
125 m_upscaleRatio = 1.0f;
129 float aspect = m_windowResolution.x /
static_cast<float>(m_windowResolution.y);
130 m_renderResolution.y = 240;
131 uint32_t calculatedWidth =
static_cast<uint32_t
>(240 * aspect);
132 m_renderResolution.x = std::clamp(calculatedWidth, 64u, 32768u);
133 m_upscaleRatio = std::clamp(m_windowResolution.y / 240.0f, 0.5f, 136.5f);