Triangle shaders and pipeline

This commit is contained in:
nothke
2024-06-11 02:19:48 +02:00
parent 2135613c49
commit baca95edea
3 changed files with 592 additions and 1 deletions

View File

@@ -1,10 +1,17 @@
const std = @import("std");
const sokol = @import("sokol");
const sg = sokol.gfx;
const shader = @import("shaders/triangle.glsl.zig");
var pass_action: sg.PassAction = .{};
const state = struct {
var bind: sg.Bindings = .{};
var pip: sg.Pipeline = .{};
};
export fn init() void {
sg.setup(.{
.logger = .{ .func = sokol.log.func },
@@ -13,6 +20,26 @@ export fn init() void {
sokol.time.setup();
std.log.info("Vertex buffers len: {}", .{state.bind.vertex_buffers.len});
state.bind.vertex_buffers[0] = sg.makeBuffer(.{
.data = sg.asRange(&[_]f32{
// positions colors
0.0, 0.5, 0.5, 1.0, 0.0, 0.0, 1.0,
0.5, -0.5, 0.5, 0.0, 1.0, 0.0, 1.0,
-0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 1.0,
}),
});
var pip_desc: sg.PipelineDesc = .{
.shader = sg.makeShader(shader.triangleShaderDesc(sg.queryBackend())),
};
pip_desc.layout.attrs[0].format = .FLOAT3;
pip_desc.layout.attrs[1].format = .FLOAT4;
state.pip = sg.makePipeline(pip_desc);
pass_action.colors[0] = .{
.load_action = .CLEAR,
.clear_value = .{ .r = 0, .g = 1, .b = 0, .a = 1 },