else
glFramebufferRenderbuffer(GL_FRAMEBUFFER, attch.attachment, GL_RENDERBUFFER, attch.rbuf->get_id());
}
- else if(attch.type==GL_TEXTURE_2D)
+ else if(attch.type)
{
- static_cast<Texture2D *>(attch.tex)->allocate(attch.level);
if(ARB_direct_state_access)
- glNamedFramebufferTexture(id, attch.attachment, attch.tex->get_id(), attch.level);
- else
+ {
+ if(attch.type==GL_TEXTURE_2D)
+ 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(attch.type==GL_TEXTURE_2D)
glFramebufferTexture2D(GL_FRAMEBUFFER, attch.attachment, attch.type, attch.tex->get_id(), attch.level);
- }
- else if(attch.type==GL_TEXTURE_3D || attch.type==GL_TEXTURE_2D_ARRAY)
- {
- static_cast<Texture3D *>(attch.tex)->allocate(attch.level);
- if(ARB_direct_state_access)
- glNamedFramebufferTextureLayer(id, attch.attachment, attch.tex->get_id(), attch.level, attch.layer);
else if(attch.type==GL_TEXTURE_2D_ARRAY)
glFramebufferTextureLayer(GL_FRAMEBUFFER, attch.attachment, attch.tex->get_id(), attch.level, attch.layer);
- else
+ else if(attch.type==GL_TEXTURE_3D)
glFramebufferTexture3D(GL_FRAMEBUFFER, attch.attachment, attch.type, attch.tex->get_id(), attch.level, attch.layer);
- }
- else if(attch.type==GL_TEXTURE_CUBE_MAP)
- {
- static_cast<TextureCube *>(attch.tex)->allocate(attch.level);
- if(ARB_direct_state_access)
- glNamedFramebufferTextureLayer(id, attch.attachment, attch.tex->get_id(), attch.level, attch.layer);
- else
+ else if(attch.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)
return attachments.size()-1;
}
-void Framebuffer::attach(FramebufferAttachment attch, Renderbuffer &rbuf)
+void Framebuffer::set_texture_attachment(FramebufferAttachment attch, Texture &tex, unsigned level, int layer)
{
if(!id)
throw invalid_operation("Framebuffer::attach");
unsigned i = get_attachment_index(attch);
- attachments[i].set(rbuf);
+ attachments[i].set(tex, level, layer);
update_attachment(1<<i);
check_size();
}
-void Framebuffer::attach(FramebufferAttachment attch, Texture2D &tex, unsigned level)
+void Framebuffer::attach(FramebufferAttachment attch, Renderbuffer &rbuf)
{
if(!id)
throw invalid_operation("Framebuffer::attach");
unsigned i = get_attachment_index(attch);
- attachments[i].set(tex, level, 0);
+ attachments[i].set(rbuf);
update_attachment(1<<i);
check_size();
}
-void Framebuffer::attach(FramebufferAttachment attch, Texture3D &tex, unsigned layer, unsigned level)
+void Framebuffer::attach(FramebufferAttachment attch, Texture2D &tex, unsigned level)
{
- if(!id)
- throw invalid_operation("Framebuffer::attach");
+ tex.allocate(level);
+ set_texture_attachment(attch, tex, level, 0);
+}
- unsigned i = get_attachment_index(attch);
- attachments[i].set(tex, level, layer);
- update_attachment(1<<i);
- check_size();
+void Framebuffer::attach(FramebufferAttachment attch, Texture3D &tex, unsigned layer, unsigned level)
+{
+ tex.allocate(level);
+ set_texture_attachment(attch, tex, level, layer);
}
void Framebuffer::attach(FramebufferAttachment attch, TextureCube &tex, TextureCubeFace face, unsigned level)
{
- if(!id)
- throw invalid_operation("Framebuffer::attach");
-
- unsigned i = get_attachment_index(attch);
- attachments[i].set(tex, level, TextureCube::get_face_index(face));
- update_attachment(1<<i);
- check_size();
+ tex.allocate(level);
+ set_texture_attachment(attch, tex, level, TextureCube::get_face_index(face));
}
void Framebuffer::detach(FramebufferAttachment attch)