X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Ftexunit.cpp;h=b19e791727c0e9f6d006c7a51eb58d3b0d634ed2;hp=91a33ecc378d966644e11aaf90c11524ffbc1bd0;hb=6afbace895a7bbcf216ab8e48280ea0303ab5892;hpb=f098a871fc6dc7b61a5aca5581fa327e4124c036 diff --git a/source/texunit.cpp b/source/texunit.cpp index 91a33ecc..b19e7917 100644 --- a/source/texunit.cpp +++ b/source/texunit.cpp @@ -1,13 +1,7 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#define GL_GLEXT_PROTOTYPES -#include -#include +#include +#include "arb_multitexture.h" +#include "arb_vertex_shader.h" +#include "gl.h" #include "texunit.h" using namespace std; @@ -15,24 +9,74 @@ 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 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(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); - 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]; } @@ -44,8 +88,5 @@ TexUnit &TexUnit::current() return *cur_unit; } -vector TexUnit::units; -TexUnit *TexUnit::cur_unit=0; - } // namespace GL } // namespace Msp