diff --git a/src/main.zig b/src/main.zig index 21ed0cba3..c01d6fc32 100644 --- a/src/main.zig +++ b/src/main.zig @@ -57,16 +57,8 @@ pub fn main() !void { try vao.bind(); var binding = try vbo.bind(c.GL_ARRAY_BUFFER); try binding.setData(&vertices, c.GL_STATIC_DRAW); - - c.glVertexAttribPointer( - 0, - 3, - c.GL_FLOAT, - c.GL_FALSE, - 3 * @sizeOf(f32), - null, - ); - c.glEnableVertexAttribArray(0); + try binding.vertexAttribPointer(0, 3, c.GL_FLOAT, false, 3 * @sizeOf(f32), null); + try binding.enableVertexAttribArray(0); binding.unbind(); try gl.VertexArray.unbind(); diff --git a/src/opengl/Buffer.zig b/src/opengl/Buffer.zig index c980669af..692a3dc60 100644 --- a/src/opengl/Buffer.zig +++ b/src/opengl/Buffer.zig @@ -52,11 +52,26 @@ pub const Binding = struct { try errors.getError(); } + pub inline fn enableVertexAttribArray(_: Binding, idx: c.GLuint) !void { + c.glEnableVertexAttribArray(idx); + } + + pub inline fn vertexAttribPointer( + _: Binding, + idx: c.GLuint, + size: c.GLint, + typ: c.GLenum, + normalized: bool, + stride: c.GLsizei, + ptr: ?*const anyopaque, + ) !void { + const normalized_c: c.GLboolean = if (normalized) c.GL_TRUE else c.GL_FALSE; + c.glVertexAttribPointer(idx, size, typ, normalized_c, stride, ptr); + try errors.getError(); + } + pub inline fn unbind(b: *Binding) void { c.glBindBuffer(b.target, 0); - - // By setting this to undefined, this ensures that any future calls - // error in safe build modes. b.* = undefined; } };