namespace Msp {
namespace GL {
-const RenderPass *RenderPass::current = 0;
-
RenderPass::RenderPass():
shprog(0),
shdata(0),
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)
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);
}