Files
ghostty/pkg/opengl/VertexArray.zig
Mitchell Hashimoto eccd07f009 pkg: replace @cImport with addTranslateC in pkg/
@cImport is going to disappear in Zig 0.17. Its deprecated in Zig 0.16.
Let's remove it now.

Replace @cImport with addTranslateC across pkg/ packages. Each
package now has a c_import.h header that is translated at build
time via addTranslateC and exposed as a "cimport" module import.

Converted packages:
- dcimgui
- fontconfig
- freetype
- glslang
- harfbuzz
- macos
- oniguruma
- opengl
- sentry
- spirv-cross
- wuffs

Omitted:
- gtk4-layer-shell - This has a bit more complexity with how it
  interacts with GTK headers, so I need to consider this a bit more.
- src/ - It'll be cleaner to do this separately.
2026-04-16 21:35:51 -07:00

117 lines
2.6 KiB
Zig

const VertexArray = @This();
const c = @import("c");
const glad = @import("glad.zig");
const errors = @import("errors.zig");
id: c.GLuint,
/// Create a single vertex array object.
pub fn create() !VertexArray {
var vao: c.GLuint = undefined;
glad.context.GenVertexArrays.?(1, &vao);
return VertexArray{ .id = vao };
}
/// glBindVertexArray
pub fn bind(v: VertexArray) !Binding {
glad.context.BindVertexArray.?(v.id);
try errors.getError();
return .{};
}
pub fn destroy(v: VertexArray) void {
glad.context.DeleteVertexArrays.?(1, &v.id);
}
pub const Binding = struct {
pub fn unbind(self: Binding) void {
_ = self;
glad.context.BindVertexArray.?(0);
}
pub fn enableAttribArray(_: Binding, idx: c.GLuint) !void {
glad.context.EnableVertexAttribArray.?(idx);
try errors.getError();
}
pub fn bindingDivisor(_: Binding, idx: c.GLuint, divisor: c.GLuint) !void {
glad.context.VertexBindingDivisor.?(idx, divisor);
try errors.getError();
}
pub fn attributeBinding(
_: Binding,
attrib_idx: c.GLuint,
binding_idx: c.GLuint,
) !void {
glad.context.VertexAttribBinding.?(attrib_idx, binding_idx);
try errors.getError();
}
pub fn attributeFormat(
_: Binding,
idx: c.GLuint,
size: c.GLint,
typ: c.GLenum,
normalized: bool,
offset: c.GLuint,
) !void {
glad.context.VertexAttribFormat.?(
idx,
size,
typ,
@intCast(@intFromBool(normalized)),
offset,
);
try errors.getError();
}
pub fn attributeIFormat(
_: Binding,
idx: c.GLuint,
size: c.GLint,
typ: c.GLenum,
offset: c.GLuint,
) !void {
glad.context.VertexAttribIFormat.?(
idx,
size,
typ,
offset,
);
try errors.getError();
}
pub fn attributeLFormat(
_: Binding,
idx: c.GLuint,
size: c.GLint,
offset: c.GLuint,
) !void {
glad.context.VertexAttribLFormat.?(
idx,
size,
c.GL_DOUBLE,
offset,
);
try errors.getError();
}
pub fn bindVertexBuffer(
_: Binding,
idx: c.GLuint,
buffer: c.GLuint,
offset: c.GLintptr,
stride: c.GLsizei,
) !void {
glad.context.BindVertexBuffer.?(
idx,
buffer,
offset,
stride,
);
try errors.getError();
}
};