- vector<GLenum> color_bufs;
- color_bufs.reserve(format.size());
- unsigned i = 0;
- for(FrameAttachment a: format)
- {
- GLenum gl_attach_point = get_gl_attachment(a);
- if(dirty&(1<<i))
- {
- const Attachment &attch = attachments[i];
- if(attch.tex)
- {
- if(ARB_direct_state_access)
- {
- if(attch.tex->target==GL_TEXTURE_2D || attch.tex->target==GL_TEXTURE_2D_MULTISAMPLE || attch.layer<0)
- glNamedFramebufferTexture(id, gl_attach_point, attch.tex->id, attch.level);
- else
- glNamedFramebufferTextureLayer(id, gl_attach_point, attch.tex->id, attch.level, attch.layer);
- }
- else if(attch.tex->target==GL_TEXTURE_2D || attch.tex->target==GL_TEXTURE_2D_MULTISAMPLE)
- glFramebufferTexture2D(GL_FRAMEBUFFER, gl_attach_point, attch.tex->target, attch.tex->id, attch.level);
- else if(attch.layer<0)
- glFramebufferTexture(GL_FRAMEBUFFER, gl_attach_point, attch.tex->id, attch.level);
- else if(attch.tex->target==GL_TEXTURE_2D_ARRAY)
- glFramebufferTextureLayer(GL_FRAMEBUFFER, gl_attach_point, attch.tex->id, attch.level, attch.layer);
- else if(attch.tex->target==GL_TEXTURE_3D)
- glFramebufferTexture3D(GL_FRAMEBUFFER, gl_attach_point, attch.tex->target, attch.tex->id, attch.level, attch.layer);
- else if(attch.tex->target==GL_TEXTURE_CUBE_MAP)
- glFramebufferTexture2D(GL_FRAMEBUFFER, gl_attach_point, get_gl_cube_face(static_cast<TextureCubeFace>(attch.layer)), attch.tex->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);
-
- ++i;
- }
-
- 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 = glCheckNamedFramebufferStatus(id, GL_FRAMEBUFFER);
- else
- status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
-