]> git.tdb.fi Git - libs/gl.git/blobdiff - source/renderpass.cpp
Rework Bind and enable it to restore the old binding
[libs/gl.git] / source / renderpass.cpp
index 4aa41dba2d0136a1f164a843003fcd31f8a62463..70fa546afcddc0a0f2bcafb04da1313ddbd2b85b 100644 (file)
@@ -19,8 +19,6 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-const RenderPass *RenderPass::current = 0;
-
 RenderPass::RenderPass():
        shprog(0),
        shdata(0),
@@ -64,23 +62,21 @@ void RenderPass::set_texture(const string &slot, const Texture *tex)
 
 void RenderPass::bind() const
 {
-       if(this==current)
+       const RenderPass *old = current();
+       if(!set_current(this))
                return;
 
-       const RenderPass *old = current;
-       current = this;
-
        if(shprog)
        {
                shprog->bind();
                shdata->apply();
        }
-       else if(old && !old->shprog)
+       else if(old && old->shprog)
                GL::Program::unbind();
 
        if(material)
                material->bind();
-       else if(old && !old->material)
+       else if(old && old->material)
                GL::Material::unbind();
 
        for(unsigned i=0; i<textures.size(); ++i)
@@ -95,19 +91,18 @@ void RenderPass::bind() const
 
 void RenderPass::unbind()
 {
-       if(current)
-       {
-               if(current->shprog)
-                       GL::Program::unbind();
+       const RenderPass *old = current();
+       if(!set_current(0))
+               return;
 
-               if(current->material)
-                       GL::Material::unbind();
+       if(old->shprog)
+               GL::Program::unbind();
 
-               for(unsigned i=current->textures.size(); i--; )
-                       GL::Texture::unbind_from(i);
+       if(old->material)
+               GL::Material::unbind();
 
-               current = 0;
-       }
+       for(unsigned i=old->textures.size(); i--; )
+               GL::Texture::unbind_from(i);
 }