Browse Source

Pass image as reference, not pointer to *Framebuffer::read().

Avoids some nullptr-related errors.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
6025946e5e
  1. 18
      src/AbstractFramebuffer.cpp
  2. 4
      src/AbstractFramebuffer.h

18
src/AbstractFramebuffer.cpp

@ -141,20 +141,20 @@ void AbstractFramebuffer::clear(FramebufferClearMask mask) {
glClear(static_cast<GLbitfield>(mask)); glClear(static_cast<GLbitfield>(mask));
} }
void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, Image2D* image) { void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, Image2D& image) {
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
bindInternal(FramebufferTarget::Read); bindInternal(FramebufferTarget::Read);
#else #else
bindInternal(readTarget); bindInternal(readTarget);
#endif #endif
const std::size_t dataSize = image->pixelSize()*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, image->format(), image->type(), dataSize, data); readImplementation(offset, size, image.format(), image.type(), dataSize, data);
image->setData(size, image->format(), image->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, BufferImage2D* image, Buffer::Usage usage) { void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, BufferImage2D& image, Buffer::Usage usage) {
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
bindInternal(FramebufferTarget::Read); bindInternal(FramebufferTarget::Read);
#else #else
@ -162,12 +162,12 @@ void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, Buf
#endif #endif
/* 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) if(image.size() != size)
image->setData(size, image->format(), image->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, image->format(), image->type(), image->pixelSize()*size.product(), nullptr); readImplementation(offset, size, image.format(), image.type(), image.pixelSize()*size.product(), nullptr);
} }
#endif #endif

4
src/AbstractFramebuffer.h

@ -246,7 +246,7 @@ class MAGNUM_EXPORT AbstractFramebuffer {
* @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}
*/ */
void read(const Vector2i& offset, const Vector2i& size, Image2D* image); void read(const Vector2i& offset, const Vector2i& size, Image2D& image);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
/** /**
@ -260,7 +260,7 @@ class MAGNUM_EXPORT AbstractFramebuffer {
* 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.
*/ */
void read(const Vector2i& offset, const Vector2i& size, 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