Add framebuffer::read_pixels
This commit is contained in:
parent
34cdba80a1
commit
67c6e18ef0
2 changed files with 24 additions and 0 deletions
|
|
@ -3,6 +3,8 @@
|
|||
#include <psemek/gfx/gl.hpp>
|
||||
#include <psemek/gfx/texture.hpp>
|
||||
#include <psemek/gfx/renderbuffer.hpp>
|
||||
#include <psemek/gfx/pixel.hpp>
|
||||
#include <psemek/gfx/pixmap.hpp>
|
||||
|
||||
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 <typename Pixel>
|
||||
void read_pixels(basic_pixmap<Pixel> & p) const
|
||||
{
|
||||
using traits = pixel_traits<Pixel>;
|
||||
bind_read();
|
||||
gl::ReadPixels(0, 0, p.width(), p.height(), traits::format, traits::type, p.data());
|
||||
}
|
||||
|
||||
template <typename Pixel>
|
||||
basic_pixmap<Pixel> read_pixels(std::size_t width, std::size_t height) const
|
||||
{
|
||||
basic_pixmap<Pixel> p({width, height});
|
||||
read_pixels(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
private:
|
||||
GLuint id_;
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue