-#define GL_GLEXT_PROTOTYPES
-#include <GL/gl.h>
-#include <GL/glext.h>
+/* $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"
+#include "version_1_3.h"
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)
{
- bool result=(tex!=texture);
- texture=tex;
+ bool result = (tex!=texture);
+ texture = tex;
+ return result;
+}
+
+bool TexUnit::set_texenv(const TexEnv *env)
+{
+ bool result = (texenv!=env);
+ texenv = env;
return result;
}
+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);
+ 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(units.size()<=n)
units.resize(n+1);
- glActiveTextureARB(GL_TEXTURE0+n);
- cur_unit=&units[n];
+ if(cur_unit!=&units[n] && (cur_unit || n))
+ glActiveTexture(GL_TEXTURE0+n);
+ cur_unit = &units[n];
return units[n];
}
return *cur_unit;
}
-vector<TexUnit> TexUnit::units;
-TexUnit *TexUnit::cur_unit=0;
-
} // namespace GL
} // namespace Msp