]> git.tdb.fi Git - libs/gl.git/blob - source/material.h
Remove support for legacy OpenGL features
[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 basic material properties.  This includes color and reflection
14 parameters, but does not include texturing.  Materials interact with light
15 soucres and ambient lighting to produce the base color of a surface.  Textures
16 can be used to add detail.
17
18 Material provides a set of uniform variables for use with shaders.
19 */
20 class Material
21 {
22 public:
23         class Loader: public DataFile::CollectionObjectLoader<Material>
24         {
25         private:
26                 bool srgb;
27
28         public:
29                 Loader(Material &);
30                 Loader(Material &, Collection &);
31         private:
32                 void init();
33
34                 Color make_color(float, float, float, float);
35                 void ambient(float, float, float, float);
36                 void diffuse(float, float, float, float);
37                 void specular(float, float, float, float);
38                 void emission(float, float, float, float);
39                 void shininess(float);
40                 void reflectivity(float);
41         };
42
43 private:
44         Color ambient;
45         Color diffuse;
46         Color specular;
47         Color emission;
48         float shininess;
49         float reflectivity;
50         ProgramData shdata;
51
52 public:
53         Material();
54
55         /** Sets the ambient color of the material.  Provided to shaders with the
56         name material.ambient. */
57         void set_ambient(const Color &);
58
59         /** Sets the diffuse (direction-independent) color of the material.
60         Provided to shaders with the name material.diffuse. */
61         void set_diffuse(const Color &);
62
63         /** Sets the specular (direction-dependent) color of the material.  Provided
64         to shaders with the name material.specular. */
65         void set_specular(const Color &);
66         void set_emission(const Color &);
67
68         /** Sets the specular exponent of the material.  Provided to shaders with
69         the name material.shininess. */
70         void set_shininess(float);
71
72         /** Sets the reflectivity of the material.  Provided to shaders with the
73         name reflectivity.  Has no effect when shaders are not used. */
74         void set_reflectivity(float);
75
76         const Color &get_ambient() const { return ambient; }
77         const Color &get_diffuse() const { return diffuse; }
78         const Color &get_specular() const { return specular; }
79         const Color &get_emission() const { return emission; }
80         float get_shininess() const { return shininess; }
81         float get_reflectivity() const { return reflectivity; }
82
83         /** Returns the uniforms for the material. */
84         const ProgramData &get_shader_data() const { return shdata; }
85 };
86
87 } // namespace GL
88 } // namespace Msp
89
90 #endif