]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texturing.cpp
Keep track of which components have been set in Transform
[libs/gl.git] / source / texturing.cpp
index 880f3f0751a40df642d4b7d713d3497c94476da2..77bb15435c7391a62a0298ea653f6699417eb55f 100644 (file)
@@ -1,4 +1,3 @@
-#include "texenv.h"
 #include "texture.h"
 #include "texturing.h"
 #include "texunit.h"
@@ -8,6 +7,8 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
+bool Texturing::legacy_used = true;
+
 Texturing::~Texturing()
 {
        if(current()==this)
@@ -16,20 +17,15 @@ Texturing::~Texturing()
 
 void Texturing::attach(unsigned attch, const Texture &tex)
 {
-       set_attachment(attch, &tex, 0);
-}
-
-void Texturing::attach(unsigned attch, const Texture &tex, const TexEnv &env)
-{
-       set_attachment(attch, &tex, &env);
+       set_attachment(attch, &tex);
 }
 
 void Texturing::detach(unsigned attch)
 {
-       set_attachment(attch, 0, 0);
+       set_attachment(attch, 0);
 }
 
-void Texturing::set_attachment(unsigned attch, const Texture *tex, const TexEnv *env)
+void Texturing::set_attachment(unsigned attch, const Texture *tex)
 {
        if(attch>=TexUnit::get_n_units())
                throw out_of_range("Texturing::set_attachment");
@@ -37,41 +33,38 @@ void Texturing::set_attachment(unsigned attch, const Texture *tex, const TexEnv
        if(attachments.size()<=attch)
                attachments.resize(attch+1);
 
-       attachments[attch].tex = tex;
-       attachments[attch].env = env;
+       attachments[attch] = tex;
 
        if(current()==this)
-               bind_attachment(attch);
+               bind_attachment(attch, legacy_used);
 }
 
-void Texturing::bind_attachment(unsigned i) const
+const Texture *Texturing::get_attached_texture(unsigned i) const
 {
-       const Attachment &attch = attachments[i];
-       TexUnit::activate(i);
-       if(attch.tex)
-               attch.tex->bind();
-       else
-               Texture::unbind();
-       if(attch.env)
-               attch.env->bind();
+       return i<attachments.size() ? attachments[i] : 0;
+}
+
+void Texturing::bind_attachment(unsigned i, bool legacy) const
+{
+       if(const Texture *tex = attachments[i])
+               tex->bind_to(i, legacy);
        else
-               TexEnv::unbind();
+               Texture::unbind_from(i);
 }
 
 void Texturing::unbind_attachment(unsigned i)
 {
-       TexUnit::activate(i);
-       Texture::unbind();
-       TexEnv::unbind();
+       Texture::unbind_from(i);
 }
 
-void Texturing::bind() const
+void Texturing::bind(bool legacy) const
 {
        const Texturing *old = current();
-       if(set_current(this))
+       if(set_current(this) || legacy!=legacy_used)
        {
+               legacy_used = legacy;
                for(unsigned i=0; i<attachments.size(); ++i)
-                       bind_attachment(i);
+                       bind_attachment(i, legacy);
                if(old)
                {
                        for(unsigned i=attachments.size(); i<old->attachments.size(); ++i)
@@ -90,11 +83,5 @@ void Texturing::unbind()
        }
 }
 
-
-Texturing::Attachment::Attachment():
-       tex(0),
-       env(0)
-{ }
-
 } // namespace GL
 } // namespace Msp;