Properties.h
Go to the documentation of this file.
1 #ifndef B_PROPERTIES_H
2 #define B_PROPERTIES_H
3 
4 #include <memory>
5 #include <map>
6 #include "vmmlib/matrix.hpp"
7 
8 #include "Shader.h"
9 
18 {
19 public:
20  /* Typedefs */
21  // Since properties are likely to change every frame (transformation matrices) maps are used over unordered maps
22  typedef std::map<std::string, vmml::Matrix4f> Matrix4x4Map;
23  typedef std::map<std::string, vmml::Matrix3f> Matrix3x3Map;
24  typedef std::map<std::string, vmml::Vector4f> Vector4Map;
25  typedef std::map<std::string, vmml::Vector3f> Vector3Map;
26  typedef std::map<std::string, GLfloat> ScalarMap;
27 
28  /* Functions */
29 
32  virtual ~Properties() {}
33 
36  const Matrix4x4Map &getMatrices4x4() { return _matrices4x4; }
37 
41  vmml::Matrix4f getMatrix4x4(const std::string &name) { return _matrices4x4[name]; }
42 
45  const Matrix3x3Map &getMatrices3x3() { return _matrices3x3; }
46 
50  vmml::Matrix3f getMatrix3x3(const std::string &name) { return _matrices3x3[name]; }
51 
54  const Vector4Map &getVectors4() { return _vectors4; }
55 
59  vmml::Vector4f getVector4(const std::string &name) { return _vectors4[name]; }
60 
63  const Vector3Map &getVectors3() { return _vectors3; }
64 
68  vmml::Vector3f getVector3(const std::string &name) { return _vectors3[name]; }
69 
72  const ScalarMap &getScalars() { return _scalars; }
73 
77  GLfloat getScalar(const std::string &name) { return _scalars[name]; }
78 
82  void setMatrices4x4(const Matrix4x4Map& arg) { _matrices4x4 = arg; }
83 
88  void setMatrix(const std::string &name, const vmml::Matrix4f &arg) { _matrices4x4[name] = arg; }
89 
93  void setMatrices3x3(const Matrix3x3Map& arg) { _matrices3x3 = arg; }
94 
99  void setMatrix(const std::string &name, const vmml::Matrix3f &arg) { _matrices3x3[name] = arg; }
100 
104  void setVectors4(const Vector4Map& arg) { _vectors4 = arg; }
105 
110  void setVector(const std::string &name, const vmml::Vector4f &arg) { _vectors4[name] = arg; }
111 
115  void setVectors3(const Vector3Map& arg) { _vectors3 = arg; }
116 
121  void setVector(const std::string &name, const vmml::Vector3f &arg) { _vectors3[name] = arg; }
122 
126  void setScalars(const ScalarMap &arg) { _scalars = arg; }
127 
132  void setScalar(const std::string &name, GLfloat arg) { _scalars[name] = arg; }
133 
136  const std::string &getName() { return _name; }
137 
141  void setName(const std::string &arg) { _name = arg; }
142 
146  void passToShader(ShaderPtr shader)
147  {
148  shader->setUniforms(_matrices4x4);
149  shader->setUniforms(_matrices3x3);
150  shader->setUniforms(_vectors4);
151  shader->setUniforms(_vectors3);
152  shader->setUniforms(_scalars);
153  }
154 
157  void clear()
158  {
159  _matrices4x4.clear();
160  _matrices3x3.clear();
161  _vectors4.clear();
162  _vectors3.clear();
163  _scalars.clear();
164  }
165 
166 
167 private:
168 
169  /* Variables */
170  Matrix4x4Map _matrices4x4;
171  Matrix3x3Map _matrices3x3;
172  Vector4Map _vectors4;
173  Vector3Map _vectors3;
174  ScalarMap _scalars;
175 
176  std::string _name;
177 };
178 
179 typedef std::shared_ptr< Properties > PropertiesPtr;
180 
181 #endif /* defined(B_PROPERTIES_H) */
void setVectors4(const Vector4Map &arg)
Sets all 4x1 vectors.
Definition: Properties.h:104
std::map< std::string, vmml::Matrix4f > Matrix4x4Map
Definition: Properties.h:22
void setVector(const std::string &name, const vmml::Vector4f &arg)
Sets a 4x1 vector.
Definition: Properties.h:110
void clear()
Clear all properties.
Definition: Properties.h:157
void setMatrix(const std::string &name, const vmml::Matrix4f &arg)
Sets a 4x4 matrix.
Definition: Properties.h:88
std::shared_ptr< Shader > ShaderPtr
Definition: Shader.h:211
std::shared_ptr< Properties > PropertiesPtr
Definition: Properties.h:179
const Vector4Map & getVectors4()
Returns all 4x1 vectors.
Definition: Properties.h:54
GLfloat getScalar(const std::string &name)
Returns a scalar.
Definition: Properties.h:77
std::map< std::string, vmml::Vector3f > Vector3Map
Definition: Properties.h:25
void passToShader(ShaderPtr shader)
Pass properties to specified shader.
Definition: Properties.h:146
void setMatrix(const std::string &name, const vmml::Matrix3f &arg)
Sets a 3x3 matrix.
Definition: Properties.h:99
void setMatrices3x3(const Matrix3x3Map &arg)
Sets all 3x3 matrices.
Definition: Properties.h:93
std::map< std::string, vmml::Matrix3f > Matrix3x3Map
Definition: Properties.h:23
void setMatrices4x4(const Matrix4x4Map &arg)
Sets all 4x4 matrices.
Definition: Properties.h:82
const std::string & getName()
Returns the name of the properties.
Definition: Properties.h:136
virtual ~Properties()
Virtual destructor.
Definition: Properties.h:32
const Matrix3x3Map & getMatrices3x3()
Returns all 3x3 matrices.
Definition: Properties.h:45
const Vector3Map & getVectors3()
Returns all 3x1 vectors.
Definition: Properties.h:63
void setName(const std::string &arg)
Sets the name of the properties.
Definition: Properties.h:141
void setVector(const std::string &name, const vmml::Vector3f &arg)
Sets a 3x1 vector.
Definition: Properties.h:121
std::map< std::string, GLfloat > ScalarMap
Definition: Properties.h:26
void setVectors3(const Vector3Map &arg)
Sets all 3x1 vectors.
Definition: Properties.h:115
vmml::Vector4f getVector4(const std::string &name)
Returns a 4x1 vector.
Definition: Properties.h:59
void setScalar(const std::string &name, GLfloat arg)
Sets a scalar.
Definition: Properties.h:132
void setScalars(const ScalarMap &arg)
Sets all scalars.
Definition: Properties.h:126
vmml::Vector3f getVector3(const std::string &name)
Returns a 3x1 vector.
Definition: Properties.h:68
std::map< std::string, vmml::Vector4f > Vector4Map
Definition: Properties.h:24
A properties object caches data to pass to a shader (such as matrices, vectors and scalars) and can b...
Definition: Properties.h:17
const ScalarMap & getScalars()
Returns all scalars.
Definition: Properties.h:72
const Matrix4x4Map & getMatrices4x4()
Returns all 4x4 matrices.
Definition: Properties.h:36
vmml::Matrix4f getMatrix4x4(const std::string &name)
Returns a 4x4 matrix.
Definition: Properties.h:41
vmml::Matrix3f getMatrix3x3(const std::string &name)
Returns a 3x3 matrix.
Definition: Properties.h:50