* `@import("mach").core.gpu` has been renamed to `@import("mach").gpu`
* `pub const SYSGPUInterface` now has a default value (i.e. you do not need to write it in your main.zig, if you were.)
* You can now check `if (comptime mach.use_sysgpu)` for any conditional code you might have that should only run with sysgpu.
This (old):
```
pub const mach_core_options = core.ComptimeOptions{
.use_wgpu = false,
.use_sysgpu = true,
};
```
Has been replaced by this:
```
pub const use_sysgpu = true;
```
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
68 lines
1.7 KiB
Zig
68 lines
1.7 KiB
Zig
const std = @import("std");
|
|
|
|
const mach = @import("mach");
|
|
const core = mach.core;
|
|
const gpu = mach.gpu;
|
|
|
|
const renderer = @import("renderer.zig");
|
|
|
|
pub const App = @This();
|
|
|
|
// Use experimental sysgpu graphics API
|
|
pub const use_sysgpu = true;
|
|
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
|
|
title_timer: core.Timer,
|
|
|
|
pub fn init(app: *App) !void {
|
|
try core.init(.{ .required_limits = gpu.Limits{
|
|
.max_vertex_buffers = 1,
|
|
.max_vertex_attributes = 2,
|
|
.max_bind_groups = 1,
|
|
.max_uniform_buffers_per_shader_stage = 1,
|
|
.max_uniform_buffer_binding_size = 16 * 1 * @sizeOf(f32),
|
|
} });
|
|
|
|
const allocator = gpa.allocator();
|
|
const timer = try core.Timer.start();
|
|
try renderer.init(allocator, timer);
|
|
app.* = .{ .title_timer = try core.Timer.start() };
|
|
}
|
|
|
|
pub fn deinit(app: *App) void {
|
|
_ = app;
|
|
defer _ = gpa.deinit();
|
|
defer core.deinit();
|
|
defer renderer.deinit();
|
|
}
|
|
|
|
pub fn update(app: *App) !bool {
|
|
var iter = core.pollEvents();
|
|
while (iter.next()) |event| {
|
|
switch (event) {
|
|
.key_press => |ev| {
|
|
if (ev.key == .space) return true;
|
|
if (ev.key == .right) {
|
|
renderer.curr_primitive_index += 1;
|
|
renderer.curr_primitive_index %= 7;
|
|
}
|
|
},
|
|
.close => return true,
|
|
else => {},
|
|
}
|
|
}
|
|
|
|
renderer.update();
|
|
|
|
// update the window title every second
|
|
if (app.title_timer.read() >= 1.0) {
|
|
app.title_timer.reset();
|
|
try core.printTitle("Procedural Primitives [ {d}fps ] [ Input {d}hz ]", .{
|
|
core.frameRate(),
|
|
core.inputRate(),
|
|
});
|
|
}
|
|
|
|
return false;
|
|
}
|