X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftexunit.cpp;h=4d71e3b9492674a3a3e0f1712d6d45d526c679bb;hb=2157e9320c60d561208dfdf6034e9a06781c9f30;hp=7aced5cc3ba2ab182a4c5e37ce6b37f42e6e21a6;hpb=dc1d1159a61f378bda11e5989ad694a86b9a3c77;p=libs%2Fgl.git diff --git a/source/texunit.cpp b/source/texunit.cpp index 7aced5cc..4d71e3b9 100644 --- a/source/texunit.cpp +++ b/source/texunit.cpp @@ -1,10 +1,4 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - +#include #include "extension.h" #include "gl.h" #include "texunit.h" @@ -15,29 +9,54 @@ 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; + return result; } -bool TexUnit::set_texture(const Texture *tex) +bool TexUnit::set_texenv(const TexEnv *env) { - bool result=(tex!=texture); - texture=tex; + 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 out_of_range("TexUnit::activate"); + 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]; + cur_unit = &units[n]; return units[n]; } @@ -49,8 +68,5 @@ TexUnit &TexUnit::current() return *cur_unit; } -vector TexUnit::units; -TexUnit *TexUnit::cur_unit=0; - } // namespace GL } // namespace Msp