opengl: unbind programs

This commit is contained in:
Mitchell Hashimoto
2022-04-06 08:42:39 -07:00
parent a9e887315a
commit 263c9e4aac
2 changed files with 12 additions and 3 deletions

View File

@ -92,7 +92,8 @@ pub fn setScreenSize(self: *TextRenderer, w: i32, h: i32) !void {
@intToFloat(f32, h),
);
try self.program.use();
const bind = try self.program.use();
defer bind.unbind();
try self.program.setUniform("projection", self.projection);
}
@ -153,7 +154,8 @@ pub fn render(
}
}
try self.program.use();
const pbind = try self.program.use();
defer pbind.unbind();
// Bind our texture and set our data
try gl.Texture.active(gl.c.GL_TEXTURE0);

View File

@ -11,6 +11,12 @@ const errors = @import("errors.zig");
id: c.GLuint,
const Binding = struct {
pub inline fn unbind(_: Binding) void {
c.glUseProgram(0);
}
};
pub inline fn create() !Program {
const id = c.glCreateProgram();
if (id == 0) try errors.mustError();
@ -61,8 +67,9 @@ pub inline fn link(p: Program) !void {
return error.CompileFailed;
}
pub inline fn use(p: Program) !void {
pub inline fn use(p: Program) !Binding {
c.glUseProgram(p.id);
return Binding{};
}
/// Requires the program is currently in use.