Store Sprite Colors, and all others, as 4x floats, not 0-255 ints
Enhancement request:
What should be added/changed?
BasicSprite._color should be stored as floats internally, not as ints from 0 to 255.
What would it help with?
A list of reasons discussed here: https://discord.com/channels/458662222697070613/458662458198982676/1110348630956720158
Color manipulation within python is easier and has greater precision w/floats. Useful for smoothly lerping between colors using float math instead of imprecise int math.
Easier for consumers to think about. More performant(?) since we never need to convert back and forth between int and float, only copy the float values to the GPU. A bit more data transfer.
Shaders already convert the ints to floats anyway.
Related to #1772
I really want these to be floats because of the flexibility this adds, but I'm not entirely sure yet if this is worth it. At least I don't think there's a fast way to have backwards compatible support for both byte and float colors. Worst case it could be something we consider futher down the line. Some more thinking is needed here.
We do have some places were float colors are used, so having the type certainly doesn't hurt.
I see three orthogonal concerns:
- lerping and intermediate generation, also solvable by generators or other internal error-tracking approaches
- Speed comparisons of color types & annotations (
NamedTuplevsTuple, protocol vs tuple subclass, etc), answerable with benchmarks - Internal storage /
object.color_floatproperty interaction withobject.color
The most urgent issue for me is the last one since it determines whether I should continue work on #1772.
- Do we have an efficient & clean way to handle lazily calculating the RGBA255
object.colorproperty? - In the absence of anything better, is
object._color_dirty+ properties acceptable?