
This makes the [New Bevy Renderer](#2535) the default (and only) renderer. The new renderer isn't _quite_ ready for the final release yet, but I want as many people as possible to start testing it so we can identify bugs and address feedback prior to release. The examples are all ported over and operational with a few exceptions: * I removed a good portion of the examples in the `shader` folder. We still have some work to do in order to make these examples possible / ergonomic / worthwhile: #3120 and "high level shader material plugins" are the big ones. This is a temporary measure. * Temporarily removed the multiple_windows example: doing this properly in the new renderer will require the upcoming "render targets" changes. Same goes for the render_to_texture example. * Removed z_sort_debug: entity visibility sort info is no longer available in app logic. we could do this on the "render app" side, but i dont consider it a priority.
47 lines
1.4 KiB
Rust
47 lines
1.4 KiB
Rust
use ab_glyph::{FontArc, FontVec, InvalidFont, OutlinedGlyph};
|
|
use bevy_reflect::TypeUuid;
|
|
use bevy_render::{
|
|
render_resource::{Extent3d, TextureDimension, TextureFormat},
|
|
texture::Image,
|
|
};
|
|
|
|
#[derive(Debug, TypeUuid)]
|
|
#[uuid = "97059ac6-c9ba-4da9-95b6-bed82c3ce198"]
|
|
pub struct Font {
|
|
pub font: FontArc,
|
|
}
|
|
|
|
impl Font {
|
|
pub fn try_from_bytes(font_data: Vec<u8>) -> Result<Self, InvalidFont> {
|
|
let font = FontVec::try_from_vec(font_data)?;
|
|
let font = FontArc::new(font);
|
|
Ok(Font { font })
|
|
}
|
|
|
|
pub fn get_outlined_glyph_texture(outlined_glyph: OutlinedGlyph) -> Image {
|
|
let bounds = outlined_glyph.px_bounds();
|
|
let width = bounds.width() as usize;
|
|
let height = bounds.height() as usize;
|
|
let mut alpha = vec![0.0; width * height];
|
|
outlined_glyph.draw(|x, y, v| {
|
|
alpha[y as usize * width + x as usize] = v;
|
|
});
|
|
|
|
// TODO: make this texture grayscale
|
|
Image::new(
|
|
Extent3d {
|
|
width: width as u32,
|
|
height: height as u32,
|
|
depth_or_array_layers: 1,
|
|
},
|
|
TextureDimension::D2,
|
|
alpha
|
|
.iter()
|
|
.map(|a| vec![255, 255, 255, (*a * 255.0) as u8])
|
|
.flatten()
|
|
.collect::<Vec<u8>>(),
|
|
TextureFormat::Rgba8UnormSrgb,
|
|
)
|
|
}
|
|
}
|