From 1d24ddbc35f9e0480d30c66d47b7ea3834c15fbf Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 21 Dec 2013 13:20:21 +0200 Subject: [PATCH] Use RAII binders in place of manual binding --- source/buffer.cpp | 19 ++----------------- source/buffer.h | 1 - source/environmentmap.cpp | 4 +--- source/shadowmap.cpp | 3 +-- 4 files changed, 4 insertions(+), 23 deletions(-) diff --git a/source/buffer.cpp b/source/buffer.cpp index d8bb2802..61670cf9 100644 --- a/source/buffer.cpp +++ b/source/buffer.cpp @@ -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 BufferRange::bound_uniform; diff --git a/source/buffer.h b/source/buffer.h index 4f9f3294..bfbfd148 100644 --- a/source/buffer.h +++ b/source/buffer.h @@ -94,7 +94,6 @@ public: private: static const Buffer *&binding(BufferType); static bool set_current(BufferType, const Buffer *); - static void restore(const Buffer *, BufferType); }; diff --git a/source/environmentmap.cpp b/source/environmentmap.cpp index c789fe48..f61d2c40 100644 --- a/source/environmentmap.cpp +++ b/source/environmentmap.cpp @@ -75,7 +75,7 @@ void EnvironmentMap::render(Renderer &renderer, const Tag &tag) const unsigned unit = renderer.allocate_effect_texunit(); shdata.uniform("environment", static_cast(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 diff --git a/source/shadowmap.cpp b/source/shadowmap.cpp index 21e67c38..7575051e 100644 --- a/source/shadowmap.cpp +++ b/source/shadowmap.cpp @@ -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); -- 2.45.2