]> git.tdb.fi Git - libs/gl.git/blob - source/texunit.cpp
Get rid of the generic Texture::parameter method
[libs/gl.git] / source / texunit.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007-2008  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "extension.h"
9 #include "gl.h"
10 #include "texunit.h"
11 #include "version_1_3.h"
12
13 using namespace std;
14
15 namespace Msp {
16 namespace GL {
17
18 vector<TexUnit> TexUnit::units;
19 TexUnit *TexUnit::cur_unit = 0;
20
21 TexUnit::TexUnit():
22         texture(0),
23         texenv(0)
24 { }
25
26 bool TexUnit::set_texture(const Texture *tex)
27 {
28         bool result = (tex!=texture);
29         texture = tex;
30         return result;
31 }
32
33 bool TexUnit::set_texenv(const TexEnv *env)
34 {
35         bool result = (texenv!=env);
36         texenv = env;
37         return result;
38 }
39
40 unsigned TexUnit::get_n_units()
41 {
42         static int count = -1;
43         if(count<0)
44                 // XXX Should use GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS since GL 2.0
45                 glGetIntegerv(GL_MAX_TEXTURE_UNITS, &count);
46         return count;
47 }
48
49 TexUnit &TexUnit::activate(unsigned n)
50 {
51         if(n>0)
52         {
53                 static RequireVersion _ver(1, 3);
54                 if(n>=get_n_units())
55                         throw InvalidParameterValue("Invalid texture unit number");
56         }
57
58         if(units.size()<=n)
59                 units.resize(n+1);
60
61         if(cur_unit!=&units[n] && (cur_unit || n))
62                 glActiveTexture(GL_TEXTURE0+n);
63         cur_unit = &units[n];
64
65         return units[n];
66 }
67
68 TexUnit &TexUnit::current()
69 {
70         if(!cur_unit)
71                 return activate(0);
72         return *cur_unit;
73 }
74
75 } // namespace GL
76 } // namespace Msp