rust-windowing / softbuffer

Easily write an image to a window
Apache License 2.0
333 stars 48 forks source link

u32 pixel color vs f32 #199

Closed Alphapage closed 9 months ago

Alphapage commented 9 months ago

Hello,

Why softbuffer provides u32 for the pixel color ? Wouldn't it be better to provide f32 color to be aligned to gpu ?

Thank you in advance for your answers.

madsmtm commented 9 months ago

See also https://github.com/rust-windowing/softbuffer/issues/98.

The u32 is actually roughly something like the following (probably depends on endianness):

#[repr(C)]
#[align(4)]
struct Color {
    reserved: u8,
    red: u8,
    green: u8,
    blue: u8,
}

So it doesn't actually have anything to do with the f32s that GPUs use.

Alphapage commented 9 months ago

I thought it would be better to be able to have a vec4 of f32 buffer instead of having to convert vec4 f32 color to u32 at each pixel. But it is strange that the api doesn't give a vec4 of f32 for color because gpu handles colors with a vec4 instead of the old RGBA of u8. The buffer will increase a lot, so maybe it is more a performance problem and you prefer sacrify color precision in favour of speed.

jackpot51 commented 9 months ago

Most windowing systems use 8-bit per channel color when doing software rendering, which is why this crate exposes that. It would be a significant performance hit to use anything else.