- renderInfo
- fix: no guardava el preset actual
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
#include "core/rendering/screen.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
|
||||
#include "core/rendering/overlay.hpp"
|
||||
#include "core/rendering/sdl3gpu/sdl3gpu_shader.hpp"
|
||||
#include "game/defines.hpp"
|
||||
#include "game/options.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
Screen* Screen::instance_ = nullptr;
|
||||
|
||||
@@ -81,10 +83,8 @@ void Screen::initShaders() {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* gpu = dynamic_cast<Rendering::SDL3GPUShader*>(shader_backend_.get());
|
||||
if (gpu) {
|
||||
std::cout << "GPU driver: " << gpu->getDriverName() << '\n';
|
||||
}
|
||||
gpu_driver_ = shader_backend_->getDriverName();
|
||||
std::cout << "GPU driver: " << gpu_driver_ << '\n';
|
||||
|
||||
// Aplica opcions de vídeo
|
||||
shader_backend_->setScaleMode(Options::video.integer_scale);
|
||||
@@ -97,12 +97,35 @@ void Screen::initShaders() {
|
||||
shader_backend_->setOversample(3);
|
||||
}
|
||||
|
||||
// Aplica presets per defecte (de moment hardcoded, futur: YAML)
|
||||
// Resol el shader actiu des del config
|
||||
if (Options::video.current_shader == "crtpi") {
|
||||
shader_backend_->setActiveShader(Rendering::ShaderType::CRTPI);
|
||||
} else {
|
||||
shader_backend_->setActiveShader(Rendering::ShaderType::POSTFX);
|
||||
}
|
||||
|
||||
// Resol presets per nom
|
||||
for (int i = 0; i < static_cast<int>(Options::postfx_presets.size()); i++) {
|
||||
if (Options::postfx_presets[i].name == Options::video.current_postfx_preset) {
|
||||
Options::current_postfx_preset = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < static_cast<int>(Options::crtpi_presets.size()); i++) {
|
||||
if (Options::crtpi_presets[i].name == Options::video.current_crtpi_preset) {
|
||||
Options::current_crtpi_preset = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
applyCurrentPostFXPreset();
|
||||
applyCurrentCrtPiPreset();
|
||||
}
|
||||
|
||||
void Screen::present(Uint32* pixel_data) {
|
||||
fps_.increment();
|
||||
fps_.calculate(SDL_GetTicks());
|
||||
updateRenderInfo();
|
||||
Overlay::render(pixel_data);
|
||||
|
||||
if (shader_backend_ && shader_backend_->isHardwareAccelerated() && Options::video.shader_enabled) {
|
||||
@@ -192,9 +215,11 @@ void Screen::nextShaderType() {
|
||||
|
||||
if (shader_backend_->getActiveShader() == Rendering::ShaderType::POSTFX) {
|
||||
shader_backend_->setActiveShader(Rendering::ShaderType::CRTPI);
|
||||
Options::video.current_shader = "crtpi";
|
||||
applyCurrentCrtPiPreset();
|
||||
} else {
|
||||
shader_backend_->setActiveShader(Rendering::ShaderType::POSTFX);
|
||||
Options::video.current_shader = "postfx";
|
||||
applyCurrentPostFXPreset();
|
||||
}
|
||||
}
|
||||
@@ -205,10 +230,12 @@ void Screen::nextPreset() {
|
||||
if (shader_backend_->getActiveShader() == Rendering::ShaderType::POSTFX) {
|
||||
if (Options::postfx_presets.empty()) return;
|
||||
Options::current_postfx_preset = (Options::current_postfx_preset + 1) % static_cast<int>(Options::postfx_presets.size());
|
||||
Options::video.current_postfx_preset = Options::postfx_presets[Options::current_postfx_preset].name;
|
||||
applyCurrentPostFXPreset();
|
||||
} else {
|
||||
if (Options::crtpi_presets.empty()) return;
|
||||
Options::current_crtpi_preset = (Options::current_crtpi_preset + 1) % static_cast<int>(Options::crtpi_presets.size());
|
||||
Options::video.current_crtpi_preset = Options::crtpi_presets[Options::current_crtpi_preset].name;
|
||||
applyCurrentCrtPiPreset();
|
||||
}
|
||||
}
|
||||
@@ -276,6 +303,20 @@ auto Screen::getActiveShaderName() const -> const char* {
|
||||
return shader_backend_->getActiveShader() == Rendering::ShaderType::POSTFX ? "POSTFX" : "CRT-PI";
|
||||
}
|
||||
|
||||
void Screen::updateRenderInfo() {
|
||||
std::string driver = gpu_driver_.empty() ? "sdl" : toLower(gpu_driver_);
|
||||
std::string info = std::to_string(fps_.last_value) + " fps - " + driver;
|
||||
|
||||
if (Options::video.shader_enabled) {
|
||||
std::string shader_name = toLower(getActiveShaderName());
|
||||
std::string preset_name = toLower(getCurrentPresetName());
|
||||
info += " - " + shader_name + " " + preset_name;
|
||||
if (Options::video.supersampling) info += " (ss)";
|
||||
}
|
||||
|
||||
Overlay::setRenderInfoText(info.c_str());
|
||||
}
|
||||
|
||||
void Screen::adjustWindowSize() {
|
||||
int w = GAME_WIDTH * zoom_;
|
||||
// Si 4:3 actiu, l'alçada visual és 240 per zoom (200 * 1.2)
|
||||
|
||||
Reference in New Issue
Block a user