[C++] 根据运算符获取对应枚举

// app::DepthTest::Func::Type
enum class Type : GLenum 
{
	Always = GL_ALWAYS,
	Never = GL_NEVER,
	Less = GL_LESS,
	Equal = GL_EQUAL,
	LEqual = GL_LEQUAL,
	Greater = GL_GREATER,
	NotEqual = GL_NOTEQUAL,
	GEqual = GL_GEQUAL,

	Default = Less,
};
#define APP_DEPTH_FUNC_OP(op)\
(([] {\
	struct { void operator##op (int) { } };/* X APP_DEPTH_FUNC_OP(== 1 && 2 ==) X */\
	static_assert(std::is_same_v<bool, decltype(0 op 0)>, "Comparison operator only.");\
	switch (((1 op 2) << 2) | ((3 op 3) << 1) | (5 op 4))\
	{\
	case 0b001: return app::DepthTest::Func::Type::Greater;\
	case 0b010: return app::DepthTest::Func::Type::Equal;\
	case 0b011: return app::DepthTest::Func::Type::GEqual;\
	case 0b100: return app::DepthTest::Func::Type::Less;\
	case 0b101: return app::DepthTest::Func::Type::NotEqual;\
	case 0b110: return app::DepthTest::Func::Type::LEqual;\
	}\
})())

用例:

APP_DEPTH_FUNC_OP(==) == Type::Equal;// (bool)true

[GLSL] HSV 转为 RGB

vec3 rgb(float h, float s, float v)
{
    int hi = int(mod(floor(h / 60), 6));
    float f = h / 60 - hi;
    float p = v * (1 - s);
    float q = v * (1 - f * s);
    float t = v * (1 - (1 - f) * s);
    switch(hi)
    {
    case 0:
        return vec3(v, t, p);
    case 1:
        return vec3(q, v, p);
    case 2:
        return vec3(p, v, t);
    case 3:
        return vec3(p, q, v);
    case 4:
        return vec3(t, p, v);
    case 5:
        return vec3(v, p, q);
    }
}

参考:颜色空间RGB与HSV(HSL)的转换_jiangxinyu的专栏-CSDN博客