]> git.tdb.fi Git - libs/gl.git/blob - source/materials/unlitmaterial.cpp
21f2b2f3037ed2a1a1eef0f194041727e55fcaf7
[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 const Tag UnlitMaterial::texture_tags[] =
9 {
10         Tag("color_tex"),
11         Tag()
12 };
13
14 UnlitMaterial::UnlitMaterial():
15         texture(0),
16         vertex_color(false)
17 {
18         set_color(Color(1.0f));
19 }
20
21 void UnlitMaterial::fill_program_info(string &module_name, map<string, int> &spec_values) const
22 {
23         module_name = "unlit.glsl";
24         spec_values["use_texture"] = (texture!=0);
25         spec_values["use_vertex_color"] = vertex_color;
26 }
27
28 const Texture *UnlitMaterial::get_texture(Tag tag) const
29 {
30         if(tag==texture_tags[0])
31                 return texture;
32         else
33                 return 0;
34 }
35
36 void UnlitMaterial::set_texture(const Texture *tex)
37 {
38         texture = tex;
39 }
40
41 void UnlitMaterial::set_color(const Color &c)
42 {
43         color = c;
44         shdata.uniform("unlit_material.color", color);
45 }
46
47 void UnlitMaterial::set_vertex_color(bool vc)
48 {
49         vertex_color = vc;
50 }
51
52
53 DataFile::Loader::ActionMap UnlitMaterial::Loader::shared_actions;
54
55 UnlitMaterial::Loader::Loader(UnlitMaterial &m):
56         DerivedObjectLoader<UnlitMaterial, Material::PropertyLoader<UnlitMaterial> >(m)
57 {
58         set_actions(shared_actions);
59 }
60
61 UnlitMaterial::Loader::Loader(UnlitMaterial &m, Collection &c):
62         DerivedObjectLoader<UnlitMaterial, Material::PropertyLoader<UnlitMaterial> >(m, c)
63 {
64         set_actions(shared_actions);
65 }
66
67 void UnlitMaterial::Loader::init_actions()
68 {
69         Material::PropertyLoader<UnlitMaterial>::init_actions();
70         add("texture", &Loader::property_texture, &UnlitMaterial::set_texture);
71         add_property("color", &UnlitMaterial::set_color, 0, true);
72         add("vertex_color", &UnlitMaterial::vertex_color);
73 }
74
75 } // namespace GL
76 } // namespace Msp