- vector<GLenum> color_bufs;
- color_bufs.reserve(attachments.size());
- for(unsigned i=0; i<attachments.size(); ++i)
- {
- const Attachment &attch = attachments[i];
- if(dirty&(1<<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, attch.attachment, attch.tex->get_id(), attch.level);
- else
- glNamedFramebufferTextureLayer(id, attch.attachment, attch.tex->get_id(), attch.level, attch.layer);
- }
- else if(type==GL_TEXTURE_2D || type==GL_TEXTURE_2D_MULTISAMPLE)
- glFramebufferTexture2D(GL_FRAMEBUFFER, attch.attachment, type, attch.tex->get_id(), attch.level);
- else if(attch.layer<0)
- glFramebufferTexture(GL_FRAMEBUFFER, attch.attachment, attch.tex->get_id(), attch.level);
- else if(type==GL_TEXTURE_2D_ARRAY)
- glFramebufferTextureLayer(GL_FRAMEBUFFER, attch.attachment, attch.tex->get_id(), attch.level, attch.layer);
- else if(type==GL_TEXTURE_3D)
- glFramebufferTexture3D(GL_FRAMEBUFFER, attch.attachment, type, attch.tex->get_id(), attch.level, attch.layer);
- else if(type==GL_TEXTURE_CUBE_MAP)
- glFramebufferTexture2D(GL_FRAMEBUFFER, attch.attachment, TextureCube::enumerate_faces(attch.layer), attch.tex->get_id(), attch.level);
- }
- else if(ARB_direct_state_access)
- glNamedFramebufferTexture(id, attch.attachment, 0, 0);
- else
- glFramebufferTexture2D(GL_FRAMEBUFFER, attch.attachment, GL_TEXTURE_2D, 0, 0);
- }
-
- 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_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);
- }