presentation: bool integer_scale -> enum PresentationMode (integer_scale|letterbox|stretched|overscan) amb migracio de configs antics
This commit is contained in:
@@ -292,21 +292,48 @@ namespace Rendering {
|
||||
// computeViewport — dimensions lògiques del canvas dins del swapchain (letterbox)
|
||||
// ---------------------------------------------------------------------------
|
||||
auto SDL3GPUShader::computeViewport(Uint32 sw, Uint32 sh) const -> Viewport {
|
||||
const auto SWF = static_cast<float>(sw);
|
||||
const auto SHF = static_cast<float>(sh);
|
||||
const float CANVAS_RATIO = static_cast<float>(game_width_) / static_cast<float>(game_height_);
|
||||
const float WINDOW_RATIO = SWF / SHF;
|
||||
|
||||
float vw = 0.0F;
|
||||
float vh = 0.0F;
|
||||
if (integer_scale_) {
|
||||
const int SCALE = std::max(1, std::min(static_cast<int>(sw) / game_width_, static_cast<int>(sh) / game_height_));
|
||||
vw = static_cast<float>(game_width_ * SCALE);
|
||||
vh = static_cast<float>(game_height_ * SCALE);
|
||||
} else {
|
||||
const float SCALE = std::min(
|
||||
static_cast<float>(sw) / static_cast<float>(game_width_),
|
||||
static_cast<float>(sh) / static_cast<float>(game_height_));
|
||||
vw = static_cast<float>(game_width_) * SCALE;
|
||||
vh = static_cast<float>(game_height_) * SCALE;
|
||||
switch (presentation_mode_) {
|
||||
case PresentationMode::INTEGER_SCALE: {
|
||||
const int SCALE = std::max(1, std::min(static_cast<int>(sw) / game_width_, static_cast<int>(sh) / game_height_));
|
||||
vw = static_cast<float>(game_width_ * SCALE);
|
||||
vh = static_cast<float>(game_height_ * SCALE);
|
||||
break;
|
||||
}
|
||||
case PresentationMode::LETTERBOX: {
|
||||
if (WINDOW_RATIO >= CANVAS_RATIO) {
|
||||
vh = SHF;
|
||||
vw = SHF * CANVAS_RATIO;
|
||||
} else {
|
||||
vw = SWF;
|
||||
vh = SWF / CANVAS_RATIO;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PresentationMode::STRETCHED: {
|
||||
vw = SWF;
|
||||
vh = SHF;
|
||||
break;
|
||||
}
|
||||
case PresentationMode::OVERSCAN: {
|
||||
if (WINDOW_RATIO >= CANVAS_RATIO) {
|
||||
vw = SWF;
|
||||
vh = SWF / CANVAS_RATIO;
|
||||
} else {
|
||||
vh = SHF;
|
||||
vw = SHF * CANVAS_RATIO;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
const float VX = std::floor((static_cast<float>(sw) - vw) * 0.5F);
|
||||
const float VY = std::floor((static_cast<float>(sh) - vh) * 0.5F);
|
||||
const float VX = std::floor((SWF - vw) * 0.5F);
|
||||
const float VY = std::floor((SHF - vh) * 0.5F);
|
||||
return {.x = VX, .y = VY, .w = vw, .h = vh};
|
||||
}
|
||||
|
||||
@@ -569,8 +596,8 @@ namespace Rendering {
|
||||
}
|
||||
}
|
||||
|
||||
void SDL3GPUShader::setScaleMode(bool integer_scale) {
|
||||
integer_scale_ = integer_scale;
|
||||
void SDL3GPUShader::setPresentationMode(PresentationMode mode) {
|
||||
presentation_mode_ = mode;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user