Browse Source

Using Rectangle in framebuffer.

pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
a45b4fba8b
  1. 22
      src/AbstractFramebuffer.cpp
  2. 39
      src/AbstractFramebuffer.h
  3. 3
      src/DefaultFramebuffer.cpp
  4. 5
      src/Framebuffer.cpp
  5. 4
      src/Framebuffer.h
  6. 4
      src/Implementation/FramebufferState.h

22
src/AbstractFramebuffer.cpp

@ -78,25 +78,22 @@ AbstractFramebuffer::Target AbstractFramebuffer::bindInternal() {
}
#endif
void AbstractFramebuffer::blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Vector2i& sourceBottomLeft, const Vector2i& sourceTopRight, const Vector2i& destinationBottomLeft, const Vector2i& destinationTopRight, AbstractFramebuffer::BlitMask mask, AbstractFramebuffer::BlitFilter filter) {
void AbstractFramebuffer::blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Rectanglei& sourceRectangle, const Rectanglei& destinationRectangle, AbstractFramebuffer::BlitMask mask, AbstractFramebuffer::BlitFilter filter) {
source.bindInternal(AbstractFramebuffer::Target::Read);
destination.bindInternal(AbstractFramebuffer::Target::Draw);
/** @todo Get some extension wrangler instead to avoid undeclared glBlitFramebuffer() on ES2 */
#ifndef MAGNUM_TARGET_GLES2
glBlitFramebuffer(sourceBottomLeft.x(), sourceBottomLeft.y(), sourceTopRight.x(), sourceTopRight.y(), destinationBottomLeft.x(), destinationBottomLeft.y(), destinationTopRight.x(), destinationTopRight.y(), static_cast<GLbitfield>(mask), static_cast<GLenum>(filter));
glBlitFramebuffer(sourceRectangle.left(), sourceRectangle.bottom(), sourceRectangle.right(), sourceRectangle.top(), destinationRectangle.left(), destinationRectangle.bottom(), destinationRectangle.right(), destinationRectangle.top(), static_cast<GLbitfield>(mask), static_cast<GLenum>(filter));
#else
static_cast<void>(sourceBottomLeft);
static_cast<void>(sourceTopRight);
static_cast<void>(destinationBottomLeft);
static_cast<void>(destinationTopRight);
static_cast<void>(sourceRectangle);
static_cast<void>(destinationRectangle);
static_cast<void>(mask);
static_cast<void>(filter);
#endif
}
void AbstractFramebuffer::setViewport(const Vector2i& position, const Vector2i& size) {
_viewportPosition = position;
_viewportSize = size;
void AbstractFramebuffer::setViewport(const Rectanglei& rectangle) {
_viewport = rectangle;
/* Update the viewport if the framebuffer is currently bound */
if(Context::current()->state()->framebuffer->drawBinding == _id)
@ -110,13 +107,12 @@ void AbstractFramebuffer::setViewportInternal() {
CORRADE_INTERNAL_ASSERT(state->drawBinding == _id);
/* Already up-to-date, nothing to do */
if(state->viewportPosition == _viewportPosition && state->viewportSize == _viewportSize)
if(state->viewport == _viewport)
return;
/* Update the state and viewport */
state->viewportPosition = _viewportPosition;
state->viewportSize = _viewportSize;
glViewport(_viewportPosition.x(), _viewportPosition.y(), _viewportSize.x(), _viewportSize.y());
state->viewport = _viewport;
glViewport(_viewport.left(), _viewport.bottom(), _viewport.width(), _viewport.height());
}
#endif

39
src/AbstractFramebuffer.h

@ -21,7 +21,7 @@
#include <Containers/EnumSet.h>
#include "Math/Vector2.h"
#include "Math/Geometry/Rectangle.h"
#include "AbstractImage.h"
#include "Buffer.h"
@ -139,11 +139,8 @@ class MAGNUM_EXPORT AbstractFramebuffer {
* @brief Copy block of pixels
* @param source Source framebuffer
* @param destination Destination framebuffer
* @param sourceBottomLeft Bottom left coordinates of source rectangle
* @param sourceTopRight Top right coordinates of source rectangle
* @param destinationBottomLeft Bottom left coordinates of destination rectangle
* @param destinationTopRight Top right coordinates of destination
* rectangle
* @param sourceRectangle Source rectangle
* @param destinationRectangle Destination rectangle
* @param mask Which buffers to perform blit operation on
* @param filter Interpolation filter
*
@ -157,16 +154,13 @@ class MAGNUM_EXPORT AbstractFramebuffer {
* @requires_gl30 %Extension @extension{EXT,framebuffer_blit}
* @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit}
*/
static void blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Vector2i& sourceBottomLeft, const Vector2i& sourceTopRight, const Vector2i& destinationBottomLeft, const Vector2i& destinationTopRight, BlitMask mask, BlitFilter filter);
static void blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Rectanglei& sourceRectangle, const Rectanglei& destinationRectangle, BlitMask mask, BlitFilter filter);
/**
* @brief Copy block of pixels
* @param source Source framebuffer
* @param destination Destination framebuffer
* @param bottomLeft Bottom left coordinates of source and
* destination rectangle
* @param topRight Top right coordinates of source and
* destination rectangle
* @param rectangle Source and destination rectangle
* @param mask Which buffers to perform blit operation on
*
* Convenience alternative to above function when source rectangle is
@ -178,8 +172,8 @@ class MAGNUM_EXPORT AbstractFramebuffer {
* @requires_gl30 %Extension @extension{EXT,framebuffer_blit}
* @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit}
*/
inline static void blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Vector2i& bottomLeft, const Vector2i& topRight, BlitMask mask) {
blit(source, destination, bottomLeft, topRight, bottomLeft, topRight, mask, BlitFilter::NearestNeighbor);
inline static void blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Rectanglei& rectangle, BlitMask mask) {
blit(source, destination, rectangle, rectangle, mask, BlitFilter::NearestNeighbor);
}
explicit AbstractFramebuffer() = default;
@ -196,21 +190,18 @@ class MAGNUM_EXPORT AbstractFramebuffer {
*/
void bind(Target target);
/** @brief Viewport position */
inline Vector2i viewportPosition() const { return _viewportPosition; }
/** @brief Viewport size */
inline Vector2i viewportSize() const { return _viewportSize; }
/** @brief Viewport rectangle */
inline Rectanglei viewport() const { return _viewport; }
/**
* @brief Set viewport size
* @brief Set viewport
*
* Saves the viewport size to be used at later time in bind(). If the
* Saves the viewport to be used at later time in bind(). If the
* framebuffer is currently bound, updates the viewport to given
* dimensions.
* rectangle.
* @see @fn_gl{Viewport}
*/
void setViewport(const Vector2i& position, const Vector2i& size);
void setViewport(const Rectanglei& rectangle);
/**
* @brief Clear specified buffers in framebuffer
@ -231,6 +222,7 @@ class MAGNUM_EXPORT AbstractFramebuffer {
* @param image %Image where to put the data
*
* @see @fn_gl{BindFramebuffer}, @fn_gl{ReadPixels}
* @todo Read size, format & type from image?
*/
void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image);
@ -246,6 +238,7 @@ class MAGNUM_EXPORT AbstractFramebuffer {
*
* @see @fn_gl{BindFramebuffer}, @fn_gl{ReadPixels}
* @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);
#endif
@ -269,7 +262,7 @@ class MAGNUM_EXPORT AbstractFramebuffer {
static ReadBufferImplementation readBufferImplementation;
GLuint _id;
Vector2i _viewportPosition, _viewportSize;
Rectanglei _viewport;
#endif
private:

3
src/DefaultFramebuffer.cpp

@ -50,8 +50,7 @@ void DefaultFramebuffer::initializeContextBasedFunctionality(Context* context) {
/* Initial framebuffer size */
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
defaultFramebuffer._viewportPosition = state->viewportPosition = {viewport[0], viewport[1]};
defaultFramebuffer._viewportSize = state->viewportSize = {viewport[2], viewport[3]};
defaultFramebuffer._viewport = state->viewport = Rectanglei::fromSize({viewport[0], viewport[1]}, {viewport[2], viewport[3]});
}
}

