Browse Source

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.
pull/87/head
Vladimír Vondruš 12 years ago
parent
commit
c69acaf3f8
  1. 10
      src/Magnum/AbstractFramebuffer.cpp
  2. 18
      src/Magnum/AbstractFramebuffer.h
  3. 2
      src/Magnum/BufferImage.h
  4. 2
      src/Magnum/Image.h

10
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); 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 #ifndef MAGNUM_TARGET_GLES2
void AbstractFramebuffer::read(const Range2Di& rectangle, BufferImage2D& image, BufferUsage usage) { void AbstractFramebuffer::read(const Range2Di& rectangle, BufferImage2D& image, BufferUsage usage) {
bindInternal(FramebufferTarget::Read); bindInternal(FramebufferTarget::Read);
@ -253,6 +258,11 @@ void AbstractFramebuffer::read(const Range2Di& rectangle, BufferImage2D& image,
image.buffer().bindInternal(Buffer::TargetHint::PixelPack); image.buffer().bindInternal(Buffer::TargetHint::PixelPack);
(Context::current()->state().framebuffer->readImplementation)(rectangle, image.format(), image.type(), image.dataSize(rectangle.size()), nullptr); (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 #endif
void AbstractFramebuffer::invalidateImplementationNoOp(GLsizei, const GLenum* const) {} void AbstractFramebuffer::invalidateImplementationNoOp(GLsizei, const GLenum* const) {}

18
src/Magnum/AbstractFramebuffer.h

@ -310,6 +310,15 @@ class MAGNUM_EXPORT AbstractFramebuffer {
*/ */
void read(const Range2Di& rectangle, Image2D& image); 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 #ifdef MAGNUM_BUILD_DEPRECATED
/** /**
* @copybrief read(const Range2Di&, Image2D&) * @copybrief read(const Range2Di&, Image2D&)
@ -335,6 +344,15 @@ class MAGNUM_EXPORT AbstractFramebuffer {
*/ */
void read(const Range2Di& rectangle, BufferImage2D& image, BufferUsage usage); 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 #ifdef MAGNUM_BUILD_DEPRECATED
/** /**
* @copybrief read(const Range2Di&, BufferImage2D&, BufferUsage) * @copybrief read(const Range2Di&, BufferImage2D&, BufferUsage)

2
src/Magnum/BufferImage.h

@ -74,7 +74,7 @@ template<UnsignedInt dimensions> class BufferImage: public AbstractImage {
* Size is zero and buffer are empty, call @ref setData() to fill the * Size is zero and buffer are empty, call @ref setData() to fill the
* image with data. * image with data.
*/ */
explicit BufferImage(ColorFormat format, ColorType type); /*implicit*/ BufferImage(ColorFormat format, ColorType type);
/** @brief Copying is not allowed */ /** @brief Copying is not allowed */
BufferImage(const BufferImage<dimensions>&) = delete; BufferImage(const BufferImage<dimensions>&) = delete;

2
src/Magnum/Image.h

@ -64,7 +64,7 @@ template<UnsignedInt dimensions> class Image: public AbstractImage {
* Dimensions are set to zero and data pointer to `nullptr`, call * Dimensions are set to zero and data pointer to `nullptr`, call
* @ref setData() to fill the image with data. * @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 */ /** @brief Copying is not allowed */
Image(const Image<dimensions>&) = delete; Image(const Image<dimensions>&) = delete;

Loading…
Cancel
Save