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));
}
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

13
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

Loading…
Cancel
Save