]> git.tdb.fi Git - libs/gl.git/commitdiff
Use RAII binders in place of manual binding
authorMikko Rasa <tdb@tdb.fi>
Sat, 21 Dec 2013 11:20:21 +0000 (13:20 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 21 Dec 2013 11:26:39 +0000 (13:26 +0200)
source/buffer.cpp
source/buffer.h
source/environmentmap.cpp
source/shadowmap.cpp

index d8bb28028ee686380e48b77613c039906df40a35..61670cf9d378245f9a96ddead7f0fcea32ffb584 100644 (file)
@@ -45,19 +45,15 @@ void Buffer::set_usage(BufferUsage u)
 
 void Buffer::data(unsigned sz, const void *d)
 {
-       const Buffer *old = current(type);
-       bind();
+       BindRestore _bind(this, type);
        glBufferData(type, sz, d, usage);
        size = sz;
-       restore(old, type);
 }
 
 void Buffer::sub_data(unsigned off, unsigned sz, const void *d)
 {
-       const Buffer *old = current(type);
-       bind();
+       BindRestore _bind(this, type);
        glBufferSubData(type, off, sz, d);
-       restore(old, type);
 }
 
 BufferRange *Buffer::create_range(unsigned s, unsigned o)
@@ -107,17 +103,6 @@ bool Buffer::set_current(BufferType type, const Buffer *buf)
        return true;
 }
 
-void Buffer::restore(const Buffer *buf, BufferType type)
-{
-       if(buf!=current(type))
-       {
-               if(buf)
-                       buf->bind_to(type);
-               else
-                       unbind_from(type);
-       }
-}
-
 
 vector<const BufferRange *> BufferRange::bound_uniform;
 
index 4f9f32943df58e420848832d2d298914c74676e4..bfbfd14891ff024a7d509198710deffa439e73f7 100644 (file)
@@ -94,7 +94,6 @@ public:
 private:
        static const Buffer *&binding(BufferType);
        static bool set_current(BufferType, const Buffer *);
-       static void restore(const Buffer *, BufferType);
 };
 
 
index c789fe48d0f4c449f628778aac0b1c32f4ecac18..f61d2c40ed9a45507fcf5e87f1db4adf9ce54181 100644 (file)
@@ -75,7 +75,7 @@ void EnvironmentMap::render(Renderer &renderer, const Tag &tag) const
 
        unsigned unit = renderer.allocate_effect_texunit();
        shdata.uniform("environment", static_cast<int>(unit));
-       env_tex.bind_to(unit);
+       Bind _bind_env(env_tex, unit);
 
        const Matrix &view_matrix = renderer.get_camera()->get_matrix();
        // XXX The camera should maybe have store its own object matrix
@@ -93,8 +93,6 @@ void EnvironmentMap::render(Renderer &renderer, const Tag &tag) const
 
        renderer.add_shader_data(shdata);
        renderer.render(renderable, tag);
-
-       env_tex.unbind_from(unit);
 }
 
 } // namespace GL
index 21e67c38a5efeeb08a20fcbd917dc2b767f9ed39..7575051e6e7d956e89299a8eed47db54ca8f9546 100644 (file)
@@ -128,7 +128,7 @@ void ShadowMap::render(Renderer &renderer, const Tag &tag) const
        shdata.uniform("shadow", iunit);
        shdata.uniform("shadow_unit", iunit);
 
-       depth_buf.bind_to(unit);
+       Bind _bind_depth(depth_buf, unit);
        TexGen tg_s, tg_t, tg_r;
        tg_s.set_plane(Vector4(shadow_matrix(0, 0), shadow_matrix(0, 1), shadow_matrix(0, 2), shadow_matrix(0, 3)));
        tg_t.set_plane(Vector4(shadow_matrix(1, 0), shadow_matrix(1, 1), shadow_matrix(1, 2), shadow_matrix(1, 3)));
@@ -147,7 +147,6 @@ void ShadowMap::render(Renderer &renderer, const Tag &tag) const
        renderer.add_shader_data(shdata);
        renderer.render(renderable, tag);
 
-       Texture::unbind_from(unit);
        TexGen::unbind_from(unit, SCOORD);
        TexGen::unbind_from(unit, TCOORD);
        TexGen::unbind_from(unit, RCOORD);