fix(ui): remove flickering on ui pause/timeout

This commit is contained in:
Rekai Nyangadzayi Musuka 2023-05-23 02:24:11 -05:00
parent 2b9a479b96
commit d9e09a9cbe
2 changed files with 21 additions and 14 deletions

View File

@ -12,6 +12,7 @@ const emu = @import("core/emu.zig");
const Gui = @import("platform.zig").Gui;
const Arm7tdmi = @import("core/cpu.zig").Arm7tdmi;
const RingBuffer = @import("zba-util").RingBuffer;
const Dimensions = @import("platform.zig").Dimensions;
const Allocator = std.mem.Allocator;
const GLuint = gl.GLuint;
@ -66,8 +67,10 @@ pub const State = struct {
}
};
pub fn draw(state: *State, tex_id: GLuint, cpu: *Arm7tdmi) void {
const win_scale = config.config().host.win_scale;
pub fn draw(state: *State, win_dim: Dimensions, tex_id: GLuint, cpu: *Arm7tdmi) bool {
const scn_scale = config.config().host.win_scale;
zgui.backend.newFrame(@intToFloat(f32, win_dim.width), @intToFloat(f32, win_dim.height));
{
_ = zgui.beginMainMenuBar();
@ -142,8 +145,8 @@ pub fn draw(state: *State, tex_id: GLuint, cpu: *Arm7tdmi) void {
}
{
const w = @intToFloat(f32, gba_width * win_scale);
const h = @intToFloat(f32, gba_height * win_scale);
const w = @intToFloat(f32, gba_width * scn_scale);
const h = @intToFloat(f32, gba_height * scn_scale);
const window_title = std.mem.sliceTo(&state.title, 0);
_ = zgui.begin(window_title, .{ .flags = .{ .no_resize = true, .always_auto_resize = true } });
@ -318,6 +321,8 @@ pub fn draw(state: *State, tex_id: GLuint, cpu: *Arm7tdmi) void {
{
zgui.showDemoWindow(null);
}
return true; // request redraw
}
const widgets = struct {

View File

@ -21,7 +21,7 @@ const GLsizei = gl.GLsizei;
const SDL_GLContext = *anyopaque;
const Allocator = std.mem.Allocator;
const Dimensions = struct { width: u32, height: u32 };
pub const Dimensions = struct { width: u32, height: u32 };
const default_dim: Dimensions = .{ .width = 1280, .height = 720 };
pub const sample_rate = 1 << 15;
@ -187,7 +187,7 @@ pub const Gui = struct {
}
}
zgui.backend.newFrame(@intToFloat(f32, win_dim.width), @intToFloat(f32, win_dim.height));
var zgui_redraw: bool = false;
switch (self.state.emulation) {
.Transition => |inner| switch (inner) {
@ -249,18 +249,20 @@ pub const Gui = struct {
opengl_impl.drawScreenTexture(emu_tex, prog_id, objects, buf);
}
imgui.draw(&self.state, out_tex, cpu);
zgui_redraw = imgui.draw(&self.state, win_dim, out_tex, cpu);
},
.Inactive => imgui.draw(&self.state, out_tex, cpu),
.Inactive => zgui_redraw = imgui.draw(&self.state, win_dim, out_tex, cpu),
}
// Background Colour
const size = zgui.io.getDisplaySize();
gl.viewport(0, 0, @floatToInt(GLsizei, size[0]), @floatToInt(GLsizei, size[1]));
gl.clearColor(0, 0, 0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
if (zgui_redraw) {
// Background Colour
const size = zgui.io.getDisplaySize();
gl.viewport(0, 0, @floatToInt(GLsizei, size[0]), @floatToInt(GLsizei, size[1]));
gl.clearColor(0, 0, 0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
zgui.backend.draw();
zgui.backend.draw();
}
SDL.SDL_GL_SwapWindow(self.window);
}