opengl: more bindings

This commit is contained in:
Mitchell Hashimoto
2022-04-01 18:44:18 -07:00
parent a5a2196d52
commit 045dd704ec
2 changed files with 20 additions and 13 deletions

View File

@ -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();

View File

@ -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;
}
};