]> git.tdb.fi Git - libs/gl.git/blob - source/material.h
Move the reflectivity parameter to material
[libs/gl.git] / source / material.h
1 #ifndef MSP_GL_MATERIAL_H_
2 #define MSP_GL_MATERIAL_H_
3
4 #include <msp/datafile/objectloader.h>
5 #include "bindable.h"
6 #include "color.h"
7 #include "programdata.h"
8
9 namespace Msp {
10 namespace GL {
11
12 /**
13 Stores OpenGL material properties.  Since OpenGL does not support material
14 objects, application of material is done with several calls to glMaterial.
15 */
16 class Material: public BindableWithDefault<Material>
17 {
18 public:
19         class Loader: public DataFile::CollectionObjectLoader<Material>
20         {
21         private:
22                 bool srgb;
23
24         public:
25                 Loader(Material &);
26                 Loader(Material &, Collection &);
27         private:
28                 void init();
29
30                 Color make_color(float, float, float, float);
31                 void ambient(float, float, float, float);
32                 void diffuse(float, float, float, float);
33                 void specular(float, float, float, float);
34                 void emission(float, float, float, float);
35                 void shininess(float);
36                 void reflectivity(float);
37         };
38
39 private:
40         enum ParameterMask
41         {
42                 AMBIENT = 1,
43                 DIFFUSE = 2,
44                 SPECULAR = 4,
45                 EMISSION = 8,
46                 SHININESS = 16
47         };
48
49         Color ambient;
50         Color diffuse;
51         Color specular;
52         Color emission;
53         float shininess;
54         float reflectivity;
55         ProgramData shdata;
56
57 public:
58         Material();
59
60 private:
61         void update_parameter(int) const;
62
63 public:
64         void set_ambient(const Color &a);
65         void set_diffuse(const Color &d);
66         void set_specular(const Color &s);
67         void set_emission(const Color &e);
68         void set_shininess(float s);
69         void set_reflectivity(float);
70         const Color &get_ambient() const { return ambient; }
71         const Color &get_diffuse() const { return diffuse; }
72         const Color &get_specular() const { return specular; }
73         const Color &get_emission() const { return emission; }
74         float get_shininess() const { return shininess; }
75         float get_reflectivity() const { return reflectivity; }
76         const ProgramData &get_shader_data() const { return shdata; }
77         void bind() const;
78 };
79
80 } // namespace GL
81 } // namespace Msp
82
83 #endif