#if MLN_RENDER_BACKEND_OPENGL #include #include #include #include #include using namespace mln; using namespace mln::gfx; using namespace mln::gl; TEST(GL, DrawModeType) { ASSERT_EQ(GL_POINTS, Enum::to(DrawModeType::Points)); ASSERT_EQ(GL_LINES, Enum::to(DrawModeType::Lines)); ASSERT_EQ(GL_LINE_LOOP, Enum::to(DrawModeType::LineLoop)); ASSERT_EQ(GL_LINE_STRIP, Enum::to(DrawModeType::LineStrip)); ASSERT_EQ(GL_TRIANGLES, Enum::to(DrawModeType::Triangles)); ASSERT_EQ(GL_TRIANGLE_STRIP, Enum::to(DrawModeType::TriangleStrip)); ASSERT_EQ(GL_TRIANGLE_FAN, Enum::to(DrawModeType::TriangleFan)); ASSERT_EQ( GL_INVALID_ENUM, Enum::to(static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) } namespace { template auto enumIdentity(T x) { return Enum::from(Enum::to(x)); } } // namespace TEST(GL, ColorBlendEquationType) { // const auto identity = [](auto x){ return Enum::from(Enum::to(x)); // }; ASSERT_EQ(ColorBlendEquationType::Add, enumIdentity(ColorBlendEquationType::Add)); ASSERT_EQ(ColorBlendEquationType::Subtract, enumIdentity(ColorBlendEquationType::Subtract)); ASSERT_EQ(ColorBlendEquationType::ReverseSubtract, enumIdentity(ColorBlendEquationType::ReverseSubtract)); ASSERT_EQ(GL_INVALID_ENUM, Enum::to( static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(ColorBlendEquationType{}, Enum::from(GL_RGBA8)); } TEST(GL, ColorBlendFactorType) { ASSERT_EQ(ColorBlendFactorType::Zero, enumIdentity(ColorBlendFactorType::Zero)); ASSERT_EQ(ColorBlendFactorType::One, enumIdentity(ColorBlendFactorType::One)); ASSERT_EQ(ColorBlendFactorType::SrcColor, enumIdentity(ColorBlendFactorType::SrcColor)); ASSERT_EQ(ColorBlendFactorType::OneMinusSrcColor, enumIdentity(ColorBlendFactorType::OneMinusSrcColor)); ASSERT_EQ(ColorBlendFactorType::DstColor, enumIdentity(ColorBlendFactorType::DstColor)); ASSERT_EQ(ColorBlendFactorType::OneMinusDstColor, enumIdentity(ColorBlendFactorType::OneMinusDstColor)); ASSERT_EQ(ColorBlendFactorType::SrcAlpha, enumIdentity(ColorBlendFactorType::SrcAlpha)); ASSERT_EQ(ColorBlendFactorType::OneMinusSrcAlpha, enumIdentity(ColorBlendFactorType::OneMinusSrcAlpha)); ASSERT_EQ(ColorBlendFactorType::DstAlpha, enumIdentity(ColorBlendFactorType::DstAlpha)); ASSERT_EQ(ColorBlendFactorType::OneMinusDstAlpha, enumIdentity(ColorBlendFactorType::OneMinusDstAlpha)); ASSERT_EQ(ColorBlendFactorType::ConstantColor, enumIdentity(ColorBlendFactorType::ConstantColor)); ASSERT_EQ(ColorBlendFactorType::OneMinusConstantColor, enumIdentity(ColorBlendFactorType::OneMinusConstantColor)); ASSERT_EQ(ColorBlendFactorType::ConstantAlpha, enumIdentity(ColorBlendFactorType::ConstantAlpha)); ASSERT_EQ(ColorBlendFactorType::OneMinusConstantAlpha, enumIdentity(ColorBlendFactorType::OneMinusConstantAlpha)); ASSERT_EQ(ColorBlendFactorType::SrcAlphaSaturate, enumIdentity(ColorBlendFactorType::SrcAlphaSaturate)); ASSERT_EQ(GL_INVALID_ENUM, Enum::to( static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(ColorBlendFactorType{}, Enum::from(GL_RGBA8)); } TEST(GL, DepthFunctionType) { ASSERT_EQ(DepthFunctionType::Never, enumIdentity(DepthFunctionType::Never)); ASSERT_EQ(DepthFunctionType::Less, enumIdentity(DepthFunctionType::Less)); ASSERT_EQ(DepthFunctionType::Equal, enumIdentity(DepthFunctionType::Equal)); ASSERT_EQ(DepthFunctionType::LessEqual, enumIdentity(DepthFunctionType::LessEqual)); ASSERT_EQ(DepthFunctionType::Greater, enumIdentity(DepthFunctionType::Greater)); ASSERT_EQ(DepthFunctionType::NotEqual, enumIdentity(DepthFunctionType::NotEqual)); ASSERT_EQ(DepthFunctionType::GreaterEqual, enumIdentity(DepthFunctionType::GreaterEqual)); ASSERT_EQ(DepthFunctionType::Always, enumIdentity(DepthFunctionType::Always)); ASSERT_EQ(GL_INVALID_ENUM, Enum::to( static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(DepthFunctionType{}, Enum::from(GL_RGBA8)); } TEST(GL, DepthMaskType) { ASSERT_EQ(DepthMaskType::ReadOnly, enumIdentity(DepthMaskType::ReadOnly)); ASSERT_EQ(DepthMaskType::ReadWrite, enumIdentity(DepthMaskType::ReadWrite)); // anything non-zero is true, there's no way to represent invalid ASSERT_EQ(GL_TRUE, Enum::to(static_cast(-1))); } TEST(GL, StencilFunctionType) { ASSERT_EQ(StencilFunctionType::Never, enumIdentity(StencilFunctionType::Never)); ASSERT_EQ(StencilFunctionType::Less, enumIdentity(StencilFunctionType::Less)); ASSERT_EQ(StencilFunctionType::Equal, enumIdentity(StencilFunctionType::Equal)); ASSERT_EQ(StencilFunctionType::LessEqual, enumIdentity(StencilFunctionType::LessEqual)); ASSERT_EQ(StencilFunctionType::Greater, enumIdentity(StencilFunctionType::Greater)); ASSERT_EQ(StencilFunctionType::NotEqual, enumIdentity(StencilFunctionType::NotEqual)); ASSERT_EQ(StencilFunctionType::GreaterEqual, enumIdentity(StencilFunctionType::GreaterEqual)); ASSERT_EQ(StencilFunctionType::Always, enumIdentity(StencilFunctionType::Always)); ASSERT_EQ(GL_INVALID_ENUM, Enum::to( static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(StencilFunctionType{}, Enum::from(GL_RGBA8)); } TEST(GL, StencilOpType) { ASSERT_EQ(StencilOpType::Keep, enumIdentity(StencilOpType::Keep)); ASSERT_EQ(StencilOpType::Zero, enumIdentity(StencilOpType::Zero)); ASSERT_EQ(StencilOpType::Replace, enumIdentity(StencilOpType::Replace)); ASSERT_EQ(StencilOpType::Increment, enumIdentity(StencilOpType::Increment)); ASSERT_EQ(StencilOpType::IncrementWrap, enumIdentity(StencilOpType::IncrementWrap)); ASSERT_EQ(StencilOpType::Decrement, enumIdentity(StencilOpType::Decrement)); ASSERT_EQ(StencilOpType::DecrementWrap, enumIdentity(StencilOpType::DecrementWrap)); ASSERT_EQ(StencilOpType::Invert, enumIdentity(StencilOpType::Invert)); ASSERT_EQ(GL_INVALID_ENUM, Enum::to( static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(StencilOpType{}, Enum::from(GL_RGBA8)); } TEST(GL, CullFaceSideType) { ASSERT_EQ(CullFaceSideType::Front, enumIdentity(CullFaceSideType::Front)); ASSERT_EQ(CullFaceSideType::Back, enumIdentity(CullFaceSideType::Back)); ASSERT_EQ(CullFaceSideType::FrontAndBack, enumIdentity(CullFaceSideType::FrontAndBack)); ASSERT_EQ(GL_INVALID_ENUM, Enum::to( static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(CullFaceSideType{}, Enum::from(GL_RGBA8)); } TEST(GL, CullFaceWindingType) { ASSERT_EQ(CullFaceWindingType::Clockwise, enumIdentity(CullFaceWindingType::Clockwise)); ASSERT_EQ(CullFaceWindingType::CounterClockwise, enumIdentity(CullFaceWindingType::CounterClockwise)); ASSERT_EQ(GL_INVALID_ENUM, Enum::to( static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(CullFaceWindingType{}, Enum::from(GL_RGBA8)); } TEST(GL, BufferUsageType) { ASSERT_EQ(BufferUsageType::StreamDraw, enumIdentity(BufferUsageType::StreamDraw)); ASSERT_EQ(BufferUsageType::StaticDraw, enumIdentity(BufferUsageType::StaticDraw)); ASSERT_EQ(BufferUsageType::DynamicDraw, enumIdentity(BufferUsageType::DynamicDraw)); ASSERT_EQ(GL_INVALID_ENUM, Enum::to( static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(BufferUsageType{}, Enum::from(GL_RGBA8)); } TEST(GL, TexturePixelType) { ASSERT_EQ(TexturePixelType::RGBA, enumIdentity(TexturePixelType::RGBA)); ASSERT_EQ(TexturePixelType::Alpha, enumIdentity(TexturePixelType::Alpha)); ASSERT_EQ(TexturePixelType::Stencil, enumIdentity(TexturePixelType::Stencil)); ASSERT_EQ(TexturePixelType::Depth, enumIdentity(TexturePixelType::Depth)); ASSERT_EQ(TexturePixelType::Luminance, enumIdentity(TexturePixelType::Luminance)); ASSERT_EQ(GL_INVALID_ENUM, Enum::to( static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(TexturePixelType{}, Enum::from(GL_RGBA8)); } TEST(GL, TextureChannelDataType) { ASSERT_EQ(TextureChannelDataType::UnsignedByte, enumIdentity(TextureChannelDataType::UnsignedByte)); ASSERT_EQ(TextureChannelDataType::HalfFloat, enumIdentity(TextureChannelDataType::HalfFloat)); ASSERT_EQ(TextureChannelDataType::Float, enumIdentity(TextureChannelDataType::Float)); ASSERT_EQ(GL_INVALID_ENUM, Enum::to( static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(TextureChannelDataType{}, Enum::from(GL_RGBA8)); } TEST(GL, RenderbufferPixelType) { ASSERT_EQ(RenderbufferPixelType::RGBA, enumIdentity(RenderbufferPixelType::RGBA)); ASSERT_EQ(RenderbufferPixelType::Depth, enumIdentity(RenderbufferPixelType::Depth)); ASSERT_EQ(RenderbufferPixelType::DepthStencil, enumIdentity(RenderbufferPixelType::DepthStencil)); ASSERT_EQ(GL_INVALID_ENUM, Enum::to( static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) ASSERT_EQ(RenderbufferPixelType{}, Enum::from(GL_RGBA8)); } TEST(GL, sizedFor) { ASSERT_EQ(GL_RGBA, Enum::sizedFor(TexturePixelType::RGBA, TextureChannelDataType::UnsignedByte)); ASSERT_EQ(GL_RGBA16F, Enum::sizedFor(TexturePixelType::RGBA, TextureChannelDataType::HalfFloat)); ASSERT_EQ(GL_INVALID_ENUM, Enum::sizedFor(TexturePixelType::Alpha, TextureChannelDataType::HalfFloat)); ASSERT_EQ(GL_RGBA32F, Enum::sizedFor(TexturePixelType::RGBA, TextureChannelDataType::Float)); ASSERT_EQ(GL_INVALID_ENUM, Enum::sizedFor(TexturePixelType::Alpha, TextureChannelDataType::Float)); ASSERT_EQ(GL_INVALID_ENUM, Enum::sizedFor( TexturePixelType::RGBA, static_cast(-1))); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) } #endif