From fdac0a7150f15686fc5a176fa2df632289178a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 1 Mar 2019 23:06:22 +0100 Subject: [PATCH] GL: expect less precision on ES2 tests that use RGBA4 renderbuffers. --- src/Magnum/GL/Test/FramebufferGLTest.cpp | 17 +- src/Magnum/GL/Test/MeshGLTest.cpp | 231 +++++++++++++++++++++-- 2 files changed, 227 insertions(+), 21 deletions(-) diff --git a/src/Magnum/GL/Test/FramebufferGLTest.cpp b/src/Magnum/GL/Test/FramebufferGLTest.cpp index 963e4f4b0..6b6f3ddd6 100644 --- a/src/Magnum/GL/Test/FramebufferGLTest.cpp +++ b/src/Magnum/GL/Test/FramebufferGLTest.cpp @@ -1401,6 +1401,8 @@ const auto DataStorage = PixelStorage{}.setSkip({0, 16, 0}); const std::size_t DataOffset = 16*8; void FramebufferGLTest::read() { + using namespace Math::Literals; + #ifndef MAGNUM_TARGET_GLES if(!Context::current().isExtensionSupported()) CORRADE_SKIP(Extensions::ARB::framebuffer_object::string() + std::string(" is not available.")); @@ -1450,7 +1452,14 @@ void FramebufferGLTest::read() { CORRADE_COMPARE(framebuffer.checkStatus(FramebufferTarget::Read), Framebuffer::Status::Complete); CORRADE_COMPARE(framebuffer.checkStatus(FramebufferTarget::Draw), Framebuffer::Status::Complete); - Renderer::setClearColor(Math::unpack(Color4ub(128, 64, 32, 17))); + #ifndef MAGNUM_TARGET_GLES2 + Renderer::setClearColor(0x80402011_rgbaf); + #else + /* Using only RGBA4, supply less precision. This has to be one on the input + because SwiftShader stores RGBA4 as RGBA8 internally, thus preserving + the full precision of the input. */ + Renderer::setClearColor(0x88442211_rgbaf); + #endif Renderer::setClearDepth(Math::unpack(48352)); Renderer::setClearStencil(67); framebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth|FramebufferClear::Stencil); @@ -1461,7 +1470,11 @@ void FramebufferGLTest::read() { MAGNUM_VERIFY_NO_GL_ERROR(); CORRADE_COMPARE(colorImage.size(), Vector2i(8, 16)); CORRADE_COMPARE(colorImage.data().size(), (DataOffset + 8*16)*sizeof(Color4ub)); - CORRADE_COMPARE(colorImage.data()[DataOffset], Color4ub(128, 64, 32, 17)); + #ifndef MAGNUM_TARGET_GLES2 + CORRADE_COMPARE(colorImage.data()[DataOffset], 0x80402011_rgba); + #else /* using only RGBA4, less precision */ + CORRADE_COMPARE(colorImage.data()[DataOffset], 0x88442211_rgba); + #endif #ifndef MAGNUM_TARGET_WEBGL #ifdef MAGNUM_TARGET_GLES diff --git a/src/Magnum/GL/Test/MeshGLTest.cpp b/src/Magnum/GL/Test/MeshGLTest.cpp index 4e390eec7..531d4d0b0 100644 --- a/src/Magnum/GL/Test/MeshGLTest.cpp +++ b/src/Magnum/GL/Test/MeshGLTest.cpp @@ -287,6 +287,8 @@ MeshGLTest::MeshGLTest() { }); } +using namespace Math::Literals; + void MeshGLTest::construct() { { const Mesh mesh; @@ -311,7 +313,16 @@ struct FloatShader: AbstractShaderProgram { }; void MeshGLTest::constructMove() { - const Float data = Math::unpack(96); + const Float data = Math::unpack( + #ifndef MAGNUM_TARGET_GLES2 + 96 + #else + /* Using only RGBA4, supply less precision. This has to be one on the + input because SwiftShader stores RGBA4 as RGBA8 internally, thus + preserving the full precision of the input. */ + 85 + #endif + ); Buffer buffer1, buffer2; buffer1.setData({&data, 1}, BufferUsage::StaticDraw); buffer2.setData({nullptr, 8}, BufferUsage::StaticDraw); @@ -390,7 +401,11 @@ void MeshGLTest::constructMove() { MAGNUM_VERIFY_NO_GL_ERROR(); + #ifndef MAGNUM_TARGET_GLES2 CORRADE_COMPARE(framebuffer.read({{}, Vector2i{1}}, {PixelFormat::RGBA, PixelType::UnsignedByte}).data()[0], 96); + #else /* RGBA4, so less precision */ + CORRADE_COMPARE(framebuffer.read({{}, Vector2i{1}}, {PixelFormat::RGBA, PixelType::UnsignedByte}).data()[0], 85); + #endif } } @@ -725,7 +740,16 @@ void MeshGLTest::addVertexBufferInt() { #endif void MeshGLTest::addVertexBufferFloat() { - const Float data[] = { 0.0f, -0.7f, Math::unpack(96) }; + const Float data[] = { 0.0f, -0.7f, Math::unpack( + #ifndef MAGNUM_TARGET_GLES2 + 96 + #else + /* Using only RGBA4, supply less precision. This has to be one on the + input because SwiftShader stores RGBA4 as RGBA8 internally, thus + preserving the full precision of the input. */ + 85 + #endif + ) }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -754,7 +778,11 @@ void MeshGLTest::addVertexBufferFloat() { mesh).get(PixelFormat::RGBA, PixelType::UnsignedByte); MAGNUM_VERIFY_NO_GL_ERROR(); + #ifndef MAGNUM_TARGET_GLES2 CORRADE_COMPARE(value, 96); + #else /* RGBA4, so less precision */ + CORRADE_COMPARE(value, 85); + #endif } #ifndef MAGNUM_TARGET_GLES @@ -859,7 +887,16 @@ void MeshGLTest::addVertexBufferVectorNi() { #endif void MeshGLTest::addVertexBufferVectorN() { - const Vector3 data[] = { {}, {0.0f, -0.9f, 1.0f}, Math::unpack(Color3ub(96, 24, 156)) }; + const Vector3 data[] = { {}, {0.0f, -0.9f, 1.0f}, + #ifndef MAGNUM_TARGET_GLES2 + 0x60189c_rgbf + #else + /* Using only RGBA4, supply less precision. This has to be one on the + input because SwiftShader stores RGBA4 as RGBA8 internally, thus + preserving the full precision of the input. */ + 0x551199_rgbf + #endif + }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -888,7 +925,11 @@ void MeshGLTest::addVertexBufferVectorN() { mesh).get(PixelFormat::RGBA, PixelType::UnsignedByte); MAGNUM_VERIFY_NO_GL_ERROR(); - CORRADE_COMPARE(value, Color3ub(96, 24, 156)); + #ifndef MAGNUM_TARGET_GLES2 + CORRADE_COMPARE(value, 0x60189c_rgb); + #else /* RGBA4, so less precision */ + CORRADE_COMPARE(value, 0x551199_rgb); + #endif } #ifndef MAGNUM_TARGET_GLES @@ -931,7 +972,16 @@ void MeshGLTest::addVertexBufferMatrixNxN() { const Matrix3x3 data[] = { {}, Matrix3x3::fromDiagonal({0.0f, -0.9f, 1.0f}), - Matrix3x3::fromDiagonal(Math::unpack(Color3ub(96, 24, 156))) + Matrix3x3::fromDiagonal( + #ifndef MAGNUM_TARGET_GLES2 + 0x60189c_rgbf + #else + /* Using only RGBA4, supply less precision. This has to be one on + the input because SwiftShader stores RGBA4 as RGBA8 internally, + thus preserving the full precision of the input. */ + 0x551199_rgbf + #endif + ) }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -970,7 +1020,11 @@ void MeshGLTest::addVertexBufferMatrixNxN() { mesh).get(PixelFormat::RGBA, PixelType::UnsignedByte); MAGNUM_VERIFY_NO_GL_ERROR(); - CORRADE_COMPARE(value, Color3ub(96, 24, 156)); + #ifndef MAGNUM_TARGET_GLES2 + CORRADE_COMPARE(value, 0x60189c_rgb); + #else /* RGBA4, so less precision */ + CORRADE_COMPARE(value, 0x551199_rgb); + #endif } #ifndef MAGNUM_TARGET_GLES @@ -1270,8 +1324,6 @@ void MeshGLTest::addVertexBufferFloatWithHalfFloat() { CORRADE_SKIP(Extensions::OES::vertex_half_float::string() + std::string(" is not supported.")); #endif - using namespace Math::Literals; - const Half data[] = { 0.0_h, -0.7_h, Half(Math::unpack(186)) }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -1417,7 +1469,14 @@ void MeshGLTest::addVertexBufferVector4WithInt2101010Rev() { void MeshGLTest::addVertexBufferLessVectorComponents() { const Vector3 data[] = { {}, {0.0f, -0.9f, 1.0f}, - Math::unpack(Color3ub(96, 24, 156)) + #ifndef MAGNUM_TARGET_GLES2 + 0x60189c_rgbf + #else + /* Using only RGBA4, supply less precision. This has to be one on the + input because SwiftShader stores RGBA4 as RGBA8 internally, thus + preserving the full precision of the input. */ + 0x551199_rgbf + #endif }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -1447,11 +1506,24 @@ void MeshGLTest::addVertexBufferLessVectorComponents() { mesh).get(PixelFormat::RGBA, PixelType::UnsignedByte); MAGNUM_VERIFY_NO_GL_ERROR(); - CORRADE_COMPARE(value, Color4ub(96, 24, 156, 255)); + #ifndef MAGNUM_TARGET_GLES2 + CORRADE_COMPARE(value, 0x60189cff_rgba); + #else /* RGBA4, so less precision */ + CORRADE_COMPARE(value, 0x551199ff_rgba); + #endif } void MeshGLTest::addVertexBufferNormalized() { - constexpr Color4ub data[] = { {}, {0, 128, 64}, {32, 156, 228} }; + constexpr Color4ub data[] = { {}, {0, 128, 64}, + #ifndef MAGNUM_TARGET_GLES2 + 0x209ce4_rgb + #else + /* Using only RGBA4, supply less precision. This has to be one on the + input because SwiftShader stores RGBA4 as RGBA8 internally, thus + preserving the full precision of the input. */ + 0x1199dd_rgb + #endif + }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -1481,7 +1553,11 @@ void MeshGLTest::addVertexBufferNormalized() { mesh).get(PixelFormat::RGBA, PixelType::UnsignedByte); MAGNUM_VERIFY_NO_GL_ERROR(); - CORRADE_COMPARE(value, Color3ub(32, 156, 228)); + #ifndef MAGNUM_TARGET_GLES2 + CORRADE_COMPARE(value, 0x209ce4_rgb); + #else /* RGBA4, so less precision */ + CORRADE_COMPARE(value, 0x1199dd_rgb); + #endif } #ifndef MAGNUM_TARGET_GLES @@ -1603,9 +1679,18 @@ void MeshGLTest::addVertexBufferMultiple() { Math::unpack(64), Math::unpack(17), Math::unpack(56), + #ifndef MAGNUM_TARGET_GLES2 Math::unpack(15), Math::unpack(164), Math::unpack(17), + #else + /* Using only RGBA4, supply less precision. This has to be one on the + input because SwiftShader stores RGBA4 as RGBA8 internally, thus + preserving the full precision of the input. */ + Math::unpack(9), + Math::unpack(159), + Math::unpack(12), + #endif Math::unpack(97), Math::unpack(28) }; @@ -1629,7 +1714,11 @@ void MeshGLTest::addVertexBufferMultiple() { mesh).get(PixelFormat::RGBA, PixelType::UnsignedByte); MAGNUM_VERIFY_NO_GL_ERROR(); + #ifndef MAGNUM_TARGET_GLES2 CORRADE_COMPARE(value, Color4ub(64 + 15 + 97, 17 + 164 + 28, 56 + 17, 255)); + #else /* RGBA4, so less precision */ + CORRADE_COMPARE(value, 0xaacc44ff_rgba); + #endif } void MeshGLTest::addVertexBufferMultipleGaps() { @@ -1645,9 +1734,18 @@ void MeshGLTest::addVertexBufferMultipleGaps() { Math::unpack(64), Math::unpack(17), Math::unpack(56), 0.0f, + #ifndef MAGNUM_TARGET_GLES2 Math::unpack(15), Math::unpack(164), Math::unpack(17), 0.0f, + #else + /* Using only RGBA4, supply less precision. This has to be one on the + input because SwiftShader stores RGBA4 as RGBA8 internally, thus + preserving the full precision of the input. */ + Math::unpack(9), + Math::unpack(159), + Math::unpack(12), 0.0f, + #endif Math::unpack(97), Math::unpack(28), 0.0f, 0.0f }; @@ -1672,7 +1770,11 @@ void MeshGLTest::addVertexBufferMultipleGaps() { mesh).get(PixelFormat::RGBA, PixelType::UnsignedByte); MAGNUM_VERIFY_NO_GL_ERROR(); + #ifndef MAGNUM_TARGET_GLES2 CORRADE_COMPARE(value, Color4ub(64 + 15 + 97, 17 + 164 + 28, 56 + 17, 255)); + #else /* RGBA4, so less precision */ + CORRADE_COMPARE(value, 0xaacc44ff_rgba); + #endif } void MeshGLTest::addVertexBufferMovedOutInstance() { @@ -1844,9 +1946,18 @@ const Float indexedVertexData[] = { Math::unpack(64), Math::unpack(17), Math::unpack(56), + #ifndef MAGNUM_TARGET_GLES2 Math::unpack(15), Math::unpack(164), Math::unpack(17), + #else + /* Using only RGBA4, supply less precision. This has to be one on the input + because SwiftShader stores RGBA4 as RGBA8 internally, thus preserving + the full precision of the input. */ + Math::unpack(9), + Math::unpack(159), + Math::unpack(12), + #endif Math::unpack(97), Math::unpack(28), @@ -1887,7 +1998,11 @@ const Float indexedVertexDataBaseVertex[] = { }; #endif -constexpr Color4ub indexedResult(64 + 15 + 97, 17 + 164 + 28, 56 + 17, 255); +#ifndef MAGNUM_TARGET_GLES2 +constexpr Color4ub indexedResult{64 + 15 + 97, 17 + 164 + 28, 56 + 17, 255}; +#else /* RGBA4, so less precision */ +constexpr Color4ub indexedResult{0xaa, 0xcc, 0x44, 0xff}; +#endif template void MeshGLTest::setIndexBuffer() { setTestCaseName(std::is_same::value ? @@ -2080,7 +2195,16 @@ void MeshGLTest::unbindVAOWhenSettingIndexBufferData() { typedef Attribute<0, Float> Attribute; - const Float data[] = { -0.7f, Math::unpack(92), Math::unpack(32) }; + const Float data[] = { -0.7f, Math::unpack( + #ifndef MAGNUM_TARGET_GLES2 + 92 + #else + /* Using only RGBA4, supply less precision. This has to be one on the + input because SwiftShader stores RGBA4 as RGBA8 internally, thus + preserving the full precision of the input. */ + 85 + #endif + ), Math::unpack(32) }; Buffer buffer{Buffer::TargetHint::Array}; buffer.setData(data, BufferUsage::StaticDraw); @@ -2106,7 +2230,11 @@ void MeshGLTest::unbindVAOWhenSettingIndexBufferData() { mesh).get(PixelFormat::RGBA, PixelType::UnsignedByte); MAGNUM_VERIFY_NO_GL_ERROR(); + #ifndef MAGNUM_TARGET_GLES2 CORRADE_COMPARE(value, 92); + #else /* RGBA4, so less precision */ + CORRADE_COMPARE(value, 85); + #endif } void MeshGLTest::unbindIndexBufferWhenBindingVao() { @@ -2124,7 +2252,16 @@ void MeshGLTest::unbindIndexBufferWhenBindingVao() { typedef Attribute<0, Float> Attribute; - const Float data[] = { -0.7f, Math::unpack(92), Math::unpack(32) }; + const Float data[] = { -0.7f, Math::unpack( + #ifndef MAGNUM_TARGET_GLES2 + 92 + #else + /* Using only RGBA4, supply less precision. This has to be one on the + input because SwiftShader stores RGBA4 as RGBA8 internally, thus + preserving the full precision of the input. */ + 85 + #endif + ), Math::unpack(32) }; Buffer vertices{Buffer::TargetHint::Array}; vertices.setData(data, BufferUsage::StaticDraw); @@ -2157,7 +2294,11 @@ void MeshGLTest::unbindIndexBufferWhenBindingVao() { indexed).get(PixelFormat::RGBA, PixelType::UnsignedByte); MAGNUM_VERIFY_NO_GL_ERROR(); + #ifndef MAGNUM_TARGET_GLES2 CORRADE_COMPARE(value, 92); + #else /* RGBA4, so less precision */ + CORRADE_COMPARE(value, 85); + #endif } void MeshGLTest::resetIndexBufferBindingWhenBindingVao() { @@ -2175,7 +2316,16 @@ void MeshGLTest::resetIndexBufferBindingWhenBindingVao() { typedef Attribute<0, Float> Attribute; - const Float data[] = { -0.7f, Math::unpack(92), Math::unpack(32) }; + const Float data[] = { -0.7f, Math::unpack( + #ifndef MAGNUM_TARGET_GLES2 + 92 + #else + /* Using only RGBA4, supply less precision. This has to be one on the + input because SwiftShader stores RGBA4 as RGBA8 internally, thus + preserving the full precision of the input. */ + 85 + #endif + ), Math::unpack(32) }; Buffer vertices{Buffer::TargetHint::Array}; vertices.setData(data); @@ -2206,7 +2356,11 @@ void MeshGLTest::resetIndexBufferBindingWhenBindingVao() { indexed).get(PixelFormat::RGBA, PixelType::UnsignedByte); MAGNUM_VERIFY_NO_GL_ERROR(); + #ifndef MAGNUM_TARGET_GLES2 CORRADE_COMPARE(value, 92); + #else /* RGBA4, so less precision */ + CORRADE_COMPARE(value, 85); + #endif } void MeshGLTest::unbindVAOBeforeEnteringExternalSection() { @@ -2220,7 +2374,16 @@ void MeshGLTest::unbindVAOBeforeEnteringExternalSection() { typedef Attribute<0, Float> Attribute; - const Float data[] = { -0.7f, Math::unpack(92), Math::unpack(32) }; + const Float data[] = { -0.7f, Math::unpack( + #ifndef MAGNUM_TARGET_GLES2 + 92 + #else + /* Using only RGBA4, supply less precision. This has to be one on the + input because SwiftShader stores RGBA4 as RGBA8 internally, thus + preserving the full precision of the input. */ + 85 + #endif + ), Math::unpack(32) }; Buffer buffer{Buffer::TargetHint::Array}; buffer.setData(data, BufferUsage::StaticDraw); @@ -2252,13 +2415,26 @@ void MeshGLTest::unbindVAOBeforeEnteringExternalSection() { mesh).get(PixelFormat::RGBA, PixelType::UnsignedByte); MAGNUM_VERIFY_NO_GL_ERROR(); + #ifndef MAGNUM_TARGET_GLES2 CORRADE_COMPARE(value, 92); + #else /* RGBA4, so less precision */ + CORRADE_COMPARE(value, 85); + #endif } void MeshGLTest::bindScratchVaoWhenEnteringExternalSection() { typedef Attribute<0, Float> Attribute; - const Float data[] = { -0.7f, Math::unpack(92), Math::unpack(32) }; + const Float data[] = { -0.7f, Math::unpack( + #ifndef MAGNUM_TARGET_GLES2 + 92 + #else + /* Using only RGBA4, supply less precision. This has to be one on the + input because SwiftShader stores RGBA4 as RGBA8 internally, thus + preserving the full precision of the input. */ + 85 + #endif + ), Math::unpack(32) }; Buffer buffer{Buffer::TargetHint::Array}; buffer.setData(data, BufferUsage::StaticDraw); @@ -2294,7 +2470,11 @@ void MeshGLTest::bindScratchVaoWhenEnteringExternalSection() { mesh).get(PixelFormat::RGBA, PixelType::UnsignedByte); MAGNUM_VERIFY_NO_GL_ERROR(); + #ifndef MAGNUM_TARGET_GLES2 CORRADE_COMPARE(value, 92); + #else /* RGBA4, so less precision */ + CORRADE_COMPARE(value, 85); + #endif } #ifndef MAGNUM_TARGET_GLES @@ -2824,7 +3004,16 @@ void MeshGLTest::multiDraw() { typedef Attribute<0, Float> Attribute; - const Float data[] = { 0.0f, -0.7f, Math::unpack(96) }; + const Float data[] = { 0.0f, -0.7f, Math::unpack( + #ifndef MAGNUM_TARGET_GLES2 + 96 + #else + /* Using only RGBA4, supply less precision. This has to be one on the + input because SwiftShader stores RGBA4 as RGBA8 internally, thus + preserving the full precision of the input. */ + 85 + #endif + ) }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -2837,7 +3026,11 @@ void MeshGLTest::multiDraw() { mesh).get(PixelFormat::RGBA, PixelType::UnsignedByte); MAGNUM_VERIFY_NO_GL_ERROR(); + #ifndef MAGNUM_TARGET_GLES2 CORRADE_COMPARE(value, 96); + #else /* RGBA4, so less precision */ + CORRADE_COMPARE(value, 85); + #endif } void MeshGLTest::multiDrawIndexed() {