mach: Create binding methods for all glfw methods in use and update

examples
This commit is contained in:
iddev5 2022-05-12 12:54:01 +05:30 committed by Stephen Gutekanst
parent 9106a9839d
commit 8b46f46cf8
11 changed files with 62 additions and 24 deletions

View file

@ -23,7 +23,7 @@ cube: Cube,
camera: Camera,
light: Light,
depth: Texture,
depth_size: glfw.Window.Size,
depth_size: mach.Size,
keys: u8 = 0,
const Dir = struct {
@ -48,12 +48,12 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
// }
// }
// }.callback);
try engine.core.internal.window.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
try engine.core.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
const eye = vec3(5.0, 7.0, 5.0);
const target = vec3(0.0, 0.0, 0.0);
const size = try engine.core.internal.window.getFramebufferSize();
const size = try engine.core.getFramebufferSize();
const aspect_ratio = @intToFloat(f32, size.width) / @intToFloat(f32, size.height);
app.queue = engine.gpu_driver.device.getQueue();
@ -68,7 +68,7 @@ pub fn deinit(_: *App, _: *mach.Engine) void {}
pub fn update(app: *App, engine: *mach.Engine) !bool {
// If window is resized, recreate depth buffer otherwise we cannot use it.
const size = engine.core.internal.window.getFramebufferSize() catch unreachable; // TODO: return type inference can't handle this
const size = engine.core.getFramebufferSize() catch unreachable; // TODO: return type inference can't handle this
if (size.width != app.depth_size.width or size.height != app.depth_size.height) {
app.depth = Texture.depth(engine.gpu_driver.device, size.width, size.height);
app.depth_size = size;
@ -874,7 +874,7 @@ const Instance = struct {
fn keyCallback(app: *App, engine: *mach.Engine, key: mach.Key, action: mach.Action) void {
if (action == .press) {
switch (key) {
.q, .escape, .space => engine.core.internal.window.setShouldClose(true),
.q, .escape, .space => engine.core.setShouldClose(true),
.w, .up => {
app.keys |= Dir.up;
},

View file

@ -44,13 +44,13 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void {
if (action == .press) {
switch (key) {
.space => eng.core.internal.window.setShouldClose(true),
.space => eng.core.setShouldClose(true),
else => {},
}
}
}
}.callback);
try engine.core.internal.window.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
try engine.core.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
const vs_module = engine.gpu_driver.device.createShaderModule(&.{
.label = "my vertex shader",

View file

@ -50,19 +50,17 @@ frag_uniform_buffer: gpu.Buffer,
bind_group: gpu.BindGroup,
pub fn init(app: *App, engine: *mach.Engine) !void {
engine.core.internal.window.setKeyCallback(struct {
fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void {
_ = scancode;
_ = mods;
engine.core.setKeyCallback(struct {
fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void {
if (action == .press) {
switch (key) {
.space => window.setShouldClose(true),
.space => eng.core.setShouldClose(true),
else => {},
}
}
}
}.callback);
try engine.core.internal.window.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
try engine.core.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
const vs_module = engine.gpu_driver.device.createShaderModule(&.{
.label = "my vertex shader",

View file

@ -27,13 +27,13 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void {
if (action == .press) {
switch (key) {
.space => eng.core.internal.window.setShouldClose(true),
.space => eng.core.setShouldClose(true),
else => {},
}
}
}
}.callback);
try engine.core.internal.window.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
try engine.core.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
const vs_module = engine.gpu_driver.device.createShaderModule(&.{
.label = "my vertex shader",

View file

@ -28,13 +28,13 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void {
if (action == .press) {
switch (key) {
.space => eng.core.internal.window.setShouldClose(true),
.space => eng.core.setShouldClose(true),
else => {},
}
}
}
}.callback);
try engine.core.internal.window.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
try engine.core.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
const vs_module = engine.gpu_driver.device.createShaderModule(&.{
.label = "my vertex shader",

View file

@ -19,7 +19,7 @@ vertex_buffer: gpu.Buffer,
uniform_buffer: gpu.Buffer,
bind_group: gpu.BindGroup,
depth_texture: gpu.Texture,
depth_size: glfw.Window.Size,
depth_size: mach.Size,
const App = @This();
@ -30,13 +30,13 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void {
if (action == .press) {
switch (key) {
.space => eng.core.internal.window.setShouldClose(true),
.space => eng.core.setShouldClose(true),
else => {},
}
}
}
}.callback);
try engine.core.internal.window.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
try engine.core.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
const vs_module = engine.gpu_driver.device.createShaderModule(&.{
.label = "my vertex shader",
@ -165,7 +165,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
},
);
const size = try engine.core.internal.window.getFramebufferSize();
const size = try engine.core.getFramebufferSize();
const depth_texture = engine.gpu_driver.device.createTexture(&gpu.Texture.Descriptor{
.size = gpu.Extent3D{
.width = size.width,
@ -198,7 +198,7 @@ pub fn deinit(app: *App, _: *mach.Engine) void {
pub fn update(app: *App, engine: *mach.Engine) !bool {
// If window is resized, recreate depth buffer otherwise we cannot use it.
const size = engine.core.internal.window.getFramebufferSize() catch unreachable; // TODO: return type inference can't handle this
const size = engine.core.getFramebufferSize() catch unreachable; // TODO: return type inference can't handle this
if (size.width != app.depth_size.width or size.height != app.depth_size.height) {
app.depth_texture = engine.gpu_driver.device.createTexture(&gpu.Texture.Descriptor{
.size = gpu.Extent3D{

View file

@ -28,13 +28,13 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void {
if (action == .press) {
switch (key) {
.space => eng.core.internal.window.setShouldClose(true),
.space => eng.core.setShouldClose(true),
else => {},
}
}
}
}.callback);
try engine.core.internal.window.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
try engine.core.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
const vs_module = engine.gpu_driver.device.createShaderModule(&.{
.label = "my vertex shader",