wip
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
18e32ee6bf
commit
f79351ed59
4 changed files with 19 additions and 9 deletions
|
|
@ -209,10 +209,10 @@ fn updatePipeline(
|
|||
// defer font.deinit(allocator);
|
||||
|
||||
const font_size = text_style.get(style, .font_size).?;
|
||||
const font_color = text_style.get(style, .font_color) orelse vec4(0, 0, 0, 1.0);
|
||||
// TODO(text): respect these style parameters
|
||||
// const font_weight = text_style.get(style, .font_weight).?;
|
||||
// const italic = text_style.get(style, .italic).?;
|
||||
// const color = text_style.get(style, .color).?;
|
||||
|
||||
// Create a text shaper
|
||||
var run = try gfx.TextRun.init();
|
||||
|
|
@ -274,6 +274,7 @@ fn updatePipeline(
|
|||
.size = size.divScalar(px_density),
|
||||
.text_index = num_texts,
|
||||
.uv_pos = vec2(@floatFromInt(r.x), @floatFromInt(r.y)),
|
||||
.font_color = font_color,
|
||||
});
|
||||
origin_x += glyph.advance.x();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,6 +107,9 @@ pub const Glyph = extern struct {
|
|||
|
||||
/// Which text this glyph belongs to; this is the index for transforms[i], colors[i].
|
||||
text_index: u32,
|
||||
|
||||
/// Color of the glyph
|
||||
color: math.Vec4,
|
||||
};
|
||||
|
||||
const GlyphKey = struct {
|
||||
|
|
|
|||
|
|
@ -11,10 +11,9 @@ pub const components = .{
|
|||
// \\ TODO(text): this is not currently implemented
|
||||
// },
|
||||
|
||||
// e.g. 12 * mach.gfx.px_per_pt // 12pt
|
||||
.font_size = .{ .type = f32, .description =
|
||||
\\ Font size in pixels
|
||||
\\ TODO(text): this is not currently implemented
|
||||
\\ e.g. 12 * mach.gfx.px_per_pt for 12pt font size
|
||||
},
|
||||
|
||||
// // e.g. mach.gfx.font_weight_normal
|
||||
|
|
@ -29,11 +28,11 @@ pub const components = .{
|
|||
// \\ TODO(text): this is not currently implemented
|
||||
// },
|
||||
|
||||
// // e.g. vec4(0, 0, 0, 1.0)
|
||||
// .color = .{ .type = math.Vec4, .description =
|
||||
// \\ Fill color
|
||||
// \\ TODO(text): this is not currently implemented
|
||||
// },
|
||||
.font_color = .{ .type = math.Vec4, .description =
|
||||
\\ Fill color of text
|
||||
\\ e.g. vec4(0.0, 0.0, 0.0, 1.0) // black
|
||||
\\ e.g. vec4(1.0, 1.0, 1.0, 1.0) // white
|
||||
},
|
||||
|
||||
// TODO(text): allow user to specify projection matrix (3d-space flat text etc.)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ struct VertexOutput {
|
|||
|
||||
// UV coordinate
|
||||
@location(0) fragUV : vec2<f32>,
|
||||
|
||||
// Color of the glyph
|
||||
@location(1) color : vec4<f32>,
|
||||
};
|
||||
|
||||
// Our vertex shader will recieve these parameters
|
||||
|
|
@ -30,6 +33,9 @@ struct Glyph {
|
|||
|
||||
// Which text this glyph belongs to; this is the index for transforms[i], colors[i]
|
||||
text_index: u32,
|
||||
|
||||
// Color of the glyph
|
||||
color: vec4<f32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(0) var<uniform> uniforms : Uniforms;
|
||||
|
|
@ -96,10 +102,11 @@ fn vertMain(
|
|||
@fragment
|
||||
fn fragMain(
|
||||
@location(0) fragUV: vec2<f32>
|
||||
@location(1) color: vec4<f32>
|
||||
) -> @location(0) vec4<f32> {
|
||||
var c = textureSample(glyphTexture, glyphSampler, fragUV);
|
||||
if (c.a <= 0.0) {
|
||||
discard;
|
||||
}
|
||||
return c;
|
||||
return c * color;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue