opcions per defecte d'emscripten
This commit is contained in:
@@ -42,10 +42,9 @@ Screen::Screen() {
|
|||||||
|
|
||||||
window_ = SDL_CreateWindow(Locale::get("window.title"), w, h, fullscreen_ ? SDL_WINDOW_FULLSCREEN : 0);
|
window_ = SDL_CreateWindow(Locale::get("window.title"), w, h, fullscreen_ ? SDL_WINDOW_FULLSCREEN : 0);
|
||||||
renderer_ = SDL_CreateRenderer(window_, nullptr);
|
renderer_ = SDL_CreateRenderer(window_, nullptr);
|
||||||
SDL_SetRenderLogicalPresentation(renderer_, GAME_WIDTH, GAME_HEIGHT, SDL_LOGICAL_PRESENTATION_LETTERBOX);
|
|
||||||
|
|
||||||
texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING, GAME_WIDTH, GAME_HEIGHT);
|
texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING, GAME_WIDTH, GAME_HEIGHT);
|
||||||
SDL_SetTextureScaleMode(texture_, SDL_SCALEMODE_NEAREST);
|
applyFallbackPresentation();
|
||||||
|
|
||||||
// Inicialitza backend GPU si l'acceleració està activada
|
// Inicialitza backend GPU si l'acceleració està activada
|
||||||
initShaders();
|
initShaders();
|
||||||
@@ -204,6 +203,8 @@ void Screen::toggleAspectRatio() {
|
|||||||
Options::video.aspect_ratio_4_3 = !Options::video.aspect_ratio_4_3;
|
Options::video.aspect_ratio_4_3 = !Options::video.aspect_ratio_4_3;
|
||||||
if (shader_backend_) {
|
if (shader_backend_) {
|
||||||
shader_backend_->setStretch4_3(Options::video.aspect_ratio_4_3);
|
shader_backend_->setStretch4_3(Options::video.aspect_ratio_4_3);
|
||||||
|
} else {
|
||||||
|
applyFallbackPresentation();
|
||||||
}
|
}
|
||||||
if (!fullscreen_) {
|
if (!fullscreen_) {
|
||||||
adjustWindowSize();
|
adjustWindowSize();
|
||||||
@@ -214,6 +215,8 @@ void Screen::toggleIntegerScale() {
|
|||||||
Options::video.integer_scale = !Options::video.integer_scale;
|
Options::video.integer_scale = !Options::video.integer_scale;
|
||||||
if (shader_backend_) {
|
if (shader_backend_) {
|
||||||
shader_backend_->setScaleMode(Options::video.integer_scale);
|
shader_backend_->setScaleMode(Options::video.integer_scale);
|
||||||
|
} else {
|
||||||
|
applyFallbackPresentation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,6 +231,8 @@ void Screen::toggleStretchFilter() {
|
|||||||
Options::video.stretch_filter_linear = !Options::video.stretch_filter_linear;
|
Options::video.stretch_filter_linear = !Options::video.stretch_filter_linear;
|
||||||
if (shader_backend_) {
|
if (shader_backend_) {
|
||||||
shader_backend_->setStretchFilter(Options::video.stretch_filter_linear);
|
shader_backend_->setStretchFilter(Options::video.stretch_filter_linear);
|
||||||
|
} else {
|
||||||
|
applyFallbackPresentation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,6 +388,27 @@ void Screen::updateRenderInfo() {
|
|||||||
0b1001);
|
0b1001);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Screen::applyFallbackPresentation() {
|
||||||
|
// Fallback SDL_Renderer (p.ex. emscripten/WebGL2 sense shaders GPU): tria
|
||||||
|
// el mode de presentació lògica segons 4:3 i integer_scale, i aplica el
|
||||||
|
// filtre de la textura segons stretch_filter_linear. Sense açò, el path
|
||||||
|
// fallback mostrava sempre LETTERBOX i ignorava les tres flags.
|
||||||
|
SDL_ScaleMode scale = Options::video.stretch_filter_linear ? SDL_SCALEMODE_LINEAR : SDL_SCALEMODE_NEAREST;
|
||||||
|
if (texture_) SDL_SetTextureScaleMode(texture_, scale);
|
||||||
|
|
||||||
|
SDL_RendererLogicalPresentation mode;
|
||||||
|
if (Options::video.aspect_ratio_4_3) {
|
||||||
|
// La finestra ja té aspect 4:3 (alçada × 1.2); STRETCH estira la
|
||||||
|
// textura 320×200 fins a omplir-la exactament.
|
||||||
|
mode = SDL_LOGICAL_PRESENTATION_STRETCH;
|
||||||
|
} else if (Options::video.integer_scale) {
|
||||||
|
mode = SDL_LOGICAL_PRESENTATION_INTEGER_SCALE;
|
||||||
|
} else {
|
||||||
|
mode = SDL_LOGICAL_PRESENTATION_LETTERBOX;
|
||||||
|
}
|
||||||
|
SDL_SetRenderLogicalPresentation(renderer_, GAME_WIDTH, GAME_HEIGHT, mode);
|
||||||
|
}
|
||||||
|
|
||||||
void Screen::adjustWindowSize() {
|
void Screen::adjustWindowSize() {
|
||||||
int w = GAME_WIDTH * zoom_;
|
int w = GAME_WIDTH * zoom_;
|
||||||
// Si 4:3 actiu, l'alçada visual és 240 per zoom (200 * 1.2)
|
// Si 4:3 actiu, l'alçada visual és 240 per zoom (200 * 1.2)
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ class Screen {
|
|||||||
void adjustWindowSize();
|
void adjustWindowSize();
|
||||||
void calculateMaxZoom();
|
void calculateMaxZoom();
|
||||||
void initShaders();
|
void initShaders();
|
||||||
|
void applyFallbackPresentation(); // Logical presentation + scale mode per al path SDL_Renderer
|
||||||
|
|
||||||
static Screen* instance_;
|
static Screen* instance_;
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,15 @@ SDL_AppResult SDL_AppInit(void** /*appstate*/, int /*argc*/, char* /*argv*/[]) {
|
|||||||
Options::setConfigFile(std::string(file_getconfigfolder()) + "config.yaml");
|
Options::setConfigFile(std::string(file_getconfigfolder()) + "config.yaml");
|
||||||
Options::loadFromFile();
|
Options::loadFromFile();
|
||||||
|
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
// MEMFS no persistix entre recàrregues: força valors sensats per a web.
|
||||||
|
Options::window.fullscreen = false;
|
||||||
|
Options::window.zoom = 1;
|
||||||
|
Options::video.aspect_ratio_4_3 = true;
|
||||||
|
Options::video.integer_scale = true;
|
||||||
|
Options::video.stretch_filter_linear = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Carrega textos (idioma per defecte: valencià)
|
// Carrega textos (idioma per defecte: valencià)
|
||||||
Locale::load("locale/ca.yaml");
|
Locale::load("locale/ca.yaml");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user