renderer/opengl: start custom program work

This commit is contained in:
Mitchell Hashimoto
2023-11-17 09:07:42 -08:00
parent cc630f10ac
commit 3502db0f5f
3 changed files with 51 additions and 10 deletions

View File

@@ -0,0 +1,36 @@
/// The OpenGL program for custom shaders.
const CustomProgram = @This();
const std = @import("std");
const Allocator = std.mem.Allocator;
const gl = @import("opengl");
program: gl.Program,
pub fn createList(alloc: Allocator, srcs: []const [:0]const u8) ![]const CustomProgram {
var programs = std.ArrayList(CustomProgram).init(alloc);
defer programs.deinit();
errdefer for (programs.items) |program| program.deinit();
for (srcs) |src| {
try programs.append(try CustomProgram.init(src));
}
return try programs.toOwnedSlice();
}
pub fn init(src: [:0]const u8) !CustomProgram {
const program = try gl.Program.createVF(
@embedFile("../shaders/custom.v.glsl"),
src,
);
errdefer program.destroy();
return .{
.program = program,
};
}
pub fn deinit(self: CustomProgram) void {
self.program.destroy();
}