|
|
@ -37,12 +37,16 @@ primitive_data: []PrimitiveData, |
|
|
|
object_data: []ObjectData, |
|
|
|
object_data: []ObjectData, |
|
|
|
|
|
|
|
|
|
|
|
pub fn init(app: *App) !*Renderer { |
|
|
|
pub fn init(app: *App) !*Renderer { |
|
|
|
|
|
|
|
// A string buffer used to format objects' labels. |
|
|
|
|
|
|
|
var label_buffer: [256]u8 = undefined; |
|
|
|
|
|
|
|
|
|
|
|
const shader_module = core.device.createShaderModuleWGSL("shader.wgsl", @embedFile("shader.wgsl")); |
|
|
|
const shader_module = core.device.createShaderModuleWGSL("shader.wgsl", @embedFile("shader.wgsl")); |
|
|
|
defer shader_module.release(); |
|
|
|
defer shader_module.release(); |
|
|
|
|
|
|
|
|
|
|
|
// Define layouts for our bind groups and pipeline. |
|
|
|
// Define layouts for our bind groups and pipeline. |
|
|
|
// This helps find errors with missing or mismatching shader properties. |
|
|
|
// This helps find errors with missing or mismatching shader properties. |
|
|
|
var camera_bind_group_layout = core.device.createBindGroupLayout(&gpu.BindGroupLayout.Descriptor.init(.{ |
|
|
|
var camera_bind_group_layout = core.device.createBindGroupLayout(&gpu.BindGroupLayout.Descriptor.init(.{ |
|
|
|
|
|
|
|
.label = "Camera Bind Group Layout", |
|
|
|
.entries = &.{ |
|
|
|
.entries = &.{ |
|
|
|
gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, false, 0), |
|
|
|
gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, false, 0), |
|
|
|
}, |
|
|
|
}, |
|
|
@ -50,6 +54,7 @@ pub fn init(app: *App) !*Renderer { |
|
|
|
defer camera_bind_group_layout.release(); |
|
|
|
defer camera_bind_group_layout.release(); |
|
|
|
|
|
|
|
|
|
|
|
var model_bind_group_layout = core.device.createBindGroupLayout(&gpu.BindGroupLayout.Descriptor.init(.{ |
|
|
|
var model_bind_group_layout = core.device.createBindGroupLayout(&gpu.BindGroupLayout.Descriptor.init(.{ |
|
|
|
|
|
|
|
.label = "Model Bind Group Layout", |
|
|
|
.entries = &.{ |
|
|
|
.entries = &.{ |
|
|
|
gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, false, 0), |
|
|
|
gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, false, 0), |
|
|
|
gpu.BindGroupLayout.Entry.buffer(1, .{ .vertex = true }, .uniform, false, 0), |
|
|
|
gpu.BindGroupLayout.Entry.buffer(1, .{ .vertex = true }, .uniform, false, 0), |
|
|
@ -104,6 +109,7 @@ pub fn init(app: *App) !*Renderer { |
|
|
|
// "Bind groups" are used to associate data from buffers with shader parameters. |
|
|
|
// "Bind groups" are used to associate data from buffers with shader parameters. |
|
|
|
// So for example the `camera_bind_group` is accessible via `@group(0)` in our shader. |
|
|
|
// So for example the `camera_bind_group` is accessible via `@group(0)` in our shader. |
|
|
|
const camera_bind_group = core.device.createBindGroup(&gpu.BindGroup.Descriptor.init(.{ |
|
|
|
const camera_bind_group = core.device.createBindGroup(&gpu.BindGroup.Descriptor.init(.{ |
|
|
|
|
|
|
|
.label = "Camera Bind Group", |
|
|
|
.layout = camera_bind_group_layout, |
|
|
|
.layout = camera_bind_group_layout, |
|
|
|
.entries = &.{ |
|
|
|
.entries = &.{ |
|
|
|
gpu.BindGroup.Entry.buffer(0, view_proj_buffer, 0, @sizeOf(zm.Mat)), |
|
|
|
gpu.BindGroup.Entry.buffer(0, view_proj_buffer, 0, @sizeOf(zm.Mat)), |
|
|
@ -160,7 +166,9 @@ pub fn init(app: *App) !*Renderer { |
|
|
|
const model_color_buffer = createAndWriteBuffer([3]f32, &.{model_color}, .{ .copy_dst = true, .uniform = true }); |
|
|
|
const model_color_buffer = createAndWriteBuffer([3]f32, &.{model_color}, .{ .copy_dst = true, .uniform = true }); |
|
|
|
defer model_color_buffer.release(); |
|
|
|
defer model_color_buffer.release(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const model_bind_group_label = try std.fmt.bufPrintZ(&label_buffer, "Model Bind Group {d}", .{i}); |
|
|
|
const model_bind_group = core.device.createBindGroup(&gpu.BindGroup.Descriptor.init(.{ |
|
|
|
const model_bind_group = core.device.createBindGroup(&gpu.BindGroup.Descriptor.init(.{ |
|
|
|
|
|
|
|
.label = model_bind_group_label, |
|
|
|
.layout = model_bind_group_layout, |
|
|
|
.layout = model_bind_group_layout, |
|
|
|
.entries = &.{ |
|
|
|
.entries = &.{ |
|
|
|
gpu.BindGroup.Entry.buffer(0, model_matrix_buffer, 0, @sizeOf(zm.Mat)), |
|
|
|
gpu.BindGroup.Entry.buffer(0, model_matrix_buffer, 0, @sizeOf(zm.Mat)), |
|
|
@ -319,6 +327,7 @@ pub fn recreateDepthTexture(self: *Renderer) void { |
|
|
|
if (self.depth_texture_view) |v| v.release(); |
|
|
|
if (self.depth_texture_view) |v| v.release(); |
|
|
|
|
|
|
|
|
|
|
|
self.depth_texture = core.device.createTexture(&.{ |
|
|
|
self.depth_texture = core.device.createTexture(&.{ |
|
|
|
|
|
|
|
.label = "Depth Texture", |
|
|
|
.usage = .{ .render_attachment = true }, |
|
|
|
.usage = .{ .render_attachment = true }, |
|
|
|
.size = .{ .width = core.descriptor.width, .height = core.descriptor.height }, |
|
|
|
.size = .{ .width = core.descriptor.width, .height = core.descriptor.height }, |
|
|
|
.format = .depth24_plus, |
|
|
|
.format = .depth24_plus, |
|
|
|