X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftexunit.cpp;h=4d5ff81a297dc9f4d3b1f5dfb564111a3257ecbb;hb=5172d32d67595ea0b70184fadcfcb8e023cccbc8;hp=fd0fe31423db1c6f76413f818f493eb661167b02;hpb=84bc56b96c21c831104a22e0cbd0f3b72ab5d8c3;p=libs%2Fgl.git diff --git a/source/texunit.cpp b/source/texunit.cpp index fd0fe314..4d5ff81a 100644 --- a/source/texunit.cpp +++ b/source/texunit.cpp @@ -1,31 +1,68 @@ -#define GL_GLEXT_PROTOTYPES -#include -#include +/* $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::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) + { + 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); - 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]; } @@ -37,8 +74,5 @@ TexUnit &TexUnit::current() return *cur_unit; } -vector TexUnit::units; -TexUnit *TexUnit::cur_unit=0; - } // namespace GL } // namespace Msp