- vector<GLenum> color_bufs;
- color_bufs.reserve(format.size());
- unsigned i = 0;
- for(const UInt16 *j=format.begin(); j!=format.end(); ++j, ++i)
- {
- GLenum gl_attach_point = get_gl_attachment(static_cast<FrameAttachment>(*j));
- if(dirty&(1<<i))
- {
- const Attachment &attch = attachments[i];
- if(attch.tex)
- {
- GLenum type = attch.tex->get_target();
- if(ARB_direct_state_access)
- {
- if(type==GL_TEXTURE_2D || type==GL_TEXTURE_2D_MULTISAMPLE || attch.layer<0)
- glNamedFramebufferTexture(id, gl_attach_point, attch.tex->get_id(), attch.level);
- else
- glNamedFramebufferTextureLayer(id, gl_attach_point, attch.tex->get_id(), attch.level, attch.layer);
- }
- else if(type==GL_TEXTURE_2D || type==GL_TEXTURE_2D_MULTISAMPLE)
- glFramebufferTexture2D(GL_FRAMEBUFFER, gl_attach_point, type, attch.tex->get_id(), attch.level);
- else if(attch.layer<0)
- glFramebufferTexture(GL_FRAMEBUFFER, gl_attach_point, attch.tex->get_id(), attch.level);
- else if(type==GL_TEXTURE_2D_ARRAY)
- glFramebufferTextureLayer(GL_FRAMEBUFFER, gl_attach_point, attch.tex->get_id(), attch.level, attch.layer);
- else if(type==GL_TEXTURE_3D)
- glFramebufferTexture3D(GL_FRAMEBUFFER, gl_attach_point, type, attch.tex->get_id(), attch.level, attch.layer);
- else if(type==GL_TEXTURE_CUBE_MAP)
- glFramebufferTexture2D(GL_FRAMEBUFFER, gl_attach_point, TextureCube::enumerate_faces(attch.layer), attch.tex->get_id(), attch.level);
- }
- else if(ARB_direct_state_access)
- glNamedFramebufferTexture(id, gl_attach_point, 0, 0);
- else
- glFramebufferTexture2D(GL_FRAMEBUFFER, gl_attach_point, GL_TEXTURE_2D, 0, 0);
- }
-
- if(gl_attach_point!=GL_DEPTH_ATTACHMENT && gl_attach_point!=GL_STENCIL_ATTACHMENT)
- color_bufs.push_back(gl_attach_point);
- }
-
- if(color_bufs.size()>1)
- static Require _req(ARB_draw_buffers);
-
- GLenum first_buffer = (color_bufs.empty() ? GL_NONE : color_bufs.front());
- if(ARB_direct_state_access)
- {
- /* ARB_direct_state_access ties the availability of these functions to
- framebuffers themselves, so no further checks are needed. */
- glNamedFramebufferDrawBuffers(id, color_bufs.size(), &color_bufs[0]);
- glNamedFramebufferReadBuffer(id, first_buffer);
- }
- else
- {
- if(ARB_draw_buffers)
- glDrawBuffers(color_bufs.size(), &color_bufs[0]);
- else if(MSP_buffer_control)
- glDrawBuffer(first_buffer);
-
- if(MSP_buffer_control)
- glReadBuffer(first_buffer);
- }
-
- if(ARB_direct_state_access)
- status = static_cast<FramebufferStatus>(glCheckNamedFramebufferStatus(id, GL_FRAMEBUFFER));
- else
- status = static_cast<FramebufferStatus>(glCheckFramebufferStatus(GL_FRAMEBUFFER));
-