Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
uniform_manager.h
1 #pragma once
2 
3 #include <functional>
4 #include <unordered_map>
5 #include <string>
6 #include <stdexcept>
7 
8 namespace smlt {
9 
10 /*
11  Automatic uniforms that are set by the renderer
12 */
13 enum ShaderAvailableAuto {
14  SP_AUTO_MODELVIEW_PROJECTION_MATRIX,
15  SP_AUTO_VIEW_MATRIX,
16  SP_AUTO_MODELVIEW_MATRIX,
17  SP_AUTO_PROJECTION_MATRIX,
18  SP_AUTO_INVERSE_TRANSPOSE_MODELVIEW_MATRIX,
19  SP_AUTO_MATERIAL_DIFFUSE,
20  SP_AUTO_MATERIAL_SPECULAR,
21  SP_AUTO_MATERIAL_AMBIENT,
22  SP_AUTO_MATERIAL_SHININESS,
23  SP_AUTO_MATERIAL_TEX_MATRIX0,
24  SP_AUTO_MATERIAL_TEX_MATRIX1,
25  SP_AUTO_MATERIAL_TEX_MATRIX2,
26  SP_AUTO_MATERIAL_TEX_MATRIX3,
27  SP_AUTO_MATERIAL_TEX_MATRIX4,
28  SP_AUTO_MATERIAL_TEX_MATRIX5,
29  SP_AUTO_MATERIAL_TEX_MATRIX6,
30  SP_AUTO_MATERIAL_TEX_MATRIX7,
31  SP_AUTO_MATERIAL_ACTIVE_TEXTURE_UNITS,
32  SP_AUTO_MATERIAL_POINT_SIZE,
33  SP_AUTO_LIGHT_GLOBAL_AMBIENT,
34  SP_AUTO_LIGHT_POSITION,
35  SP_AUTO_LIGHT_DIRECTION,
36  SP_AUTO_LIGHT_DIFFUSE,
37  SP_AUTO_LIGHT_SPECULAR,
38  SP_AUTO_LIGHT_AMBIENT,
39  SP_AUTO_LIGHT_CONSTANT_ATTENUATION,
40  SP_AUTO_LIGHT_LINEAR_ATTENUATION,
41  SP_AUTO_LIGHT_QUADRATIC_ATTENUATION,
42 
43  /* Arrays */
44  SP_AUTO_LIGHTS_GLOBAL_AMBIENT,
45  SP_AUTO_LIGHTS_POSITION,
46  SP_AUTO_LIGHTS_DIRECTION,
47  SP_AUTO_LIGHTS_DIFFUSE,
48  SP_AUTO_LIGHTS_SPECULAR,
49  SP_AUTO_LIGHTS_AMBIENT,
50  SP_AUTO_LIGHTS_CONSTANT_ATTENUATION,
51  SP_AUTO_LIGHTS_LINEAR_ATTENUATION,
52  SP_AUTO_LIGHTS_QUADRATIC_ATTENUATION,
53  SP_AUTO_LIGHT_COUNT
54  //TODO: cameras(?)
55 };
56 
57 }
58 
59 namespace std {
60  using smlt::ShaderAvailableAuto;
61 
62  template<>
63  struct hash<ShaderAvailableAuto> {
64  size_t operator()(const ShaderAvailableAuto& a) const {
65  hash<int32_t> make_hash;
66  return make_hash(int32_t(a));
67  }
68  };
69 }
70 
71 namespace smlt {
72 
74 public:
75  bool uses_auto(ShaderAvailableAuto uniform) const {
76  return auto_uniforms_.find(uniform) != auto_uniforms_.end();
77  }
78 
79  std::string auto_variable_name(ShaderAvailableAuto auto_name) const {
80  auto it = auto_uniforms_.find(auto_name);
81  if(it == auto_uniforms_.end()) {
82  throw std::logic_error("Specified auto is not registered");
83  }
84 
85  return (*it).second;
86  }
87 
88  void register_auto(ShaderAvailableAuto uniform, const std::string& var_name);
89  const std::unordered_map<ShaderAvailableAuto, std::string>& auto_uniforms() const {
90  return auto_uniforms_;
91  }
92 
93 private:
94  std::unordered_map<ShaderAvailableAuto, std::string> auto_uniforms_;
95 };
96 
97 
98 }
99 
100 
smlt
Definition: animation.cpp:25
std
Extensions to the C++ standard library.
Definition: unique_id.h:200
smlt::UniformManager
Definition: uniform_manager.h:73