Material.h
Go to the documentation of this file.
1 #ifndef B_MATERIAL_H
2 #define B_MATERIAL_H
3 
4 #include <memory>
5 
6 #include "Shader.h"
7 #include "Texture.h"
8 #include "MaterialData.h"
9 
10 class ObjectManager;
11 
15 class Material
16 {
17 public:
18  /* Typedefs */
19  typedef std::unordered_map<std::string, TexturePtr> TextureMap;
20  typedef std::unordered_map<std::string, vmml::Vector3f> Vector3Map;
21  typedef std::unordered_map<std::string, GLfloat> ScalarMap;
22 
23  /* Functions */
24 
27  Material() {}
28 
31  virtual ~Material() {}
32 
38  virtual void initialize(ObjectManager *o, const MaterialData &materialData, ShaderPtr shader);
39 
42  virtual void bind();
43 
46  const TextureMap &getTextures() { return _textures; }
47 
51  TexturePtr getTexture(const std::string &name) { return _textures[name]; }
52 
55  const Vector3Map &getVectors() { return _vectors; }
56 
60  vmml::Vector3f getVector(const std::string &name) { return _vectors[name]; }
61 
64  const ScalarMap &getScalars() { return _scalars; }
65 
69  GLfloat getScalar(const std::string &name) { return _scalars[name]; }
70 
74  void setTextures(const TextureMap &arg) { _textures = arg; }
75 
80  void setTexture(const std::string &name, TexturePtr arg) { _textures[name] = arg; }
81 
85  void setVectors(const Vector3Map& arg) { _vectors = arg; }
86 
91  void setVector(const std::string &name, const vmml::Vector3f &arg) { _vectors[name] = arg; }
92 
96  void setScalars(const ScalarMap &arg) { _scalars = arg; }
97 
102  void setScalar(const std::string &name, GLfloat arg) { _scalars[name] = arg; }
103 
106  ShaderPtr getShader() { return _shader; }
107 
111  void setShader(ShaderPtr arg) { _shader = arg; }
112 
115  const std::string &getName() { return _name; }
116 
120  void setName(const std::string &arg) { _name = arg; }
121 
122 private:
123 
124  /* Variables */
125 
126  TextureMap _textures;
127  Vector3Map _vectors;
128  ScalarMap _scalars;
129 
130  ShaderPtr _shader = nullptr;
131 
132  std::string _name;
133 };
134 
135 typedef std::shared_ptr< Material > MaterialPtr;
136 
137 #endif /* defined(B_MATERIAL_H) */
void setVector(const std::string &name, const vmml::Vector3f &arg)
Sets a vector for the material.
Definition: Material.h:91
void setShader(ShaderPtr arg)
Sets the shader of the material.
Definition: Material.h:111
const TextureMap & getTextures()
Returns the textures associated with the material.
Definition: Material.h:46
std::shared_ptr< Texture > TexturePtr
Definition: Texture.h:67
std::shared_ptr< Shader > ShaderPtr
Definition: Shader.h:211
virtual void bind()
Bind the shader and pass the attributes of the material.
Definition: Material.cpp:32
void setScalars(const ScalarMap &arg)
Sets all scalars for the material.
Definition: Material.h:96
Material()
Constructor.
Definition: Material.h:27
const ScalarMap & getScalars()
Returns the scalars associated with the material.
Definition: Material.h:64
const Vector3Map & getVectors()
Returns the vectors associated with the material.
Definition: Material.h:55
std::unordered_map< std::string, GLfloat > ScalarMap
Definition: Material.h:21
void setVectors(const Vector3Map &arg)
Sets all vectors for the material.
Definition: Material.h:85
GLfloat getScalar(const std::string &name)
Returns a scalar associated with the material.
Definition: Material.h:69
void setTextures(const TextureMap &arg)
Sets all textures for the material.
Definition: Material.h:74
A material is associated with textures and a shader to define the look of an object.
Definition: Material.h:15
const std::string & getName()
Returns the name of the material.
Definition: Material.h:115
std::unordered_map< std::string, vmml::Vector3f > Vector3Map
Definition: Material.h:20
void setName(const std::string &arg)
Sets the name of the material.
Definition: Material.h:120
TexturePtr getTexture(const std::string &name)
Returns a texture associated with the material.
Definition: Material.h:51
void setTexture(const std::string &name, TexturePtr arg)
Sets a texture for the material.
Definition: Material.h:80
virtual ~Material()
Virtual destructor.
Definition: Material.h:31
std::unordered_map< std::string, TexturePtr > TextureMap
Definition: Material.h:19
This class manages all objects in a project and makes sure no object is created twice.
Definition: ObjectManager.h:32
virtual void initialize(ObjectManager *o, const MaterialData &materialData, ShaderPtr shader)
Initializes the geometry object based on material data and a shader.
Definition: Material.cpp:5
vmml::Vector3f getVector(const std::string &name)
Returns a vector associated with the material.
Definition: Material.h:60
ShaderPtr getShader()
Returns the shader of the material.
Definition: Material.h:106
The underlying data of a material.
Definition: MaterialData.h:10
void setScalar(const std::string &name, GLfloat arg)
Sets a scalar for the material.
Definition: Material.h:102
std::shared_ptr< Material > MaterialPtr
Definition: Material.h:135