From d0a02a24292b703809bbd88ccffb4e1a785bfa75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 4 Aug 2019 13:23:03 +0200 Subject: [PATCH] GL: allow reading of zero-size images. It's useless, but not disallowed -- it shouldn't assert on that. --- src/Magnum/GL/AbstractFramebuffer.cpp | 2 +- src/Magnum/GL/AbstractTexture.cpp | 11 +++++------ src/Magnum/GL/CubeMapTexture.cpp | 16 +++++++--------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/Magnum/GL/AbstractFramebuffer.cpp b/src/Magnum/GL/AbstractFramebuffer.cpp index 0b2a84117..9e50b0877 100644 --- a/src/Magnum/GL/AbstractFramebuffer.cpp +++ b/src/Magnum/GL/AbstractFramebuffer.cpp @@ -336,7 +336,7 @@ AbstractFramebuffer& AbstractFramebuffer::clearDepthStencil(const Float depth, c #endif void AbstractFramebuffer::read(const Range2Di& rectangle, const MutableImageView2D& image) { - CORRADE_ASSERT(image.data().data() != nullptr, + CORRADE_ASSERT(image.data().data() != nullptr || !rectangle.size().product(), "GL::AbstractFramebuffer::read(): image view is nullptr", ); CORRADE_ASSERT(image.size() == rectangle.size(), "GL::AbstractFramebuffer::read(): expected image view size" << rectangle.size() << "but got" << image.size(), ); diff --git a/src/Magnum/GL/AbstractTexture.cpp b/src/Magnum/GL/AbstractTexture.cpp index 4f80b6e50..8290d9b34 100644 --- a/src/Magnum/GL/AbstractTexture.cpp +++ b/src/Magnum/GL/AbstractTexture.cpp @@ -1605,7 +1605,7 @@ template void MAGNUM_GL_EXPORT AbstractTexture::image<3>(GLint, Image<3>&); template void AbstractTexture::image(GLint level, const BasicMutableImageView& image) { #ifndef CORRADE_NO_ASSERT const Math::Vector size = DataHelper::imageSize(*this, level); - CORRADE_ASSERT(image.data().data() != nullptr, + CORRADE_ASSERT(image.data().data() != nullptr || !size.product(), "GL::AbstractTexture::image(): image view is nullptr", ); CORRADE_ASSERT(image.size() == size, "GL::AbstractTexture::image(): expected image view size" << size << "but got" << image.size(), ); @@ -1672,11 +1672,10 @@ template void MAGNUM_GL_EXPORT AbstractTexture::compressedImage<3>(GLint, Compre template void AbstractTexture::compressedImage(const GLint level, const BasicMutableCompressedImageView& image) { #ifndef CORRADE_NO_ASSERT - CORRADE_ASSERT(image.data().data() != nullptr, - "GL::AbstractTexture::compressedImage(): image view is nullptr", ); - const Math::Vector size = DataHelper::imageSize(*this, level); + CORRADE_ASSERT(image.data().data() != nullptr || !size.product(), + "GL::AbstractTexture::compressedImage(): image view is nullptr", ); CORRADE_ASSERT(image.size() == size, "GL::AbstractTexture::compressedImage(): expected image view size" << size << "but got" << image.size(), ); @@ -1757,7 +1756,7 @@ template void MAGNUM_GL_EXPORT AbstractTexture::subImage<2>(GLint, const Range2D template void MAGNUM_GL_EXPORT AbstractTexture::subImage<3>(GLint, const Range3Di&, Image<3>&); template void AbstractTexture::subImage(const GLint level, const RangeTypeFor& range, const BasicMutableImageView& image) { - CORRADE_ASSERT(image.data().data() != nullptr, + CORRADE_ASSERT(image.data().data() != nullptr || !(Math::Vector(range.size()).product()), "GL::AbstractTexture::subImage(): image view is nullptr", ); CORRADE_ASSERT(image.size() == range.size(), "GL::AbstractTexture::subImage(): expected image view size" << range.size() << "but got" << image.size(), ); @@ -1848,7 +1847,7 @@ template void MAGNUM_GL_EXPORT AbstractTexture::compressedSubImage<3>(GLint, con template void AbstractTexture::compressedSubImage(const GLint level, const RangeTypeFor& range, const BasicMutableCompressedImageView& image) { #ifndef CORRADE_NO_ASSERT - CORRADE_ASSERT(image.data().data() != nullptr, + CORRADE_ASSERT(image.data().data() != nullptr || !(Math::Vector(range.size()).product()), "GL::AbstractTexture::compressedSubImage(): image view is nullptr", ); CORRADE_ASSERT(image.size() == range.size(), "GL::AbstractTexture::compressedSubImage(): expected image view size" << range.size() << "but got" << image.size(), ); diff --git a/src/Magnum/GL/CubeMapTexture.cpp b/src/Magnum/GL/CubeMapTexture.cpp index 1a72defed..282745910 100644 --- a/src/Magnum/GL/CubeMapTexture.cpp +++ b/src/Magnum/GL/CubeMapTexture.cpp @@ -88,7 +88,7 @@ Image3D CubeMapTexture::image(const Int level, Image3D&& image) { void CubeMapTexture::image(const Int level, const MutableImageView3D& image) { #ifndef CORRADE_NO_ASSERT const Vector3i size{imageSize(level), 6}; - CORRADE_ASSERT(image.data().data() != nullptr, + CORRADE_ASSERT(image.data().data() != nullptr || !size.product(), "GL::CubeMapTexture::image(): image view is nullptr", ); CORRADE_ASSERT(image.size() == size, "GL::CubeMapTexture::image(): expected image view size" << size << "but got" << image.size(), ); @@ -156,11 +156,10 @@ CompressedImage3D CubeMapTexture::compressedImage(const Int level, CompressedIma void CubeMapTexture::compressedImage(const Int level, const MutableCompressedImageView3D& image) { #ifndef CORRADE_NO_ASSERT - CORRADE_ASSERT(image.data().data() != nullptr, - "GL::CubeMapTexture::compressedImage(): image view is nullptr", ); - const Vector3i size{imageSize(level), 6}; + CORRADE_ASSERT(image.data().data() != nullptr || !size.product(), + "GL::CubeMapTexture::compressedImage(): image view is nullptr", ); CORRADE_ASSERT(image.size() == size, "GL::CubeMapTexture::compressedImage(): expected image view size" << size << "but got" << image.size(), ); @@ -244,7 +243,7 @@ Image2D CubeMapTexture::image(const CubeMapCoordinate coordinate, const Int leve void CubeMapTexture::image(const CubeMapCoordinate coordinate, const Int level, const MutableImageView2D& image) { #ifndef CORRADE_NO_ASSERT const Vector2i size = imageSize(level); - CORRADE_ASSERT(image.data().data() != nullptr, + CORRADE_ASSERT(image.data().data() != nullptr || !size.product(), "GL::CubeMapTexture::image(): image view is nullptr", ); CORRADE_ASSERT(image.size() == size, "GL::CubeMapTexture::image(): expected image view size" << size << "but got" << image.size(), ); @@ -310,11 +309,10 @@ CompressedImage2D CubeMapTexture::compressedImage(const CubeMapCoordinate coordi void CubeMapTexture::compressedImage(const CubeMapCoordinate coordinate, const Int level, const MutableCompressedImageView2D& image) { #ifndef CORRADE_NO_ASSERT - CORRADE_ASSERT(image.data().data() != nullptr, - "GL::CubeMapTexture::compressedImage(): image view is nullptr", ); - const Vector2i size = imageSize(level); + CORRADE_ASSERT(image.data().data() != nullptr || !size.product(), + "GL::CubeMapTexture::compressedImage(): image view is nullptr", ); CORRADE_ASSERT(image.size() == size, "GL::CubeMapTexture::compressedImage(): expected image view size" << size << "but got" << image.size(), ); @@ -422,7 +420,7 @@ CompressedImage3D CubeMapTexture::compressedSubImage(const Int level, const Rang void CubeMapTexture::compressedSubImage(const Int level, const Range3Di& range, const MutableCompressedImageView3D& image) { #ifndef CORRADE_NO_ASSERT - CORRADE_ASSERT(image.data().data() != nullptr, + CORRADE_ASSERT(image.data().data() != nullptr || !range.size().product(), "GL::CubeMapTexture::compressedSubImage(): image view is nullptr", ); CORRADE_ASSERT(image.size() == range.size(), "GL::CubeMapTexture::compressedSubImage(): expected image view size" << range.size() << "but got" << image.size(), );