27#ifndef EASY3D_RENDERER_FRAMEBUFFER_OBJECT_H
28#define EASY3D_RENDERER_FRAMEBUFFER_OBJECT_H
34#include <easy3d/renderer/opengl.h>
152 GLenum internal_format = GL_RGBA8,
153 GLenum format = GL_RGBA,
154 GLenum type = GL_UNSIGNED_BYTE,
155 GLenum filter = GL_NEAREST
166 GLenum internal_format = GL_RGBA8,
167 GLenum format = GL_RGBA,
168 GLenum type = GL_UNSIGNED_BYTE
181 GLenum internal_format = GL_DEPTH24_STENCIL8,
182 GLenum filter = GL_NEAREST,
183 GLenum compare_mode = GL_NONE,
184 GLenum compare_func = GL_LEQUAL
227 bool bind(GLenum target = GL_FRAMEBUFFER);
233 bool release(GLenum target = GL_FRAMEBUFFER);
245 bool is_bound(GLenum target = GL_FRAMEBUFFER)
const;
287 GLuint
handle()
const {
return fbo_id_; }
293 int width()
const {
return width_; }
350 GLuint
color_texture(
unsigned int index = 0,
bool resolve =
true)
const;
402 GLuint& texture_handle,
403 unsigned int index = 0,
404 int internal_format = GL_RGBA8,
405 GLenum format = GL_RGBA,
406 GLenum type = GL_UNSIGNED_BYTE,
407 GLenum filter = GL_NEAREST
420 GLuint& texture_handle,
421 unsigned int internal_format = GL_DEPTH24_STENCIL8,
422 GLenum filter = GL_NEAREST
440 bool read_color(
unsigned int index,
unsigned char*
buffer,
unsigned int format,
bool flip_vertically =
true)
const;
449 bool read_color(
unsigned int index, std::vector<unsigned char>&
buffer,
unsigned int format,
bool flip_vertically =
true)
const;
464 bool read_depth(std::vector<float>&
buffer,
bool flip_vertically =
true)
const;
476 bool read_color(
unsigned char rgba[4],
int x,
int y,
int index = 0)
const;
486 bool read_depth(
float& depth,
int x,
int y)
const;
495 bool snapshot_color(
unsigned int index,
const std::string& file_name)
const;
536 GLenum filter = GL_NEAREST
552 int target_color_attachment_index,
int source_color_attachment_index,
554 GLenum filter = GL_NEAREST
577 GLenum filter = GL_NEAREST
601 int target_color_attachment_index,
int source_color_attachment_index,
603 GLenum filter = GL_NEAREST
608 void init(
int w,
int h,
int samples);
612 bool check_status()
const;
615 void _print_attachment(
unsigned int index)
const;
618 void _print_buffer(
int value)
const;
620 void _prepare_resolve_fbo();
624 GLuint prev_draw_fbo_;
625 GLuint prev_read_fbo_;
633 GLenum texture_target_;
635 GLuint depth_buffer_;
636 GLuint depth_texture_;
637 GLenum depth_internal_format_;
638 GLenum depth_texture_filter_;
639 GLenum depth_texture_compare_mode_;
640 GLenum depth_texture_compare_func_;
642 struct ColorAttachment {
643 ColorAttachment() :
buffer(0), texture(0), internal_format(GL_RGBA8), format(GL_RGBA), type(GL_UNSIGNED_BYTE), texture_filter(GL_NEAREST) {}
646 GLenum internal_format;
649 GLenum texture_filter;
651 std::vector<ColorAttachment> color_attachments_;
An implementation of framebuffer object (FBO).
Definition framebuffer_object.h:122
bool snapshot_color(unsigned int index, const std::string &file_name) const
Snapshots the color render buffer attached to color attachment at the given index into an image file.
Definition framebuffer_object.cpp:1443
bool copy_color_to_texture(GLuint &texture_handle, unsigned int index=0, int internal_format=GL_RGBA8, GLenum format=GL_RGBA, GLenum type=GL_UNSIGNED_BYTE, GLenum filter=GL_NEAREST)
Makes a copy of the current buffer into a texture (regardless the attachments already have textures).
Definition framebuffer_object.cpp:1805
void print_attachments() const
Print all the attachments of the current framebuffer object.
Definition framebuffer_object.cpp:1112
void deactivate_read_buffer() const
Deactivates reading from the buffers.
Definition framebuffer_object.cpp:966
void deactivate_draw_buffers() const
Deactivate all draw buffers.
Definition framebuffer_object.cpp:928
GLuint color_texture(unsigned int index=0, bool resolve=true) const
Returns the texture ID attached to the color attachment at the given index.
Definition framebuffer_object.cpp:1032
void activate_read_buffer(unsigned int index) const
Choose the buffers to read from. This command lets you select which attachment to read from.
Definition framebuffer_object.cpp:948
void ensure_size(int w, int h)
Ensure the size of the buffers is (w, h). If its size matches the required size, i....
Definition framebuffer_object.cpp:144
bool release(GLenum target=GL_FRAMEBUFFER)
Switches rendering back to the default framebuffer.
Definition framebuffer_object.cpp:813
FramebufferObject(int w, int h, int samples=0)
Constructor.
Definition framebuffer_object.cpp:49
bool read_depth(float *buffer, bool flip_vertically=true) const
Read the depth render buffer into a specified buffer.
Definition framebuffer_object.cpp:1484
bool add_depth_texture(GLenum internal_format=GL_DEPTH24_STENCIL8, GLenum filter=GL_NEAREST, GLenum compare_mode=GL_NONE, GLenum compare_func=GL_LEQUAL)
Add a depth texture render buffer.
Definition framebuffer_object.cpp:436
GLenum texture_target() const
Returns the texture target.
Definition framebuffer_object.cpp:1073
bool attach_depth_texture(GLenum target, GLuint texture_id, GLenum attachment)
Attach an existing depth texture to the framebuffer.
Definition framebuffer_object.cpp:629
int num_color_attachments() const
Returns the number of color attachments.
Definition framebuffer_object.cpp:983
static bool is_supported()
Queries if FramebufferObject is supported.
Definition framebuffer_object.cpp:42
bool add_depth_buffer(GLenum internal_format=GL_DEPTH24_STENCIL8)
Add a depth render buffer.
Definition framebuffer_object.cpp:534
void activate_draw_buffer(unsigned int index) const
Choose the buffers to render into. This command lets you select which attachments are written to.
Definition framebuffer_object.cpp:850
void print_draw_buffers() const
Print the draw buffers.
Definition framebuffer_object.cpp:1235
bool is_valid() const
Returns true if the framebuffer object is valid.
Definition framebuffer_object.cpp:739
GLuint depth_texture(bool resolve=true) const
Returns the texture ID for the texture attached to the depth attachment.
Definition framebuffer_object.cpp:1055
int samples() const
Returns the number of samples per pixel.
Definition framebuffer_object.h:306
bool copy_depth_to_texture(GLuint &texture_handle, unsigned int internal_format=GL_DEPTH24_STENCIL8, GLenum filter=GL_NEAREST)
Makes a copy of the current depth buffer into a texture.
Definition framebuffer_object.cpp:1858
bool bind(GLenum target=GL_FRAMEBUFFER)
Bind FBO to FRAMEBUFFER, DRAW_FRAMEBUFFER, or READ_FRAMEBUFFER.
Definition framebuffer_object.cpp:772
void activate_draw_buffers(unsigned int num_buffers, const unsigned int indices[]) const
Choose the buffers to render into.
Definition framebuffer_object.cpp:870
void print_read_buffer() const
Print the read buffer.
Definition framebuffer_object.cpp:1265
bool has_color_texture(unsigned int index) const
Checks if the framebuffer object has a color texture at the given index.
Definition framebuffer_object.cpp:993
bool has_color_attachment(unsigned int index) const
Checks if the framebuffer object has a color attachment at the given index.
Definition framebuffer_object.cpp:988
bool add_color_buffer(GLenum internal_format=GL_RGBA8, GLenum format=GL_RGBA, GLenum type=GL_UNSIGNED_BYTE)
Add a color render buffer.
Definition framebuffer_object.cpp:356
bool attach_color_texture(GLenum target, GLuint texture_id, GLenum attachment)
Attach an existing color texture to the framebuffer.
Definition framebuffer_object.cpp:597
virtual ~FramebufferObject()
Destructor.
Definition framebuffer_object.cpp:103
bool has_depth_attachment() const
Checks if the framebuffer object has a depth attachment.
Definition framebuffer_object.cpp:1083
int depth_bits() const
Returns the depth bits.
Definition framebuffer_object.cpp:1093
int height() const
Returns the height of the render buffers.
Definition framebuffer_object.h:298
int width() const
Returns the width of the render buffers.
Definition framebuffer_object.h:293
bool add_color_texture(GLenum internal_format=GL_RGBA8, GLenum format=GL_RGBA, GLenum type=GL_UNSIGNED_BYTE, GLenum filter=GL_NEAREST)
Add a color texture render buffer.
Definition framebuffer_object.cpp:271
static void blit_framebuffer(FramebufferObject *target, const FramebufferObject *source, GLbitfield buffers, GLenum filter=GL_NEAREST)
Blit the whole sized buffer.
Definition framebuffer_object.cpp:1631
GLuint handle() const
Returns the OpenGL framebuffer object handle for this framebuffer object. This handle can be used to ...
Definition framebuffer_object.h:287
bool is_bound(GLenum target=GL_FRAMEBUFFER) const
Check if the framebuffer object is currently bound to the current context.
Definition framebuffer_object.cpp:744
bool has_depth_texture() const
Checks if the framebuffer object has a depth texture.
Definition framebuffer_object.cpp:1088
bool read_color(unsigned int index, unsigned char *buffer, unsigned int format, bool flip_vertically=true) const
Read the color render buffer attached to color attachment at the given index.
Definition framebuffer_object.cpp:1348
bool snapshot_depth(const std::string &file_name) const
Snapshots the depth render buffer into an image file.
Definition framebuffer_object.cpp:1539
bool has_stencil() const
Checks if the framebuffer object has a stencil buffer.
Definition framebuffer_object.cpp:1078
Functions for updating render buffers.
Definition buffer.cpp:45
Definition collider.cpp:182