diff --git a/libs/gfx/include/psemek/gfx/framebuffer.hpp b/libs/gfx/include/psemek/gfx/framebuffer.hpp index e8e97375..d781cb17 100644 --- a/libs/gfx/include/psemek/gfx/framebuffer.hpp +++ b/libs/gfx/include/psemek/gfx/framebuffer.hpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include namespace psemek::gfx { @@ -24,6 +26,7 @@ namespace psemek::gfx explicit operator bool() const { return id() != 0; } void bind() const; + void bind_read() const; void reset(); @@ -47,6 +50,22 @@ namespace psemek::gfx bool complete() const; void assert_complete() const; + template + void read_pixels(basic_pixmap & p) const + { + using traits = pixel_traits; + bind_read(); + gl::ReadPixels(0, 0, p.width(), p.height(), traits::format, traits::type, p.data()); + } + + template + basic_pixmap read_pixels(std::size_t width, std::size_t height) const + { + basic_pixmap p({width, height}); + read_pixels(p); + return p; + } + private: GLuint id_; diff --git a/libs/gfx/source/framebuffer.cpp b/libs/gfx/source/framebuffer.cpp index 3fca7d5e..6ac82cde 100644 --- a/libs/gfx/source/framebuffer.cpp +++ b/libs/gfx/source/framebuffer.cpp @@ -53,6 +53,11 @@ namespace psemek::gfx gl::BindFramebuffer(gl::DRAW_FRAMEBUFFER, id_); } + void framebuffer::bind_read() const + { + gl::BindFramebuffer(gl::READ_FRAMEBUFFER, id_); + } + void framebuffer::reset() { if (id_ != 0)