Stream: Now doing indexed rendering

This commit is contained in:
nothke 2024-06-12 00:29:16 +02:00
parent c4c104538b
commit d8f5c9bb61
2 changed files with 20 additions and 12 deletions

View File

@ -9,7 +9,6 @@ var pass_action: sg.PassAction = .{};
const state = struct { const state = struct {
var bind: sg.Bindings = .{}; var bind: sg.Bindings = .{};
var bind2: sg.Bindings = .{};
var pip: sg.Pipeline = .{}; var pip: sg.Pipeline = .{};
var vsParams: shader.FsParams = .{ .offset = .{ 0, 0, 0 } }; var vsParams: shader.FsParams = .{ .offset = .{ 0, 0, 0 } };
}; };
@ -35,15 +34,13 @@ export fn init() void {
.data = sg.asRange(&triangleVerts), .data = sg.asRange(&triangleVerts),
}); });
for (&triangleVerts) |*vert| { state.bind.index_buffer = sg.makeBuffer(.{
vert.* += 0.2; .type = .INDEXBUFFER,
} .data = sg.asRange(&[_]u16{ 0, 1, 2 }),
state.bind2.vertex_buffers[0] = sg.makeBuffer(.{
.data = sg.asRange(&triangleVerts),
}); });
var pip_desc: sg.PipelineDesc = .{ var pip_desc: sg.PipelineDesc = .{
.index_type = .UINT16,
.shader = sg.makeShader(shader.triangleShaderDesc(sg.queryBackend())), .shader = sg.makeShader(shader.triangleShaderDesc(sg.queryBackend())),
}; };
@ -75,12 +72,8 @@ export fn frame() void {
sg.applyUniforms(.FS, shader.SLOT_fs_params, sg.asRange(&state.vsParams)); sg.applyUniforms(.FS, shader.SLOT_fs_params, sg.asRange(&state.vsParams));
sg.applyBindings(state.bind); sg.applyBindings(state.bind);
sg.draw(0, 3, 1); sg.draw(0, 3, 1);
state.vsParams.offset[0] = col.g;
sg.applyUniforms(.FS, shader.SLOT_fs_params, sg.asRange(&state.vsParams));
sg.applyBindings(state.bind2);
sg.draw(0, 3, 1);
sg.endPass(); sg.endPass();
sg.commit(); sg.commit();
} }

15
todo.todo Normal file
View File

@ -0,0 +1,15 @@
What are we doing here?:
☐ using sokol in zig
☐ part of a gamejam
Today:
☐ Guide through the code
Draw a circle!:
☐ Draw indices instead of triangle elements
☐ Create a circle vertices
☐ Draw the circle
☐ Make the circle move with uniforms