Changeset 30
- Timestamp:
- 05/27/13 23:30:13 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/types.hh
r6 r30 6 6 #define NV_TYPES_HH 7 7 8 #include <glm/glm.hpp> 8 9 #include <nv/common.hh> 9 10 #include <utility> … … 13 14 namespace nv 14 15 { 16 enum type 17 { 18 FLOAT, 19 FLOAT_VECTOR_2, 20 FLOAT_VECTOR_3, 21 FLOAT_VECTOR_4, 22 FLOAT_MATRIX_2, 23 FLOAT_MATRIX_3, 24 FLOAT_MATRIX_4, 25 INT, 26 INT_VECTOR_2, 27 INT_VECTOR_3, 28 INT_VECTOR_4 29 }; 30 31 typedef glm::vec2 vec2; 32 typedef glm::vec3 vec3; 33 typedef glm::vec4 vec4; 34 35 typedef glm::ivec2 ivec2; 36 typedef glm::ivec3 ivec3; 37 typedef glm::ivec4 ivec4; 38 39 typedef glm::mat2 mat2; 40 typedef glm::mat3 mat3; 41 typedef glm::mat4 mat4; 42 43 template < type EnumType > struct enum_to_type {}; 44 45 template <> struct enum_to_type< FLOAT > { typedef f32 type; }; 46 template <> struct enum_to_type< INT > { typedef int type; }; 47 48 template <> struct enum_to_type< FLOAT_VECTOR_2 > { typedef vec2 type; }; 49 template <> struct enum_to_type< FLOAT_VECTOR_3 > { typedef vec3 type; }; 50 template <> struct enum_to_type< FLOAT_VECTOR_4 > { typedef vec4 type; }; 51 52 template <> struct enum_to_type< INT_VECTOR_2 > { typedef ivec2 type; }; 53 template <> struct enum_to_type< INT_VECTOR_3 > { typedef ivec3 type; }; 54 template <> struct enum_to_type< INT_VECTOR_4 > { typedef ivec4 type; }; 55 56 template <> struct enum_to_type< FLOAT_MATRIX_2 > { typedef mat2 type; }; 57 template <> struct enum_to_type< FLOAT_MATRIX_3 > { typedef mat3 type; }; 58 template <> struct enum_to_type< FLOAT_MATRIX_4 > { typedef mat4 type; }; 59 60 template < typename Type > struct type_to_enum {}; 61 62 template <> struct type_to_enum< f32 > { static const type type = FLOAT; }; 63 template <> struct type_to_enum< int > { static const type type = INT; }; 64 65 template <> struct type_to_enum< vec2 > { static const type type = FLOAT_VECTOR_2; }; 66 template <> struct type_to_enum< vec3 > { static const type type = FLOAT_VECTOR_3; }; 67 template <> struct type_to_enum< vec4 > { static const type type = FLOAT_VECTOR_4; }; 68 69 template <> struct type_to_enum< ivec2 > { static const type type = INT_VECTOR_2; }; 70 template <> struct type_to_enum< ivec3 > { static const type type = INT_VECTOR_3; }; 71 template <> struct type_to_enum< ivec4 > { static const type type = INT_VECTOR_4; }; 72 73 template <> struct type_to_enum< mat2 > { static const type type = FLOAT_MATRIX_2; }; 74 template <> struct type_to_enum< mat3 > { static const type type = FLOAT_MATRIX_3; }; 75 template <> struct type_to_enum< mat4 > { static const type type = FLOAT_MATRIX_4; }; 76 15 77 template <typename TYPE> 16 78 const char* get_type_name() … … 74 136 { 75 137 76 struct type 138 struct type_entry 77 139 { 78 140 // Function types for the constructor and destructor of registered types … … 98 160 public: 99 161 template< typename TYPE > 100 type & create_type()162 type_entry& create_type() 101 163 { 102 164 hash_string name( get_type_name<TYPE>() ); 103 type * i_type = nullptr;165 type_entry* i_type = nullptr; 104 166 type_map::iterator it = m_types.find( name ); 105 167 if ( it != m_types.end() ) … … 107 169 return *(it->second); 108 170 } 109 i_type = new type ;171 i_type = new type_entry; 110 172 i_type->type_db = this; 111 173 i_type->name = name; … … 118 180 return *i_type; 119 181 } 120 type * get_type( hash_string name )182 type_entry* get_type( hash_string name ) 121 183 { 122 184 type_map::iterator it = m_types.find( name ); … … 128 190 } 129 191 private: 130 typedef std::unordered_map<hash_string, type *> type_map;192 typedef std::unordered_map<hash_string, type_entry*> type_map; 131 193 type_map m_types; 132 194 };
Note: See TracChangeset
for help on using the changeset viewer.