From: Mikko Rasa Date: Tue, 30 Nov 2010 14:34:46 +0000 (+0000) Subject: Allocate textures attached to framebuffers automatically X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=656b4577fccfb02bea747871e5ab10148f002443;p=libs%2Fgl.git Allocate textures attached to framebuffers automatically --- diff --git a/source/bloom.cpp b/source/bloom.cpp index 7c4338f8..0e5ce9d6 100644 --- a/source/bloom.cpp +++ b/source/bloom.cpp @@ -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); diff --git a/source/framebuffer.cpp b/source/framebuffer.cpp index 77ac21be..a0fcbc47 100644 --- a/source/framebuffer.cpp +++ b/source/framebuffer.cpp @@ -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(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; diff --git a/source/framebuffer.h b/source/framebuffer.h index 514208d6..89147b2c 100644 --- a/source/framebuffer.h +++ b/source/framebuffer.h @@ -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) diff --git a/source/pipeline.cpp b/source/pipeline.cpp index 95f96536..62aeaab9 100644 --- a/source/pipeline.cpp +++ b/source/pipeline.cpp @@ -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); diff --git a/source/shadowmap.cpp b/source/shadowmap.cpp index dbc4bd56..96539f1d 100644 --- a/source/shadowmap.cpp +++ b/source/shadowmap.cpp @@ -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); } diff --git a/source/texture3d.cpp b/source/texture3d.cpp index 6515946b..70dcf772 100644 --- a/source/texture3d.cpp +++ b/source/texture3d.cpp @@ -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)