]> git.tdb.fi Git - libs/gl.git/blob - source/materials/unlitmaterial.cpp
Implement an unlit material type
[libs/gl.git] / source / materials / unlitmaterial.cpp
1 #include "unlitmaterial.h"
2
3 using namespace std;
4
5 namespace Msp {
6 namespace GL {
7
8 UnlitMaterial::UnlitMaterial():
9         texture(0),
10         vertex_color(false)
11 {
12         set_tint(Color(1.0f));
13 }
14
15 string UnlitMaterial::create_program_source() const
16 {
17         string source = "import unlit;\n";
18         if(texture)
19                 source += "const bool use_texture = true;\n";
20         if(vertex_color)
21                 source += "const bool use_vertex_color = true;\n";
22         return source;
23 }
24
25 void UnlitMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const
26 {
27         attach_texture_to(texture, texturing, tex_shdata, "texture");
28 }
29
30 void UnlitMaterial::set_texture(const Texture *tex)
31 {
32         texture = tex;
33 }
34
35 void UnlitMaterial::set_tint(const Color &t)
36 {
37         tint = t;
38         shdata.uniform("tint", tint);
39 }
40
41 void UnlitMaterial::set_vertex_color(bool vc)
42 {
43         vertex_color = vc;
44 }
45
46
47 DataFile::Loader::ActionMap UnlitMaterial::Loader::shared_actions;
48
49 UnlitMaterial::Loader::Loader(UnlitMaterial &m):
50         DerivedObjectLoader<UnlitMaterial, Material::PropertyLoader<UnlitMaterial> >(m)
51 {
52         set_actions(shared_actions);
53 }
54
55 UnlitMaterial::Loader::Loader(UnlitMaterial &m, Collection &c):
56         DerivedObjectLoader<UnlitMaterial, Material::PropertyLoader<UnlitMaterial> >(m, c)
57 {
58         set_actions(shared_actions);
59 }
60
61 void UnlitMaterial::Loader::init_actions()
62 {
63         Material::PropertyLoader<UnlitMaterial>::init_actions();
64         add("texture", &Loader::property_texture, &UnlitMaterial::set_texture);
65         add_property("tint", &UnlitMaterial::set_tint, 0, true);
66         add("vertex_color", &UnlitMaterial::vertex_color);
67 }
68
69 } // namespace GL
70 } // namespace Msp