Changeset 30


Ignore:
Timestamp:
05/27/13 23:30:13 (12 years ago)
Author:
epyon
Message:
  • types from old nova
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/types.hh

    r6 r30  
    66#define NV_TYPES_HH
    77
     8#include <glm/glm.hpp>
    89#include <nv/common.hh>
    910#include <utility>
     
    1314namespace nv
    1415{
     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
    1577        template <typename TYPE>
    1678    const char* get_type_name()
     
    74136{
    75137
    76     struct type
     138    struct type_entry
    77139    {
    78140                 // Function types for the constructor and destructor of registered types
     
    98160    public:
    99161                template< typename TYPE >
    100         type& create_type()
     162        type_entry& create_type()
    101163                {
    102164                        hash_string name( get_type_name<TYPE>() );
    103                         type* i_type = nullptr;
     165                        type_entry* i_type = nullptr;
    104166                        type_map::iterator it = m_types.find( name );
    105167                        if ( it != m_types.end() )
     
    107169                                return *(it->second);
    108170                        }
    109                         i_type          = new type;
     171                        i_type          = new type_entry;
    110172                        i_type->type_db = this;
    111173                        i_type->name    = name;
     
    118180                        return *i_type;
    119181                }
    120         type* get_type( hash_string name )
     182        type_entry* get_type( hash_string name )
    121183                {
    122184                        type_map::iterator it = m_types.find( name );
     
    128190                }
    129191    private:
    130         typedef std::unordered_map<hash_string, type*> type_map;
     192        typedef std::unordered_map<hash_string, type_entry*> type_map;
    131193        type_map m_types;
    132194        };
Note: See TracChangeset for help on using the changeset viewer.