]> git.tdb.fi Git - libs/gl.git/commitdiff
Support layered framebuffer attachments
authorMikko Rasa <tdb@tdb.fi>
Thu, 6 May 2021 08:14:47 +0000 (11:14 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 6 May 2021 10:32:42 +0000 (13:32 +0300)
source/core/framebuffer.cpp
source/core/framebuffer.h

index c90d6a70670b4560155d6a84f86d613a9565b193..810f0cf1c2675da6741648568408d221412d7c77 100644 (file)
@@ -121,13 +121,15 @@ void Framebuffer::update_attachment(unsigned mask) const
                        {
                                if(ARB_direct_state_access)
                                {
-                                       if(attch.type==GL_TEXTURE_2D)
+                                       if(attch.type==GL_TEXTURE_2D || 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(attch.type==GL_TEXTURE_2D)
                                        glFramebufferTexture2D(GL_FRAMEBUFFER, attch.attachment, attch.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(attch.type==GL_TEXTURE_2D_ARRAY)
                                        glFramebufferTextureLayer(GL_FRAMEBUFFER, attch.attachment, attch.tex->get_id(), attch.level, attch.layer);
                                else if(attch.type==GL_TEXTURE_3D)
@@ -251,6 +253,20 @@ void Framebuffer::attach(FramebufferAttachment attch, TextureCube &tex, TextureC
        set_texture_attachment(attch, tex, level, TextureCube::get_face_index(face));
 }
 
+void Framebuffer::attach_layered(FramebufferAttachment attch, Texture3D &tex, unsigned level)
+{
+       static Require _req(ARB_geometry_shader4);
+       tex.allocate(level);
+       set_texture_attachment(attch, tex, level, -1);
+}
+
+void Framebuffer::attach_layered(FramebufferAttachment attch, TextureCube &tex, unsigned level)
+{
+       static Require _req(ARB_geometry_shader4);
+       tex.allocate(level);
+       set_texture_attachment(attch, tex, level, -1);
+}
+
 void Framebuffer::detach(FramebufferAttachment attch)
 {
        if(!id)
@@ -399,7 +415,7 @@ void Framebuffer::Attachment::set(Renderbuffer &r)
        layer = 0;
 }
 
-void Framebuffer::Attachment::set(Texture &t, unsigned l, unsigned z)
+void Framebuffer::Attachment::set(Texture &t, unsigned l, int z)
 {
        type = t.get_target();
        tex = &t;
index 3086685e1ce29234e8f1e8629bb7ffd103f7050f..88ab465aaea52a8fb68f5fa7a774f43923443589 100644 (file)
@@ -82,11 +82,11 @@ private:
                        Texture *tex;
                };
                unsigned level;
-               unsigned layer;
+               int layer;
 
                Attachment(FramebufferAttachment);
                void set(Renderbuffer &);
-               void set(Texture &, unsigned, unsigned);
+               void set(Texture &, unsigned, int);
                void clear();
        };
 
@@ -125,6 +125,8 @@ public:
        void attach(FramebufferAttachment attch, Texture2D &tex, unsigned level = 0);
        void attach(FramebufferAttachment attch, Texture3D &tex, unsigned layer, unsigned level = 0);
        void attach(FramebufferAttachment attch, TextureCube &tex, TextureCubeFace face, unsigned level = 0);
+       void attach_layered(FramebufferAttachment attch, Texture3D &tex, unsigned level = 0);
+       void attach_layered(FramebufferAttachment attch, TextureCube &tex, unsigned level = 0);
        void detach(FramebufferAttachment attch);
 
        /** Checks the completeness of the framebuffer.  Returns