]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texunit.cpp
Complete rewrite of extension handling
[libs/gl.git] / source / texunit.cpp
index 4d5ff81a297dc9f4d3b1f5dfb564111a3257ecbb..b19e791727c0e9f6d006c7a51eb58d3b0d634ed2 100644 (file)
@@ -1,14 +1,8 @@
-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2007-2008  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
-#include "extension.h"
+#include <stdexcept>
+#include "arb_multitexture.h"
+#include "arb_vertex_shader.h"
 #include "gl.h"
 #include "texunit.h"
-#include "version_1_3.h"
 
 using namespace std;
 
@@ -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,14 +33,30 @@ 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)
        {
-               if(is_version_at_least(2, 0) || is_supported("ARB_vertex_shader"))
+               if(ARB_vertex_shader)
                        glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &count);
-               else if(is_version_at_least(1, 3))
+               else if(ARB_multitexture)
                        glGetIntegerv(GL_MAX_TEXTURE_UNITS, &count);
                else
                        count = 1;
@@ -54,8 +66,10 @@ unsigned TexUnit::get_n_units()
 
 TexUnit &TexUnit::activate(unsigned n)
 {
+       if(n>0)
+               static Require _req(ARB_multitexture);
        if(n>=get_n_units())
-               throw InvalidParameterValue("Invalid texture unit number");
+               throw out_of_range("TexUnit::activate");
 
        if(units.size()<=n)
                units.resize(n+1);