Browse Source

Using old framebuffer binding internally if new is not supported.

pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
6ffa8eac51
  1. 24
      src/AbstractFramebuffer.cpp
  2. 11
      src/AbstractFramebuffer.h
  3. 2
      src/Context.cpp
  4. 2
      src/DefaultFramebuffer.cpp
  5. 2
      src/DefaultFramebuffer.h

24
src/AbstractFramebuffer.cpp

@ -16,12 +16,19 @@
#include "AbstractFramebuffer.h"
#include "BufferImage.h"
#include "Context.h"
#include "Extensions.h"
#include "Image.h"
namespace Magnum {
#ifndef DOXYGEN_GENERATING_OUTPUT
AbstractFramebuffer::Target AbstractFramebuffer::readTarget = AbstractFramebuffer::Target::ReadDraw;
AbstractFramebuffer::Target AbstractFramebuffer::drawTarget = AbstractFramebuffer::Target::ReadDraw;
#endif
void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image) {
bind(Target::ReadDraw);
bind(readTarget);
char* data = new char[AbstractImage::pixelSize(format, type)*size.product()];
glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast<GLenum>(format), static_cast<GLenum>(type), data);
image->setData(size, format, type, data);
@ -29,7 +36,7 @@ void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, Abs
#ifndef MAGNUM_TARGET_GLES2
void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferImage2D* image, Buffer::Usage usage) {
bind(Target::ReadDraw);
bind(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)
@ -40,4 +47,17 @@ void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, Abs
}
#endif
void AbstractFramebuffer::initializeContextBasedFunctionality(Context* context) {
#ifndef MAGNUM_TARGET_GLES
if(context->isExtensionSupported<Extensions::GL::EXT::framebuffer_blit>()) {
Debug() << "AbstractFramebuffer: using" << Extensions::GL::EXT::framebuffer_blit::string() << "features";
readTarget = Target::Read;
drawTarget = Target::Draw;
}
#else
static_cast<void>(context);
#endif
}
}

11
src/AbstractFramebuffer.h

@ -34,6 +34,8 @@ See DefaultFramebuffer and Framebuffer for more information.
@todo @extension{ARB,viewport_array}
*/
class MAGNUM_EXPORT AbstractFramebuffer {
friend class Context;
AbstractFramebuffer(const AbstractFramebuffer& other) = delete;
AbstractFramebuffer(AbstractFramebuffer&& other) = delete;
AbstractFramebuffer& operator=(const AbstractFramebuffer& other) = delete;
@ -208,7 +210,7 @@ class MAGNUM_EXPORT AbstractFramebuffer {
* @see @fn_gl{Viewport}
*/
inline void setViewport(const Vector2i& position, const Vector2i& size) {
bind(Target::ReadDraw);
bind(drawTarget);
glViewport(position.x(), position.y(), size.x(), size.y());
}
@ -220,7 +222,7 @@ class MAGNUM_EXPORT AbstractFramebuffer {
* Renderer::setClearStencil(), @fn_gl{Clear}
*/
inline void clear(ClearMask mask) {
bind(Target::ReadDraw);
bind(drawTarget);
glClear(static_cast<GLbitfield>(mask));
}
@ -254,8 +256,13 @@ class MAGNUM_EXPORT AbstractFramebuffer {
#ifndef DOXYGEN_GENERATING_OUTPUT
protected:
static Target readTarget, drawTarget;
GLuint _id;
#endif
private:
static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context);
};
inline AbstractFramebuffer::~AbstractFramebuffer() {}

2
src/Context.cpp

@ -20,6 +20,7 @@
#include <Utility/Debug.h>
#include <Utility/String.h>
#include "AbstractFramebuffer.h"
#include "AbstractShaderProgram.h"
#include "AbstractTexture.h"
#include "Buffer.h"
@ -292,6 +293,7 @@ Context::Context() {
_state = new Implementation::State;
/* Initialize functionality based on current OpenGL version and extensions */
AbstractFramebuffer::initializeContextBasedFunctionality(this);
AbstractShaderProgram::initializeContextBasedFunctionality(this);
AbstractTexture::initializeContextBasedFunctionality(this);
Buffer::initializeContextBasedFunctionality(this);

2
src/DefaultFramebuffer.cpp

@ -27,7 +27,7 @@ void DefaultFramebuffer::mapForDraw(std::initializer_list<DrawAttachment> attach
for(auto it = attachments.begin(); it != attachments.end(); ++it)
_attachments[it-attachments.begin()] = static_cast<GLenum>(*it);
bind(Target::Draw);
bind(drawTarget);
glDrawBuffers(attachments.size(), _attachments);
delete[] _attachments;
}

2
src/DefaultFramebuffer.h

@ -186,7 +186,7 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer {
* @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer}
*/
inline void mapForRead(ReadAttachment attachment) {
bind(Target::Read);
bind(readTarget);
/** @todo Get some extension wrangler instead to avoid undeclared glReadBuffer() on ES2 */
#ifndef MAGNUM_TARGET_GLES2
glReadBuffer(static_cast<GLenum>(attachment));

Loading…
Cancel
Save