]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/framebuffer.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / core / framebuffer.cpp
index 613277233a84d78258fe40c2c585cbca24cf41bb..4f30dbb158b346a71d726fcd9f431da171193b9a 100644 (file)
@@ -16,21 +16,11 @@ framebuffer_incomplete::framebuffer_incomplete(const std::string &reason):
 
 
 Framebuffer::Framebuffer(bool s):
-       FramebufferBackend(s),
-       dirty(0)
-{
-       if(s)
-       {
-               format = get_system_format();
-               get_system_size(width, height);
-       }
-}
+       FramebufferBackend(s)
+{ }
 
 Framebuffer::Framebuffer():
-       FramebufferBackend(false),
-       width(0),
-       height(0),
-       dirty(0)
+       FramebufferBackend(false)
 { }
 
 Framebuffer::Framebuffer(FrameAttachment fa):
@@ -47,13 +37,14 @@ Framebuffer::Framebuffer(const FrameFormat &f):
 
 void Framebuffer::set_format(const FrameFormat &fmt)
 {
-       if(!format.empty() || !id)
+       if(!format.empty())
                throw invalid_operation("Framebuffer::set_format");
        if(fmt.empty() || !is_format_supported(fmt))
                throw invalid_argument("Framebuffer::set_format");
 
        format = fmt;
        attachments.resize(format.size());
+       format_changed(format);
 }
 
 void Framebuffer::update() const
@@ -70,6 +61,7 @@ void Framebuffer::check_size()
                {
                        unsigned w = 0;
                        unsigned h = 0;
+                       unsigned l = 1;
                        if(const Texture2D *tex2d = dynamic_cast<const Texture2D *>(a.tex))
                        {
                                w = max(tex2d->get_width()>>a.level, 1U);
@@ -84,30 +76,34 @@ void Framebuffer::check_size()
                        {
                                w = max(tex3d->get_width()>>a.level, 1U);
                                h = max(tex3d->get_height()>>a.level, 1U);
+                               l = (a.layer<0 ? tex3d->get_depth() : 1);
                        }
                        else if(const TextureCube *tex_cube = dynamic_cast<const TextureCube *>(a.tex))
                        {
                                w = max(tex_cube->get_size()>>a.level, 1U);
                                h = w;
+                               l = (a.layer<0 ? 6 : 1);
                        }
 
                        if(first)
                        {
                                width = w;
                                height = h;
+                               layers = l;
                                first = false;
                        }
                        else
                        {
                                width = min(width, w);
                                height = min(height, h);
+                               layers = min(layers, l);
                        }
                }
 }
 
