Sceneview
 All Classes Functions Variables Enumerations Enumerator Groups Pages
material_resource.hpp
1 // Copyright [2015] Albert Huang
2 
3 #ifndef SCENEVIEW_MATERIAL_RESOURCE_HPP__
4 #define SCENEVIEW_MATERIAL_RESOURCE_HPP__
5 
6 #include <map>
7 #include <memory>
8 #include <utility>
9 #include <vector>
10 
11 #include <sceneview/shader_resource.hpp>
12 #include <sceneview/geometry_resource.hpp>
13 #include <sceneview/shader_uniform.hpp>
14 
15 class QOpenGLTexture;
16 
17 namespace sv {
18 
35  public:
36  typedef std::shared_ptr<MaterialResource> Ptr;
37 
38  typedef std::shared_ptr<QOpenGLTexture> TexturePtr;
39 
40  typedef std::map<QString, TexturePtr> TextureDictionary;
41 
42  typedef std::map<QString, TexturePtr> Textures;
43 
44  const ShaderResource::Ptr& Shader() { return shader_; }
45 
46  ShaderUniformMap& ShaderParameters() { return shader_parameters_; }
47 
48  void SetParam(const QString& name, int val);
49 
50  void SetParam(const QString& name, const std::vector<int>& val);
51 
52  void SetParam(const QString& name, float val);
53 
54  void SetParam(const QString& name,
55  float val1, float val2);
56 
57  void SetParam(const QString& name,
58  float val1, float val2, float val3);
59 
60  void SetParam(const QString& name,
61  float val1, float val2, float val3, float val4);
62 
63  void SetParam(const QString& name, const std::vector<float>& val);
64 
65  void SetParam(const QString& name, const QMatrix4x4& value);
66 
67  void AddTexture(const QString& name, const TexturePtr& texture);
68 
69  const TextureDictionary& GetTextures() { return textures_; }
70 
74  void SetTwoSided(bool two_sided);
75 
76  bool TwoSided() const { return two_sided_; }
77 
78  void SetDepthWrite(bool val) { depth_write_ = val; }
79 
80  bool DepthWrite() const { return depth_write_; }
81 
82  void SetDepthTest(bool val) { depth_test_ = val; }
83 
84  bool DepthTest() const { return depth_test_; }
85 
86  void SetDepthFunc(GLenum func) { depth_func_ = func; }
87 
88  GLenum DepthFunc() const { return depth_func_; }
89 
90  void SetColorWrite(bool val) { color_write_ = val; }
91 
92  bool ColorWrite() const { return color_write_; }
93 
94  void SetPointSize(float size) { point_size_ = size; }
95 
96  float PointSize() const { return point_size_; }
97 
98  void SetLineWidth(float line_width) { line_width_ = line_width; }
99 
100  float LineWidth() const { return line_width_; }
101 
108  void SetBlend(bool value) { blend_ = value; }
109 
113  bool Blend() const { return blend_; }
114 
115  void SetBlendFunc(GLenum sfactor, GLenum dfactor) {
116  blend_sfactor_ = sfactor;
117  blend_dfactor_ = dfactor;
118  }
119 
120  void BlendFunc(GLenum* sfactor, GLenum* dfactor) {
121  *sfactor = blend_sfactor_;
122  *dfactor = blend_dfactor_;
123  }
124 
125  private:
126  friend class ResourceManager;
127 
128  MaterialResource(const QString& name, ShaderResource::Ptr shader);
129 
130  const QString name_;
131 
132  ShaderResource::Ptr shader_;
133 
134  ShaderUniformMap shader_parameters_;
135 
136  bool two_sided_ = false;
137 
138  bool depth_write_ = true;
139 
140  bool depth_test_ = true;
141 
142  GLenum depth_func_ = GL_LESS;
143 
144  bool color_write_ = true;
145 
146  float point_size_ = 1;
147 
148  float line_width_ = 1;
149 
150  bool blend_ = false;
151 
152  GLenum blend_sfactor_ = GL_ONE;
153 
154  GLenum blend_dfactor_ = GL_ZERO;
155 
156  TextureDictionary textures_;
157 };
158 
159 } // namespace sv
160 
161 #endif // SCENEVIEW_MATERIAL_RESOURCE_HPP__
Controls the appearance of a Drawable.
Definition: material_resource.hpp:34
void SetTwoSided(bool two_sided)
Sets whether or not to draw back-facing polygons.
void SetBlend(bool value)
Controls GL_BLEND.
Definition: material_resource.hpp:108
bool Blend() const
Retrieve whether GL_BLEND should be enabled or disabled.
Definition: material_resource.hpp:113