]> git.tdb.fi Git - libs/gl.git/blob - source/texunit.cpp
Object model for Material and TexEnv
[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 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 bool TexUnit::set_texenv(const TexEnv *env)
31 {
32         bool result=(texenv!=env);
33         texenv=env;
34         return result;
35 }
36
37 TexUnit &TexUnit::activate(unsigned n)
38 {
39         if(units.size()<=n)
40                 units.resize(n+1);
41
42         if(cur_unit!=&units[n] && (cur_unit || n))
43         {
44                 static RequireVersion _ver(1, 3);
45                 glActiveTexture(GL_TEXTURE0+n);
46         }
47         cur_unit=&units[n];
48
49         return units[n];
50 }
51
52 TexUnit &TexUnit::current()
53 {
54         if(!cur_unit)
55                 return activate(0);
56         return *cur_unit;
57 }
58
59 vector<TexUnit> TexUnit::units;
60 TexUnit *TexUnit::cur_unit=0;
61
62 } // namespace GL
63 } // namespace Msp