diff --git a/src/Magnum/GL/BufferImage.cpp b/src/Magnum/GL/BufferImage.cpp index 34d7742b3..efd6d84c9 100644 --- a/src/Magnum/GL/BufferImage.cpp +++ b/src/Magnum/GL/BufferImage.cpp @@ -38,22 +38,22 @@ template BufferImage::BufferImage(const Pixe template BufferImage::BufferImage(const PixelStorage storage, const Magnum::PixelFormat format, const VectorTypeFor& size, Containers::ArrayView const data, const BufferUsage usage): BufferImage{storage, GL::pixelFormat(format), GL::pixelType(format), size, data, usage} {} -template BufferImage::BufferImage(const PixelStorage storage, const PixelFormat format, const PixelType type, const VectorTypeFor& size, Buffer&& buffer, const std::size_t dataSize) noexcept: _storage{storage}, _format{format}, _type{type}, _size{size}, _buffer{Utility::move(buffer)}, _dataSize{dataSize} { +template BufferImage::BufferImage(const PixelStorage storage, const PixelFormat format, const PixelType type, const VectorTypeFor& size, Buffer&& buffer, const std::size_t dataSize) noexcept: _storage{storage}, _format{format}, _type{type}, _size{size}, _buffer{Utility::move(buffer)}, _pixelSize{pixelFormatSize(format, type)}, _dataSize{dataSize} { CORRADE_ASSERT(Magnum::Implementation::imageDataSize(*this) <= dataSize, "GL::BufferImage::BufferImage(): data too small, got" << dataSize << "but expected at least" << Magnum::Implementation::imageDataSize(*this) << "bytes", ); } template BufferImage::BufferImage(const PixelStorage storage, const Magnum::PixelFormat format, const VectorTypeFor& size, Buffer&& buffer, const std::size_t dataSize) noexcept: BufferImage{storage, GL::pixelFormat(format), GL::pixelType(format), size, Utility::move(buffer), dataSize} {} -template BufferImage::BufferImage(const PixelStorage storage, const PixelFormat format, const PixelType type): _storage{storage}, _format{format}, _type{type}, _buffer{Buffer::TargetHint::PixelPack}, _dataSize{} { +template BufferImage::BufferImage(const PixelStorage storage, const PixelFormat format, const PixelType type): _storage{storage}, _format{format}, _type{type}, _buffer{Buffer::TargetHint::PixelPack}, _pixelSize{pixelFormatSize(format, type)}, _dataSize{} { /* Not delegating to the (buffer&&, dataSize) constructor to avoid a size assertion that'd happen with certain storage parameters */ } template BufferImage::BufferImage(const PixelStorage storage, const Magnum::PixelFormat format): BufferImage{storage, GL::pixelFormat(format), GL::pixelType(format)} {} -template BufferImage::BufferImage(NoCreateT) noexcept: _format{PixelFormat::RGBA}, _type{PixelType::UnsignedByte}, _buffer{NoCreate}, _dataSize{} {} +template BufferImage::BufferImage(NoCreateT) noexcept: _format{PixelFormat::RGBA}, _type{PixelType::UnsignedByte}, _buffer{NoCreate}, _pixelSize{4}, _dataSize{} {} -template BufferImage::BufferImage(BufferImage&& other) noexcept: _storage{Utility::move(other._storage)}, _format{Utility::move(other._format)}, _type{Utility::move(other._type)}, _size{Utility::move(other._size)}, _buffer{Utility::move(other._buffer)}, _dataSize{Utility::move(other._dataSize)} { +template BufferImage::BufferImage(BufferImage&& other) noexcept: _storage{Utility::move(other._storage)}, _format{Utility::move(other._format)}, _type{Utility::move(other._type)}, _size{Utility::move(other._size)}, _buffer{Utility::move(other._buffer)}, _pixelSize{Utility::move(other._pixelSize)}, _dataSize{Utility::move(other._dataSize)} { other._size = {}; } @@ -64,12 +64,11 @@ template BufferImage& BufferImage UnsignedInt BufferImage::pixelSize() const { return pixelFormatSize(_format, _type); } - template std::pair, VectorTypeFor> BufferImage::dataProperties() const { return Magnum::Implementation::imageDataProperties(*this); } @@ -79,6 +78,7 @@ template void BufferImage::setData(const Pix _format = format; _type = type; _size = size; + _pixelSize = pixelFormatSize(format, type); /* Keep the old storage if zero-sized nullptr buffer was passed */ if(data.data() == nullptr && data.size() == 0) diff --git a/src/Magnum/GL/BufferImage.h b/src/Magnum/GL/BufferImage.h index bbe817a5b..250197fc3 100644 --- a/src/Magnum/GL/BufferImage.h +++ b/src/Magnum/GL/BufferImage.h @@ -286,7 +286,7 @@ template class BufferImage { * * @see @ref Magnum::pixelFormatSize(), @ref GL::pixelFormatSize() */ - UnsignedInt pixelSize() const; + UnsignedInt pixelSize() const { return _pixelSize; } /** @brief Image size in pixels */ VectorTypeFor size() const { return _size; } @@ -374,6 +374,7 @@ template class BufferImage { PixelType _type; Math::Vector _size; Buffer _buffer; + UnsignedInt _pixelSize; std::size_t _dataSize; }; diff --git a/src/Magnum/GL/Test/BufferImageGLTest.cpp b/src/Magnum/GL/Test/BufferImageGLTest.cpp index 63ca42fcc..620ac88aa 100644 --- a/src/Magnum/GL/Test/BufferImageGLTest.cpp +++ b/src/Magnum/GL/Test/BufferImageGLTest.cpp @@ -112,6 +112,7 @@ void BufferImageGLTest::construct() { CORRADE_COMPARE(a.storage().alignment(), 1); CORRADE_COMPARE(a.format(), GL::PixelFormat::Red); CORRADE_COMPARE(a.type(), PixelType::UnsignedByte); + CORRADE_COMPARE(a.pixelSize(), 1); CORRADE_COMPARE(a.size(), Vector2i(1, 3)); CORRADE_COMPARE(a.dataSize(), 3); @@ -136,6 +137,7 @@ void BufferImageGLTest::constructGeneric() { CORRADE_COMPARE(a.storage().alignment(), 1); CORRADE_COMPARE(a.format(), GL::PixelFormat::Red); CORRADE_COMPARE(a.type(), PixelType::UnsignedByte); + CORRADE_COMPARE(a.pixelSize(), 1); CORRADE_COMPARE(a.size(), Vector2i(1, 3)); CORRADE_COMPARE(a.dataSize(), 3); @@ -280,6 +282,7 @@ void BufferImageGLTest::constructBuffer() { CORRADE_COMPARE(a.storage().alignment(), 1); CORRADE_COMPARE(a.format(), GL::PixelFormat::Red); CORRADE_COMPARE(a.type(), PixelType::UnsignedByte); + CORRADE_COMPARE(a.pixelSize(), 1); CORRADE_COMPARE(a.size(), Vector2i(1, 3)); CORRADE_COMPARE(a.dataSize(), 3); @@ -310,6 +313,7 @@ void BufferImageGLTest::constructBufferGeneric() { CORRADE_COMPARE(a.storage().alignment(), 1); CORRADE_COMPARE(a.format(), GL::PixelFormat::Red); CORRADE_COMPARE(a.type(), PixelType::UnsignedByte); + CORRADE_COMPARE(a.pixelSize(), 1); CORRADE_COMPARE(a.size(), Vector2i(1, 3)); CORRADE_COMPARE(a.dataSize(), 3); @@ -421,8 +425,7 @@ void BufferImageGLTest::constructCompressedInvalidSize() { } void BufferImageGLTest::constructMove() { - const char data[4] = { 'a', 'b', 'c', 'd' }; - BufferImage2D a{PixelFormat::Red, PixelType::UnsignedByte, {4, 1}, data, BufferUsage::StaticDraw}; + BufferImage2D a{PixelFormat::RGB, PixelType::UnsignedByte, {4, 1}, "abcabcabcab", BufferUsage::StaticDraw}; const Int id = a.buffer().id(); MAGNUM_VERIFY_NO_GL_ERROR(); @@ -434,10 +437,11 @@ void BufferImageGLTest::constructMove() { CORRADE_COMPARE(a.size(), Vector2i()); CORRADE_COMPARE(b.storage().alignment(), 4); - CORRADE_COMPARE(b.format(), GL::PixelFormat::Red); + CORRADE_COMPARE(b.format(), GL::PixelFormat::RGB); CORRADE_COMPARE(b.type(), PixelType::UnsignedByte); + CORRADE_COMPARE(b.pixelSize(), 3); CORRADE_COMPARE(b.size(), Vector2i(4, 1)); - CORRADE_COMPARE(b.dataSize(), 4); + CORRADE_COMPARE(b.dataSize(), 12); CORRADE_COMPARE(b.buffer().id(), id); const unsigned short data2[2*4] = { 1, 2, 3, 4, 5, 6, 7, 8 }; @@ -453,10 +457,11 @@ void BufferImageGLTest::constructMove() { CORRADE_COMPARE(b.size(), Vector2i(1, 2)); CORRADE_COMPARE(c.storage().alignment(), 4); - CORRADE_COMPARE(c.format(), GL::PixelFormat::Red); + CORRADE_COMPARE(c.format(), GL::PixelFormat::RGB); CORRADE_COMPARE(c.type(), PixelType::UnsignedByte); + CORRADE_COMPARE(c.pixelSize(), 3); CORRADE_COMPARE(c.size(), Vector2i(4, 1)); - CORRADE_COMPARE(c.dataSize(), 4); + CORRADE_COMPARE(c.dataSize(), 12); CORRADE_COMPARE(c.buffer().id(), id); CORRADE_VERIFY(std::is_nothrow_move_constructible::value); @@ -556,6 +561,7 @@ void BufferImageGLTest::setData() { CORRADE_COMPARE(a.format(), GL::PixelFormat::RGBA); CORRADE_COMPARE(a.type(), PixelType::UnsignedShort); CORRADE_COMPARE(a.size(), Vector2i(1, 2)); + CORRADE_COMPARE(a.pixelSize(), 8); CORRADE_COMPARE(a.dataSize(), 16); /** @todo How to verify the contents in ES? */ @@ -584,6 +590,7 @@ void BufferImageGLTest::setDataGeneric() { CORRADE_COMPARE(a.format(), GL::PixelFormat::RGBA); CORRADE_COMPARE(a.type(), PixelType::UnsignedShort); CORRADE_COMPARE(a.size(), Vector2i(1, 2)); + CORRADE_COMPARE(a.pixelSize(), 8); CORRADE_COMPARE(a.dataSize(), 16); /** @todo How to verify the contents in ES? */ diff --git a/src/Magnum/GL/Test/BufferImageTest.cpp b/src/Magnum/GL/Test/BufferImageTest.cpp index 085747ac1..f362e4462 100644 --- a/src/Magnum/GL/Test/BufferImageTest.cpp +++ b/src/Magnum/GL/Test/BufferImageTest.cpp @@ -56,6 +56,7 @@ void BufferImageTest::constructNoCreate() { CORRADE_COMPARE(image.size(), Vector2i{}); CORRADE_COMPARE(image.format(), PixelFormat::RGBA); CORRADE_COMPARE(image.type(), PixelType::UnsignedByte); + CORRADE_COMPARE(image.pixelSize(), 4); CORRADE_COMPARE(image.dataSize(), 0); }