]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/framebuffer.cpp
Adapt to changes in mspmath
[libs/gl.git] / source / core / framebuffer.cpp
index 01fd626598c676a7417f2772f8d72c3b4ae5b700..45eaff656b65322a5d137133061e9e2ce35924ac 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):
@@ -70,6 +60,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,23 +75,27 @@ 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);
                        }
                }
 }
@@ -175,13 +170,18 @@ void Framebuffer::detach(FrameAttachment attch)
        }
 }
 
-void Framebuffer::resize(const WindowView &view)
+const Texture *Framebuffer::get_attachment(FrameAttachment attch) const
 {
        if(attachments.empty())
-               throw invalid_operation("Framebuffer::resize");
+               return 0;
+
+       int i = format.index(attch);
+       return (i>=0 ? attachments[i].tex : 0);
+}
 
-       width = view.get_width();
-       height = view.get_height();
+const Texture *Framebuffer::get_attachment(unsigned i) const
+{
+       return (i<attachments.size() ? attachments[i].tex : 0);
 }
 
 void Framebuffer::require_complete() const
@@ -198,12 +198,6 @@ void Framebuffer::require_complete() const
        FramebufferBackend::require_complete();
 }
 
-Framebuffer &Framebuffer::system()
-{
-       static Framebuffer sys_framebuf(true);
-       return sys_framebuf;
-}
-
 
 void Framebuffer::Attachment::set(Texture &t, unsigned l, int z)
 {