mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-09-19 12:08:07 +00:00
I'm so dumb like honestly, always double check if your unreachables are *comptime*. Whether the value being switched on is comptime or not does not matter
53 lines
1.2 KiB
Zig
53 lines
1.2 KiB
Zig
const Sampler = @This();
|
|
|
|
const std = @import("std");
|
|
const c = @import("opengl_c");
|
|
const errors = @import("errors.zig");
|
|
const glad = @import("glad.zig");
|
|
const Texture = @import("Texture.zig");
|
|
|
|
id: c.GLuint,
|
|
|
|
/// Create a single sampler.
|
|
pub fn create() errors.Error!Sampler {
|
|
var id: c.GLuint = undefined;
|
|
glad.context.GenSamplers.?(1, &id);
|
|
try errors.getError();
|
|
return .{ .id = id };
|
|
}
|
|
|
|
/// glBindSampler
|
|
pub fn bind(v: Sampler, index: c_uint) !void {
|
|
glad.context.BindSampler.?(index, v.id);
|
|
try errors.getError();
|
|
}
|
|
|
|
pub fn parameter(
|
|
self: Sampler,
|
|
comptime name: Texture.Parameter,
|
|
value: name.Type(),
|
|
) errors.Error!void {
|
|
const T = name.Type();
|
|
|
|
switch (T) {
|
|
c.GLint => glad.context.SamplerParameteri.?(
|
|
self.id,
|
|
@intFromEnum(name),
|
|
value,
|
|
),
|
|
else => switch (@typeInfo(T)) {
|
|
.@"enum" => glad.context.SamplerParameteri.?(
|
|
self.id,
|
|
@intFromEnum(name),
|
|
@intFromEnum(value),
|
|
),
|
|
else => @compileLog("unsupported parameter type", T),
|
|
},
|
|
}
|
|
try errors.getError();
|
|
}
|
|
|
|
pub fn destroy(v: Sampler) void {
|
|
glad.context.DeleteSamplers.?(1, &v.id);
|
|
}
|