vector<GLenum> color_bufs;
color_bufs.reserve(format.size());
unsigned i = 0;
- for(const UInt16 *j=format.begin(); j!=format.end(); ++j, ++i)
+ for(FrameAttachment a: format)
{
- GLenum gl_attach_point = get_gl_attachment(static_cast<FrameAttachment>(*j));
+ GLenum gl_attach_point = get_gl_attachment(a);
if(dirty&(1<<i))
{
const Attachment &attch = attachments[i];
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)
void Framebuffer::check_size()
{
- for(vector<Attachment>::iterator i=attachments.begin(); i!=attachments.end(); ++i)
- if(i->tex)
+ bool first = true;
+ for(Attachment &a: attachments)
+ if(a.tex)
{
- GLenum type = i->tex->get_target();
+ GLenum type = a.tex->get_target();
+ unsigned w = 0;
+ unsigned h = 0;
if(type==GL_TEXTURE_2D)
{
- Texture2D *tex = static_cast<Texture2D *>(i->tex);
- width = max(tex->get_width()>>i->level, 1U);
- height = max(tex->get_height()>>i->level, 1U);
+ Texture2D *tex = static_cast<Texture2D *>(a.tex);
+ w = max(tex->get_width()>>a.level, 1U);
+ h = max(tex->get_height()>>a.level, 1U);
}
else if(type==GL_TEXTURE_2D_MULTISAMPLE)
{
- Texture2DMultisample *tex = static_cast<Texture2DMultisample *>(i->tex);
- width = tex->get_width();
- height = tex->get_height();
+ Texture2DMultisample *tex = static_cast<Texture2DMultisample *>(a.tex);
+ w = tex->get_width();
+ h = tex->get_height();
}
else if(type==GL_TEXTURE_3D || type==GL_TEXTURE_2D_ARRAY)
{
- Texture3D *tex = static_cast<Texture3D *>(i->tex);
- width = max(tex->get_width()>>i->level, 1U);
- height = max(tex->get_height()>>i->level, 1U);
+ Texture3D *tex = static_cast<Texture3D *>(a.tex);
+ w = max(tex->get_width()>>a.level, 1U);
+ h = max(tex->get_height()>>a.level, 1U);
}
else if(type==GL_TEXTURE_CUBE_MAP)
{
- width = max(static_cast<TextureCube *>(i->tex)->get_size()>>i->level, 1U);
- height = width;
+ w = max(static_cast<TextureCube *>(a.tex)->get_size()>>a.level, 1U);
+ h = w;
}
- break;
- }
+ if(first)
+ {
+ width = w;
+ height = h;
+ first = false;
+ }
+ else
+ {
+ width = min(width, w);
+ height = min(height, h);
+ }
+ }
}
void Framebuffer::set_attachment(FrameAttachment attch, Texture &tex, unsigned level, int layer, unsigned samples)
throw incompatible_data("Framebuffer::attach");
unsigned i = 0;
- for(const UInt16 *j=format.begin(); j!=format.end(); ++j, ++i)
- if(*j==attch)
+ for(FrameAttachment a: format)
+ {
+ if(a==attch)
{
attachments[i].set(tex, level, layer);
dirty |= 1<<i;
check_size();
return;
}
+ ++i;
+ }
throw incompatible_data("Framebuffer::attach");
}
void Framebuffer::attach(FrameAttachment attch, Texture2D &tex, unsigned level)
{
- tex.allocate(level);
set_attachment(make_typed_attachment(attch, tex.get_format()), tex, level, 0, 0);
}
void Framebuffer::attach(FrameAttachment attch, Texture3D &tex, unsigned layer, unsigned level)
{
- tex.allocate(level);
set_attachment(make_typed_attachment(attch, tex.get_format()), tex, level, layer, 0);
}
void Framebuffer::attach(FrameAttachment attch, TextureCube &tex, TextureCubeFace face, unsigned level)
{
- tex.allocate(level);
set_attachment(make_typed_attachment(attch, tex.get_format()), tex, level, TextureCube::get_face_index(face), 0);
}
void Framebuffer::attach_layered(FrameAttachment attch, Texture3D &tex, unsigned level)
{
static Require _req(ARB_geometry_shader4);
- tex.allocate(level);
set_attachment(make_typed_attachment(attch, tex.get_format()), tex, level, -1, 0);
}
void Framebuffer::attach_layered(FrameAttachment attch, TextureCube &tex, unsigned level)
{
static Require _req(ARB_geometry_shader4);
- tex.allocate(level);
set_attachment(make_typed_attachment(attch, tex.get_format()), tex, level, -1, 0);
}