]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texunit.cpp
Add TexGen wrapper class
[libs/gl.git] / source / texunit.cpp
index a542796548f0ae120bc9037b81bf0e2e3071c0fd..d581598a6c190e2caf46c59d11140d403c30e79b 100644 (file)
@@ -1,10 +1,4 @@
-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2007-2008  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
+#include <stdexcept>
 #include "extension.h"
 #include "gl.h"
 #include "texunit.h"
@@ -21,7 +15,9 @@ TexUnit *TexUnit::cur_unit = 0;
 TexUnit::TexUnit():
        texture(0),
        texenv(0)
-{ }
+{
+       fill(texgen, texgen+4, static_cast<const TexGen *>(0));
+}
 
 bool TexUnit::set_texture(const Texture *tex)
 {
@@ -37,23 +33,41 @@ bool TexUnit::set_texenv(const TexEnv *env)
        return result;
 }
 
+bool TexUnit::set_texgen(unsigned i, const TexGen *gen)
+{
+       if(i>=4)
+               throw invalid_argument("TexUnit::set_texgen");
+       bool result = (texgen[i]!=gen);
+       texgen[i] = gen;
+       return result;
+}
+
+const TexGen *TexUnit::get_texgen(unsigned i)
+{
+       if(i>=4)
+               throw invalid_argument("TexUnit::get_texgen");
+       return texgen[i];
+}
+
 unsigned TexUnit::get_n_units()
 {
        static int count = -1;
        if(count<0)
-               // XXX Should use GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS since GL 2.0
-               glGetIntegerv(GL_MAX_TEXTURE_UNITS, &count);
+       {
+               if(is_version_at_least(2, 0) || is_supported("ARB_vertex_shader"))
+                       glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &count);
+               else if(is_version_at_least(1, 3))
+                       glGetIntegerv(GL_MAX_TEXTURE_UNITS, &count);
+               else
+                       count = 1;
+       }
        return count;
 }
 
 TexUnit &TexUnit::activate(unsigned n)
 {
-       if(n>0)
-       {
-               static RequireVersion _ver(1, 3);
-               if(n>=get_n_units())
-                       throw InvalidParameterValue("Invalid texture unit number");
-       }
+       if(n>=get_n_units())
+               throw out_of_range("TexUnit::activate");
 
        if(units.size()<=n)
                units.resize(n+1);