20#ifndef HEADER_FRAME_BUFFER_HPP
21#define HEADER_FRAME_BUFFER_HPP
23#include "graphics/gl_headers.hpp"
24#include "graphics/irr_driver.hpp"
25#include "utils/log.hpp"
26#include "utils/leak_check.hpp"
27#include "utils/no_copy.hpp"
37 std::vector<GLuint> m_render_targets;
39 GLuint m_depth_texture = 0;
43 unsigned m_height = 0;
50 FrameBuffer(
const std::vector<GLuint> &rtts,
unsigned w,
unsigned h)
52 m_render_targets = rtts;
56 glGenFramebuffers(1, &m_fbo);
57 glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
58 for (
unsigned i = 0; i < rtts.size(); i++)
60 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
61 GL_TEXTURE_2D, rtts[i], 0);
63 assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) ==
64 GL_FRAMEBUFFER_COMPLETE_EXT);
67 FrameBuffer(
const std::vector<GLuint> &rtts, GLuint depth_stencil,
68 unsigned w,
unsigned h)
70 m_render_targets = rtts;
71 m_depth_texture = depth_stencil;
75 glGenFramebuffers(1, &m_fbo);
76 glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
77 for (
unsigned i = 0; i < rtts.size(); i++)
79 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
80 GL_TEXTURE_2D, rtts[i], 0);
82 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
83 GL_TEXTURE_2D, depth_stencil, 0);
84 assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) ==
85 GL_FRAMEBUFFER_COMPLETE_EXT);
92 glDeleteFramebuffers(1, &m_fbo);
98 glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
99 glViewport(0, 0, (
int)m_width, (
int)m_height);
100 GLenum bufs[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1,
101 GL_COLOR_ATTACHMENT2 };
102 glDrawBuffers((
int)m_render_targets.size(), bufs);
105 void bindDepthOnly()
const
107 glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
108 glViewport(0, 0, (
int)m_width, (
int)m_height);
109 GLenum bufs[] = { GL_NONE, GL_NONE, GL_NONE };
110 glDrawBuffers((
int)m_render_targets.size(), bufs);
113 const std::vector<GLuint>& getRTT()
const {
return m_render_targets; }
115 GLuint getDepthTexture()
const
117 assert(m_depth_texture != 0);
118 return m_depth_texture;
121 unsigned int getWidth()
const {
return m_width; }
123 unsigned int getHeight()
const {
return m_height; }
126 GLbitfield mask = GL_COLOR_BUFFER_BIT,
127 GLenum filter = GL_NEAREST)
129 glBindFramebuffer(GL_READ_FRAMEBUFFER, src.m_fbo);
130 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dst.m_fbo);
131 glBlitFramebuffer(0, 0, (
int)src.m_width, (
int)src.m_height, 0, 0,
132 (
int)dst.m_width, (
int)dst.m_height, mask, filter);
133 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
134 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
137 void blitToDefault(
size_t x0,
size_t y0,
size_t x1,
size_t y1)
141 Log::warn(
"FrameBuffer",
"Don't blit layered framebuffer");
144 glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo);
145 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, irr_driver->getDefaultFramebuffer());
146 glBlitFramebuffer(0, 0, (
int)m_width, (
int)m_height, (
int)x0, (
int)y0,
147 (
int)x1, (
int)y1, GL_COLOR_BUFFER_BIT, GL_NEAREST);
148 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
149 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, irr_driver->getDefaultFramebuffer());
Definition: frame_buffer.hpp:33
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26