Skip to content

Commit

Permalink
#5953: Sort OpenGLStates by colour, if all the other checks produced …
Browse files Browse the repository at this point in the history
…the same result.

Darker state colours will be considered less than the ones with brighter colours.
  • Loading branch information
codereader committed May 1, 2022
1 parent 56cb8a1 commit 160c5e8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions radiantcore/rendersystem/backend/OpenGLStateLess.h
Expand Up @@ -5,6 +5,13 @@
namespace render
{

// Compare two Colour4 values
inline bool Colour4_less(const Colour4& a, const Colour4& b)
{
return a.x() * a.x() + a.y() * a.y() + a.z() * a.z() + a.w() * a.w() <
b.x() * b.x() + b.y() * b.y() + b.z() * b.z() + b.w() * b.w();
}

/**
* Comparison class for OpenGLState objects.
*/
Expand Down Expand Up @@ -35,6 +42,11 @@ struct OpenGLStateLess
{
return self->getRenderFlags() < other->getRenderFlags();
}
// Sort brighter colours on top if all of the above are equivalent
if (self->getColour() != other->getColour())
{
return Colour4_less(self->getColour(), other->getColour());
}
//! Comparing address makes sure states are never equal.
return self < other;
}
Expand Down

0 comments on commit 160c5e8

Please sign in to comment.