]> git.tdb.fi Git - libs/gl.git/blob - source/material.h
Support linear to sRGB conversion when loading materials and textures
[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         };
37
38 private:
39         enum ParameterMask
40         {
41                 AMBIENT = 1,
42                 DIFFUSE = 2,
43                 SPECULAR = 4,
44                 EMISSION = 8,
45                 SHININESS = 16
46         };
47
48         Color ambient;
49         Color diffuse;
50         Color specular;
51         Color emission;
52         float shininess;
53         ProgramData shdata;
54
55 public:
56         Material();
57
58 private:
59         void update_parameter(int) const;
60
61 public:
62         void set_ambient(const Color &a);
63         void set_diffuse(const Color &d);
64         void set_specular(const Color &s);
65         void set_emission(const Color &e);
66         void set_shininess(float s);
67         const Color &get_ambient() const { return ambient; }
68         const Color &get_diffuse() const { return diffuse; }
69         const Color &get_specular() const { return specular; }
70         const Color &get_emission() const { return emission; }
71         float get_shininess() const { return shininess; }
72         const ProgramData &get_shader_data() const { return shdata; }
73         void bind() const;
74 };
75
76 } // namespace GL
77 } // namespace Msp
78
79 #endif