Sceneview
 All Classes Functions Variables Enumerations Enumerator Groups Pages
shader_resource.hpp
1 // Copyright [2015] Albert Huang
2 
3 #ifndef SCENEVIEW_SHADER_RESOURCE_HPP__
4 #define SCENEVIEW_SHADER_RESOURCE_HPP__
5 
6 #include <memory>
7 #include <vector>
8 
9 #include <QOpenGLShaderProgram>
10 
11 namespace sv {
12 
13 extern int kShaderMaxLights;
14 
22  int is_directional;
23  int position;
24  int direction;
25  int color;
26  int ambient;
27  int specular;
28  int attenuation;
29  int cone_angle;
30 };
31 
41  // ============ Uniform variables
42  // Automatically populated based on the scene graph structure
43 
49 
55 
61 
67 
74 
80  int sv_mv_mat;
81 
88 
89  // Lights
90  std::vector<ShaderLightLocation> sv_lights;
91 
92  // ============== Per-vertex attributes
93  // Automatically populated based on the object geometry
94 
99 
104 
109 
114 
119 
124 
129 };
130 
141  public:
142  typedef std::shared_ptr<ShaderResource> Ptr;
143 
144  const QString Name() const { return name_; }
145 
153  void LoadFromFiles(const QString& prefix);
154 
165  void LoadFromFiles(const QString& prefix, const QString& preamble);
166 
167  QOpenGLShaderProgram* Program() { return program_.get(); }
168 
169  const ShaderStandardVariables& StandardVariables() const;
170 
171  private:
172  friend class ResourceManager;
173 
174  explicit ShaderResource(const QString& name);
175 
176  void LoadLocations();
177 
178  QString name_;
179 
180  std::unique_ptr<QOpenGLShaderProgram> program_;
181 
182  ShaderStandardVariables locations_;
183 };
184 
185 } // namespace sv
186 
187 #endif // SCENEVIEW_SHADER_RESOURCE_HPP__
void LoadFromFiles(const QString &prefix)
Loads a vertex shader and fragment shader into this resource.
int sv_model_mat
Model matrix.
Definition: shader_resource.hpp:66
int sv_tex_coords_0
Texture coordinates set 0.
Definition: shader_resource.hpp:128
int sv_model_normal_mat
Model normal matrix.
Definition: shader_resource.hpp:87
int sv_mv_mat
Model-view matrix.
Definition: shader_resource.hpp:80
An OpenGL shader program.
Definition: shader_resource.hpp:140
int sv_ambient
Per-vertex ambient color.
Definition: shader_resource.hpp:113
int sv_proj_mat
Projection matrix.
Definition: shader_resource.hpp:48
int sv_specular
Per-vertex specular color.
Definition: shader_resource.hpp:118
Holds the GLSL locations of light parameters in a shader program.
Definition: shader_resource.hpp:21
int sv_normal
Vertex normal vector.
Definition: shader_resource.hpp:103
int sv_vert_pos
Vertex position.
Definition: shader_resource.hpp:98
int sv_view_mat
View matrix.
Definition: shader_resource.hpp:54
int sv_mvp_mat
Model-view-projection matrix.
Definition: shader_resource.hpp:73
Holds the GLSL locations of shader variables.
Definition: shader_resource.hpp:40
Central repository for resources.
Definition: resource_manager.hpp:36
int sv_view_mat_inv
View matrix inverse.
Definition: shader_resource.hpp:60
int sv_diffuse
Per-vertex diffuse color.
Definition: shader_resource.hpp:108
int sv_shininess
Per-vertex shininess.
Definition: shader_resource.hpp:123