]> git.tdb.fi Git - libs/gl.git/blob - source/texenv.cpp
Add a Texturing class to encapsulate the state of multiple texturing units
[libs/gl.git] / source / texenv.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2008  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "texenv.h"
9 #include "texunit.h"
10
11 namespace Msp {
12 namespace GL {
13
14 TexEnv::TexEnv():
15         mode(MODULATE)
16 { }
17
18 void TexEnv::set_mode(TexEnvMode m)
19 {
20         mode = m;
21         if(current()==this)
22                 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode);
23 }
24
25 void TexEnv::set_color(const Color &c)
26 {
27         color = c;
28         if(current()==this)
29                 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &color.r);
30 }
31
32 void TexEnv::bind() const
33 {
34         if(TexUnit::current().set_texenv(this))
35         {
36                 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode);
37                 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &color.r);
38         }
39 }
40
41 void TexEnv::unbind()
42 {
43         if(TexUnit::current().set_texenv(0))
44         {
45                 Color black(0, 0, 0, 0);
46                 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, MODULATE);
47                 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &black.r);
48         }
49 }
50
51 } // namespace GL
52 } // namespace Msp