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
|
|
@ -26,47 +26,44 @@ pub fn init(
|
||||||
core.on_exit = app_mod.id.deinit;
|
core.on_exit = app_mod.id.deinit;
|
||||||
|
|
||||||
const main_window = core.windows.getValue(core.main_window);
|
const main_window = core.windows.getValue(core.main_window);
|
||||||
if (main_window.native != null) {
|
|
||||||
// if window.native is not null, the window is initialized
|
|
||||||
|
|
||||||
// Create our shader module
|
// Create our shader module
|
||||||
const shader_module = main_window.device.createShaderModuleWGSL("shader.wgsl", @embedFile("shader.wgsl"));
|
const shader_module = main_window.device.createShaderModuleWGSL("shader.wgsl", @embedFile("shader.wgsl"));
|
||||||
defer shader_module.release();
|
defer shader_module.release();
|
||||||
|
|
||||||
// Blend state describes how rendered colors get blended
|
// Blend state describes how rendered colors get blended
|
||||||
const blend = gpu.BlendState{};
|
const blend = gpu.BlendState{};
|
||||||
|
|
||||||
// Color target describes e.g. the pixel format of the window we are rendering to.
|
// Color target describes e.g. the pixel format of the window we are rendering to.
|
||||||
const color_target = gpu.ColorTargetState{
|
const color_target = gpu.ColorTargetState{
|
||||||
.format = core.windows.get(core.main_window, .framebuffer_format),
|
.format = main_window.framebuffer_format,
|
||||||
.blend = &blend,
|
.blend = &blend,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fragment state describes which shader and entrypoint to use for rendering fragments.
|
// Fragment state describes which shader and entrypoint to use for rendering fragments.
|
||||||
const fragment = gpu.FragmentState.init(.{
|
const fragment = gpu.FragmentState.init(.{
|
||||||
|
.module = shader_module,
|
||||||
|
.entry_point = "frag_main",
|
||||||
|
.targets = &.{color_target},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create our render pipeline that will ultimately get pixels onto the screen.
|
||||||
|
const label = @tagName(mach_module) ++ ".init";
|
||||||
|
const pipeline_descriptor = gpu.RenderPipeline.Descriptor{
|
||||||
|
.label = label,
|
||||||
|
.fragment = &fragment,
|
||||||
|
.vertex = gpu.VertexState{
|
||||||
.module = shader_module,
|
.module = shader_module,
|
||||||
.entry_point = "frag_main",
|
.entry_point = "vertex_main",
|
||||||
.targets = &.{color_target},
|
},
|
||||||
});
|
};
|
||||||
|
const pipeline = main_window.device.createRenderPipeline(&pipeline_descriptor);
|
||||||
|
|
||||||
// Create our render pipeline that will ultimately get pixels onto the screen.
|
// Store our render pipeline in our module's state, so we can access it later on.
|
||||||
const label = @tagName(mach_module) ++ ".init";
|
app.* = .{
|
||||||
const pipeline_descriptor = gpu.RenderPipeline.Descriptor{
|
.title_timer = try mach.time.Timer.start(),
|
||||||
.label = label,
|
.pipeline = pipeline,
|
||||||
.fragment = &fragment,
|
};
|
||||||
.vertex = gpu.VertexState{
|
|
||||||
.module = shader_module,
|
|
||||||
.entry_point = "vertex_main",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const pipeline = main_window.device.createRenderPipeline(&pipeline_descriptor);
|
|
||||||
|
|
||||||
// Store our render pipeline in our module's state, so we can access it later on.
|
|
||||||
app.* = .{
|
|
||||||
.title_timer = try mach.time.Timer.start(),
|
|
||||||
.pipeline = pipeline,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(object): window-title
|
// TODO(object): window-title
|
||||||
|
|
@ -101,9 +98,7 @@ pub fn tick(app: *App, core: *mach.Core) void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var main_window = core.windows.getValue(core.main_window);
|
const main_window = core.windows.getValue(core.main_window);
|
||||||
|
|
||||||
// Window is ready when device is not null
|
|
||||||
|
|
||||||
// Grab the back buffer of the swapchain
|
// Grab the back buffer of the swapchain
|
||||||
// TODO(Core)
|
// TODO(Core)
|
||||||
|
|
|
||||||
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 {
|
pub fn initWindow(core: *Core, window_id: mach.ObjectID) !void {
|
||||||
var core_window = core.windows.getValue(window_id);
|
var core_window = core.windows.getValue(window_id);
|
||||||
defer core.windows.setValueRaw(window_id, core_window);
|
defer core.windows.setValueRaw(window_id, core_window);
|
||||||
|
|
||||||
core_window.instance = gpu.createInstance(null) orelse {
|
core_window.instance = gpu.createInstance(null) orelse {
|
||||||
log.err("failed to create GPU instance", .{});
|
log.err("failed to create GPU instance", .{});
|
||||||
std.process.exit(1);
|
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");
|
if (core.on_exit == null) @panic("core.on_exit callback must be set");
|
||||||
|
|
||||||
try Platform.tick(core);
|
try Platform.tick(core);
|
||||||
|
|
||||||
core_mod.run(core.on_tick.?);
|
core_mod.run(core.on_tick.?);
|
||||||
core_mod.call(.presentFrame);
|
core_mod.call(.presentFrame);
|
||||||
|
|
||||||
|
|
@ -526,6 +524,7 @@ pub fn presentFrame(core: *Core, core_mod: mach.Mod(Core)) !void {
|
||||||
var windows = core.windows.slice();
|
var windows = core.windows.slice();
|
||||||
while (windows.next()) |window_id| {
|
while (windows.next()) |window_id| {
|
||||||
var core_window = core.windows.getValue(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);
|
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.
|
// Record to frame rate frequency monitor that a frame was finished.
|
||||||
core.frame.tick();
|
core.frame.tick();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -238,8 +238,6 @@ fn initWindow(
|
||||||
|
|
||||||
_ = w.SetWindowLongPtrW(native_window, w.GWLP_USERDATA, @bitCast(@intFromPtr(&context)));
|
_ = w.SetWindowLongPtrW(native_window, w.GWLP_USERDATA, @bitCast(@intFromPtr(&context)));
|
||||||
|
|
||||||
_ = w.ShowWindow(native_window, w.SW_SHOW);
|
|
||||||
|
|
||||||
restoreWindowPosition(core, window_id);
|
restoreWindowPosition(core, window_id);
|
||||||
|
|
||||||
const size = getClientRect(core, window_id);
|
const size = getClientRect(core, window_id);
|
||||||
|
|
@ -251,6 +249,7 @@ fn initWindow(
|
||||||
core_window.native = native;
|
core_window.native = native;
|
||||||
core.windows.setValueRaw(window_id, core_window);
|
core.windows.setValueRaw(window_id, core_window);
|
||||||
try core.initWindow(window_id);
|
try core.initWindow(window_id);
|
||||||
|
_ = w.ShowWindow(native_window, w.SW_SHOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub fn update(self: *Win32) !void {
|
// pub fn update(self: *Win32) !void {
|
||||||
|
|
@ -262,116 +261,116 @@ fn initWindow(
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
pub fn setTitle(self: *Win32, title: [:0]const u8) void {
|
// pub fn setTitle(self: *Win32, title: [:0]const u8) void {
|
||||||
const wtitle = std.unicode.utf8ToUtf16LeAllocZ(self.allocator, title) catch {
|
// const wtitle = std.unicode.utf8ToUtf16LeAllocZ(self.allocator, title) catch {
|
||||||
self.state.oom.set();
|
// self.state.oom.set();
|
||||||
return;
|
// return;
|
||||||
};
|
// };
|
||||||
defer self.allocator.free(wtitle);
|
// defer self.allocator.free(wtitle);
|
||||||
_ = w.SetWindowTextW(self.window, wtitle);
|
// _ = w.SetWindowTextW(self.window, wtitle);
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn setDisplayMode(self: *Win32, mode: DisplayMode) void {
|
// pub fn setDisplayMode(self: *Win32, mode: DisplayMode) void {
|
||||||
self.display_mode = mode;
|
// self.display_mode = mode;
|
||||||
|
|
||||||
switch (mode) {
|
// switch (mode) {
|
||||||
.windowed => {
|
// .windowed => {
|
||||||
const window_style: w.WINDOW_STYLE = if (self.border) w.WS_OVERLAPPEDWINDOW else w.WS_POPUPWINDOW;
|
// 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 };
|
// 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_STYLE, @bitCast(window_style));
|
||||||
_ = w.SetWindowLongW(self.window, w.GWL_EXSTYLE, @bitCast(window_ex_style));
|
// _ = w.SetWindowLongW(self.window, w.GWL_EXSTYLE, @bitCast(window_ex_style));
|
||||||
|
|
||||||
restoreWindowPosition(self);
|
// restoreWindowPosition(self);
|
||||||
},
|
// },
|
||||||
.fullscreen => {
|
// .fullscreen => {
|
||||||
// TODO (win32) - change to use exclusive fullscreen using ChangeDisplaySetting
|
// // 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_style = w.WINDOW_STYLE{ .POPUP = 1, .VISIBLE = 1 };
|
||||||
const window_ex_style = w.WINDOW_EX_STYLE{ .APPWINDOW = 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_STYLE, @bitCast(window_style));
|
||||||
_ = w.SetWindowLongW(self.window, w.GWL_EXSTYLE, @bitCast(window_ex_style));
|
// _ = w.SetWindowLongW(self.window, w.GWL_EXSTYLE, @bitCast(window_ex_style));
|
||||||
|
|
||||||
const monitor = w.MonitorFromWindow(self.window, w.MONITOR_DEFAULTTONEAREST);
|
// const monitor = w.MonitorFromWindow(self.window, w.MONITOR_DEFAULTTONEAREST);
|
||||||
var monitor_info: w.MONITORINFO = undefined;
|
// var monitor_info: w.MONITORINFO = undefined;
|
||||||
monitor_info.cbSize = @sizeOf(w.MONITORINFO);
|
// monitor_info.cbSize = @sizeOf(w.MONITORINFO);
|
||||||
if (w.GetMonitorInfoW(monitor, &monitor_info) == w.TRUE) {
|
// 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);
|
// _ = 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 => {
|
// .borderless => {
|
||||||
_ = 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_style = w.WINDOW_STYLE{ .POPUP = 1, .VISIBLE = 1 };
|
||||||
const window_ex_style = w.WINDOW_EX_STYLE{ .APPWINDOW = 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_STYLE, @bitCast(window_style));
|
||||||
_ = w.SetWindowLongW(self.window, w.GWL_EXSTYLE, @bitCast(window_ex_style));
|
// _ = w.SetWindowLongW(self.window, w.GWL_EXSTYLE, @bitCast(window_ex_style));
|
||||||
|
|
||||||
const monitor = w.MonitorFromWindow(self.window, w.MONITOR_DEFAULTTONEAREST);
|
// const monitor = w.MonitorFromWindow(self.window, w.MONITOR_DEFAULTTONEAREST);
|
||||||
var monitor_info: w.MONITORINFO = undefined;
|
// var monitor_info: w.MONITORINFO = undefined;
|
||||||
monitor_info.cbSize = @sizeOf(w.MONITORINFO);
|
// monitor_info.cbSize = @sizeOf(w.MONITORINFO);
|
||||||
if (w.GetMonitorInfoW(monitor, &monitor_info) == w.TRUE) {
|
// 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);
|
// _ = 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 {
|
// pub fn setBorder(self: *Win32, value: bool) void {
|
||||||
const overlappedwindow: i32 = @bitCast(w.WS_OVERLAPPEDWINDOW);
|
// const overlappedwindow: i32 = @bitCast(w.WS_OVERLAPPEDWINDOW);
|
||||||
const popupwindow: i32 = @bitCast(w.WS_POPUPWINDOW);
|
// const popupwindow: i32 = @bitCast(w.WS_POPUPWINDOW);
|
||||||
_ = w.SetWindowLongW(self.window, w.GWL_STYLE, if (value) overlappedwindow else popupwindow);
|
// _ = w.SetWindowLongW(self.window, w.GWL_STYLE, if (value) overlappedwindow else popupwindow);
|
||||||
self.border = value;
|
// self.border = value;
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn setHeadless(self: *Win32, value: bool) void {
|
// pub fn setHeadless(self: *Win32, value: bool) void {
|
||||||
_ = w.ShowWindow(self.window, if (value) w.SW_HIDE else w.SW_SHOW);
|
// _ = w.ShowWindow(self.window, if (value) w.SW_HIDE else w.SW_SHOW);
|
||||||
self.headless = value;
|
// self.headless = value;
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn setVSync(self: *Win32, mode: VSyncMode) void {
|
// pub fn setVSync(self: *Win32, mode: VSyncMode) void {
|
||||||
self.vsync_mode = mode;
|
// self.vsync_mode = mode;
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn setSize(self: *Win32, value: Size) void {
|
// pub fn setSize(self: *Win32, value: Size) void {
|
||||||
// TODO (win32) - use AdjustClientRect to get correct client rect.
|
// // 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 });
|
// _ = 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;
|
// self.size = value;
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn setCursorMode(self: *Win32, mode: CursorMode) void {
|
// pub fn setCursorMode(self: *Win32, mode: CursorMode) void {
|
||||||
switch (mode) {
|
// switch (mode) {
|
||||||
.normal => while (w.ShowCursor(w.TRUE) < 0) {},
|
// .normal => while (w.ShowCursor(w.TRUE) < 0) {},
|
||||||
.hidden => while (w.ShowCursor(w.FALSE) >= 0) {},
|
// .hidden => while (w.ShowCursor(w.FALSE) >= 0) {},
|
||||||
.disabled => {},
|
// .disabled => {},
|
||||||
}
|
// }
|
||||||
self.cursor_mode = mode;
|
// self.cursor_mode = mode;
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn setCursorShape(self: *Win32, shape: CursorShape) void {
|
// pub fn setCursorShape(self: *Win32, shape: CursorShape) void {
|
||||||
const name: i32 = switch (shape) {
|
// const name: i32 = switch (shape) {
|
||||||
.arrow => w.IDC_ARROW,
|
// .arrow => w.IDC_ARROW,
|
||||||
.ibeam => w.IDC_IBEAM,
|
// .ibeam => w.IDC_IBEAM,
|
||||||
.crosshair => w.IDC_CROSS,
|
// .crosshair => w.IDC_CROSS,
|
||||||
.pointing_hand => w.IDC_HAND,
|
// .pointing_hand => w.IDC_HAND,
|
||||||
.resize_ew => w.IDC_SIZEWE,
|
// .resize_ew => w.IDC_SIZEWE,
|
||||||
.resize_ns => w.IDC_SIZENS,
|
// .resize_ns => w.IDC_SIZENS,
|
||||||
.resize_nwse => w.IDC_SIZENWSE,
|
// .resize_nwse => w.IDC_SIZENWSE,
|
||||||
.resize_nesw => w.IDC_SIZENESW,
|
// .resize_nesw => w.IDC_SIZENESW,
|
||||||
.resize_all => w.IDC_SIZEALL,
|
// .resize_all => w.IDC_SIZEALL,
|
||||||
.not_allowed => w.IDC_NO,
|
// .not_allowed => w.IDC_NO,
|
||||||
};
|
// };
|
||||||
_ = w.SetCursor(w.LoadCursorW(null, @ptrFromInt(@as(usize, @intCast(name)))));
|
// _ = w.SetCursor(w.LoadCursorW(null, @ptrFromInt(@as(usize, @intCast(name)))));
|
||||||
self.cursor_shape = shape;
|
// self.cursor_shape = shape;
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn nativeWindowWin32(self: *Win32) w.HWND {
|
// pub fn nativeWindowWin32(self: *Win32) w.HWND {
|
||||||
return self.window;
|
// return self.window;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
// Internal functions
|
// 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),
|
else => return w.DefWindowProcW(wnd, msg, wParam, lParam),
|
||||||
}
|
}
|
||||||
|
|
||||||
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