Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The changes in this PR are the additions needed to implement the proposal as a usable API. More things might need to be added later. Breaking changes are described below but not included in the PR so that reading the code is easier.
Keep in mind that this is a proposal and while the commits in this PR could be merged, they exist more to demonstrate the API as code. I don't mind changing stuff.
API overview
ColourInfo
: Semantically unchanged. Describes the colours of the four vertices of a quad.SRGBColour
: Main single-colour type that framework users interact with. Contains a gamma-corrected sRGB colour. Thin wrapper aroundColour4
. The type discourages invalid things like gamma-incorrect colour math1.LinearColour
(new): Secondary colour type for framework users. Contains a linear-light sRGB colour2. Thin wrapper aroundColour4
. Basically only exists to do colour math.Colour4
: Should rarely be used directly. Low level, raw colour values, no inherent colour space. This is where the real math (and optimization) should happen so that all abstractions can benefit.Color4
: Semantically the same asColour4
.Colour4
(noosuTK
dependency, usesSystem.Numerics.Vector4
which should optimise better) should always be preferred overColor4
unless interacting with an osuTK API that requires it.Implementation notes
MultiplyAlpha
into a pure method is a hidden trap for existing usage ([Pure]
should help with this, but not sure it's enough). Renaming it is an alternative, but making it pure is a requirement for a readonlySRGBColour
.Color4.Red
etc. are copies of the CSS<named-color>
values and are defined to be in the sRGB colour space, so they should live inSRGBColour
. This is also necessary to remove the implicit conversionsColor4
/Colour4
<->SRGBColour
later on.Color4
toColour4
insideSRGBColour
is most likely going to have performance implications. I am not sure how to test this because colours are used everywhere, and I do not have enough insight into the renderer implementations to know how this impacts them.Next steps
This list is mostly unordered.
Colour4
andColourInfo
docsSRGBColour
readonly and extend API to cover common usageSRGBColour.Linear
(breaking with low impact)Colour4
which loses colour space informationToLinear()
should be used insteadSRGBColour
operator overloads (*
,/
,+
) (breaking with low impact)ToLinear()
andLinearColour
insteadSRGBColour
operators is slow and imprecise and turns the operators into a footgun3Color4
andColour4
in public API withSRGBColour
or maybeColour4
instead (breaking with very high impact)OsuColour
,Color4Extensions
Color4
/Colour4
andSRGBColour
(see Implicit conversions inSRGBColour
should not exist #5714) (breaking with high impact)Color4
/Colour4
andColourInfo
(breaking with very high impact)drawable.Colour = Color4.Red
must be replaced withdrawable.Colour = SRGBColour.Red
), but can often be done with search-and-replace.osuTK
from a lot of places.Bindable
typesSRGBColour
(these are also semantically sRGB)Colour4
Footnotes
Gamma-incorrect operations could be done with helper functions. ↩
As described here (search for "srgb-linear"). Can also be called "linear sRGB" or "gamma-expanded sRGB". This is usually called "linear colour"/"linear colour space" in and around o!f, which is why the struct is named
LinearColour
. ↩For example,
a * b * c
will: Converta
andb
to linear. Multiply those two. Convert the result back to sRGB. Convert the first result andc
to linear. Multiply those two. Convert that result back to sRGB. ↩