]> git.tdb.fi Git - libs/gl.git/commitdiff
Allocate textures attached to framebuffers automatically
authorMikko Rasa <tdb@tdb.fi>
Tue, 30 Nov 2010 14:34:46 +0000 (14:34 +0000)
committerMikko Rasa <tdb@tdb.fi>
Tue, 30 Nov 2010 14:34:46 +0000 (14:34 +0000)
source/bloom.cpp
source/framebuffer.cpp
source/framebuffer.h
source/pipeline.cpp
source/shadowmap.cpp
source/texture3d.cpp

index 7c4338f8e1fe975706b677ec810e42b9dd91bd36..0e5ce9d616d9f6827aec8b80b029e87c15e0aba0 100644 (file)
@@ -77,7 +77,6 @@ Bloom::Bloom(unsigned w, unsigned h):
                blur_shdata[i].uniform(loc, 0);
                tex[i].set_min_filter(NEAREST);
                tex[i].storage(RGB16F, w, h);
-               tex[i].image(0, RGB, UNSIGNED_BYTE, 0);
        }
 
        combine_shdata.uniform(combine_shader.get_uniform_location("source"), 1);
index 77ac21be6b0e6ef76da3928247b54b2c69074c5b..a0fcbc474203c5588d04e410bf4d0975c49fa983 100644 (file)
@@ -62,7 +62,10 @@ void Framebuffer::update_attachment(unsigned mask) const
                                if(attch.type==GL_RENDERBUFFER_EXT)
                                        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, attch.attachment, GL_RENDERBUFFER_EXT, attch.rbuf->get_id());
                                else if(attch.type==GL_TEXTURE_2D)
+                               {
+                                       static_cast<Texture2D *>(attch.tex)->allocate(attch.level);
                                        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attch.attachment, attch.type, attch.tex->get_id(), attch.level);
+                               }
                                else
                                        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, attch.attachment, 0, 0);
                        }
@@ -113,7 +116,7 @@ void Framebuffer::attach(FramebufferAttachment attch, Renderbuffer &rbuf)
        check_size();
 }
 
-void Framebuffer::attach(FramebufferAttachment attch, Texture2D &tex, int level)
+void Framebuffer::attach(FramebufferAttachment attch, Texture2D &tex, unsigned level)
 {
        if(!id)
                throw InvalidState("Can't attach to system framebuffer");
@@ -203,7 +206,7 @@ void Framebuffer::Attachment::set(Renderbuffer &r)
        level = 0;
 }
 
-void Framebuffer::Attachment::set(Texture &t, int l)
+void Framebuffer::Attachment::set(Texture &t, unsigned l)
 {
        type = t.get_target();
        tex = &t;
index 514208d6db161fd3635f39538760bc6435160b94..89147b2c250cb265be3a7805cb927062499f1655 100644 (file)
@@ -86,11 +86,11 @@ private:
                        Renderbuffer *rbuf;
                        Texture *tex;
                };
-               int level;
+               unsigned level;
 
                Attachment(FramebufferAttachment);
                void set(Renderbuffer &);
-               void set(Texture &, int);
+               void set(Texture &, unsigned);
                void clear();
        };
 
@@ -110,7 +110,7 @@ private:
        void check_size();
 public:
        void attach(FramebufferAttachment attch, Renderbuffer &rbuf);
-       void attach(FramebufferAttachment attch, Texture2D &tex, int level);
+       void attach(FramebufferAttachment attch, Texture2D &tex, unsigned level);
        void detach(FramebufferAttachment attch);
 
        /**
@@ -130,9 +130,6 @@ public:
        static Framebuffer &system();
 private:
        unsigned get_attachment_index(FramebufferAttachment);
-
-public:
-       
 };
 
 inline BufferBits operator|(BufferBits a, BufferBits b)
index 95f96536f81c1f6891c5be726c2517ca95a08e2a..62aeaab938b60830d30dad685443a1e6490b95bb 100644 (file)
@@ -120,7 +120,6 @@ void Pipeline::add_postprocessor(PostProcessor &pp)
                color_buf->set_min_filter(NEAREST);
                color_buf->set_mag_filter(NEAREST);
                color_buf->storage((hdr ? RGB16F : RGB), width, height);
-               color_buf->image(0, RGB, UNSIGNED_BYTE, 0);
                fbo->attach(COLOR_ATTACHMENT0, *color_buf, 0);
                depth_buf = new Renderbuffer;
                depth_buf->storage(DEPTH_COMPONENT, width, height);
index dbc4bd56524688170770d0e5d9fabe68ea3eac3c..96539f1d4d70c2241e0699e60dc5da757595a961 100644 (file)
@@ -31,7 +31,6 @@ ShadowMap::ShadowMap(unsigned s, const Scene &c, const Light &l):
        depth_buf.set_compare_func(LEQUAL);
        depth_buf.set_wrap(CLAMP_TO_EDGE);
        depth_buf.storage(DEPTH_COMPONENT, size, size);
-       depth_buf.image(0, DEPTH_COMPONENT, UNSIGNED_BYTE, 0);
        fbo.attach(DEPTH_ATTACHMENT, depth_buf, 0);
 }
 
index 6515946bb2bba5885dd6dd6d5c425438804cc400..70dcf7725568bef6637f18cf95fe1d89e5c61493 100644 (file)
@@ -39,8 +39,6 @@ void Texture3D::storage(PixelFormat f, unsigned w, unsigned h, unsigned d)
        height = h;
        depth = d;
        ifmt = f;
-
-       image(0, ifmt, UNSIGNED_BYTE, 0);
 }
 
 void Texture3D::allocate(unsigned level)