display: Correctly update for changed pixel scale

This commit is contained in:
Tommy 2022-07-18 23:02:58 +12:00
parent 0548f5a490
commit 5c575548fd
3 changed files with 23 additions and 9 deletions

View File

@ -2603,7 +2603,7 @@ bool display::expose(const SDL_Rect& region)
draw::fill(map_outside_area().intersect(region), fade_color_);
}
LOG_DP << "display::expose " << region;
DBG_DP << "display::expose " << region;
return true; // TODO: draw_manager - maybe don't flip yeah?
}
@ -2630,17 +2630,25 @@ void display::update_render_textures()
// Check that the front buffer size is correct.
// Buffers are always resized together, so we only need to check one.
point size = front_.get_raw_size();
if (size.x == oarea.w && size.y == oarea.h) {
point dsize = front_.draw_size();
bool raw_size_changed = size.x != oarea.w || size.y != oarea.h;
bool draw_size_changed = dsize.x != darea.w || dsize.y != darea.h;
if (!raw_size_changed && !draw_size_changed) {
// buffers are fine
return;
}
// For now, just clobber and regenerate both textures.
LOG_DP << "updating display render buffers to " << oarea;
front_ = texture(oarea.w, oarea.h, SDL_TEXTUREACCESS_TARGET);
front_.set_draw_size(darea.w, darea.h);
back_ = texture(oarea.w, oarea.h, SDL_TEXTUREACCESS_TARGET);
back_.set_draw_size(darea.w, darea.h);
// TODO: draw_manager - these need to account for the logical offset
if(raw_size_changed) {
LOG_DP << "regenerating render buffers as " << oarea;
front_ = texture(oarea.w, oarea.h, SDL_TEXTUREACCESS_TARGET);
back_ = texture(oarea.w, oarea.h, SDL_TEXTUREACCESS_TARGET);
}
if(raw_size_changed || draw_size_changed) {
LOG_DP << "updating render buffer draw size to " << darea;
front_.set_draw_size(darea.w, darea.h);
back_.set_draw_size(darea.w, darea.h);
}
// Fill entire texture with black, just in case
for(int i = 0; i < 2; ++i) {

View File

@ -18,6 +18,7 @@
#include "gui/dialogs/preferences_dialog.hpp"
#include "display.hpp"
#include "events.hpp"
#include "filesystem.hpp"
#include "formatter.hpp"
@ -326,6 +327,11 @@ void preferences_dialog::apply_pixel_scale()
// Update draw buffers, taking these into account.
video::update_buffers();
// Update game display, if active
if(::display* disp = display::get_singleton()) {
disp->queue_rerender();
}
// Raise a window resize event so we can react to the change
events::raise_resize_event();
}

View File

@ -775,7 +775,7 @@ bool set_resolution(const point& resolution)
void update_buffers(bool autoupdate)
{
LOG_DP << "updating buffers";
LOG_DP << "updating video buffers";
if(update_framebuffer() && autoupdate) {
draw_manager::invalidate_all();
}