Sceneview
 All Classes Functions Variables Enumerations Enumerator Groups Pages
shader_uniform.hpp
1 // Copyright [2015] Albert Huang
2 
3 #ifndef SCENEVIEW_SHADER_UNIFORM_HPP__
4 #define SCENEVIEW_SHADER_UNIFORM_HPP__
5 
6 #include <vector>
7 #include <map>
8 
9 #include <QOpenGLShaderProgram>
10 
11 namespace sv {
12 
20  public:
21  enum class Type {
22  kInvalid,
23  kFloat,
24  kInt,
25  kMat4f
26  };
27 
28  ShaderUniform();
29 
30  explicit ShaderUniform(const QString& name);
31 
32  ShaderUniform(const ShaderUniform& other) = delete;
33 
34  ~ShaderUniform();
35 
36  void SetLocation(int location) { location_ = location; }
37 
38  int Location() const { return location_; }
39 
40  Type ParamType() const { return type_; }
41 
42  void Set(int val);
43 
44  void Set(const std::vector<int>& val);
45 
46  void Set(float val);
47 
48  void Set(const std::vector<float>& val);
49 
50  void Set(const QMatrix4x4& val);
51 
52  void LoadToProgram(QOpenGLShaderProgram* program);
53 
54  ShaderUniform& operator=(const ShaderUniform& other);
55 
56  private:
57  typedef std::vector<int> IntVec;
58  typedef std::vector<float> FloatVec;
59 
60  union Value {
61  IntVec int_data;
62  FloatVec float_data;
63  QMatrix4x4 mat4f;
64 
65  Value() {}
66  ~Value() {}
67  };
68 
69  void Clear();
70 
71  void CheckType(Type expected);
72 
73  QString name_;
74  Type type_;
75  int location_;
76  Value value_;
77 };
78 
79 typedef std::map<QString, ShaderUniform> ShaderUniformMap;
80 
81 } // namespace sv
82 
83 #endif // SCENEVIEW_SHADER_UNIFORM_HPP__
Stores the location, type, and value for a GLSL shader uniform variable.
Definition: shader_uniform.hpp:19