]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texunit.cpp
Drop Id tags and copyright notices from files
[libs/gl.git] / source / texunit.cpp
index 1155fa96286be0ab199280e61ea909115545df30..dde3d406ca71fcbb5cfa034805a91a9784da6fe7 100644 (file)
@@ -1,10 +1,3 @@
-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2007-2008  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include "extension.h"
 #include "gl.h"
 #include "texunit.h"
@@ -15,10 +8,13 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
+vector<TexUnit> TexUnit::units;
+TexUnit *TexUnit::cur_unit = 0;
+
 TexUnit::TexUnit():
-       texture(0)
-{
-}
+       texture(0),
+       texenv(0)
+}
 
 bool TexUnit::set_texture(const Texture *tex)
 {
@@ -34,16 +30,31 @@ bool TexUnit::set_texenv(const TexEnv *env)
        return result;
 }
 
+unsigned TexUnit::get_n_units()
+{
+       static int count = -1;
+       if(count<0)
+       {
+               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>=get_n_units())
+               throw InvalidParameterValue("Invalid texture unit number");
+
        if(units.size()<=n)
                units.resize(n+1);
 
        if(cur_unit!=&units[n] && (cur_unit || n))
-       {
-               static RequireVersion _ver(1, 3);
                glActiveTexture(GL_TEXTURE0+n);
-       }
        cur_unit = &units[n];
 
        return units[n];
@@ -56,8 +67,5 @@ TexUnit &TexUnit::current()
        return *cur_unit;
 }
 
-vector<TexUnit> TexUnit::units;
-TexUnit *TexUnit::cur_unit = 0;
-
 } // namespace GL
 } // namespace Msp