Browse Source

GL: avoid using deprecated templated Image::data() in tests.

This discovered quite a few potentially dangerous casts, so yay!
pull/362/head
Vladimír Vondruš 7 years ago
parent
commit
6144a73c8e
  1. 30
      src/Magnum/GL/Test/FramebufferGLTest.cpp
  2. 50
      src/Magnum/GL/Test/MeshGLTest.cpp
  3. 2
      src/Magnum/GL/Test/TransformFeedbackGLTest.cpp

30
src/Magnum/GL/Test/FramebufferGLTest.cpp

@ -1159,7 +1159,7 @@ void FramebufferGLTest::clearColorI() {
{PixelFormat::RGBAInteger, PixelType::Int}); {PixelFormat::RGBAInteger, PixelType::Int});
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(colorImage.data<Vector4i>()[0], (Vector4i{-124, 67, 37, 17})); CORRADE_COMPARE(Containers::arrayCast<Vector4i>(colorImage.data())[0], (Vector4i{-124, 67, 37, 17}));
} }
void FramebufferGLTest::clearColorUI() { void FramebufferGLTest::clearColorUI() {
@ -1186,7 +1186,7 @@ void FramebufferGLTest::clearColorUI() {
{PixelFormat::RGBAInteger, PixelType::UnsignedInt}); {PixelFormat::RGBAInteger, PixelType::UnsignedInt});
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(colorImage.data<Vector4ui>()[0], (Vector4ui{240, 67, 37, 17})); CORRADE_COMPARE(Containers::arrayCast<Vector4ui>(colorImage.data())[0], (Vector4ui{240, 67, 37, 17}));
} }
void FramebufferGLTest::clearColorF() { void FramebufferGLTest::clearColorF() {
@ -1213,7 +1213,7 @@ void FramebufferGLTest::clearColorF() {
{PixelFormat::RGBA, PixelType::UnsignedByte}); {PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(colorImage.data<Color4ub>()[0], (Color4ub{128, 64, 32, 17})); CORRADE_COMPARE(Containers::arrayCast<Color4ub>(colorImage.data())[0], (Color4ub{128, 64, 32, 17}));
} }
void FramebufferGLTest::clearDepth() { void FramebufferGLTest::clearDepth() {
@ -1254,7 +1254,7 @@ void FramebufferGLTest::clearDepth() {
Image2D depthImage = framebuffer.read({{}, Vector2i{1}}, {PixelFormat::DepthComponent, PixelType::UnsignedShort}); Image2D depthImage = framebuffer.read({{}, Vector2i{1}}, {PixelFormat::DepthComponent, PixelType::UnsignedShort});
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(depthImage.data<UnsignedShort>()[0], 48352); CORRADE_COMPARE(Containers::arrayCast<UnsignedShort>(depthImage.data())[0], 48352);
} }
#endif #endif
} }
@ -1295,7 +1295,7 @@ void FramebufferGLTest::clearStencil() {
Image2D stencilImage = framebuffer.read({{}, Vector2i{1}}, {PixelFormat::StencilIndex, PixelType::UnsignedByte}); Image2D stencilImage = framebuffer.read({{}, Vector2i{1}}, {PixelFormat::StencilIndex, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(stencilImage.data<UnsignedByte>()[0], 67); CORRADE_COMPARE(Containers::arrayCast<UnsignedByte>(stencilImage.data())[0], 67);
} }
#endif #endif
} }
@ -1337,8 +1337,8 @@ void FramebufferGLTest::clearDepthStencil() {
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
/** @todo This will probably fail on different systems */ /** @todo This will probably fail on different systems */
CORRADE_COMPARE(depthStencilImage.data<UnsignedInt>()[0] >> 8, 12378300); CORRADE_COMPARE(Containers::arrayCast<UnsignedInt>(depthStencilImage.data())[0] >> 8, 12378300);
CORRADE_COMPARE(depthStencilImage.data<UnsignedByte>()[0], 67); CORRADE_COMPARE(Containers::arrayCast<UnsignedByte>(depthStencilImage.data())[0], 67);
} }
#endif #endif
} }
@ -1475,9 +1475,9 @@ void FramebufferGLTest::read() {
CORRADE_COMPARE(colorImage.size(), Vector2i(8, 16)); CORRADE_COMPARE(colorImage.size(), Vector2i(8, 16));
CORRADE_COMPARE(colorImage.data().size(), (DataOffset + 8*16)*sizeof(Color4ub)); CORRADE_COMPARE(colorImage.data().size(), (DataOffset + 8*16)*sizeof(Color4ub));
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
CORRADE_COMPARE(colorImage.data<Color4ub>()[DataOffset], 0x80402011_rgba); CORRADE_COMPARE(Containers::arrayCast<Color4ub>(colorImage.data())[DataOffset], 0x80402011_rgba);
#else /* using only RGBA4, less precision */ #else /* using only RGBA4, less precision */
CORRADE_COMPARE(colorImage.data<Color4ub>()[DataOffset], 0x88442211_rgba); CORRADE_COMPARE(Containers::arrayCast<Color4ub>(colorImage.data())[DataOffset], 0x88442211_rgba);
#endif #endif
#ifndef MAGNUM_TARGET_WEBGL #ifndef MAGNUM_TARGET_WEBGL
@ -1492,7 +1492,7 @@ void FramebufferGLTest::read() {
Image2D depthImage = framebuffer.read({{}, Vector2i{1}}, {PixelFormat::DepthComponent, PixelType::UnsignedShort}); Image2D depthImage = framebuffer.read({{}, Vector2i{1}}, {PixelFormat::DepthComponent, PixelType::UnsignedShort});
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(depthImage.data<UnsignedShort>()[0], 48352); CORRADE_COMPARE(Containers::arrayCast<UnsignedShort>(depthImage.data())[0], 48352);
} }
#ifdef MAGNUM_TARGET_GLES #ifdef MAGNUM_TARGET_GLES
@ -1506,7 +1506,7 @@ void FramebufferGLTest::read() {
Image2D stencilImage = framebuffer.read({{}, Vector2i{1}}, {PixelFormat::StencilIndex, PixelType::UnsignedByte}); Image2D stencilImage = framebuffer.read({{}, Vector2i{1}}, {PixelFormat::StencilIndex, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(stencilImage.data<UnsignedByte>()[0], 67); CORRADE_COMPARE(Containers::arrayCast<UnsignedByte>(stencilImage.data())[0], 67);
} }
#ifdef MAGNUM_TARGET_GLES #ifdef MAGNUM_TARGET_GLES
@ -1521,8 +1521,8 @@ void FramebufferGLTest::read() {
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
/** @todo This will probably fail on different systems */ /** @todo This will probably fail on different systems */
CORRADE_COMPARE(depthStencilImage.data<UnsignedInt>()[0] >> 8, 12378300); CORRADE_COMPARE(Containers::arrayCast<UnsignedInt>(depthStencilImage.data())[0] >> 8, 12378300);
CORRADE_COMPARE(depthStencilImage.data<UnsignedByte>()[0], 67); CORRADE_COMPARE(Containers::arrayCast<UnsignedByte>(depthStencilImage.data())[0], 67);
} }
#endif #endif
} }
@ -2127,14 +2127,14 @@ void FramebufferGLTest::blit() {
Image2D imageBefore = b.read({{}, Vector2i{1}}, {PixelFormat::RGBA, PixelType::UnsignedByte}); Image2D imageBefore = b.read({{}, Vector2i{1}}, {PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(imageBefore.data<Color4ub>()[0], Color4ub()); CORRADE_COMPARE(Containers::arrayCast<Color4ub>(imageBefore.data())[0], Color4ub());
/* And have given color after */ /* And have given color after */
Framebuffer::blit(a, b, a.viewport(), FramebufferBlit::Color); Framebuffer::blit(a, b, a.viewport(), FramebufferBlit::Color);
Image2D imageAfter = b.read({{}, Vector2i{1}}, {PixelFormat::RGBA, PixelType::UnsignedByte}); Image2D imageAfter = b.read({{}, Vector2i{1}}, {PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(imageAfter.data<Color4ub>()[0], Color4ub(128, 64, 32, 17)); CORRADE_COMPARE(Containers::arrayCast<Color4ub>(imageAfter.data())[0], Color4ub(128, 64, 32, 17));
} }
#endif #endif

50
src/Magnum/GL/Test/MeshGLTest.cpp

@ -403,9 +403,9 @@ void MeshGLTest::constructMove() {
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
CORRADE_COMPARE(framebuffer.read({{}, Vector2i{1}}, {PixelFormat::RGBA, PixelType::UnsignedByte}).data<UnsignedByte>()[0], 96); CORRADE_COMPARE(Containers::arrayCast<UnsignedByte>(framebuffer.read({{}, Vector2i{1}}, {PixelFormat::RGBA, PixelType::UnsignedByte}).data())[0], 96);
#else /* RGBA4, so less precision */ #else /* RGBA4, so less precision */
CORRADE_COMPARE(framebuffer.read({{}, Vector2i{1}}, {PixelFormat::RGBA, PixelType::UnsignedByte}).data<UnsignedByte>()[0], 85); CORRADE_COMPARE(Containers::arrayCast<UnsignedByte>(framebuffer.read({{}, Vector2i{1}}, {PixelFormat::RGBA, PixelType::UnsignedByte}).data())[0], 85);
#endif #endif
} }
} }
@ -668,7 +668,7 @@ Checker::Checker(AbstractShaderProgram&& shader, RenderbufferFormat format, Mesh
} }
template<class T> T Checker::get(PixelFormat format, PixelType type) { template<class T> T Checker::get(PixelFormat format, PixelType type) {
return framebuffer.read({{}, Vector2i{1}}, {format, type}).data<T>()[0]; return Containers::arrayCast<T>(framebuffer.read({{}, Vector2i{1}}, {format, type}).data())[0];
} }
#endif #endif
@ -847,10 +847,10 @@ void MeshGLTest::addVertexBufferVectorNui() {
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
const auto value = Checker(IntegerShader("uvec3"), RenderbufferFormat::RGBA32UI, mesh) const auto value = Checker(IntegerShader("uvec3"), RenderbufferFormat::RGBA32UI, mesh)
.get<Vector3ui>(PixelFormat::RGBAInteger, PixelType::UnsignedInt); .get<Vector4ui>(PixelFormat::RGBAInteger, PixelType::UnsignedInt);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(value, Vector3ui(27592, 157, 25)); CORRADE_COMPARE(value.xyz(), Vector3ui(27592, 157, 25));
} }
void MeshGLTest::addVertexBufferVectorNi() { void MeshGLTest::addVertexBufferVectorNi() {
@ -923,13 +923,13 @@ void MeshGLTest::addVertexBufferVectorN() {
#else #else
RenderbufferFormat::RGBA4, RenderbufferFormat::RGBA4,
#endif #endif
mesh).get<Color3ub>(PixelFormat::RGBA, PixelType::UnsignedByte); mesh).get<Color4ub>(PixelFormat::RGBA, PixelType::UnsignedByte);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
CORRADE_COMPARE(value, 0x60189c_rgb); CORRADE_COMPARE(value.xyz(), 0x60189c_rgb);
#else /* RGBA4, so less precision */ #else /* RGBA4, so less precision */
CORRADE_COMPARE(value, 0x551199_rgb); CORRADE_COMPARE(value.xyz(), 0x551199_rgb);
#endif #endif
} }
@ -1018,13 +1018,13 @@ void MeshGLTest::addVertexBufferMatrixNxN() {
#else #else
RenderbufferFormat::RGBA4, RenderbufferFormat::RGBA4,
#endif #endif
mesh).get<Color3ub>(PixelFormat::RGBA, PixelType::UnsignedByte); mesh).get<Color4ub>(PixelFormat::RGBA, PixelType::UnsignedByte);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
CORRADE_COMPARE(value, 0x60189c_rgb); CORRADE_COMPARE(value.xyz(), 0x60189c_rgb);
#else /* RGBA4, so less precision */ #else /* RGBA4, so less precision */
CORRADE_COMPARE(value, 0x551199_rgb); CORRADE_COMPARE(value.xyz(), 0x551199_rgb);
#endif #endif
} }
@ -1067,7 +1067,7 @@ void MeshGLTest::addVertexBufferMatrixNxNd() {
const auto value = Checker(DoubleShader("dmat3", "vec4", const auto value = Checker(DoubleShader("dmat3", "vec4",
"vec4(value[0][0], value[1][1], value[2][2], 0.0)"), "vec4(value[0][0], value[1][1], value[2][2], 0.0)"),
RenderbufferFormat::RGBA16, mesh).get<Math::Vector3<UnsignedShort>>(PixelFormat::RGB, PixelType::UnsignedShort); RenderbufferFormat::RGBA16, mesh).get<Math::Vector4<UnsignedShort>>(PixelFormat::RGBA, PixelType::UnsignedShort);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
@ -1077,13 +1077,13 @@ void MeshGLTest::addVertexBufferMatrixNxNd() {
drivers |= Context::DetectedDriver::IntelWindows; drivers |= Context::DetectedDriver::IntelWindows;
#endif #endif
CORRADE_EXPECT_FAIL_IF(Context::current().detectedDriver() & drivers, "Somehow only first two values are extracted on AMD, NVidia and Intel Windows drivers."); CORRADE_EXPECT_FAIL_IF(Context::current().detectedDriver() & drivers, "Somehow only first two values are extracted on AMD, NVidia and Intel Windows drivers.");
CORRADE_COMPARE(value, Math::Vector3<UnsignedShort>(315, 65201, 2576)); CORRADE_COMPARE(value.xyz(), Math::Vector3<UnsignedShort>(315, 65201, 2576));
} }
/* This is wrong, but check if it's still the right wrong. Fails on AMD /* This is wrong, but check if it's still the right wrong. Fails on AMD
15.201.1151 but seems to be fixed in 15.300.1025.0 */ 15.201.1151 but seems to be fixed in 15.300.1025.0 */
if(Context::current().detectedDriver() & (Context::DetectedDriver::Amd|Context::DetectedDriver::NVidia)) if(Context::current().detectedDriver() & (Context::DetectedDriver::Amd|Context::DetectedDriver::NVidia))
CORRADE_COMPARE(value, Math::Vector3<UnsignedShort>(315, 65201, 0)); CORRADE_COMPARE(value.xyz(), Math::Vector3<UnsignedShort>(315, 65201, 0));
} }
#endif #endif
@ -1123,10 +1123,10 @@ void MeshGLTest::addVertexBufferMatrixMxN() {
const auto value = Checker(FloatShader("mat3x4", const auto value = Checker(FloatShader("mat3x4",
"vec4(valueInterpolated[0][0], valueInterpolated[1][1], valueInterpolated[2][2], 0.0)"), "vec4(valueInterpolated[0][0], valueInterpolated[1][1], valueInterpolated[2][2], 0.0)"),
RenderbufferFormat::RGBA8, mesh).get<Color3ub>(PixelFormat::RGBA, PixelType::UnsignedByte); RenderbufferFormat::RGBA8, mesh).get<Color4ub>(PixelFormat::RGBA, PixelType::UnsignedByte);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(value, Color3ub(96, 24, 156)); CORRADE_COMPARE(value.xyz(), Color3ub(96, 24, 156));
} }
#endif #endif
@ -1169,7 +1169,7 @@ void MeshGLTest::addVertexBufferMatrixMxNd() {
const auto value = Checker(DoubleShader("dmat3x4", "vec4", const auto value = Checker(DoubleShader("dmat3x4", "vec4",
"vec4(value[0][0], value[1][1], value[2][2], 0.0)"), "vec4(value[0][0], value[1][1], value[2][2], 0.0)"),
RenderbufferFormat::RGBA16, mesh).get<Math::Vector3<UnsignedShort>>(PixelFormat::RGB, PixelType::UnsignedShort); RenderbufferFormat::RGBA16, mesh).get<Math::Vector4<UnsignedShort>>(PixelFormat::RGBA, PixelType::UnsignedShort);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
@ -1179,13 +1179,13 @@ void MeshGLTest::addVertexBufferMatrixMxNd() {
drivers |= Context::DetectedDriver::IntelWindows; drivers |= Context::DetectedDriver::IntelWindows;
#endif #endif
CORRADE_EXPECT_FAIL_IF(Context::current().detectedDriver() & drivers, "Somehow only first two values are extracted on AMD, NVidia and Intel Windows drivers."); CORRADE_EXPECT_FAIL_IF(Context::current().detectedDriver() & drivers, "Somehow only first two values are extracted on AMD, NVidia and Intel Windows drivers.");
CORRADE_COMPARE(value, Math::Vector3<UnsignedShort>(315, 65201, 2576)); CORRADE_COMPARE(value.xyz(), Math::Vector3<UnsignedShort>(315, 65201, 2576));
} }
/* This is wrong, but check if it's still the right wrong. Fails on AMD /* This is wrong, but check if it's still the right wrong. Fails on AMD
15.201.1151 but seems to be fixed in 15.300.1025.0 */ 15.201.1151 but seems to be fixed in 15.300.1025.0 */
if(Context::current().detectedDriver() & (Context::DetectedDriver::Amd|Context::DetectedDriver::NVidia)) if(Context::current().detectedDriver() & (Context::DetectedDriver::Amd|Context::DetectedDriver::NVidia))
CORRADE_COMPARE(value, Math::Vector3<UnsignedShort>(315, 65201, 0)); CORRADE_COMPARE(value.xyz(), Math::Vector3<UnsignedShort>(315, 65201, 0));
} }
#endif #endif
@ -1579,13 +1579,13 @@ void MeshGLTest::addVertexBufferNormalized() {
#else #else
RenderbufferFormat::RGBA4, RenderbufferFormat::RGBA4,
#endif #endif
mesh).get<Color3ub>(PixelFormat::RGBA, PixelType::UnsignedByte); mesh).get<Color4ub>(PixelFormat::RGBA, PixelType::UnsignedByte);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
CORRADE_COMPARE(value, 0x209ce4_rgb); CORRADE_COMPARE(value.xyz(), 0x209ce4_rgb);
#else /* RGBA4, so less precision */ #else /* RGBA4, so less precision */
CORRADE_COMPARE(value, 0x1199dd_rgb); CORRADE_COMPARE(value.xyz(), 0x1199dd_rgb);
#endif #endif
} }
@ -2966,7 +2966,7 @@ void MeshGLTest::resetDivisorAfterInstancedDraw() {
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(framebuffer.read({{}, Vector2i{1}}, {PixelFormat::RGBA, PixelType::UnsignedByte}).data<UnsignedByte>()[0], 96); CORRADE_COMPARE(Containers::arrayCast<UnsignedByte>(framebuffer.read({{}, Vector2i{1}}, {PixelFormat::RGBA, PixelType::UnsignedByte}).data())[0], 96);
} }
/* Draw normal after. One two-vertex instance of an attribute with divisor /* Draw normal after. One two-vertex instance of an attribute with divisor
@ -2982,7 +2982,7 @@ void MeshGLTest::resetDivisorAfterInstancedDraw() {
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(framebuffer.read({{}, Vector2i{1}}, {PixelFormat::RGBA, PixelType::UnsignedByte}).data<UnsignedByte>()[0], 48); CORRADE_COMPARE(Containers::arrayCast<UnsignedByte>(framebuffer.read({{}, Vector2i{1}}, {PixelFormat::RGBA, PixelType::UnsignedByte}).data())[0], 48);
} }
} }
@ -3030,7 +3030,7 @@ MultiChecker::MultiChecker(AbstractShaderProgram&& shader, Mesh& mesh): framebuf
} }
template<class T> T MultiChecker::get(PixelFormat format, PixelType type) { template<class T> T MultiChecker::get(PixelFormat format, PixelType type) {
return framebuffer.read({{}, Vector2i{1}}, {format, type}).data<T>()[0]; return Containers::arrayCast<T>(framebuffer.read({{}, Vector2i{1}}, {format, type}).data())[0];
} }
#endif #endif

2
src/Magnum/GL/Test/TransformFeedbackGLTest.cpp

@ -706,7 +706,7 @@ void TransformFeedbackGLTest::draw() {
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
CORRADE_COMPARE(q.result<UnsignedInt>(), DrawData[testCaseInstanceId()].countDraw); CORRADE_COMPARE(q.result<UnsignedInt>(), DrawData[testCaseInstanceId()].countDraw);
CORRADE_COMPARE(fb.read({{}, Vector2i{1}}, {PixelFormat::RGBA, PixelType::UnsignedByte}).data<UnsignedByte>()[0], 153); CORRADE_COMPARE(Containers::arrayCast<UnsignedByte>(fb.read({{}, Vector2i{1}}, {PixelFormat::RGBA, PixelType::UnsignedByte}).data())[0], 153);
MAGNUM_VERIFY_NO_GL_ERROR(); MAGNUM_VERIFY_NO_GL_ERROR();
} }

Loading…
Cancel
Save