X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftexunit.cpp;h=aa52aed4525a1c398aa2cf6f08793388074a723f;hb=619aae12e01f25e79626a94c973927e5599e99a5;hp=ba3e7ca6208e3716029027dcdb253b7203221f15;hpb=d1800d7ea80290f4913d0203241cef1409656522;p=libs%2Fgl.git diff --git a/source/texunit.cpp b/source/texunit.cpp index ba3e7ca6..aa52aed4 100644 --- a/source/texunit.cpp +++ b/source/texunit.cpp @@ -1,43 +1,82 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include "extension.h" +#include +#include +#include #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) { + fill(texgen, texgen+4, static_cast(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; +} + +bool TexUnit::set_texgen(unsigned i, const TexGen *gen) +{ + if(i>=4) + throw out_of_range("TexUnit::set_texgen"); + bool result = (texgen[i]!=gen); + texgen[i] = gen; + return result; +} + +const TexGen *TexUnit::get_texgen(unsigned i) +{ + if(i>=4) + throw out_of_range("TexUnit::get_texgen"); + return texgen[i]; +} + +unsigned TexUnit::get_n_units() +{ + static int count = -1; + if(count<0) + { + if(ARB_vertex_shader) + glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &count); + else if(ARB_multitexture) + glGetIntegerv(GL_MAX_TEXTURE_UNITS, &count); + else + count = 1; + } + return count; +} + TexUnit &TexUnit::activate(unsigned n) { + if(n>0) + static Require _req(ARB_multitexture); + 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)) - { - require_version(1, 3); glActiveTexture(GL_TEXTURE0+n); - } - cur_unit=&units[n]; + cur_unit = &units[n]; return units[n]; } @@ -49,8 +88,5 @@ TexUnit &TexUnit::current() return *cur_unit; } -vector TexUnit::units; -TexUnit *TexUnit::cur_unit=0; - } // namespace GL } // namespace Msp