5
src/Framebuffer.cpp

@ -34,9 +34,8 @@ Framebuffer::Texture1DImplementation Framebuffer::texture1DImplementation = &Fra
Framebuffer::Texture2DImplementation Framebuffer::texture2DImplementation = &Framebuffer::texture2DImplementationDefault;
Framebuffer::Texture3DImplementation Framebuffer::texture3DImplementation = &Framebuffer::texture3DImplementationDefault;
Framebuffer::Framebuffer(const Vector2i& viewportPosition, const Vector2i& viewportSize) {
_viewportPosition = viewportPosition;
_viewportSize = viewportSize;
Framebuffer::Framebuffer(const Rectanglei& viewport) {
_viewport = viewport;
glGenFramebuffers(1, &_id);
}

4
src/Framebuffer.h

@ -95,9 +95,9 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer {
* @brief Constructor
*
* Generates new OpenGL framebuffer.
* @see @fn_gl{GenFramebuffers}
* @see setViewport(), @fn_gl{GenFramebuffers}
*/
explicit Framebuffer(const Vector2i& viewportPosition, const Vector2i& viewportSize);
explicit Framebuffer(const Rectanglei& viewport);
/**
* @brief Destructor

4
src/Implementation/FramebufferState.h

@ -15,7 +15,7 @@
GNU Lesser General Public License version 3 for more details.
*/
#include "Math/Vector2.h"
#include "Math/Geometry/Rectangle.h"
#include "Magnum.h"
namespace Magnum { namespace Implementation {
@ -24,7 +24,7 @@ struct FramebufferState {
inline FramebufferState(): readBinding(0), drawBinding(0), renderbufferBinding(0) {}
GLuint readBinding, drawBinding, renderbufferBinding;
Vector2i viewportPosition, viewportSize;
Rectanglei viewport;
};
}}

Loading…
Cancel
Save