32 glCreateFramebuffers(1, &m_gl_named_framebuffer);
34 GLenum gl_color_attachment = GL_COLOR_ATTACHMENT0;
35 std::vector<GLenum> gl_draw_buffers;
38 for (
const auto& attachment: m_attachments)
42 glNamedFramebufferTexture
44 m_gl_named_framebuffer,
46 attachment.image_view->m_gl_texture_name,
47 static_cast<GLuint
>(attachment.level)
50 gl_draw_buffers.emplace_back(gl_color_attachment);
51 ++gl_color_attachment;
58 glNamedFramebufferTexture
60 m_gl_named_framebuffer,
61 GL_DEPTH_STENCIL_ATTACHMENT,
62 attachment.image_view->m_gl_texture_name,
63 static_cast<GLuint
>(attachment.level)
68 glNamedFramebufferTexture
70 m_gl_named_framebuffer,
72 attachment.image_view->m_gl_texture_name,
73 static_cast<GLuint
>(attachment.level)
79 glNamedFramebufferTexture
81 m_gl_named_framebuffer,
82 GL_STENCIL_ATTACHMENT,
83 attachment.image_view->m_gl_texture_name,
84 static_cast<GLuint
>(attachment.level)
90 if (!gl_draw_buffers.empty())
92 glNamedFramebufferReadBuffer(m_gl_named_framebuffer, GL_COLOR_ATTACHMENT0);
93 glNamedFramebufferDrawBuffers
95 m_gl_named_framebuffer,
96 static_cast<GLsizei
>(gl_draw_buffers.size()),
97 gl_draw_buffers.data()
102 glNamedFramebufferReadBuffer(m_gl_named_framebuffer, GL_NONE);
103 glNamedFramebufferDrawBuffer(m_gl_named_framebuffer, GL_NONE);
106 if (glCheckNamedFramebufferStatus(m_gl_named_framebuffer, GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
108 throw std::runtime_error(
"OpenGL framebuffer incomplete.");
114 if (m_gl_named_framebuffer)
116 glDeleteFramebuffers(1, &m_gl_named_framebuffer);
framebuffer(std::span< const framebuffer_attachment > attachments, std::uint32_t width, std::uint32_t height)
Constructs a framebuffer.
~framebuffer()
Destroys a framebuffer.
constexpr const std::vector< framebuffer_attachment > & attachments() const noexcept
Returns the framebuffer attachments.
constexpr std::uint32_t width() const noexcept
Returns the width of the framebuffer.
constexpr std::uint32_t height() const noexcept
Returns the height of the framebuffer.
void resize(std::uint32_t width, std::uint32_t height)
Resizes the framebuffer.
Graphics library interface.
@ color_attachment_bit
Framebuffer color attachment.
@ depth_attachment_bit
Framebuffer depth attachment.
@ stencil_attachment_bit
Framebuffer stencil attachment.