src/core: move mach-core@9a4d09707d9f1cb6ea5602bdf58caeefc46146be package to here
Helps hexops/mach#1165 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
fa3f6161ad
commit
38f296ecce
157 changed files with 28383 additions and 0 deletions
66
src/core/examples/sysgpu/procedural-primitives/main.zig
Normal file
66
src/core/examples/sysgpu/procedural-primitives/main.zig
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
const std = @import("std");
|
||||
const core = @import("mach").core;
|
||||
const gpu = core.gpu;
|
||||
const renderer = @import("renderer.zig");
|
||||
|
||||
pub const App = @This();
|
||||
|
||||
pub const mach_core_options = core.ComptimeOptions{
|
||||
.use_wgpu = false,
|
||||
.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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue