X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Ftexunit.cpp;h=714b65027d1786f03865bdfd22ab7d3851440f2b;hb=27fe0982fc18d1f5f9efe942e18c42f508268f34;hp=a542796548f0ae120bc9037b81bf0e2e3071c0fd;hpb=7e9e15a12fb398798f2719545cc8553354c1e389;p=libs%2Fgl.git diff --git a/source/texunit.cpp b/source/texunit.cpp index a5427965..714b6502 100644 --- a/source/texunit.cpp +++ b/source/texunit.cpp @@ -1,14 +1,9 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007-2008 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include "extension.h" +#include +#include +#include #include "gl.h" +#include "misc.h" #include "texunit.h" -#include "version_1_3.h" using namespace std; @@ -21,7 +16,9 @@ TexUnit *TexUnit::cur_unit = 0; TexUnit::TexUnit(): texture(0), texenv(0) -{ } +{ + fill(texgen, texgen+4, static_cast(0)); +} bool TexUnit::set_texture(const Texture *tex) { @@ -37,30 +34,58 @@ bool TexUnit::set_texenv(const 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) - // XXX Should use GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS since GL 2.0 - glGetIntegerv(GL_MAX_TEXTURE_UNITS, &count); + { + if(ARB_vertex_shader) + count = get_i(GL_MAX_TEXTURE_IMAGE_UNITS); + else if(ARB_multitexture) + count = get_i(GL_MAX_TEXTURE_UNITS); + else + count = 1; + } return count; } -TexUnit &TexUnit::activate(unsigned n) +TexUnit &TexUnit::get_unit(unsigned n) { if(n>0) - { - static RequireVersion _ver(1, 3); - if(n>=get_n_units()) - throw InvalidParameterValue("Invalid texture unit number"); - } + 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); - - if(cur_unit!=&units[n] && (cur_unit || n)) - glActiveTexture(GL_TEXTURE0+n); - cur_unit = &units[n]; + for(; i::iterator i=units.begin(); i!=units.end(); ++i) + if(i->texture==tex) + return &*i; + return 0; +} + +TexUnit *TexUnit::find_unit(const TexEnv *env) +{ + for(vector::iterator i=units.begin(); i!=units.end(); ++i) + if(i->texenv==env) + return &*i; + return 0; +} + } // namespace GL } // namespace Msp