]> git.tdb.fi Git - libs/gl.git/blob - source/materials/unlitmaterial.cpp
Use specialization constants in the builtin material shaders
[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 void UnlitMaterial::fill_program_info(string &module_name, map<string, int> &spec_values) const
16 {
17         module_name = "unlit.glsl";
18         spec_values["use_texture"] = (texture!=0);
19         spec_values["use_vertex_color"] = vertex_color;
20 }
21
22 void UnlitMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const
23 {
24         attach_texture_to(texture, texturing, tex_shdata, "texture");
25 }
26
27 void UnlitMaterial::set_texture(const Texture *tex)
28 {
29         texture = tex;
30 }
31
32 void UnlitMaterial::set_tint(const Color &t)
33 {
34         tint = t;
35         shdata.uniform("tint", tint);
36 }
37
38 void UnlitMaterial::set_vertex_color(bool vc)
39 {
40         vertex_color = vc;
41 }
42
43
44 DataFile::Loader::ActionMap UnlitMaterial::Loader::shared_actions;
45
46 UnlitMaterial::Loader::Loader(UnlitMaterial &m):
47         DerivedObjectLoader<UnlitMaterial, Material::PropertyLoader<UnlitMaterial> >(m)
48 {
49         set_actions(shared_actions);
50 }
51
52 UnlitMaterial::Loader::Loader(UnlitMaterial &m, Collection &c):
53         DerivedObjectLoader<UnlitMaterial, Material::PropertyLoader<UnlitMaterial> >(m, c)
54 {
55         set_actions(shared_actions);
56 }
57
58 void UnlitMaterial::Loader::init_actions()
59 {
60         Material::PropertyLoader<UnlitMaterial>::init_actions();
61         add("texture", &Loader::property_texture, &UnlitMaterial::set_texture);
62         add_property("tint", &UnlitMaterial::set_tint, 0, true);
63         add("vertex_color", &UnlitMaterial::vertex_color);
64 }
65
66 } // namespace GL
67 } // namespace Msp