]> git.tdb.fi Git - libs/gl.git/commitdiff
Support attaching 3D and 2DArray textures to Framebuffer
authorMikko Rasa <tdb@tdb.fi>
Sat, 10 Dec 2016 17:32:27 +0000 (19:32 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 10 Dec 2016 17:32:27 +0000 (19:32 +0200)
source/framebuffer.cpp
source/framebuffer.h

index a3197f5947cced462fa8c12d7c5ac9b4f68ed2f8..c7bfcd5a5808120088bb72cc2c9a589742186b66 100644 (file)
@@ -2,12 +2,14 @@
 #include <msp/gl/extensions/arb_direct_state_access.h>
 #include <msp/gl/extensions/ext_framebuffer_blit.h>
 #include <msp/gl/extensions/ext_framebuffer_object.h>
+#include <msp/gl/extensions/ext_texture_array.h>
 #include <msp/gl/extensions/msp_draw_buffer.h>
 #include "error.h"
 #include "framebuffer.h"
 #include "misc.h"
 #include "renderbuffer.h"
 #include "texture2d.h"
+#include "texture3d.h"
 
 using namespace std;
 
@@ -113,6 +115,16 @@ void Framebuffer::update_attachment(unsigned mask) const
                                else
                                        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
+                                       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);
@@ -171,6 +183,12 @@ void Framebuffer::check_size()
                                width = max(tex->get_width()>>i->level, 1U);
                                height = max(tex->get_height()>>i->level, 1U);
                        }
+                       else if(i->type==GL_TEXTURE_3D || i->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);
+                       }
                        else if(i->type==GL_TEXTURE_CUBE_MAP)
                        {
                                width = max(static_cast<TextureCube *>(i->tex)->get_size()>>i->level, 1U);
@@ -213,6 +231,17 @@ void Framebuffer::attach(FramebufferAttachment attch, Texture2D &tex, unsigned l
        check_size();
 }
 
+void Framebuffer::attach(FramebufferAttachment attch, Texture3D &tex, unsigned layer, unsigned level)
+{
+       if(!id)
+               throw invalid_operation("Framebuffer::attach");
+
+       unsigned i = get_attachment_index(attch);
+       attachments[i].set(tex, level, layer);
+       update_attachment(1<<i);
+       check_size();
+}
+
 void Framebuffer::attach(FramebufferAttachment attch, TextureCube &tex, TextureCubeFace face, unsigned level)
 {
        if(!id)
index 579d22f8f33c3993be7ee7f1d1f78d984a207267..9b0360fb9354a19e428b98b7fc652b3c8d0ed951 100644 (file)
@@ -14,6 +14,7 @@ namespace GL {
 class Renderbuffer;
 class Texture;
 class Texture2D;
+class Texture3D;
 
 enum FramebufferAttachment
 {
@@ -130,6 +131,7 @@ private:
 public:
        void attach(FramebufferAttachment attch, Renderbuffer &rbuf);
        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 detach(FramebufferAttachment attch);