• Advertisement
Sign in to follow this  

Color storage convention

This topic is 382 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement

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

You are right, I missed to precise I speak about the color class in the engine to manipulate colors but not the image class or vertex color.

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
Sign in to follow this  

  • Advertisement