]> git.tdb.fi Git - libs/gl.git/blob - source/material.h
Create ProgramData for materials and lights
[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::ObjectLoader<Material>
20         {
21         public:
22                 Loader(Material &);
23
24         private:
25                 void ambient(float, float, float, float);
26                 void diffuse(float, float, float, float);
27                 void specular(float, float, float, float);
28                 void emission(float, float, float, float);
29                 void shininess(float);
30         };
31
32 private:
33         enum ParameterMask
34         {
35                 AMBIENT = 1,
36                 DIFFUSE = 2,
37                 SPECULAR = 4,
38                 EMISSION = 8,
39                 SHININESS = 16
40         };
41
42         Color ambient;
43         Color diffuse;
44         Color specular;
45         Color emission;
46         float shininess;
47         ProgramData shdata;
48
49 public:
50         Material();
51
52 private:
53         void update_parameter(int) const;
54
55 public:
56         void set_ambient(const Color &a);
57         void set_diffuse(const Color &d);
58         void set_specular(const Color &s);
59         void set_emission(const Color &e);
60         void set_shininess(float s);
61         const Color &get_ambient() const { return ambient; }
62         const Color &get_diffuse() const { return diffuse; }
63         const Color &get_specular() const { return specular; }
64         const Color &get_emission() const { return emission; }
65         float get_shininess() const { return shininess; }
66         const ProgramData &get_shader_data() const { return shdata; }
67         void bind() const;
68 };
69
70 } // namespace GL
71 } // namespace Msp
72
73 #endif