]> git.tdb.fi Git - libs/gl.git/blob - source/texgen.cpp
Get all blocks for the program before applying them
[libs/gl.git] / source / texgen.cpp
1 #include <stdexcept>
2 #include "misc.h"
3 #include "texgen.h"
4 #include "texunit.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace GL {
10
11 TexGen::TexGen():
12         mode(EYE_LINEAR)
13 { }
14
15 void TexGen::set_mode(TexGenMode m)
16 {
17         mode = m;
18 }
19
20 void TexGen::set_plane(const Vector4 &p)
21 {
22         plane = p;
23 }
24
25 void TexGen::bind_to(TexCoordComponent c) const
26 {
27         if(TexUnit::current().set_texgen(coord_index(c), this))
28         {
29                 glTexGeni(c, GL_TEXTURE_GEN_MODE, mode);
30                 if(mode==EYE_LINEAR)
31                         glTexGenfv(c, GL_EYE_PLANE, &plane.x);
32                 else if(mode==OBJECT_LINEAR)
33                         glTexGenfv(c, GL_OBJECT_PLANE, &plane.x);
34                 enable(GL_TEXTURE_GEN_S+coord_index(c));
35         }
36 }
37
38 const TexGen *TexGen::current(TexCoordComponent c)
39 {
40         return TexUnit::current().get_texgen(coord_index(c));
41 }
42
43 void TexGen::unbind_from(TexCoordComponent c)
44 {
45         if(TexUnit::current().set_texgen(coord_index(c), 0))
46                 disable(GL_TEXTURE_GEN_S+coord_index(c));
47 }
48
49 unsigned TexGen::coord_index(TexCoordComponent c)
50 {
51         switch(c)
52         {
53         case SCOORD: return 0;
54         case TCOORD: return 1;
55         case RCOORD: return 2;
56         case QCOORD: return 3;
57         default: throw invalid_argument("TexGen::coord_index");
58         }
59 }
60
61 } // namespace GL
62 } // namespace Msp