]> git.tdb.fi Git - libs/gl.git/blob - source/material.h
Better state tracking for bound objects
[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
8 namespace Msp {
9 namespace GL {
10
11 /**
12 Stores OpenGL material properties.  Since OpenGL does not support material
13 objects, application of material is done with several calls to glMaterial.
14 */
15 class Material: public BindableWithDefault<Material>
16 {
17 public:
18         class Loader: public DataFile::ObjectLoader<Material>
19         {
20         public:
21                 Loader(Material &);
22         
23         private:
24                 void ambient(float, float, float, float);
25                 void diffuse(float, float, float, float);
26                 void specular(float, float, float, float);
27                 void emission(float, float, float, float);
28         };
29
30 private:
31         enum ParameterMask
32         {
33                 AMBIENT = 1,
34                 DIFFUSE = 2,
35                 SPECULAR = 4,
36                 EMISSION = 8,
37                 SHININESS = 16
38         };
39
40         Color ambient;
41         Color diffuse;
42         Color specular;
43         Color emission;
44         float shininess;
45
46 public:
47         Material();
48
49 private:
50         void update_parameter(int) const;
51
52 public:
53         void set_ambient(const Color &a);
54         void set_diffuse(const Color &d);
55         void set_specular(const Color &s);
56         void set_emission(const Color &e);
57         void set_shininess(float s);
58         const Color &get_ambient() const { return ambient; }
59         const Color &get_diffuse() const { return diffuse; }
60         const Color &get_specular() const { return specular; }
61         const Color &get_emission() const { return emission; }
62         float get_shininess() const { return shininess; }
63         void bind() const;
64 };
65
66 } // namespace GL
67 } // namespace Msp
68
69 #endif