]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture.cpp
Support embedding textures in datafiles
[libs/gl.git] / source / texture.cpp
index 1cb169450fbde2bdb090fa2adadcf562a4148f02..7ce039acb6df2278ff8c2df8c289e63cfd290820 100644 (file)
@@ -9,9 +9,35 @@ Distributed under the LGPL
 #include "texture.h"
 #include "texunit.h"
 
+using namespace std;
+
 namespace Msp {
 namespace GL {
 
+istream &operator>>(istream &in, TextureFilter &tf)
+{
+       string str;
+       in>>str;
+
+       if(str=="NEAREST")
+               tf=NEAREST;
+       else if(str=="LINEAR")
+               tf=LINEAR;
+       else if(str=="NEAREST_MIPMAP_NEAREST")
+               tf=NEAREST_MIPMAP_NEAREST;
+       else if(str=="NEAREST_MIPMAP_LINEAR")
+               tf=NEAREST_MIPMAP_LINEAR;
+       else if(str=="LINEAR_MIPMAP_NEAREST")
+               tf=LINEAR_MIPMAP_NEAREST;
+       else if(str=="LINEAR_MIPMAP_LINEAR")
+               tf=LINEAR_MIPMAP_LINEAR;
+       else
+               in.setstate(ios_base::failbit);
+
+       return in;
+}
+
+
 void Texture::bind() const
 {
        if(!target)
@@ -68,5 +94,29 @@ void Texture::maybe_bind() const
                bind();
 }
 
+
+Texture::Loader::Loader(Texture &t):
+       tex(t)
+{
+       add("min_filter", &Loader::min_filter);
+       add("mag_filter", &Loader::mag_filter);
+       add("generate_mipmap", &Loader::generate_mipmap);
+}
+
+void Texture::Loader::min_filter(TextureFilter f)
+{
+       tex.set_min_filter(f);
+}
+
+void Texture::Loader::mag_filter(TextureFilter f)
+{
+       tex.set_mag_filter(f);
+}
+
+void Texture::Loader::generate_mipmap(bool gm)
+{
+       tex.parameter(GL_GENERATE_MIPMAP_SGIS, gm);
+}
+
 } // namespace GL
 } // namespace Msp