From c69acaf3f85e1daad4b0206ba80110057ad0003b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 10 Jan 2015 13:19:39 +0100 Subject: [PATCH] Convenience overload for *Framebuffer::read(). It's now possible to do the reading operation in one statement. Previously it was needed to have mutable variable: Image2D image{ColorFormat::RGBA, ColorType::UnsignedByte}; framebuffer.read(framebuffer.viewport(), image); Currently: const Image2D image = framebuffer.read(framebuffer.viewport(), {ColorFormat::RGBA, ColorType::UnsignedByte}); To make this possible, the two-parameter Image and BufferImage constructors are now made implicit. --- src/Magnum/AbstractFramebuffer.cpp | 10 ++++++++++ src/Magnum/AbstractFramebuffer.h | 18 ++++++++++++++++++ src/Magnum/BufferImage.h | 2 +- src/Magnum/Image.h | 2 +- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Magnum/AbstractFramebuffer.cpp b/src/Magnum/AbstractFramebuffer.cpp index a53e23865..04016645b 100644 --- a/src/Magnum/AbstractFramebuffer.cpp +++ b/src/Magnum/AbstractFramebuffer.cpp @@ -242,6 +242,11 @@ void AbstractFramebuffer::read(const Range2Di& rectangle, Image2D& image) { image.setData(image.format(), image.type(), rectangle.size(), data); } +Image2D AbstractFramebuffer::read(const Range2Di& rectangle, Image2D&& image) { + read(rectangle, image); + return std::move(image); +} + #ifndef MAGNUM_TARGET_GLES2 void AbstractFramebuffer::read(const Range2Di& rectangle, BufferImage2D& image, BufferUsage usage) { bindInternal(FramebufferTarget::Read); @@ -253,6 +258,11 @@ void AbstractFramebuffer::read(const Range2Di& rectangle, BufferImage2D& image, image.buffer().bindInternal(Buffer::TargetHint::PixelPack); (Context::current()->state().framebuffer->readImplementation)(rectangle, image.format(), image.type(), image.dataSize(rectangle.size()), nullptr); } + +BufferImage2D AbstractFramebuffer::read(const Range2Di& rectangle, BufferImage2D&& image, BufferUsage usage) { + read(rectangle, image, usage); + return std::move(image); +} #endif void AbstractFramebuffer::invalidateImplementationNoOp(GLsizei, const GLenum* const) {} diff --git a/src/Magnum/AbstractFramebuffer.h b/src/Magnum/AbstractFramebuffer.h index 8c92b0c0d..40cc4da39 100644 --- a/src/Magnum/AbstractFramebuffer.h +++ b/src/Magnum/AbstractFramebuffer.h @@ -310,6 +310,15 @@ class MAGNUM_EXPORT AbstractFramebuffer { */ void read(const Range2Di& rectangle, Image2D& image); + /** @overload + * + * Convenience alternative to the above, example usage: + * @code + * Image2D image = framebuffer.read(framebuffer.viewport(), {ColorFormat::RGBA, ColorType::UnsignedByte}); + * @endcode + */ + Image2D read(const Range2Di& rectangle, Image2D&& image); + #ifdef MAGNUM_BUILD_DEPRECATED /** * @copybrief read(const Range2Di&, Image2D&) @@ -335,6 +344,15 @@ class MAGNUM_EXPORT AbstractFramebuffer { */ void read(const Range2Di& rectangle, BufferImage2D& image, BufferUsage usage); + /** @overload + * + * Convenience alternative to the above, example usage: + * @code + * BufferImage2D image = framebuffer.read(framebuffer.viewport(), {ColorFormat::RGBA, ColorType::UnsignedByte}, BufferUsage::StaticDraw); + * @endcode + */ + BufferImage2D read(const Range2Di& rectangle, BufferImage2D&& image, BufferUsage usage); + #ifdef MAGNUM_BUILD_DEPRECATED /** * @copybrief read(const Range2Di&, BufferImage2D&, BufferUsage) diff --git a/src/Magnum/BufferImage.h b/src/Magnum/BufferImage.h index 204626cda..a85854f7e 100644 --- a/src/Magnum/BufferImage.h +++ b/src/Magnum/BufferImage.h @@ -74,7 +74,7 @@ template class BufferImage: public AbstractImage { * Size is zero and buffer are empty, call @ref setData() to fill the * image with data. */ - explicit BufferImage(ColorFormat format, ColorType type); + /*implicit*/ BufferImage(ColorFormat format, ColorType type); /** @brief Copying is not allowed */ BufferImage(const BufferImage&) = delete; diff --git a/src/Magnum/Image.h b/src/Magnum/Image.h index bf17215ca..52edd47df 100644 --- a/src/Magnum/Image.h +++ b/src/Magnum/Image.h @@ -64,7 +64,7 @@ template class Image: public AbstractImage { * Dimensions are set to zero and data pointer to `nullptr`, call * @ref setData() to fill the image with data. */ - explicit Image(ColorFormat format, ColorType type): AbstractImage(format, type), _data(nullptr) {} + /*implicit*/ Image(ColorFormat format, ColorType type): AbstractImage(format, type), _data(nullptr) {} /** @brief Copying is not allowed */ Image(const Image&) = delete;