X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftexunit.cpp;h=982e524e0189fa74a10181c9a2ff7f7014e8746e;hb=6fd9b09f47ff6a07bd5ca7f9e8887db3486bfcb1;hp=fd0fe31423db1c6f76413f818f493eb661167b02;hpb=84bc56b96c21c831104a22e0cbd0f3b72ab5d8c3;p=libs%2Fgl.git diff --git a/source/texunit.cpp b/source/texunit.cpp index fd0fe314..982e524e 100644 --- a/source/texunit.cpp +++ b/source/texunit.cpp @@ -1,6 +1,7 @@ -#define GL_GLEXT_PROTOTYPES -#include -#include +#include +#include +#include +#include "gl.h" #include "texunit.h" using namespace std; @@ -8,24 +9,82 @@ 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; } -TexUnit &TexUnit::activate(unsigned n) +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]; +} + +void TexUnit::bind() +{ + if(cur_unit!=this && (cur_unit || index)) + glActiveTexture(GL_TEXTURE0+index); + cur_unit = this; +} + +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::get_unit(unsigned n) +{ + if(n>0) + static Require _req(ARB_multitexture); + if(n>=get_n_units()) + throw out_of_range("TexUnit::get_unit"); + if(units.size()<=n) + { + unsigned i = units.size(); units.resize(n+1); - - glActiveTextureARB(GL_TEXTURE0+n); - cur_unit=&units[n]; + for(; i TexUnit::units; -TexUnit *TexUnit::cur_unit=0; - } // namespace GL } // namespace Msp