mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-17 09:16:11 +03:00
metal: glyphs show up (poorly)
This commit is contained in:
@ -810,6 +810,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object {
|
|||||||
|
|
||||||
// Value is MTLPixelFormatBGRA8Unorm
|
// Value is MTLPixelFormatBGRA8Unorm
|
||||||
attachment.setProperty("pixelFormat", @as(c_ulong, 80));
|
attachment.setProperty("pixelFormat", @as(c_ulong, 80));
|
||||||
|
attachment.setProperty("blendingEnabled", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make our state
|
// Make our state
|
||||||
@ -930,6 +931,7 @@ const MTLVertexStepFunction = enum(c_ulong) {
|
|||||||
/// https://developer.apple.com/documentation/metal/mtlpixelformat?language=objc
|
/// https://developer.apple.com/documentation/metal/mtlpixelformat?language=objc
|
||||||
const MTLPixelFormat = enum(c_ulong) {
|
const MTLPixelFormat = enum(c_ulong) {
|
||||||
r8unorm = 10,
|
r8unorm = 10,
|
||||||
|
bgra8unorm = 80,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// https://developer.apple.com/documentation/metal/mtlpurgeablestate?language=objc
|
/// https://developer.apple.com/documentation/metal/mtlpurgeablestate?language=objc
|
||||||
|
@ -39,6 +39,7 @@ struct VertexOut {
|
|||||||
float4 position [[ position ]];
|
float4 position [[ position ]];
|
||||||
uint8_t mode;
|
uint8_t mode;
|
||||||
float4 color;
|
float4 color;
|
||||||
|
float2 tex_coord;
|
||||||
};
|
};
|
||||||
|
|
||||||
vertex VertexOut uber_vertex(
|
vertex VertexOut uber_vertex(
|
||||||
@ -90,10 +91,15 @@ vertex VertexOut uber_vertex(
|
|||||||
// So we flip it with `cell_size.y - glyph_offset.y`.
|
// So we flip it with `cell_size.y - glyph_offset.y`.
|
||||||
glyph_offset.y = cell_size.y - glyph_offset.y;
|
glyph_offset.y = cell_size.y - glyph_offset.y;
|
||||||
|
|
||||||
// Calculate the final position of the cell.
|
// Calculate the final position of the cell which uses our glyph size
|
||||||
|
// and glyph offset to create the correct bounding box for the glyph.
|
||||||
cell_pos = cell_pos + glyph_size * position + glyph_offset;
|
cell_pos = cell_pos + glyph_size * position + glyph_offset;
|
||||||
|
|
||||||
out.position = uniforms.projection_matrix * float4(cell_pos.x, cell_pos.y, 0.0f, 1.0f);
|
out.position = uniforms.projection_matrix * float4(cell_pos.x, cell_pos.y, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
// Calculate the texture coordinate in pixels. This is NOT normalized
|
||||||
|
// (between 0.0 and 1.0) and must be done in the fragment shader.
|
||||||
|
// TODO: do I need to px_scale?
|
||||||
|
out.tex_coord = float2(input.glyph_pos) + float2(input.glyph_size) * position;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,13 +110,18 @@ fragment float4 uber_fragment(
|
|||||||
VertexOut in [[ stage_in ]],
|
VertexOut in [[ stage_in ]],
|
||||||
texture2d<float> textureGreyscale [[ texture(0) ]]
|
texture2d<float> textureGreyscale [[ texture(0) ]]
|
||||||
) {
|
) {
|
||||||
constexpr sampler textureSampler;
|
constexpr sampler textureSampler(address::clamp_to_edge, filter::linear);
|
||||||
|
|
||||||
switch (in.mode) {
|
switch (in.mode) {
|
||||||
case MODE_BG:
|
case MODE_BG:
|
||||||
return in.color;
|
return in.color;
|
||||||
|
|
||||||
case MODE_FG:
|
case MODE_FG:
|
||||||
return in.color;
|
// Normalize the texture coordinates to [0,1]
|
||||||
|
float2 size = float2(textureGreyscale.get_width(), textureGreyscale.get_height());
|
||||||
|
float2 coord = in.tex_coord / size;
|
||||||
|
|
||||||
|
float a = textureGreyscale.sample(textureSampler, coord).r;
|
||||||
|
return float4(in.color.rgb, in.color.a * a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user