-void Framebuffer::set_attachment(FrameAttachment attch, Texture &tex, unsigned level, int layer, unsigned samples)
+void Framebuffer::set_attachment(FrameAttachment attch, Texture &tex, Texture *res, unsigned level, int layer, unsigned samples)
 {
-       if(format.empty() || !id)
+       if(format.empty() || attachments.empty())
                throw invalid_operation("Framebuffer::attach");
 
        if((format.get_samples()>1 && samples!=format.get_samples()) || (format.get_samples()==1 && samples))
@@ -118,7 +114,7 @@ void Framebuffer::set_attachment(FrameAttachment attch, Texture &tex, unsigned l
        {
                if(a==attch)
                {
-                       attachments[i].set(tex, level, layer);
+                       attachments[i].set(tex, res, level, layer);
                        dirty |= 1<<i;
                        check_size();
                        return;
@@ -131,39 +127,39 @@ void Framebuffer::set_attachment(FrameAttachment attch, Texture &tex, unsigned l
 
 void Framebuffer::attach(FrameAttachment attch, Texture2D &tex, unsigned level)
 {
-       set_attachment(make_typed_attachment(attch, tex.get_format()), tex, level, 0, 0);
+       set_attachment(make_typed_attachment(attch, tex.get_format()), tex, 0, level, 0, 0);
 }
 
-void Framebuffer::attach(FrameAttachment attch, Texture2DMultisample &tex)
+void Framebuffer::attach(FrameAttachment attch, Texture2DMultisample &tex, Texture2D *res)
 {
-       set_attachment(make_typed_attachment(attch, tex.get_format()), tex, 0, 0, tex.get_samples());
+       set_attachment(make_typed_attachment(attch, tex.get_format()), tex, res, 0, 0, tex.get_samples());
 }
 
 void Framebuffer::attach(FrameAttachment attch, Texture3D &tex, unsigned layer, unsigned level)
 {
-       set_attachment(make_typed_attachment(attch, tex.get_format()), tex, level, layer, 0);
+       set_attachment(make_typed_attachment(attch, tex.get_format()), tex, 0, level, layer, 0);
 }
 
 void Framebuffer::attach(FrameAttachment attch, TextureCube &tex, TextureCubeFace face, unsigned level)
 {
-       set_attachment(make_typed_attachment(attch, tex.get_format()), tex, level, face, 0);
+       set_attachment(make_typed_attachment(attch, tex.get_format()), tex, 0, level, face, 0);
 }
 
 void Framebuffer::attach_layered(FrameAttachment attch, Texture3D &tex, unsigned level)
 {
        require_layered();
-       set_attachment(make_typed_attachment(attch, tex.get_format()), tex, level, -1, 0);
+       set_attachment(make_typed_attachment(attch, tex.get_format()), tex, 0, level, -1, 0);
 }
 
 void Framebuffer::attach_layered(FrameAttachment attch, TextureCube &tex, unsigned level)
 {
        require_layered();
-       set_attachment(make_typed_attachment(attch, tex.get_format()), tex, level, -1, 0);
+       set_attachment(make_typed_attachment(attch, tex.get_format()), tex, 0, level, -1, 0);
 }
 
 void Framebuffer::detach(FrameAttachment attch)
 {
-       if(!id)
+       if(attachments.empty())
                throw invalid_operation("Framebuffer::detach");
 
        int i = format.index(attch);
@@ -175,20 +171,44 @@ void Framebuffer::detach(FrameAttachment attch)
        }
 }
 
-void Framebuffer::resize(const WindowView &view)
+const Texture *Framebuffer::get_attachment(FrameAttachment attch) const
 {
-       if(id)
-               throw invalid_operation("Framebuffer::resize");
+       if(attachments.empty())
+               return 0;
 
-       width = view.get_width();
-       height = view.get_height();
+       int i = format.index(attch);
+       return (i>=0 ? attachments[i].tex : 0);
 }
 
-void Framebuffer::require_complete() const
+const Texture *Framebuffer::get_attachment(unsigned i) const
 {
-       if(!id)
-               return;
+       return (i<attachments.size() ? attachments[i].tex : 0);
+}
+
+const Texture *Framebuffer::get_resolve_attachment(FrameAttachment attch) const
+{
+       if(attachments.empty())
+               return 0;
 
+       int i = format.index(attch);
+       return (i>=0 ? attachments[i].resolve : 0);
+}
+
+const Texture *Framebuffer::get_resolve_attachment(unsigned i) const
+{
+       return (i<attachments.size() ? attachments[i].resolve : 0);
+}
+
+bool Framebuffer::has_resolve_attachments() const
+{
+       for(const Attachment &a: attachments)
+               if(a.resolve)
+                       return true;
+       return false;
+}
+
+void Framebuffer::require_complete() const
+{
        bool layered = (!attachments.empty() && attachments.front().layer<0);
        for(const Attachment &a: attachments)
        {
@@ -201,22 +221,11 @@ void Framebuffer::require_complete() const
        FramebufferBackend::require_complete();
 }
 
-Framebuffer &Framebuffer::system()
-{
-       static Framebuffer sys_framebuf(true);
-       return sys_framebuf;
-}
-
-
-Framebuffer::Attachment::Attachment():
-       tex(0),
-       level(0),
-       layer(0)
-{ }
 
-void Framebuffer::Attachment::set(Texture &t, unsigned l, int z)
+void Framebuffer::Attachment::set(Texture &t, Texture *r, unsigned l, int z)
 {
        tex = &t;
+       resolve = r;
        level = l;
        layer = z;
 }