mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-26 17:23:56 +00:00
renderer: create explicit sampler state for custom shaders
The GLSL to MSL conversion process uses a passed-in sampler state for the `iChannel0` parameter and we weren't providing it. This magically worked on Apple Silicon for unknown reasons but failed on Intel GPUs. In normal, hand-written MSL, we'd explicitly create the sampler state as a normal variable (we do this in `shaders.metal` already!), but the Shadertoy conversion stuff doesn't do this, probably because the exact sampler parameters can't be safely known. This fixes a Metal validation error when using custom shaders: ``` -[MTLDebugRenderCommandEncoder validateCommonDrawErrors:]:5970: failed assertion `Draw Errors Validation Fragment Function(main0): missing Sampler binding at index 0 for iChannel0Smplr[0]. ```
This commit is contained in:
43
pkg/opengl/Sampler.zig
Normal file
43
pkg/opengl/Sampler.zig
Normal file
@@ -0,0 +1,43 @@
|
||||
const Sampler = @This();
|
||||
|
||||
const std = @import("std");
|
||||
const c = @import("c.zig").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,
|
||||
name: Texture.Parameter,
|
||||
value: anytype,
|
||||
) errors.Error!void {
|
||||
switch (@TypeOf(value)) {
|
||||
c.GLint => glad.context.SamplerParameteri.?(
|
||||
self.id,
|
||||
@intFromEnum(name),
|
||||
value,
|
||||
),
|
||||
else => unreachable,
|
||||
}
|
||||
try errors.getError();
|
||||
}
|
||||
|
||||
pub fn destroy(v: Sampler) void {
|
||||
glad.context.DeleteSamplers.?(1, &v.id);
|
||||
}
|
||||
@@ -18,6 +18,7 @@ pub const Buffer = @import("Buffer.zig");
|
||||
pub const Framebuffer = @import("Framebuffer.zig");
|
||||
pub const Renderbuffer = @import("Renderbuffer.zig");
|
||||
pub const Program = @import("Program.zig");
|
||||
pub const Sampler = @import("Sampler.zig");
|
||||
pub const Shader = @import("Shader.zig");
|
||||
pub const Texture = @import("Texture.zig");
|
||||
pub const VertexArray = @import("VertexArray.zig");
|
||||
|
||||
Reference in New Issue
Block a user