examples: update to new Engine API

This commit is contained in:
iddev5 2022-06-01 12:28:24 +05:30 committed by Stephen Gutekanst
parent 50fe649ab1
commit 03491dfd27
9 changed files with 170 additions and 170 deletions

View file

@ -23,9 +23,9 @@ bind_group: gpu.BindGroup,
pub fn init(app: *App, engine: *mach.Engine) !void {
timer = try mach.Timer.start();
try engine.core.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
try engine.setSizeLimits(.{ .width = 20, .height = 20 }, .{ .width = null, .height = null });
const vs_module = engine.gpu_driver.device.createShaderModule(&.{
const vs_module = engine.device.createShaderModule(&.{
.label = "my vertex shader",
.code = .{ .wgsl = @embedFile("vert.wgsl") },
});
@ -41,7 +41,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
.attributes = &vertex_attributes,
};
const fs_module = engine.gpu_driver.device.createShaderModule(&.{
const fs_module = engine.device.createShaderModule(&.{
.label = "my fragment shader",
.code = .{ .wgsl = @embedFile("frag.wgsl") },
});
@ -59,7 +59,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
},
};
const color_target = gpu.ColorTargetState{
.format = engine.gpu_driver.swap_chain_format,
.format = engine.swap_chain_format,
.blend = &blend,
.write_mask = gpu.ColorWriteMask.all,
};
@ -71,14 +71,14 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
};
const bgle = gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, true, 0);
const bgl = engine.gpu_driver.device.createBindGroupLayout(
const bgl = engine.device.createBindGroupLayout(
&gpu.BindGroupLayout.Descriptor{
.entries = &.{bgle},
},
);
const bind_group_layouts = [_]gpu.BindGroupLayout{bgl};
const pipeline_layout = engine.gpu_driver.device.createPipelineLayout(&.{
const pipeline_layout = engine.device.createPipelineLayout(&.{
.bind_group_layouts = &bind_group_layouts,
});
@ -104,7 +104,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
},
};
const vertex_buffer = engine.gpu_driver.device.createBuffer(&.{
const vertex_buffer = engine.device.createBuffer(&.{
.usage = .{ .vertex = true },
.size = @sizeOf(Vertex) * vertices.len,
.mapped_at_creation = true,
@ -113,12 +113,12 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
std.mem.copy(Vertex, vertex_mapped, vertices[0..]);
vertex_buffer.unmap();
const uniform_buffer = engine.gpu_driver.device.createBuffer(&.{
const uniform_buffer = engine.device.createBuffer(&.{
.usage = .{ .copy_dst = true, .uniform = true },
.size = @sizeOf(UniformBufferObject),
.mapped_at_creation = false,
});
const bind_group = engine.gpu_driver.device.createBindGroup(
const bind_group = engine.device.createBindGroup(
&gpu.BindGroup.Descriptor{
.layout = bgl,
.entries = &.{
@ -127,8 +127,8 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
},
);
app.pipeline = engine.gpu_driver.device.createRenderPipeline(&pipeline_descriptor);
app.queue = engine.gpu_driver.device.getQueue();
app.pipeline = engine.device.createRenderPipeline(&pipeline_descriptor);
app.queue = engine.device.getQueue();
app.vertex_buffer = vertex_buffer;
app.uniform_buffer = uniform_buffer;
app.bind_group = bind_group;
@ -146,17 +146,17 @@ pub fn deinit(app: *App, _: *mach.Engine) void {
}
pub fn update(app: *App, engine: *mach.Engine) !bool {
while (engine.core.pollEvent()) |event| {
while (engine.pollEvent()) |event| {
switch (event) {
.key_press => |ev| {
if (ev.key == .space)
engine.core.setShouldClose(true);
engine.setShouldClose(true);
},
else => {},
}
}
const back_buffer_view = engine.gpu_driver.swap_chain.?.getCurrentTextureView();
const back_buffer_view = engine.swap_chain.?.getCurrentTextureView();
const color_attachment = gpu.RenderPassColorAttachment{
.view = back_buffer_view,
.resolve_target = null,
@ -165,7 +165,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
.store_op = .store,
};
const encoder = engine.gpu_driver.device.createCommandEncoder(null);
const encoder = engine.device.createCommandEncoder(null);
const render_pass_info = gpu.RenderPassEncoder.Descriptor{
.color_attachments = &.{color_attachment},
.depth_stencil_attachment = null,
@ -181,7 +181,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
);
const proj = zm.perspectiveFovRh(
(std.math.pi / 4.0),
@intToFloat(f32, engine.gpu_driver.current_desc.width) / @intToFloat(f32, engine.gpu_driver.current_desc.height),
@intToFloat(f32, engine.current_desc.width) / @intToFloat(f32, engine.current_desc.height),
0.1,
10,
);
@ -205,7 +205,7 @@ pub fn update(app: *App, engine: *mach.Engine) !bool {
app.queue.submit(&.{command});
command.release();
engine.gpu_driver.swap_chain.?.present();
engine.swap_chain.?.present();
back_buffer_view.release();
return true;