Original Post
Hi all, I've got a simple 3d engine with a renderqueue that sorts all the objects that need to be rendered by most expensive renderstate change. Each object has an unsigned int where the bits are the flags for the states. When these flags differ from the flags that are set i have a function that checks which states have to be changed: Since there are lots of states to check (about 32) it would be nice to skip the checks above (if ((oldstates ^ newstates) & somestate) == somestate)) if i know all have been done. One way I came up with is: countbits(oldstates ^ newstates) oldstates ^ newstates will be an unsigned int that had a bit set for every state that has to be changed. If there's a fast function to count the bits in this unsigned int I would be able to return from the checking (above) when I've changed the maximum number of changes. my question: Is there a faster way anyone knows of to check which states have to be changed? and : Is there a quick way to count the bits in an int. thanx a lot, Marty
if ((oldstates ^ newstates) & somestate) == somestate)
{
if (newstates & somestate) enable(somestate);
else disable(somestate);
}