core: windows: Get triangle showing, still freezing on run. Comment out more windows, set value of window back on presentFrame.
This commit is contained in:
parent
e15cbe63de
commit
06aec428de
3 changed files with 128 additions and 144 deletions
13
src/Core.zig
13
src/Core.zig
|
|
@ -162,7 +162,6 @@ pub fn init(core: *Core) !void {
|
|||
pub fn initWindow(core: *Core, window_id: mach.ObjectID) !void {
|
||||
var core_window = core.windows.getValue(window_id);
|
||||
defer core.windows.setValueRaw(window_id, core_window);
|
||||
|
||||
core_window.instance = gpu.createInstance(null) orelse {
|
||||
log.err("failed to create GPU instance", .{});
|
||||
std.process.exit(1);
|
||||
|
|
@ -247,7 +246,6 @@ pub fn main(core: *Core, core_mod: mach.Mod(Core)) !void {
|
|||
if (core.on_exit == null) @panic("core.on_exit callback must be set");
|
||||
|
||||
try Platform.tick(core);
|
||||
|
||||
core_mod.run(core.on_tick.?);
|
||||
core_mod.call(.presentFrame);
|
||||
|
||||
|
|
@ -526,6 +524,7 @@ pub fn presentFrame(core: *Core, core_mod: mach.Mod(Core)) !void {
|
|||
var windows = core.windows.slice();
|
||||
while (windows.next()) |window_id| {
|
||||
var core_window = core.windows.getValue(window_id);
|
||||
defer core.windows.setValueRaw(window_id, core_window);
|
||||
|
||||
mach.sysgpu.Impl.deviceTick(core_window.device);
|
||||
|
||||
|
|
@ -556,16 +555,6 @@ pub fn presentFrame(core: *Core, core_mod: mach.Mod(Core)) !void {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO(important): update this information in response to resize events rather than
|
||||
// after frame submission
|
||||
// var win = core.windows.getAll(core.main_window).?;
|
||||
// win.framebuffer_format = core.descriptor.format;
|
||||
// win.framebuffer_width = core.descriptor.width;
|
||||
// win.framebuffer_height = core.descriptor.height;
|
||||
// win.width = core.platform.size.width;
|
||||
// win.height = core.platform.size.height;
|
||||
// core.windows.setAll(core.main_window, win);
|
||||
|
||||
// Record to frame rate frequency monitor that a frame was finished.
|
||||
core.frame.tick();
|
||||
|
||||
|
|
|
|||
|
|
@ -238,8 +238,6 @@ fn initWindow(
|
|||
|
||||
_ = w.SetWindowLongPtrW(native_window, w.GWLP_USERDATA, @bitCast(@intFromPtr(&context)));
|
||||
|
||||
_ = w.ShowWindow(native_window, w.SW_SHOW);
|
||||
|
||||
restoreWindowPosition(core, window_id);
|
||||
|
||||
const size = getClientRect(core, window_id);
|
||||
|
|
@ -251,6 +249,7 @@ fn initWindow(
|
|||
core_window.native = native;
|
||||
core.windows.setValueRaw(window_id, core_window);
|
||||
try core.initWindow(window_id);
|
||||
_ = w.ShowWindow(native_window, w.SW_SHOW);
|
||||
}
|
||||
|
||||
// pub fn update(self: *Win32) !void {
|
||||
|
|
@ -262,116 +261,116 @@ fn initWindow(
|
|||
// }
|
||||
// }
|
||||
|
||||
pub fn setTitle(self: *Win32, title: [:0]const u8) void {
|
||||
const wtitle = std.unicode.utf8ToUtf16LeAllocZ(self.allocator, title) catch {
|
||||
self.state.oom.set();
|
||||
return;
|
||||
};
|
||||
defer self.allocator.free(wtitle);
|
||||
_ = w.SetWindowTextW(self.window, wtitle);
|
||||
}
|
||||
// pub fn setTitle(self: *Win32, title: [:0]const u8) void {
|
||||
// const wtitle = std.unicode.utf8ToUtf16LeAllocZ(self.allocator, title) catch {
|
||||
// self.state.oom.set();
|
||||
// return;
|
||||
// };
|
||||
// defer self.allocator.free(wtitle);
|
||||
// _ = w.SetWindowTextW(self.window, wtitle);
|
||||
// }
|
||||
|
||||
pub fn setDisplayMode(self: *Win32, mode: DisplayMode) void {
|
||||
self.display_mode = mode;
|
||||
// pub fn setDisplayMode(self: *Win32, mode: DisplayMode) void {
|
||||
// self.display_mode = mode;
|
||||
|
||||
switch (mode) {
|
||||
.windowed => {
|
||||
const window_style: w.WINDOW_STYLE = if (self.border) w.WS_OVERLAPPEDWINDOW else w.WS_POPUPWINDOW;
|
||||
const window_ex_style = w.WINDOW_EX_STYLE{ .APPWINDOW = 1 };
|
||||
// switch (mode) {
|
||||
// .windowed => {
|
||||
// const window_style: w.WINDOW_STYLE = if (self.border) w.WS_OVERLAPPEDWINDOW else w.WS_POPUPWINDOW;
|
||||
// const window_ex_style = w.WINDOW_EX_STYLE{ .APPWINDOW = 1 };
|
||||
|
||||
_ = w.SetWindowLongW(self.window, w.GWL_STYLE, @bitCast(window_style));
|
||||
_ = w.SetWindowLongW(self.window, w.GWL_EXSTYLE, @bitCast(window_ex_style));
|
||||
// _ = w.SetWindowLongW(self.window, w.GWL_STYLE, @bitCast(window_style));
|
||||
// _ = w.SetWindowLongW(self.window, w.GWL_EXSTYLE, @bitCast(window_ex_style));
|
||||
|
||||
restoreWindowPosition(self);
|
||||
},
|
||||
.fullscreen => {
|
||||
// TODO (win32) - change to use exclusive fullscreen using ChangeDisplaySetting
|
||||
// restoreWindowPosition(self);
|
||||
// },
|
||||
// .fullscreen => {
|
||||
// // TODO (win32) - change to use exclusive fullscreen using ChangeDisplaySetting
|
||||
|
||||
_ = w.GetWindowRect(self.window, &self.saved_window_rect);
|
||||
// _ = w.GetWindowRect(self.window, &self.saved_window_rect);
|
||||
|
||||
const window_style = w.WINDOW_STYLE{ .POPUP = 1, .VISIBLE = 1 };
|
||||
const window_ex_style = w.WINDOW_EX_STYLE{ .APPWINDOW = 1 };
|
||||
// const window_style = w.WINDOW_STYLE{ .POPUP = 1, .VISIBLE = 1 };
|
||||
// const window_ex_style = w.WINDOW_EX_STYLE{ .APPWINDOW = 1 };
|
||||
|
||||
_ = w.SetWindowLongW(self.window, w.GWL_STYLE, @bitCast(window_style));
|
||||
_ = w.SetWindowLongW(self.window, w.GWL_EXSTYLE, @bitCast(window_ex_style));
|
||||
// _ = w.SetWindowLongW(self.window, w.GWL_STYLE, @bitCast(window_style));
|
||||
// _ = w.SetWindowLongW(self.window, w.GWL_EXSTYLE, @bitCast(window_ex_style));
|
||||
|
||||
const monitor = w.MonitorFromWindow(self.window, w.MONITOR_DEFAULTTONEAREST);
|
||||
var monitor_info: w.MONITORINFO = undefined;
|
||||
monitor_info.cbSize = @sizeOf(w.MONITORINFO);
|
||||
if (w.GetMonitorInfoW(monitor, &monitor_info) == w.TRUE) {
|
||||
_ = w.SetWindowPos(self.window, null, monitor_info.rcMonitor.left, monitor_info.rcMonitor.top, monitor_info.rcMonitor.right - monitor_info.rcMonitor.left, monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top, w.SWP_NOZORDER);
|
||||
}
|
||||
},
|
||||
.borderless => {
|
||||
_ = w.GetWindowRect(self.window, &self.saved_window_rect);
|
||||
// const monitor = w.MonitorFromWindow(self.window, w.MONITOR_DEFAULTTONEAREST);
|
||||
// var monitor_info: w.MONITORINFO = undefined;
|
||||
// monitor_info.cbSize = @sizeOf(w.MONITORINFO);
|
||||
// if (w.GetMonitorInfoW(monitor, &monitor_info) == w.TRUE) {
|
||||
// _ = w.SetWindowPos(self.window, null, monitor_info.rcMonitor.left, monitor_info.rcMonitor.top, monitor_info.rcMonitor.right - monitor_info.rcMonitor.left, monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top, w.SWP_NOZORDER);
|
||||
// }
|
||||
// },
|
||||
// .borderless => {
|
||||
// _ = w.GetWindowRect(self.window, &self.saved_window_rect);
|
||||
|
||||
const window_style = w.WINDOW_STYLE{ .POPUP = 1, .VISIBLE = 1 };
|
||||
const window_ex_style = w.WINDOW_EX_STYLE{ .APPWINDOW = 1 };
|
||||
// const window_style = w.WINDOW_STYLE{ .POPUP = 1, .VISIBLE = 1 };
|
||||
// const window_ex_style = w.WINDOW_EX_STYLE{ .APPWINDOW = 1 };
|
||||
|
||||
_ = w.SetWindowLongW(self.window, w.GWL_STYLE, @bitCast(window_style));
|
||||
_ = w.SetWindowLongW(self.window, w.GWL_EXSTYLE, @bitCast(window_ex_style));
|
||||
// _ = w.SetWindowLongW(self.window, w.GWL_STYLE, @bitCast(window_style));
|
||||
// _ = w.SetWindowLongW(self.window, w.GWL_EXSTYLE, @bitCast(window_ex_style));
|
||||
|
||||
const monitor = w.MonitorFromWindow(self.window, w.MONITOR_DEFAULTTONEAREST);
|
||||
var monitor_info: w.MONITORINFO = undefined;
|
||||
monitor_info.cbSize = @sizeOf(w.MONITORINFO);
|
||||
if (w.GetMonitorInfoW(monitor, &monitor_info) == w.TRUE) {
|
||||
_ = w.SetWindowPos(self.window, null, monitor_info.rcMonitor.left, monitor_info.rcMonitor.top, monitor_info.rcMonitor.right - monitor_info.rcMonitor.left, monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top, w.SWP_NOZORDER);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
// const monitor = w.MonitorFromWindow(self.window, w.MONITOR_DEFAULTTONEAREST);
|
||||
// var monitor_info: w.MONITORINFO = undefined;
|
||||
// monitor_info.cbSize = @sizeOf(w.MONITORINFO);
|
||||
// if (w.GetMonitorInfoW(monitor, &monitor_info) == w.TRUE) {
|
||||
// _ = w.SetWindowPos(self.window, null, monitor_info.rcMonitor.left, monitor_info.rcMonitor.top, monitor_info.rcMonitor.right - monitor_info.rcMonitor.left, monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top, w.SWP_NOZORDER);
|
||||
// }
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn setBorder(self: *Win32, value: bool) void {
|
||||
const overlappedwindow: i32 = @bitCast(w.WS_OVERLAPPEDWINDOW);
|
||||
const popupwindow: i32 = @bitCast(w.WS_POPUPWINDOW);
|
||||
_ = w.SetWindowLongW(self.window, w.GWL_STYLE, if (value) overlappedwindow else popupwindow);
|
||||
self.border = value;
|
||||
}
|
||||
// pub fn setBorder(self: *Win32, value: bool) void {
|
||||
// const overlappedwindow: i32 = @bitCast(w.WS_OVERLAPPEDWINDOW);
|
||||
// const popupwindow: i32 = @bitCast(w.WS_POPUPWINDOW);
|
||||
// _ = w.SetWindowLongW(self.window, w.GWL_STYLE, if (value) overlappedwindow else popupwindow);
|
||||
// self.border = value;
|
||||
// }
|
||||
|
||||
pub fn setHeadless(self: *Win32, value: bool) void {
|
||||
_ = w.ShowWindow(self.window, if (value) w.SW_HIDE else w.SW_SHOW);
|
||||
self.headless = value;
|
||||
}
|
||||
// pub fn setHeadless(self: *Win32, value: bool) void {
|
||||
// _ = w.ShowWindow(self.window, if (value) w.SW_HIDE else w.SW_SHOW);
|
||||
// self.headless = value;
|
||||
// }
|
||||
|
||||
pub fn setVSync(self: *Win32, mode: VSyncMode) void {
|
||||
self.vsync_mode = mode;
|
||||
}
|
||||
// pub fn setVSync(self: *Win32, mode: VSyncMode) void {
|
||||
// self.vsync_mode = mode;
|
||||
// }
|
||||
|
||||
pub fn setSize(self: *Win32, value: Size) void {
|
||||
// TODO (win32) - use AdjustClientRect to get correct client rect.
|
||||
_ = w.SetWindowPos(self.window, null, 0, 0, @as(i32, @intCast(value.width)), @as(i32, @intCast(value.height)), w.SET_WINDOW_POS_FLAGS{ .NOMOVE = 1, .NOZORDER = 1, .NOACTIVATE = 1 });
|
||||
self.size = value;
|
||||
}
|
||||
// pub fn setSize(self: *Win32, value: Size) void {
|
||||
// // TODO (win32) - use AdjustClientRect to get correct client rect.
|
||||
// _ = w.SetWindowPos(self.window, null, 0, 0, @as(i32, @intCast(value.width)), @as(i32, @intCast(value.height)), w.SET_WINDOW_POS_FLAGS{ .NOMOVE = 1, .NOZORDER = 1, .NOACTIVATE = 1 });
|
||||
// self.size = value;
|
||||
// }
|
||||
|
||||
pub fn setCursorMode(self: *Win32, mode: CursorMode) void {
|
||||
switch (mode) {
|
||||
.normal => while (w.ShowCursor(w.TRUE) < 0) {},
|
||||
.hidden => while (w.ShowCursor(w.FALSE) >= 0) {},
|
||||
.disabled => {},
|
||||
}
|
||||
self.cursor_mode = mode;
|
||||
}
|
||||
// pub fn setCursorMode(self: *Win32, mode: CursorMode) void {
|
||||
// switch (mode) {
|
||||
// .normal => while (w.ShowCursor(w.TRUE) < 0) {},
|
||||
// .hidden => while (w.ShowCursor(w.FALSE) >= 0) {},
|
||||
// .disabled => {},
|
||||
// }
|
||||
// self.cursor_mode = mode;
|
||||
// }
|
||||
|
||||
pub fn setCursorShape(self: *Win32, shape: CursorShape) void {
|
||||
const name: i32 = switch (shape) {
|
||||
.arrow => w.IDC_ARROW,
|
||||
.ibeam => w.IDC_IBEAM,
|
||||
.crosshair => w.IDC_CROSS,
|
||||
.pointing_hand => w.IDC_HAND,
|
||||
.resize_ew => w.IDC_SIZEWE,
|
||||
.resize_ns => w.IDC_SIZENS,
|
||||
.resize_nwse => w.IDC_SIZENWSE,
|
||||
.resize_nesw => w.IDC_SIZENESW,
|
||||
.resize_all => w.IDC_SIZEALL,
|
||||
.not_allowed => w.IDC_NO,
|
||||
};
|
||||
_ = w.SetCursor(w.LoadCursorW(null, @ptrFromInt(@as(usize, @intCast(name)))));
|
||||
self.cursor_shape = shape;
|
||||
}
|
||||
// pub fn setCursorShape(self: *Win32, shape: CursorShape) void {
|
||||
// const name: i32 = switch (shape) {
|
||||
// .arrow => w.IDC_ARROW,
|
||||
// .ibeam => w.IDC_IBEAM,
|
||||
// .crosshair => w.IDC_CROSS,
|
||||
// .pointing_hand => w.IDC_HAND,
|
||||
// .resize_ew => w.IDC_SIZEWE,
|
||||
// .resize_ns => w.IDC_SIZENS,
|
||||
// .resize_nwse => w.IDC_SIZENWSE,
|
||||
// .resize_nesw => w.IDC_SIZENESW,
|
||||
// .resize_all => w.IDC_SIZEALL,
|
||||
// .not_allowed => w.IDC_NO,
|
||||
// };
|
||||
// _ = w.SetCursor(w.LoadCursorW(null, @ptrFromInt(@as(usize, @intCast(name)))));
|
||||
// self.cursor_shape = shape;
|
||||
// }
|
||||
|
||||
pub fn nativeWindowWin32(self: *Win32) w.HWND {
|
||||
return self.window;
|
||||
}
|
||||
// pub fn nativeWindowWin32(self: *Win32) w.HWND {
|
||||
// return self.window;
|
||||
// }
|
||||
|
||||
// -----------------------------
|
||||
// Internal functions
|
||||
|
|
@ -615,6 +614,7 @@ fn wndProc(wnd: w.HWND, msg: u32, wParam: w.WPARAM, lParam: w.LPARAM) callconv(w
|
|||
},
|
||||
else => return w.DefWindowProcW(wnd, msg, wParam, lParam),
|
||||
}
|
||||
|
||||
return w.DefWindowProcW(wnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue