+++ /dev/null
-#include "texture.h"
-#include "texturing.h"
-#include "texunit.h"
-
-using namespace std;
-
-namespace Msp {
-namespace GL {
-
-Texturing::~Texturing()
-{
- if(current()==this)
- unbind();
-}
-
-void Texturing::attach(unsigned attch, const Texture &tex)
-{
- set_attachment(attch, &tex);
-}
-
-void Texturing::detach(unsigned attch)
-{
- set_attachment(attch, 0);
-}
-
-void Texturing::set_attachment(unsigned unit, const Texture *tex)
-{
- if(unit>=TexUnit::get_n_units())
- throw out_of_range("Texturing::set_attachment");
-
- if(tex)
- {
- vector<Attachment>::iterator i;
- for(i=attachments.begin(); (i!=attachments.end() && i->unit<=unit); ++i)
- if(i->unit==unit)
- {
- i->texture = tex;
- if(current()==this)
- tex->bind_to(unit);
- return;
- }
-
- attachments.insert(i, Attachment(unit, tex));
- if(current()==this)
- tex->bind_to(unit);
- }
- else
- {
- for(vector<Attachment>::iterator i=attachments.begin(); (i!=attachments.end() && i->unit<=unit); ++i)
- if(i->unit==unit)
- {
- attachments.erase(i);
- if(current()==this)
- Texture::unbind_from(unit);
- return;
- }
- }
-}
-
-const Texture *Texturing::get_attached_texture(unsigned unit) const
-{
- for(vector<Attachment>::const_iterator i=attachments.begin(); (i!=attachments.end() && i->unit<=unit); ++i)
- if(i->unit==unit)
- return i->texture;
- return 0;
-}
-
-void Texturing::bind() const
-{
- const Texturing *old = current();
- if(set_current(this))
- {
- if(old)
- {
- vector<Attachment>::const_iterator i = attachments.begin();
- vector<Attachment>::const_iterator j = old->attachments.begin();
- while(i!=attachments.end() || j!=old->attachments.end())
- {
- if(i!=attachments.end() && (j==old->attachments.end() || i->unit<=j->unit))
- {
- i->texture->bind_to(i->unit);
- if(j!=old->attachments.end() && j->unit==i->unit)
- ++j;
- ++i;
- }
- else
- {
- Texture::unbind_from(j->unit);
- ++j;
- }
- }
- }
- else
- {
- for(vector<Attachment>::const_iterator i=attachments.begin(); i!=attachments.end(); ++i)
- i->texture->bind_to(i->unit);
- }
- }
-}
-
-void Texturing::unbind()
-{
- const Texturing *old = current();
- if(set_current(0))
- {
- for(vector<Attachment>::const_iterator i=old->attachments.begin(); i!=old->attachments.end(); ++i)
- Texture::unbind_from(i->unit);
- }
-}
-
-
-Texturing::Attachment::Attachment(unsigned u, const Texture *t):
- unit(u),
- texture(t)
-{ }
-
-} // namespace GL
-} // namespace Msp;