renderer/opengl: create ubos

This commit is contained in:
Mitchell Hashimoto
2023-11-17 09:32:52 -08:00
parent 3502db0f5f
commit 1fedc912f0
4 changed files with 85 additions and 44 deletions

View File

@@ -7,6 +7,19 @@ const gl = @import("opengl");
program: gl.Program,
pub const Uniforms = extern struct {
resolution: [3]f32 align(16),
time: f32 align(4),
time_delta: f32 align(4),
frame_rate: f32 align(4),
frame: i32 align(4),
channel_time: [4][4]f32 align(16),
channel_resolution: [4][4]f32 align(16),
mouse: [4]f32 align(16),
date: [4]f32 align(16),
sample_rate: f32 align(4),
};
pub fn createList(alloc: Allocator, srcs: []const [:0]const u8) ![]const CustomProgram {
var programs = std.ArrayList(CustomProgram).init(alloc);
defer programs.deinit();
@@ -26,6 +39,13 @@ pub fn init(src: [:0]const u8) !CustomProgram {
);
errdefer program.destroy();
// Create our uniform buffer that is shared across all custom shaders
const ubo = try gl.Buffer.create();
errdefer ubo.destroy();
var ubobind = try ubo.bind(.uniform);
defer ubobind.unbind();
try ubobind.setDataNull(Uniforms, .static_draw);
return .{
.program = program,
};