]> git.tdb.fi Git - libs/gl.git/blob - source/texenv.cpp
51adf9fb4aee45f1aa40e93effbad084e3c3b4d4
[libs/gl.git] / source / texenv.cpp
1 #include "texenv.h"
2 #include "texunit.h"
3
4 namespace Msp {
5 namespace GL {
6
7 TexEnv::TexEnv():
8         mode(MODULATE),
9         color(0, 0, 0, 0)
10 { }
11
12 const TexEnv &TexEnv::default_object()
13 {
14         static TexEnv obj;
15         return obj;
16 }
17
18 void TexEnv::update_parameter(int mask) const
19 {
20         if(TexUnit::current().get_texenv()!=this)
21         {
22                 TexUnit *unit = TexUnit::find_unit(this);
23                 if(!unit)
24                         return;
25
26                 unit->bind();
27         }
28
29         if(mask&MODE)
30                 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode);
31         if(mask&COLOR)
32                 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &color.r);
33 }
34
35 void TexEnv::set_mode(TexEnvMode m)
36 {
37         mode = m;
38         update_parameter(MODE);
39 }
40
41 void TexEnv::set_color(const Color &c)
42 {
43         color = c;
44         update_parameter(COLOR);
45 }
46
47 void TexEnv::bind_to(unsigned i) const
48 {
49         TexUnit &unit = TexUnit::get_unit(i);
50         if(unit.set_texenv(this))
51         {
52                 unit.bind();
53                 update_parameter(-1);
54         }
55 }
56
57 const TexEnv *TexEnv::current(unsigned i)
58 {
59         return TexUnit::get_unit(i).get_texenv();
60 }
61
62 void TexEnv::unbind_from(unsigned i)
63 {
64         default_object().bind_to(i);
65 }
66
67 } // namespace GL
68 } // namespace Msp