adjust the tv output image size according to the current snes resolution

This commit is contained in:
2024-11-06 22:32:12 -05:00
parent cee99d12f4
commit 05c72726d7
3 changed files with 20 additions and 5 deletions
@@ -223,7 +223,7 @@ fn paint_texture(ui: &mut Ui, texture: &mut Option<TextureHandle>, framebuffer:
if let Some(txt) = texture {
txt.set(
ColorImage::from_rgba_premultiplied([width, height], framebuffer),
TextureOptions::default(),
TextureOptions::LINEAR,
);
let (whole_rect, _) =
ui.allocate_exact_size(Vec2::from([(width * 2) as f32, (height * 2) as f32]), egui::Sense::focusable_noninteractive());
+18 -4
View File
@@ -1,4 +1,4 @@
use eframe::egui;
use eframe::egui::{self, Pos2, Rect};
use eframe::{egui::Context, epaint::ColorImage};
use eframe::egui::{TextureOptions, Ui};
use eframe::epaint::{Vec2, TextureHandle};
@@ -12,11 +12,12 @@ pub fn build_game_window(
ctx: &egui::Context,
game_tv_texture: &mut Option<TextureHandle>,
framebuffer: &[u8],
current_res: (u16, u16),
) {
egui::Window::new("TV")
.collapsible(false)
.show(ctx, |ui| {
paint_game_texture(ui, game_tv_texture, framebuffer);
paint_game_texture(ui, game_tv_texture, framebuffer, current_res);
});
}
@@ -33,21 +34,34 @@ pub fn initialize_game_texture(ctx: &Context, game_tv_texture: &mut Option<Textu
}
}
fn paint_game_texture(ui: &mut Ui, texture: &mut Option<TextureHandle>, framebuffer: &[u8]) {
fn paint_game_texture(ui: &mut Ui, texture: &mut Option<TextureHandle>, framebuffer: &[u8], current_res: (u16, u16)) {
if let Some(txt) = texture {
txt.set(
ColorImage::from_rgba_premultiplied([MAX_TV_WIDTH, MAX_TV_HEIGHT], framebuffer),
TextureOptions::default(),
TextureOptions::LINEAR,
);
let (whole_rect, _) =
ui.allocate_exact_size(
Vec2::from([(MAX_TV_WIDTH) as f32, (MAX_TV_HEIGHT) as f32]),
egui::Sense::focusable_noninteractive(),
);
let current_resolution_scale = calculate_resolution_scale(current_res);
egui::Image::new((
txt.id(),
txt.size_vec2(),
))
.texture_options(TextureOptions::LINEAR)
.uv(Rect::from_two_pos(
Pos2::new(0.0,0.0),
Pos2::new(current_resolution_scale.0, current_resolution_scale.1))
)
.paint_at(ui, whole_rect);
}
}
fn calculate_resolution_scale(current_res: (u16, u16)) -> (f32, f32) {
(
current_res.0 as f32 / MAX_TV_WIDTH as f32,
current_res.1 as f32 / MAX_TV_HEIGHT as f32,
)
}
+1
View File
@@ -30,6 +30,7 @@ impl eframe::App for SnesEmulatorApp {
ctx,
&mut self.state.game_tv_texture,
self.emulator.bus.ppu.framebuffer(),
self.emulator.bus.ppu.registers.get_current_res(),
);
emu_ui::debug::build_all_debug_options(ctx, &mut self.state.debug_options, &mut self.state.emulation_state, &mut self.emulator);
if !self.state.emulation_state.is_paused {