Browse Source

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.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
3501c3177f
  1. 16
      src/AbstractFramebuffer.cpp
  2. 13
      src/AbstractFramebuffer.h

16
src/AbstractFramebuffer.cpp

@ -128,25 +128,25 @@ void AbstractFramebuffer::clear(ClearMask mask) {
glClear(static_cast<GLbitfield>(mask)); glClear(static_cast<GLbitfield>(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); 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]; char* const data = new char[dataSize];
readImplementation(offset, size, format, type, dataSize, data); readImplementation(offset, size, image->format(), image->type(), dataSize, data);
image->setData(size, format, type, data); image->setData(size, image->format(), image->type(), data);
} }
#ifndef MAGNUM_TARGET_GLES2 #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); bindInternal(readTarget);
/* If the buffer doesn't have sufficient size, resize it */ /* If the buffer doesn't have sufficient size, resize it */
/** @todo Explicitly reset also when buffer usage changes */ /** @todo Explicitly reset also when buffer usage changes */
if(image->size() != size || image->format() != format || image->type() != type) if(image->size() != size)
image->setData(size, format, type, nullptr, usage); image->setData(size, image->format(), image->type(), nullptr, usage);
image->buffer()->bind(Buffer::Target::PixelPack); image->buffer()->bind(Buffer::Target::PixelPack);
/** @todo De-duplicate buffer size computation */ /** @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 #endif

13
src/AbstractFramebuffer.h

@ -236,34 +236,31 @@ class MAGNUM_EXPORT AbstractFramebuffer {
* @brief Read block of pixels from framebuffer to image * @brief Read block of pixels from framebuffer to image
* @param offset Offset in the framebuffer * @param offset Offset in the framebuffer
* @param size %Image size * @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 * @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 * If @extension{ARB,robustness} is available, the operation is
* protected from buffer overflow. * protected from buffer overflow.
* @see @fn_gl{BindFramebuffer}, @fn_gl{ReadPixels} or * @see @fn_gl{BindFramebuffer}, @fn_gl{ReadPixels} or
* @fn_gl_extension{ReadnPixels,ARB,robustness} * @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 #ifndef MAGNUM_TARGET_GLES2
/** /**
* @brief Read block of pixels from framebuffer to buffer image * @brief Read block of pixels from framebuffer to buffer image
* @param offset Offset in the framebuffer * @param offset Offset in the framebuffer
* @param size %Image size * @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 image %Buffer image where to put the data
* @param usage %Buffer usage * @param usage %Buffer usage
* *
* See read(const Vector2i&, const Vector2i&, Image2D*) for more * See read(const Vector2i&, const Vector2i&, Image2D*) for more
* information. * information.
* @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. * @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 #endif
#ifdef DOXYGEN_GENERATING_OUTPUT #ifdef DOXYGEN_GENERATING_OUTPUT

Loading…
Cancel
Save