X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Ftexunit.cpp;h=9277c27704ebd8347c3c6a782fc1b6ff05fc8658;hp=982e524e0189fa74a10181c9a2ff7f7014e8746e;hb=d5c26741ed3952dd54c8a7f43ad42ba79bf2d977;hpb=6fd9b09f47ff6a07bd5ca7f9e8887db3486bfcb1 diff --git a/source/texunit.cpp b/source/texunit.cpp index 982e524e..9277c277 100644 --- a/source/texunit.cpp +++ b/source/texunit.cpp @@ -1,7 +1,9 @@ #include #include #include +#include #include "gl.h" +#include "misc.h" #include "texunit.h" using namespace std; @@ -13,42 +15,20 @@ vector TexUnit::units; TexUnit *TexUnit::cur_unit = 0; TexUnit::TexUnit(): + legacy(false), texture(0), - texenv(0) -{ - fill(texgen, texgen+4, static_cast(0)); -} + tex_legacy(false) +{ } -bool TexUnit::set_texture(const Texture *tex) +bool TexUnit::set_texture(const Texture *tex, bool lgc) { - bool result = (tex!=texture); + lgc = (lgc && legacy && tex); + bool result = (tex!=texture || lgc!=tex_legacy); texture = tex; + tex_legacy = lgc; 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]; -} - void TexUnit::bind() { if(cur_unit!=this && (cur_unit || index)) @@ -62,15 +42,28 @@ unsigned TexUnit::get_n_units() if(count<0) { if(ARB_vertex_shader) - glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &count); + count = get_i(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS); else if(ARB_multitexture) - glGetIntegerv(GL_MAX_TEXTURE_UNITS, &count); + count = get_i(GL_MAX_TEXTURE_UNITS); else count = 1; } return count; } +unsigned TexUnit::get_n_legacy_units() +{ + static int count = -1; + if(count<0) + { + if(MSP_legacy_features) + count = get_i(GL_MAX_TEXTURE_UNITS); + else + count = 0; + } + return count; +} + TexUnit &TexUnit::get_unit(unsigned n) { if(n>0) @@ -81,9 +74,13 @@ TexUnit &TexUnit::get_unit(unsigned n) if(units.size()<=n) { unsigned i = units.size(); - units.resize(n+1); + unsigned n_legacy = get_n_legacy_units(); + units.resize(n+1, TexUnit()); for(; i::iterator i=units.begin(); i!=units.end(); ++i) + if(i->texture==tex) + return &*i; + return 0; +} + } // namespace GL } // namespace Msp