From 3501c3177fc72d06a4e6a27e447e7dac197a57cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 18 May 2013 20:12:22 +0200 Subject: [PATCH] Reading parameters from image in *Framebuffer::read(). There will be more parameters like row length etc. which would need to be passed too. This function now expects properly formatted empty image which it fills with data. --- src/AbstractFramebuffer.cpp | 16 ++++++++-------- src/AbstractFramebuffer.h | 13 +++++-------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/AbstractFramebuffer.cpp b/src/AbstractFramebuffer.cpp index 061a69adb..b7086b2c4 100644 --- a/src/AbstractFramebuffer.cpp +++ b/src/AbstractFramebuffer.cpp @@ -128,25 +128,25 @@ void AbstractFramebuffer::clear(ClearMask mask) { glClear(static_cast(mask)); } -void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image) { +void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, Image2D* image) { bindInternal(readTarget); - const std::size_t dataSize = AbstractImage::pixelSize(format, type)*size.product(); + const std::size_t dataSize = image->pixelSize()*size.product(); char* const data = new char[dataSize]; - readImplementation(offset, size, format, type, dataSize, data); - image->setData(size, format, type, data); + readImplementation(offset, size, image->format(), image->type(), dataSize, data); + image->setData(size, image->format(), image->type(), data); } #ifndef MAGNUM_TARGET_GLES2 -void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferImage2D* image, Buffer::Usage usage) { +void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, BufferImage2D* image, Buffer::Usage usage) { bindInternal(readTarget); /* If the buffer doesn't have sufficient size, resize it */ /** @todo Explicitly reset also when buffer usage changes */ - if(image->size() != size || image->format() != format || image->type() != type) - image->setData(size, format, type, nullptr, usage); + if(image->size() != size) + image->setData(size, image->format(), image->type(), nullptr, usage); image->buffer()->bind(Buffer::Target::PixelPack); /** @todo De-duplicate buffer size computation */ - readImplementation(offset, size, format, type, AbstractImage::pixelSize(format, type)*size.product(), nullptr); + readImplementation(offset, size, image->format(), image->type(), image->pixelSize()*size.product(), nullptr); } #endif diff --git a/src/AbstractFramebuffer.h b/src/AbstractFramebuffer.h index 78dea55cb..49e28697c 100644 --- a/src/AbstractFramebuffer.h +++ b/src/AbstractFramebuffer.h @@ -236,34 +236,31 @@ class MAGNUM_EXPORT AbstractFramebuffer { * @brief Read block of pixels from framebuffer to image * @param offset Offset in the framebuffer * @param size %Image size - * @param format Format of pixel data - * @param type Data type of pixel data * @param image %Image where to put the data * + * %Image parameters like format and type of pixel data are taken from + * given image. + * * If @extension{ARB,robustness} is available, the operation is * protected from buffer overflow. * @see @fn_gl{BindFramebuffer}, @fn_gl{ReadPixels} or * @fn_gl_extension{ReadnPixels,ARB,robustness} - * @todo Read size, format & type from image? */ - void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image); + void read(const Vector2i& offset, const Vector2i& size, Image2D* image); #ifndef MAGNUM_TARGET_GLES2 /** * @brief Read block of pixels from framebuffer to buffer image * @param offset Offset in the framebuffer * @param size %Image size - * @param format Format of pixel data - * @param type Data type of pixel data * @param image %Buffer image where to put the data * @param usage %Buffer usage * * See read(const Vector2i&, const Vector2i&, Image2D*) for more * information. * @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. - * @todo Read size, format & type from image? */ - void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferImage2D* image, Buffer::Usage usage); + void read(const Vector2i& offset, const Vector2i& size, BufferImage2D* image, Buffer::Usage usage); #endif #ifdef DOXYGEN_GENERATING_OUTPUT