From ac51b8c24d6e9e2c2e1dee7822f3957917722000 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 28 Oct 2016 18:54:39 +0300 Subject: [PATCH] Refactor Framebuffer::update_attachment for less indentation --- source/framebuffer.cpp | 71 +++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/source/framebuffer.cpp b/source/framebuffer.cpp index 1c2ae519..a80ea62b 100644 --- a/source/framebuffer.cpp +++ b/source/framebuffer.cpp @@ -81,49 +81,50 @@ Framebuffer::~Framebuffer() void Framebuffer::update_attachment(unsigned mask) const { - if(current()==this) + if(current()!=this) { - std::vector color_bufs; - color_bufs.reserve(attachments.size()); - for(unsigned i=0; i color_bufs; + color_bufs.reserve(attachments.size()); + for(unsigned i=0; iget_id()); + else if(attch.type==GL_TEXTURE_2D) { - if(attch.type==GL_RENDERBUFFER) - glFramebufferRenderbuffer(GL_FRAMEBUFFER, attch.attachment, GL_RENDERBUFFER, attch.rbuf->get_id()); - else if(attch.type==GL_TEXTURE_2D) - { - static_cast(attch.tex)->allocate(attch.level); - glFramebufferTexture2D(GL_FRAMEBUFFER, attch.attachment, attch.type, attch.tex->get_id(), attch.level); - } - else if(attch.type==GL_TEXTURE_CUBE_MAP) - { - static_cast(attch.tex)->allocate(attch.level); - glFramebufferTexture2D(GL_FRAMEBUFFER, attch.attachment, attch.cube_face, attch.tex->get_id(), attch.level); - } - else - glFramebufferRenderbuffer(GL_FRAMEBUFFER, attch.attachment, 0, 0); + static_cast(attch.tex)->allocate(attch.level); + glFramebufferTexture2D(GL_FRAMEBUFFER, attch.attachment, attch.type, attch.tex->get_id(), attch.level); } - - if(attch.attachment>=COLOR_ATTACHMENT0 && attch.attachment<=COLOR_ATTACHMENT3) - color_bufs.push_back(attch.attachment); + else if(attch.type==GL_TEXTURE_CUBE_MAP) + { + static_cast(attch.tex)->allocate(attch.level); + glFramebufferTexture2D(GL_FRAMEBUFFER, attch.attachment, attch.cube_face, attch.tex->get_id(), attch.level); + } + else + glFramebufferRenderbuffer(GL_FRAMEBUFFER, attch.attachment, 0, 0); } - if(color_bufs.size()>1) - static Require _req(ARB_draw_buffers); + if(attch.attachment>=COLOR_ATTACHMENT0 && attch.attachment<=COLOR_ATTACHMENT3) + color_bufs.push_back(attch.attachment); + } + + if(color_bufs.size()>1) + static Require _req(ARB_draw_buffers); - GLenum first_buffer = (color_bufs.empty() ? GL_NONE : color_bufs.front()); - if(ARB_draw_buffers) - glDrawBuffers(color_bufs.size(), &color_bufs[0]); - else if(MSP_draw_buffer) - glDrawBuffer(first_buffer); + GLenum first_buffer = (color_bufs.empty() ? GL_NONE : color_bufs.front()); + if(ARB_draw_buffers) + glDrawBuffers(color_bufs.size(), &color_bufs[0]); + else if(MSP_draw_buffer) + glDrawBuffer(first_buffer); - if(MSP_draw_buffer) - glReadBuffer(first_buffer); - } - else - dirty |= mask; + if(MSP_draw_buffer) + glReadBuffer(first_buffer); } void Framebuffer::check_size() -- 2.45.2