- posibilitat de desactivar la aceleració hardware desde el fitxer de configuració de manera mes intuitiva

- si no hi ha aceleració ja no va cap tecla ni comando relacionat amb els shaders
This commit is contained in:
2026-04-01 18:24:22 +02:00
parent c689507982
commit a804ad1368
8 changed files with 41 additions and 24 deletions

View File

@@ -160,6 +160,7 @@ namespace GlobalInputs {
return InputAction::WINDOW_INC_ZOOM;
}
}
if (Screen::get()->isHardwareAccelerated()) {
if (Input::get()->checkAction(InputAction::TOGGLE_SHADER, Input::DO_NOT_ALLOW_REPEAT)) {
if ((SDL_GetModState() & SDL_KMOD_CTRL) != 0U) {
return InputAction::TOGGLE_SUPERSAMPLING; // Ctrl+F4
@@ -169,6 +170,7 @@ namespace GlobalInputs {
}
return InputAction::TOGGLE_SHADER; // F4
}
}
if (Input::get()->checkAction(InputAction::NEXT_PALETTE, Input::DO_NOT_ALLOW_REPEAT)) {
return InputAction::NEXT_PALETTE;
}

View File

@@ -602,7 +602,8 @@ void Screen::initShaders() {
if (!shader_backend_) {
shader_backend_ = std::make_unique<Rendering::SDL3GPUShader>();
shader_backend_->setPreferredDriver(Options::video.gpu_preferred_driver);
const std::string fallback_driver = "none";
shader_backend_->setPreferredDriver(Options::video.gpu_acceleration ? Options::video.gpu_preferred_driver : fallback_driver);
}
shader_backend_->init(window_, tex, "", "");
gpu_driver_ = shader_backend_->getDriverName();

View File

@@ -81,6 +81,7 @@ class Screen {
[[nodiscard]] auto getText() const -> std::shared_ptr<Text> { return text_; }
[[nodiscard]] auto getGameSurfaceDstRect() const -> SDL_FRect { return game_surface_dstrect_; }
[[nodiscard]] auto getGPUDriver() const -> const std::string& { return gpu_driver_; }
[[nodiscard]] auto isHardwareAccelerated() const -> bool { return shader_backend_ && shader_backend_->isHardwareAccelerated(); }
[[nodiscard]] auto getLastFPS() const -> int { return fps_.last_value; }
[[nodiscard]] auto getZoomFactor() const -> float { return zoom_factor_; }
[[nodiscard]] auto getMaxZoom() const -> int;

View File

@@ -403,7 +403,7 @@ namespace Rendering {
// ----------------------------------------------------------------
if (preferred_driver_ == "none") {
SDL_Log("SDL3GPUShader: GPU disabled by config, using SDL_Renderer fallback");
driver_name_ = "none";
driver_name_ = ""; // vacío → RenderInfo mostrará "sdl"
return false;
}
if (device_ == nullptr) {

View File

@@ -32,6 +32,7 @@ namespace Defaults::Video {
constexpr const char* PALETTE_NAME = "zx-spectrum"; // Paleta por defecto
constexpr bool LINEAR_UPSCALE = false; // Upscale NEAREST por defecto
constexpr int DOWNSCALE_ALGO = 1; // Downscale Lanczos2 por defecto
constexpr bool GPU_ACCELERATION = true; // Aceleración GPU activada por defecto
} // namespace Defaults::Video
namespace Defaults::Border {

View File

@@ -399,6 +399,14 @@ namespace Options {
}
}
if (vid.contains("gpu_acceleration")) {
try {
video.gpu_acceleration = vid["gpu_acceleration"].get_value<bool>();
} catch (...) {
video.gpu_acceleration = Defaults::Video::GPU_ACCELERATION;
}
}
if (vid.contains("gpu_preferred_driver")) {
try {
video.gpu_preferred_driver = vid["gpu_preferred_driver"].get_value<std::string>();
@@ -715,7 +723,8 @@ namespace Options {
file << " keep_aspect: " << (video.keep_aspect ? "true" : "false") << "\n";
file << " linear_upscale: " << (video.linear_upscale ? "true" : "false") << "\n";
file << " downscale_algo: " << video.downscale_algo << " # 0=bilinear, 1=Lanczos2, 2=Lanczos3\n";
file << " gpu_preferred_driver: \"" << video.gpu_preferred_driver << "\" # GPU driver (empty = auto)\n";
file << " gpu_acceleration: " << (video.gpu_acceleration ? "true" : "false") << " # Usar aceleración hardware GPU (false = SDL fallback)\n";
file << " gpu_preferred_driver: \"" << video.gpu_preferred_driver << "\" # Driver GPU específico (empty = auto, aplica solo si gpu_acceleration: true)\n";
file << " palette: " << video.palette << "\n";
file << " border:\n";
file << " enabled: " << (video.border.enabled ? "true" : "false") << "\n";

View File

@@ -89,6 +89,7 @@ namespace Options {
Border border{}; // Borde de la pantalla
std::string palette{Defaults::Video::PALETTE_NAME}; // Paleta de colores a usar en el juego
std::string info; // Información sobre el modo de vídeo
bool gpu_acceleration{Defaults::Video::GPU_ACCELERATION}; // Usar aceleración GPU; false = path SDL fallback directo
std::string gpu_preferred_driver; // Driver GPU preferido; vacío = auto. Aplica en el próximo arranque.
};

View File

@@ -147,6 +147,7 @@ static constexpr bool CHEAT_HIDDEN = true;
static const std::vector<ConsoleCommand> COMMANDS = {
// SS [ON|OFF|SIZE|UPSCALE [NEAREST|LINEAR]|DOWNSCALE [BILINEAR|LANCZOS2|LANCZOS3]] — Supersampling
{.keyword = "SS", .execute = [](const std::vector<std::string>& args) -> std::string {
if (!Screen::get()->isHardwareAccelerated()) { return "No GPU acceleration"; }
static const std::array<std::string_view, 3> DOWNSCALE_NAMES = {"Bilinear", "Lanczos2", "Lanczos3"};
if (!args.empty() && args[0] == "SIZE") {
if (!Options::video.supersampling) { return "Supersampling is OFF: no texture"; }
@@ -210,6 +211,7 @@ static const std::vector<ConsoleCommand> COMMANDS = {
// SHADER [ON|OFF|NEXT [PRESET]|POSTFX|CRTPI] — Toggle/cicla/selecciona shader (F4 / Shift+F4)
{.keyword = "SHADER", .execute = [](const std::vector<std::string>& args) -> std::string {
if (!Screen::get()->isHardwareAccelerated()) { return "No GPU acceleration"; }
if (args.empty()) {
Screen::get()->toggleShaders();
return std::string("Shader ") + (Options::video.postfx ? "ON" : "OFF");