Sign in to follow this  
Alundra

Color storage convention

Recommended Posts

Hi,
I always stored the colors in float for the RGBA but I recently moved all to sRGB and I read it's more conventional to store the color in uint8.
Is it true or it doesn't matter ?
Thanks

Share this post


Link to post
Share on other sites

Store it where? Store what kind of color value? It all just depends on what you're doing and what the appropriate choice is for that value. I'll use uint8 for stuff loaded from textures most of the time, but half or float for engine values, vertex colors, etc.

Share this post


Link to post
Share on other sites

In that case:

template<typename T> color4
{
    T r, g, b, a;
}
typedef color4<float> color4f;
typedef color4<uint8> color4b;

Something like that should do the trick.

Share this post


Link to post
Share on other sites

There are a lot of times i'll use either 4 bytes or 4 floats - sometimes bandwidth is more important than precision, sometimes i need HDR values.

I've never bothered with an explicit type for colour, and instead use math library types e.g. float4 / ubyte4n as there aren't really any colour specific functionality besides conversions (all of which reside in the DirectXMath library anyway)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this