Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
attribute_manager.h
1 #pragma once
2 
3 #include <functional>
4 #include <unordered_map>
5 
6 #include "../vertex_data.h"
7 
8 namespace smlt {
9 
10 enum ShaderAvailableAttributes {
11  SP_ATTR_VERTEX_POSITION,
12  SP_ATTR_VERTEX_NORMAL,
13  SP_ATTR_VERTEX_TEXCOORD0,
14  SP_ATTR_VERTEX_TEXCOORD1,
15  SP_ATTR_VERTEX_TEXCOORD2,
16  SP_ATTR_VERTEX_TEXCOORD3,
17  SP_ATTR_VERTEX_DIFFUSE,
18  SP_ATTR_VERTEX_SPECULAR
19 };
20 
21 VertexAttributeType convert(ShaderAvailableAttributes attr);
22 
23 }
24 
25 namespace std {
26  using smlt::ShaderAvailableAttributes;
27 
28  template<>
29  struct hash<ShaderAvailableAttributes> {
30  size_t operator()(const ShaderAvailableAttributes& a) const {
31  hash<int32_t> make_hash;
32  return make_hash(int32_t(a));
33  }
34  };
35 
36 }
37 
38 namespace smlt {
39 
41 public:
42  void register_auto(ShaderAvailableAttributes attr, const std::string &var_name);
43 
44  std::string variable_name(ShaderAvailableAttributes attr_name) const {
45  auto it = auto_attributes_.find(attr_name);
46  if(it == auto_attributes_.end()) {
47  throw std::logic_error("Specified attribute is not registered");
48  }
49 
50  return (*it).second;
51  }
52 
53  bool uses_auto(ShaderAvailableAttributes attr) const {
54  return auto_attributes_.find(attr) != auto_attributes_.end();
55  }
56 
57  const std::unordered_map<ShaderAvailableAttributes, std::string>& auto_attributes() const {
58  return auto_attributes_;
59  }
60 
61 private:
62  std::unordered_map<ShaderAvailableAttributes, std::string> auto_attributes_;
63 };
64 
65 }
66 
67 
smlt
Definition: animation.cpp:25
smlt::AttributeManager
Definition: attribute_manager.h:40
std
Extensions to the C++ standard library.
Definition: unique_id.h:200