Suppose we have:
struct Color { r: u8, g: u8, b: u8 }
struct Colored_u8 { value: u8, color: Color }
my_screen: [[Colored_u8; 100]; 50]
is there a simple to use & efficient wgpu library for blitting my_sreen
to a wgpu surface ?
Suppose we have:
struct Color { r: u8, g: u8, b: u8 }
struct Colored_u8 { value: u8, color: Color }
my_screen: [[Colored_u8; 100]; 50]
is there a simple to use & efficient wgpu library for blitting my_sreen
to a wgpu surface ?
If you are already using wgpu
, then you do not need very much more than you have.
Change your struct declarations to have a more convenient, guaranteed layout:
#[derive(Clone, Copy, bytemuck::NoUninit)]
#[repr(C)]
struct Color { r: u8, g: u8, b: u8 }
#[derive(Clone, Copy, bytemuck::NoUninit)]
#[repr(C)]
struct Colored_u8 { color: Color, value: u8 }
Now, an array of these structs may be interpreted as a standard RGBA image (ignoring the alpha), because Colored_u8
is guaranteed (via repr(C)
) to be exactly 4 bytes, r, g, b, value
.
Take bytemuck::bytes_of()
this array and upload it as a texture, just like if it were an image.
Draw 1 full-screen triangle and have the fragment shader read your texture, ignoring the alpha component.
This is more or less as efficient as it gets; there are no extraneous copies or conversions.
Is there a crate that handles this part? Takes a font, creates sdf texture atlas, has sdf texture shader ?
Oh, I thought you meant you had an array whose elements were pixels.
I don't have any advice for high-quality text rendering. Sorry.