]> git.tdb.fi Git - libs/gl.git/blob - source/texunit.cpp
Use RAII checks for extensions and versions
[libs/gl.git] / source / texunit.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007  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 TexUnit::TexUnit():
19         texture(0)
20 {
21 }
22
23 bool TexUnit::set_texture(const Texture *tex)
24 {
25         bool result=(tex!=texture);
26         texture=tex;
27         return result;
28 }
29
30 TexUnit &TexUnit::activate(unsigned n)
31 {
32         if(units.size()<=n)
33                 units.resize(n+1);
34
35         if(cur_unit!=&units[n] && (cur_unit || n))
36         {
37                 static RequireVersion _ver(1, 3);
38                 glActiveTexture(GL_TEXTURE0+n);
39         }
40         cur_unit=&units[n];
41
42         return units[n];
43 }
44
45 TexUnit &TexUnit::current()
46 {
47         if(!cur_unit)
48                 return activate(0);
49         return *cur_unit;
50 }
51
52 vector<TexUnit> TexUnit::units;
53 TexUnit *TexUnit::cur_unit=0;
54
55 } // namespace GL
56 } // namespace Msp