enable retina on Mac, set OpenGL to pixel size properly

This makes things look a bit better, but trades pixelation for blurry
(still TODO). This also fixes an issue on Retina where if you resize
it'd make the viewport 1/4 of the size. The issue here is that OpenGL
uses pixels and glfw uses screen coordinates for everything. We adapt
the screen coords to pixels properly here.
This commit is contained in:
Mitchell Hashimoto
2022-08-09 10:06:30 -07:00
parent cbaf5b585d
commit f94f3cb5a4

View File

@ -165,11 +165,7 @@ pub fn create(alloc: Allocator, loop: libuv.Loop, config: *const Config) !*Windo
.opengl_profile = .opengl_core_profile, .opengl_profile = .opengl_core_profile,
.opengl_forward_compat = true, .opengl_forward_compat = true,
.cocoa_graphics_switching = builtin.os.tag == .macos, .cocoa_graphics_switching = builtin.os.tag == .macos,
.cocoa_retina_framebuffer = true,
// We need to disable this for now since this causes all sorts
// of artifacts and issues to debug. This probably SHOULD be re-enable
// at some point but only when we're ready to debug.
.cocoa_retina_framebuffer = false,
}); });
errdefer window.destroy(); errdefer window.destroy();
@ -417,8 +413,21 @@ fn sizeCallback(window: glfw.Window, width: i32, height: i32) void {
.ws_ypixel = @intCast(u16, height), .ws_ypixel = @intCast(u16, height),
}) catch |err| log.err("error updating pty screen size err={}", .{err}); }) catch |err| log.err("error updating pty screen size err={}", .{err});
// Update our viewport for this context to be the entire window // Get our framebuffer size since this will give us the size in pixels
gl.viewport(0, 0, width, height) catch |err| // whereas width/height in this callback is in screen coordinates. For
// Retina displays (or any other displays that have a scale factor),
// these will not match.
const px_size = window.getFramebufferSize() catch |err| err: {
log.err("error querying window size in pixels, will use screen size err={}", .{err});
break :err glfw.Window.Size{
.width = @intCast(u32, width),
.height = @intCast(u32, height),
};
};
// Update our viewport for this context to be the entire window.
// OpenGL works in pixels, so we have to use the pixel size.
gl.viewport(0, 0, @intCast(i32, px_size.width), @intCast(i32, px_size.height)) catch |err|
log.err("error updating OpenGL viewport err={}", .{err}); log.err("error updating OpenGL viewport err={}", .{err});
// Draw // Draw