core: add is_headless to specify hidden window before init (#816)

Co-authored-by: Stephen Gutekanst <stephen.gutekanst@gmail.com>
This commit is contained in:
contribuewwt 2023-06-25 14:48:26 +05:30 committed by GitHub
parent 589a181a92
commit 0319db3e53
Failed to generate hash of commit
2 changed files with 5 additions and 0 deletions

View file

@ -9,6 +9,7 @@ internal: platform.Core,
pub const Options = struct { pub const Options = struct {
is_app: bool = false, is_app: bool = false,
is_headless: bool = false,
title: [*:0]const u8 = "Mach Engine", title: [*:0]const u8 = "Mach Engine",
size: Size = .{ .width = 1920 / 2, .height = 1080 / 2 }, size: Size = .{ .width = 1920 / 2, .height = 1080 / 2 },
power_preference: gpu.PowerPreference = .undefined, power_preference: gpu.PowerPreference = .undefined,

View file

@ -87,6 +87,10 @@ pub fn init(core: *Core, allocator: std.mem.Allocator, options: Options) !void {
// Create the test window and discover adapters using it (esp. for OpenGL) // Create the test window and discover adapters using it (esp. for OpenGL)
var hints = util.glfwWindowHintsForBackend(backend_type); var hints = util.glfwWindowHintsForBackend(backend_type);
hints.cocoa_retina_framebuffer = true; hints.cocoa_retina_framebuffer = true;
if (options.is_headless) {
hints.visible = false; // Hiding window before creation otherwise you get the window showing up for a little bit then hiding.
}
const window = glfw.Window.create( const window = glfw.Window.create(
options.size.width, options.size.width,
options.size.height, options.size.height,