Changeset 505 for trunk


Ignore:
Timestamp:
07/12/16 20:22:23 (9 years ago)
Author:
epyon
Message:
  • several STL updates
  • several minor fixes
Location:
trunk
Files:
39 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/base/common.hh

    r486 r505  
    224224        typedef unsigned long long uint64;
    225225
     226        typedef signed   long long sintmax;
     227        typedef unsigned long long uintmax;
     228
    226229        typedef unsigned char      uchar8;
    227230        typedef unsigned short     uchar16;
  • trunk/nv/core/io_event.hh

    r447 r505  
    4646        struct key_event
    4747        {
     48                /// Associated window ID
     49                uint32 window_id;
     50
    4851                /// Input event ASCII code
    4952                uchar8 ascii;
     
    7073        struct mouse_button_event
    7174        {
     75                /// Associated window ID
     76                uint32 window_id;
     77
    7278                /// X position where mouse was clicked.
    7379                uint16 x;
     
    8490        struct mouse_wheel_event
    8591        {
     92                /// Associated window ID
     93                uint32 window_id;
    8694                /// amount scrolled horizontally positive to the right
    8795                sint32 x;
     
    92100        struct mouse_move_event
    93101        {
     102                /// Associated window ID
     103                uint32 window_id;
    94104                /// X Position the mouse moved to.
    95105                uint16 x;
  • trunk/nv/core/resource.hh

    r487 r505  
    4444                //virtual void release( resource_id id ) = 0;
    4545                virtual bool exists( resource_id id ) = 0;
    46                 virtual bool load_resource( const string_view& id ) = 0;
     46                virtual bool load_resource( const string_view& ) { return false; };
    4747
    4848                template< typename T >
  • trunk/nv/engine/animation.hh

    r487 r505  
    378378        };
    379379
     380        class animator_bind_manager : public nv::manual_resource_manager< nv::animator_bind_data >
     381        {
     382        public:
     383                animator_bind_manager() {}
     384                using nv::manual_resource_manager< nv::animator_bind_data >::add;
     385                using nv::manual_resource_manager< nv::animator_bind_data >::exists;
     386        protected:
     387        };
    380388
    381389}
  • trunk/nv/engine/image_manager.hh

    r504 r505  
    2424        NV_RTTI_DECLARE_NAME( image_data, "image_data" )
    2525
    26         class image_manager : public manual_resource_manager< image_data >
     26        class image_manager : public file_resource_manager< image_data >
    2727        {
    2828        public:
    2929                image_manager() {}
    30                 void add_base_path( const string_view& path );
    3130        protected:
    3231                virtual bool load_resource( const string_view& id );
    33                 vector< string128 > m_paths;
    3432        };
    3533
  • trunk/nv/engine/material_manager.hh

    r486 r505  
    4848        };
    4949
    50         class gpu_material_manager : public manual_resource_manager< gpu_material >
     50        class gpu_material_manager : public dependant_resource_manager< gpu_material, material_manager >
    5151        {
    5252        public:
    5353                gpu_material_manager( context* context, material_manager* matmgr, image_manager* imgmgr );
    5454        protected:
    55                 virtual bool load_resource( const string_view& id );
     55                resource< gpu_material > create_resource( resource< material > m );
    5656                virtual void release( gpu_material* m );
    5757        private:
    5858                texture           m_default;
    5959                context*          m_context;
    60                 material_manager* m_material_manager;
    6160                image_manager*    m_image_manager;
    6261        };
  • trunk/nv/engine/mesh_manager.hh

    r484 r505  
    3737        };
    3838
     39        struct mesh_data
     40        {
     41                vector< data_node_info >               infos;
     42                vector< resource< data_channel_set > > meshes;
     43                hash_store< shash64, uint32 >          names;
     44                hash_store< shash64, uint32 >          node_names;
     45                data_node_list*                        node_data;
     46        };
     47
    3948        NV_RTTI_DECLARE_NAME( data_channel_set, "data_channel_set" )
    4049        NV_RTTI_DECLARE_NAME( gpu_mesh, "gpu_mesh" )
     50        NV_RTTI_DECLARE_NAME( mesh_data, "mesh_data" )
    4151
    4252        using mesh_manager = manual_resource_manager< data_channel_set >;
    4353
    44         class gpu_mesh_manager : public nv::manual_resource_manager< gpu_mesh >
     54        class gpu_mesh_manager : public dependant_resource_manager< gpu_mesh, mesh_manager >
    4555        {
    4656        public:
    4757                gpu_mesh_manager( context* context, mesh_manager* mesh_manager )
    48                         : m_context( context )
    49                         , m_mesh_manager( mesh_manager ) {}
    50                 virtual bool load_resource( const string_view& id );
    51                 resource< gpu_mesh > load_resource( resource< data_channel_set > mesh );
     58                        : dependant_resource_manager( mesh_manager )
     59                        , m_context( context ) {}
    5260        protected:
     61                resource< gpu_mesh > create_resource( resource< data_channel_set > mesh );
    5362                virtual void release( gpu_mesh* m );
    5463        private:
    5564                context*      m_context;
    56                 mesh_manager* m_mesh_manager;
     65        };
     66
     67        class mesh_data_manager : public file_resource_manager< mesh_data >
     68        {
     69        public:
     70                mesh_data_manager( mesh_manager* meshes )
     71                        : m_mesh_manager( meshes ) , m_strings( new string_table ) {}
     72                string_view resolve( shash64 h ) { return ( *m_strings )[h]; }
     73                resource< data_channel_set > get_path( const string_view& path,
     74                        resource< mesh_data > default = resource< mesh_data >(),
     75                        data_node_info* info = nullptr );
     76                ~mesh_data_manager() { delete m_strings; }
     77        protected:
     78                virtual bool load_resource( const string_view& id );
     79
     80                mesh_manager*           m_mesh_manager;
     81                string_table*           m_strings;
    5782        };
    5883
  • trunk/nv/engine/program_manager.hh

    r477 r505  
    2020{
    2121
    22         class program_manager : public lua_resource_manager< program, false >
     22        class program_manager : public file_resource_manager< program, false, lua_resource_manager_base >
    2323        {
    2424        public:
     
    3030                string_buffer load_source( lua::table_guard& table, const string_view& append );
    3131                virtual void release( program p );
     32                virtual nv::const_string file_to_string( const string_view& path );
    3233        private:
    3334                context* m_context;
  • trunk/nv/engine/resource_system.hh

    r487 r505  
    1616#include <nv/common.hh>
    1717#include <nv/interface/context.hh>
     18#include <nv/stl/file_system.hh>
    1819#include <nv/core/resource.hh>
    1920#include <nv/lua/lua_state.hh>
    2021#include <nv/stl/hash_store.hh>
    2122#include <nv/stl/vector.hh>
     23#include <nv/stl/string.hh>
    2224
    2325namespace nv
     
    151153
    152154
    153         template < typename T, bool Heap = true >
    154         class manual_resource_manager : public custom_resource_manager< T, Heap >
     155        template < typename T, bool Heap = true, typename Base = resource_handler >
     156        class manual_resource_manager : public custom_resource_manager< T, Heap, Base >
    155157        {
    156158        public:
    157159                manual_resource_manager() {}
    158                 using custom_resource_manager< T, Heap >::add;
    159         protected:
    160                 virtual bool load_resource( const nv::string_view& ) { return false; }
    161 
    162         };
     160                using custom_resource_manager< T, Heap, Base >::add;
     161        };
     162
     163        template < typename T, typename SourceManager, bool Heap = true >
     164        class dependant_resource_manager : public manual_resource_manager< T, Heap >
     165        {
     166        public:
     167                typedef SourceManager source_manager_type;
     168                typedef typename SourceManager::resource_type source_type;
     169        public:
     170                explicit dependant_resource_manager( source_manager_type* source ) : m_source( source ) {}
     171                virtual resource< T > load_resource( source_type u )
     172                {
     173                        resource< T > result = get( u.id().value() );
     174                        if ( result ) return result;
     175                        return create_resource( u );
     176                }
     177        protected:
     178                virtual resource< T > create_resource( source_type u ) = 0;
     179                virtual bool load_resource( const string_view& id )
     180                {
     181                        source_type u = m_source->get( id );
     182                        return u && create_resource( u );
     183                }
     184        protected:
     185                source_manager_type* m_source;
     186        };
     187
     188        template < typename T, bool Heap = true, typename Base = resource_handler >
     189        class file_resource_manager : public manual_resource_manager< T, Heap, Base >
     190        {
     191        public:
     192                explicit file_resource_manager() {}
     193                void add_base_path( const string_view& path )
     194                {
     195                        m_paths.emplace_back( path );
     196                }
     197        protected:
     198                stream* open_stream( file_system& fs, const string_view& filename )
     199                {
     200                        if ( fs.exists( filename ) ) return fs.open( filename );
     201                        if ( m_paths.size() > 0 )
     202                        {
     203                                for ( const auto& path : m_paths )
     204                                {
     205                                        string128 fpath( path );
     206                                        fpath.append( filename );
     207                                        if ( fs.exists( fpath ) )
     208                                                return fs.open( fpath );
     209                                }
     210                        }
     211                        return nullptr;
     212                }
     213
     214                vector< string128 > m_paths;
     215        };
     216
    163217}
    164218
  • trunk/nv/gl/gl_window.hh

    r440 r505  
    3939
    4040                virtual void swap_buffers();
     41                virtual void make_current();
     42                virtual uint32 window_id();
    4143                virtual ~gl_window();
    4244        private:
     
    4749                void*       m_handle;
    4850                void*       m_hwnd;
     51                void*       m_dc;
    4952                gl_context* m_context;
    5053
  • trunk/nv/interface/context.hh

    r503 r505  
    151151                        m_device = a_device;
    152152                }
    153 
    154153                virtual vertex_array create_vertex_array( const vertex_array_desc& desc ) = 0;
    155154                virtual framebuffer create_framebuffer( uint32 temp_samples = 1 ) = 0;
  • trunk/nv/interface/window.hh

    r440 r505  
    3636                virtual bool poll_event( io_event& event ) = 0;
    3737                virtual void swap_buffers() = 0;
     38                virtual void make_current() = 0;
    3839                virtual device* get_device() = 0;
     40                virtual uint32 window_id() = 0;
    3941                virtual ~window() {}
    4042        };
  • trunk/nv/lua/lua_state.hh

    r503 r505  
    364364                        virtual ~table_guard();
    365365                        size_t get_size();
     366                       
    366367                        bool has_field( string_view element );
     368                       
    367369                        shash64 get_string_hash_64( string_view element, uint64 defval = 0 );
    368                         // remove this one
    369                         shash64 get_string( string_view element, string_table& table, uint64 defval = 0 );
    370370                        shash64 get_string( string_view element, string_table* table, uint64 defval = 0 );
    371371                        const_string get_string( string_view element, string_view defval = string_view() );
    372372                        string128 get_string128( string_view element, string_view defval = string_view() );
     373                       
    373374                        char get_char( string_view element, char defval = ' ' );
    374375                        int get_integer( string_view element, int defval = 0 );
     
    377378                        float get_float( string_view element, float defval = 0.0 );
    378379                        bool get_boolean( string_view element, bool defval = false );
     380
     381                        shash64 get_string_hash_64( int i, uint64 defval = 0 );
     382                        shash64 get_string( int i, string_table* table, uint64 defval = 0 );
     383                        const_string get_string( int i, string_view defval = string_view() );
     384                        string128 get_string128( int i, string_view defval = string_view() );
     385
     386                        char get_char( int i, char defval = ' ' );
     387                        int get_integer( int i, int defval = 0 );
     388                        unsigned get_unsigned( int i, unsigned defval = 0 );
     389                        double get_double( int i, double defval = 0.0 );
     390                        float get_float( int i, float defval = 0.0 );
     391                        bool get_boolean( int i, bool defval = false );
     392
    379393                        bool is_table( string_view element );
    380394                        bool is_number( string_view element );
    381395                        bool is_boolean( string_view element );
    382396                        bool is_string( string_view element );
     397                        bool is_table( int i );
     398                        bool is_number( int i );
     399                        bool is_boolean( int i );
     400                        bool is_string( int i );
     401
    383402                        template < typename T >
    384403                        bool read( const string_view& element, T& t )
  • trunk/nv/sdl/sdl_window.hh

    r440 r505  
    2929                        virtual void set_title( const string_view& title );
    3030                        virtual void swap_buffers();
     31                        virtual void make_current();
     32
    3133
    3234                        virtual context* get_context()    { return m_context; }
     
    3840                        virtual bool is_event_pending()            { return m_input->is_event_pending(); }
    3941                        virtual bool poll_event( io_event& event ) { return m_input->poll_event( event ); }
    40 
     42                        void* get_handle() { return m_handle;  }
     43                        virtual uint32 window_id();
    4144                        virtual ~window();
    4245                private:
  • trunk/nv/sdl/sdl_window_manager.hh

    r406 r505  
    3131                        virtual uint32 get_ticks();
    3232                        virtual ~window_manager();
     33                private:
     34                        void* primal_window;
    3335                };
    3436        }
  • trunk/nv/stl/math/common.hh

    r471 r505  
    109109                template <> struct is_bool_vec < tvec4< bool > > : true_type {};
    110110
     111                template < typename T > constexpr bool is_vec_v      = is_vec<T>::value;
     112                template < typename T > constexpr bool is_mat_v      = is_mat<T>::value;
     113                template < typename T > constexpr bool is_quat_v     = is_quat<T>::value;
     114                template < typename T > constexpr bool is_fp_v       = is_fp<T>::value;
     115                template < typename T > constexpr bool is_fp_vec_v   = is_fp_vec<T>::value;
     116                template < typename T > constexpr bool is_fp_mat_v   = is_fp_mat<T>::value;
     117                template < typename T > constexpr bool is_fp_quat_v  = is_fp_quat<T>::value;
     118                template < typename T > constexpr bool is_bool_vec_v = is_bool_vec<T>::value;
     119
    111120                namespace detail
    112121                {
     
    227236        typedef math::tmat4< float > mat4;
    228237
     238        typedef math::tquat< float > quat;
     239
    229240        template < typename T >
    230241        struct make_unsigned< math::tvec2< T > >
     
    265276}
    266277
     278NV_RTTI_DECLARE( nv::vec2 )
     279NV_RTTI_DECLARE( nv::vec3 )
     280NV_RTTI_DECLARE( nv::vec4 )
     281NV_RTTI_DECLARE( nv::ivec2 )
     282NV_RTTI_DECLARE( nv::ivec3 )
     283NV_RTTI_DECLARE( nv::ivec4 )
     284NV_RTTI_DECLARE( nv::mat2 )
     285NV_RTTI_DECLARE( nv::mat3 )
     286NV_RTTI_DECLARE( nv::mat4 )
     287NV_RTTI_DECLARE( nv::quat )
     288
    267289#endif // NV_STL_MATH_COMMON_HH
  • trunk/nv/stl/math/quaternion.hh

    r487 r505  
    112112
    113113                };
    114 
    115                 typedef tquat< f32 > quat;
    116114
    117115                namespace detail
     
    589587        }
    590588
    591         typedef math::quat quat;
    592 
    593589}
    594590
  • trunk/nv/stl/rtti_types.hh

    r397 r505  
    1515
    1616#include <nv/common.hh>
    17 #include <nv/stl/math.hh>
    1817
    1918NV_RTTI_DECLARE( void )
     
    3029NV_RTTI_DECLARE_NAME( nv::f32, "f32" )
    3130NV_RTTI_DECLARE_NAME( nv::f64, "f64" )
    32 NV_RTTI_DECLARE( nv::vec2 )
    33 NV_RTTI_DECLARE( nv::vec3 )
    34 NV_RTTI_DECLARE( nv::vec4 )
    35 NV_RTTI_DECLARE( nv::ivec2 )
    36 NV_RTTI_DECLARE( nv::ivec3 )
    37 NV_RTTI_DECLARE( nv::ivec4 )
    38 NV_RTTI_DECLARE( nv::mat2 )
    39 NV_RTTI_DECLARE( nv::mat3 )
    40 NV_RTTI_DECLARE( nv::mat4 )
    41 NV_RTTI_DECLARE( nv::quat )
    4231
    4332#endif // NV_STL_RTTI_TYPES_HH
  • trunk/nv/stl/string/short_string.hh

    r485 r505  
    220220        using string256 = short_string< 255 >;
    221221
    222 
    223222}
    224223
     224NV_RTTI_DECLARE( nv::string32 )
     225NV_RTTI_DECLARE( nv::string64 )
     226NV_RTTI_DECLARE( nv::string128 )
     227NV_RTTI_DECLARE( nv::string256 )
     228
    225229#endif // NV_STL_STRING_SHORT_STRING_HH
  • trunk/nv/stl/type_traits/common.hh

    r454 r505  
    2929        };
    3030
     31        template < typename T >
     32        constexpr T integral_constant_v = integral_constant<T>::value;
     33
    3134        // TODO: Propagate
    3235        template< bool B >
     
    3639        typedef bool_constant<false> false_type;
    3740
     41        template < typename T >
     42        constexpr T bool_constant_v = bool_constant<T>::value;
     43
    3844        template< bool Test, typename T = void>
    3945        struct enable_if {};
     
    6874        template < typename T >
    6975        struct is_same < T, T > : true_type{};
     76
     77        template < typename T1, typename T2 >
     78        constexpr bool is_same_v = is_same<T1, T2>::value;
    7079
    7180        // TODO: these seem to simple compared to MSVC/GCC - so we'll leave them in
     
    7382        template < typename T > struct is_const : false_type {};
    7483        template < typename T > struct is_const < T const > : true_type{};
     84        template < typename T > constexpr bool is_const_v = is_const<T>::value;
    7585        template < typename T > struct is_volatile : false_type {};
    7686        template < typename T > struct is_volatile < T volatile > : true_type{};
     87        template < typename T > constexpr bool is_volatile_v = is_volatile<T>::value;
    7788        // TODO END
    7889
    7990        template < typename T > struct is_lvalue_reference : false_type {};
    8091        template < typename T > struct is_lvalue_reference < T& > : true_type{};
     92        template < typename T > constexpr bool is_lvalue_reference_v = is_lvalue_reference<T>::value;
    8193        template < typename T > struct is_rvalue_reference : false_type {};
    8294        template < typename T > struct is_rvalue_reference < T&& > : true_type{};
     95        template < typename T > constexpr bool is_rvalue_reference_v = is_rvalue_reference<T>::value;
    8396
    8497        template < typename T >
     
    87100                is_rvalue_reference<T>::value
    88101        > {};
     102        template < typename T > constexpr bool is_reference_v = is_reference<T>::value;
    89103
    90104        // add const volatile and reference mutators
  • trunk/nv/stl/type_traits/primary.hh

    r402 r505  
    4545        }
    4646
    47         template< typename T > struct is_void           : is_same < void,      remove_cv_t<T> > {};
    48         template< typename T > struct is_nullptr        : is_same < nullptr_t, remove_cv_t<T> > {};
    49         template< typename T > struct is_integral       : detail::is_integral_impl < remove_cv_t<T> > {};
    50         template< typename T > struct is_floating_point : detail::is_floating_point_impl < remove_cv_t<T> > {};
     47        template < typename T > struct is_void           : is_same < void,      remove_cv_t<T> > {};
     48        template < typename T > struct is_nullptr        : is_same < nullptr_t, remove_cv_t<T> > {};
     49        template < typename T > struct is_integral       : detail::is_integral_impl < remove_cv_t<T> > {};
     50        template < typename T > struct is_floating_point : detail::is_floating_point_impl < remove_cv_t<T> > {};
     51
     52        template < typename T > constexpr bool is_void_v           = is_void<T>::value;
     53        template < typename T > constexpr bool is_nullptr_v        = is_nullptr<T>::value;
     54        template < typename T > constexpr bool is_integral_v       = is_integral<T>::value;
     55        template < typename T > constexpr bool is_floating_point_v = is_floating_point<T>::value;
     56
    5157
    5258        template < typename T >           struct is_array          : false_type {};
     
    5763        template < typename T >           struct is_union : bool_constant < __is_union( T ) > {};
    5864        template < typename T >           struct is_class : bool_constant < __is_class( T ) > {};
     65
     66        template < typename T > constexpr bool is_array_v = is_array<T>::value;
     67        template < typename T > constexpr bool is_enum_v  = is_enum<T>::value;
     68        template < typename T > constexpr bool is_union_v = is_union<T>::value;
     69        template < typename T > constexpr bool is_class_v = is_class<T>::value;
    5970
    6071        // is_function_pointer / is_member_function pointer - extension
     
    115126        template< typename T > struct is_function < T&& > : false_type{};
    116127
     128        template < typename T > constexpr bool is_function_pointer_v        = is_function_pointer<T>::value;
     129        template < typename T > constexpr bool is_member_function_pointer_v = is_member_function_pointer<T>::value;
     130        template < typename T > constexpr bool is_member_pointer_v          = is_member_pointer<T>::value;
     131        template < typename T > constexpr bool is_function_v                = is_function<T>::value;
     132
    117133}
    118134
  • trunk/nv/stl/type_traits/properties.hh

    r402 r505  
    5353        struct is_compound : bool_constant < !is_fundamental< T >::value > {};
    5454
     55        template < typename T > constexpr bool is_fundamental_v = is_fundamental<T>::value;
     56        template < typename T > constexpr bool is_arithmetic_v  = is_arithmetic<T>::value;
     57        template < typename T > constexpr bool is_scalar_v      = is_scalar<T>::value;
     58        template < typename T > constexpr bool is_object_v      = is_object<T>::value;
     59        template < typename T > constexpr bool is_compound_v    = is_compound<T>::value;
     60
    5561        // TODO : confirm conformance
    5662#if NV_COMPILER == NV_MSVC
     
    6874        template < typename T > struct is_abstract        : bool_constant < __is_abstract( T ) > {};
    6975
     76        template < typename T > constexpr bool is_trivially_copyable_v = is_trivially_copyable<T>::value;
     77        template < typename T > constexpr bool is_trivial_v            = is_trivial<T>::value;
     78        template < typename T > constexpr bool is_pod_v                = is_pod<T>::value;
     79        template < typename T > constexpr bool is_literal_type_v       = is_literal_type<T>::value;
     80        template < typename T > constexpr bool is_empty_v              = is_empty<T>::value;
     81        template < typename T > constexpr bool is_polymorphic_v        = is_polymorphic<T>::value;
     82        template < typename T > constexpr bool is_abstract_v           = is_abstract<T>::value;
     83       
    7084        template < typename T > struct is_signed : false_type {};
    7185        template <> struct is_signed<char>       : bool_constant< ( char( 0 ) > char( -1 ) ) > {};
     
    93107        template <> struct is_unsigned<unsigned long long>       : true_type{};
    94108        template <> struct is_unsigned<const unsigned long long> : true_type{};
     109
     110        template < typename T > constexpr bool is_signed_v   = is_signed<T>::value;
     111        template < typename T > constexpr bool is_unsigned_v = is_unsigned<T>::value;
    95112
    96113#if NV_COMPILER == NV_MSVC
     
    207224        struct is_assignable : detail::is_assignable_impl< To, From >::type { };
    208225
     226        template < typename To, typename From > constexpr bool is_assignable_v = is_assignable<To, From>::value;
     227
     228
    209229        namespace detail
    210230        {
     
    230250        struct is_move_assignable : detail::is_move_assignable_impl < T > {};
    231251
     252        template < typename T >
     253        constexpr bool is_copy_assignable_v = is_copy_assignable<T>::value;
     254
     255        template < typename T >
     256        constexpr bool is_move_assignable_v = is_move_assignable<T>::value;
     257
    232258// TODO : implement if needed
    233259//      template < typename T >
     
    249275
    250276        template < typename T > struct has_virtual_destructor  : bool_constant < __has_virtual_destructor( T ) > {};
     277        template < typename T > constexpr bool has_virtual_destructor_v = has_virtual_destructor<T>::value;
    251278
    252279        template< typename T >
    253280        struct alignment_of     : integral_constant < size_t, alignof( typename remove_reference< T >::type ) > {};
     281
     282        template < typename T > constexpr size_t alignment_of_v = alignment_of<T>::value;
    254283
    255284        template < typename T >
     
    259288        template < typename T, size_t N >
    260289        struct rank<T[N]> : integral_constant < size_t, rank<T>::value + 1 > {};
     290
     291        template < typename T > constexpr size_t rank_v = rank<T>::value;
    261292
    262293        template < typename T, unsigned N = 0>
     
    271302        struct extent< T[I], N > : integral_constant < size_t, extent<T, N - 1>::value > {};
    272303
     304        template < typename T > constexpr size_t extent_v = extent<T>::value;
     305
    273306        template < typename Base, typename Derived >
    274307        struct is_base_of : bool_constant < __is_base_of( Base, Derived ) > {};
     308
     309        template < typename Base, typename Derived >
     310        constexpr bool is_base_of_v = is_base_of<Base,Derived>::value;
    275311
    276312#if NV_COMPILER == NV_MSVC
     
    281317        struct is_convertible : detail::is_convertible_impl< From, To >::type {};
    282318#endif
     319
     320        template < typename From, typename To >
     321        constexpr bool is_convertible_v = is_convertible<From, To>::value;
    283322
    284323        namespace detail
     
    298337        struct is_template_base_of : bool_constant< detail::is_template_base_of_impl< T, Template >::value > {};
    299338
    300 
    301339// TODO: non-standard, remove?
    302340        template < typename T > struct has_trivial_constructor : bool_constant < __has_trivial_constructor( T ) || __is_pod( T ) > {};
     
    305343        template < typename T > struct has_trivial_destructor  : bool_constant < __has_trivial_destructor( T ) || __is_pod( T ) > {};
    306344
     345        template < typename T > constexpr bool has_trivial_constructor_v = has_trivial_constructor<T>::value;
     346        template < typename T > constexpr bool has_trivial_copy_v        = has_trivial_copy<T>::value;
     347        template < typename T > constexpr bool has_trivial_assign_v      = has_trivial_assign<T>::value;
     348        template < typename T > constexpr bool has_trivial_destructor_v  = has_trivial_destructor<T>::value;
     349
    307350}
    308351
  • trunk/nv/stl/utility/common.hh

    r469 r505  
    5151        }
    5252
     53        template < typename T, typename U = T >
     54        inline T exchange( T& t, U&& u )
     55        {
     56                T v = nv::move( t );
     57                t = nv::forward<U>( u );
     58                return v;
     59        }
     60
     61        template < typename T >
     62        constexpr add_const_t<T>& as_const( T& t )
     63        {
     64                return t;
     65        }
     66
    5367}
    5468
  • trunk/nv/wx/wx_canvas.hh

    r410 r505  
    5050        {
    5151        public:
    52                 explicit wx_gl_canvas( wxWindow *parent );
     52                explicit wx_gl_canvas( wxWindow *parent, input* in );
     53                explicit wx_gl_canvas( wxWindow *parent, wx_gl_canvas *sibling, input* in );
    5354                virtual void on_update() = 0;
    5455                virtual void stop();
    5556                virtual void start();
    5657                virtual void on_idle( wxIdleEvent& evt );
     58                virtual void make_current();
     59                uint32 window_id() { return m_window->window_id(); }
    5760                ~wx_gl_canvas();
    5861        protected:
     
    6467                nv::window*         m_window;
    6568                bool                m_render;
     69                bool                m_main;
    6670                wxDECLARE_EVENT_TABLE();
    6771        };
  • trunk/src/core/io_event.cc

    r487 r505  
    7171
    7272        db->create_type<key_event>()
    73                 .field( "ascii",   &key_event::ascii )
    74                 .field( "code",    &key_event::code )
    75                 .field( "shift",   &key_event::shift )
    76                 .field( "control", &key_event::control )
    77                 .field( "alt",     &key_event::alt )
    78                 .field( "pressed", &key_event::pressed );
     73                .field( "window_id",&key_event::window_id )
     74                .field( "ascii",    &key_event::ascii )
     75                .field( "code",     &key_event::code )
     76                .field( "shift",    &key_event::shift )
     77                .field( "control",  &key_event::control )
     78                .field( "alt",      &key_event::alt )
     79                .field( "pressed",  &key_event::pressed );
    7980
    8081        db->create_type<mouse_button_event>()
    81                 .field( "x",       &mouse_button_event::x )
    82                 .field( "y",       &mouse_button_event::y )
    83                 .field( "button",  &mouse_button_event::button )
    84                 .field( "pressed", &mouse_button_event::pressed )
    85                 .field( "code",    &mouse_button_event::code );
     82                .field( "window_id",&mouse_button_event::window_id )
     83                .field( "x",        &mouse_button_event::x )
     84                .field( "y",        &mouse_button_event::y )
     85                .field( "button",   &mouse_button_event::button )
     86                .field( "pressed",  &mouse_button_event::pressed )
     87                .field( "code",     &mouse_button_event::code );
    8688
    8789        db->create_type<mouse_move_event>()
    88                 .field( "x",       &mouse_move_event::x )
    89                 .field( "y",       &mouse_move_event::y )
    90                 .field( "rx",      &mouse_move_event::rx )
    91                 .field( "ry",      &mouse_move_event::ry )
    92                 .field( "pressed", &mouse_move_event::pressed )
    93                 .field( "code",    &mouse_move_event::code );
     90                .field( "window_id",&mouse_move_event::window_id )
     91                .field( "x",        &mouse_move_event::x )
     92                .field( "y",        &mouse_move_event::y )
     93                .field( "rx",       &mouse_move_event::rx )
     94                .field( "ry",       &mouse_move_event::ry )
     95                .field( "pressed",  &mouse_move_event::pressed )
     96                .field( "code",     &mouse_move_event::code );
    9497
    9598        db->create_type<mouse_wheel_event>()
    96                 .field( "x",       &mouse_wheel_event::x )
    97                 .field( "y",       &mouse_wheel_event::y );
     99                .field( "window_id",&mouse_wheel_event::window_id )
     100                .field( "x",        &mouse_wheel_event::x )
     101                .field( "y",        &mouse_wheel_event::y );
    98102
    99103        db->create_type<pad_button_event>()
  • trunk/src/core/types.cc

    r503 r505  
    33#include "nv/interface/clear_state.hh"
    44#include "nv/interface/render_state.hh"
     5#include "nv/stl/string.hh"
    56
    67using namespace nv;
     
    2627        db->create_type<ivec3>();
    2728        db->create_type<ivec4>();
     29        db->create_type<quat>();
     30        db->create_type<string32>();
     31        db->create_type<string64>();
     32        db->create_type<string128>();
     33        db->create_type<string256>();
    2834
    2935        db->create_type<color_mask>()
  • trunk/src/engine/image_manager.cc

    r504 r505  
    1212using namespace nv;
    1313
    14 void nv::image_manager::add_base_path( const string_view& path )
     14bool image_manager::load_resource( const string_view& filename )
    1515{
    16         m_paths.emplace_back( path );
     16        c_file_system fs;
     17        if ( stream* file = open_stream( fs, filename ) )
     18        {
     19                png_loader loader;
     20                image_data* result = loader.load( *file );
     21                delete file;
     22                if ( result )
     23                {
     24                        add( filename, result );
     25                        return true;
     26                }
     27        }
     28        return false;
    1729}
    1830
    19 bool image_manager::load_resource( const string_view& filename )
    20 {
    21         png_loader loader;
    22         c_file_system fs;
    23         image_data* result = nullptr;
    24         if ( fs.exists( filename ) )
    25         {
    26                 stream* file = fs.open( filename );
    27                 result = loader.load( *file );
    28                 delete file;
    29         }
    30         else if ( m_paths.size() > 0 )
    31         {
    32                 for ( const auto& path : m_paths )
    33                 {
    34                         string128 fpath = path;
    35                         fpath.append( filename );
    36                         if ( fs.exists( fpath ) )
    37                         {
    38                                 stream* file = fs.open( fpath );
    39                                 result = loader.load( *file );
    40                                 delete file;
    41                                 break;
    42                         }
    43                 }
    44         }
    45         if ( result )
    46                 add( filename, result );
    47         return result != nullptr;
    48 }
    49 
  • trunk/src/engine/material_manager.cc

    r501 r505  
    1414
    1515nv::gpu_material_manager::gpu_material_manager( context* context, material_manager* matmgr, image_manager* imgmgr )
    16         : m_context( context )
    17         , m_material_manager( matmgr )
     16        : dependant_resource_manager( matmgr ), m_context( context )
    1817        , m_image_manager( imgmgr )
    1918{
     
    2322}
    2423
    25 bool gpu_material_manager::load_resource( const string_view& id )
     24nv::resource< nv::gpu_material > nv::gpu_material_manager::create_resource( resource< material > m )
    2625{
    27         if ( auto mat = m_material_manager->get( id ).lock() )
     26        resource_id id = m.id();
     27        if ( auto mat = m.lock() )
    2828        {
    2929                gpu_material* result = new gpu_material;
     
    3939
    4040                // HACK
    41                 for ( uint32 i = 0; i < 8; ++i )
    42                         if ( result->textures[i].is_nil() )
    43                                 result->textures[i] = m_default;
    44                        
    45                 add( id, result );
    46                 return true;
     41                for ( uint32 i = 0; i < 8; ++i )
     42                        if ( result->textures[i].is_nil() )
     43                                result->textures[i] = m_default;
     44
     45                return add( id, result );
    4746        }
    48         return false;
     47        return resource< nv::gpu_material >();
    4948}
    5049
  • trunk/src/engine/mesh_manager.cc

    r484 r505  
    66
    77#include "nv/engine/mesh_manager.hh"
     8#include "nv/formats/nmd_loader.hh"
     9#include "nv/io/c_file_system.hh"
    810
    911using namespace nv;
    1012
    11 resource< gpu_mesh > gpu_mesh_manager::load_resource( resource< data_channel_set > mesh )
     13resource< gpu_mesh > gpu_mesh_manager::create_resource( resource< data_channel_set > mesh )
    1214{
    13         resource< gpu_mesh > result = get( mesh.id().value() );
    14         if ( result ) return result;
    1515        if ( auto lmesh = mesh.lock() )
    1616        {
     
    2424}
    2525
    26 bool nv::gpu_mesh_manager::load_resource( const string_view& id )
    27 {
    28         if ( auto lmesh = m_mesh_manager->get( id ).lock() )
    29         {
    30                 gpu_mesh* gm = new gpu_mesh;
    31                 gm->va = m_context->create_vertex_array( &*lmesh, STATIC_DRAW );
    32                 gm->count = lmesh->get_channel_size( slot::INDEX );
    33                 gm->shader = lmesh->get_channel( slot::BONEINDEX ) != nullptr ? BONE : NORMAL;
    34                 add( id, gm );
    35                 return true;
    36         }
    37         return false;
    38 }
    39 
    4026void gpu_mesh_manager::release( gpu_mesh* m )
    4127{
    4228        m_context->release( m->va );
    4329}
     30
     31nv::resource< nv::data_channel_set > nv::mesh_data_manager::get_path( const string_view& path, resource< mesh_data > default /*= resource< mesh_data >()*/, data_node_info* info /*= nullptr */ )
     32{
     33        nv::resource< nv::mesh_data > mr = default;
     34
     35        nv::string_view sub_mesh_name;
     36        nv::string128 base_mesh_name( path );
     37        nv::size_t sub_mesh_pos = path.find( ":" );
     38        nv::size_t dot_pos = path.find( "." );
     39        if ( sub_mesh_pos != nv::string_view::npos )
     40        {
     41                sub_mesh_name = path.substr( sub_mesh_pos + 1 );
     42                base_mesh_name.assign( path.substr( 0, sub_mesh_pos ) );
     43                NV_LOG_INFO( "Requested submesh - [", sub_mesh_name, "] in [", base_mesh_name, "]" );
     44        }
     45
     46        if ( dot_pos != nv::string_view::npos )
     47        {
     48                mr = get( base_mesh_name );
     49        }
     50        else
     51        {
     52                sub_mesh_name = base_mesh_name;
     53        }
     54
     55        if ( !mr )
     56        {
     57                NV_LOG_ERROR( "MESH FILE NOT FOUND - ", path );
     58                NV_ASSERT( false, "MESH FILE NOT FOUND!" );
     59                return nv::resource< nv::data_channel_set >();
     60        }
     61
     62        if ( auto mdata = mr.lock() )
     63        {
     64                sint32 index = -1;
     65                if ( sub_mesh_name.empty() )
     66                {
     67                        index = 0;
     68                }
     69                else if ( sub_mesh_name[0] >= '0' && sub_mesh_name[0] <= '9' )
     70                {
     71                        index = nv::buffer_to_uint32( sub_mesh_name.data(), nullptr );
     72                }
     73                else
     74                {
     75                        auto itr = mdata->names.find( sub_mesh_name );
     76                        if ( itr != mdata->names.end() )
     77                                index = itr->second;
     78                }
     79                if ( index >= 0 )
     80                {
     81                        if ( info )
     82                                *info = mdata->infos[index];
     83                        return mdata->meshes[index];
     84                }
     85
     86                NV_LOG_ERROR( "Resource path fail! - ", path );
     87                NV_ASSERT( false, "Resource path fail!" );
     88        }
     89        else
     90        {
     91                NV_LOG_ERROR( "Resource lock fail! - ", path );
     92                NV_ASSERT( false, "Resource lock fail!" );
     93        }
     94        return nv::resource< nv::data_channel_set >();
     95}
     96
     97bool nv::mesh_data_manager::load_resource( const string_view& id )
     98{
     99        nmd_loader* loader = nullptr;
     100        c_file_system fs;
     101        stream* mesh_file = open_stream( fs, id );
     102        if ( !mesh_file ) return false;
     103
     104        loader = new nmd_loader( m_strings );
     105        loader->load( *mesh_file );
     106        delete mesh_file;
     107
     108        mesh_data* result = new mesh_data;
     109        result->node_data = loader->release_data_node_list();
     110        if ( result->node_data )
     111        {
     112                data_node_list* nd = result->node_data;
     113                for ( uint32 i = 0; i < nd->size(); ++i )
     114                        result->node_names[(*nd)[i].name] = i;
     115        }
     116        for ( uint32 i = 0; i < loader->get_mesh_count(); ++i )
     117        {
     118                data_node_info info;
     119                data_channel_set* data = loader->release_mesh_data( i, info );
     120                result->infos.push_back( info );
     121                result->names[ info.name ] = i;
     122                auto mesh = m_mesh_manager->add( shash64( id.get_hash() + i ), data );
     123                result->meshes.push_back( mesh );
     124        }
     125        delete loader;
     126        if ( result )
     127                add( id, result );
     128        return result != nullptr;
     129}
  • trunk/src/engine/program_manager.cc

    r501 r505  
    4545}
    4646
     47nv::const_string nv::program_manager::file_to_string( const string_view& path )
     48{
     49        c_file_system fs;
     50        stream* fstream = open_stream( fs, path );
     51        if ( !fstream ) return const_string();
     52        uint32 size = fstream->size();
     53        const_string result( nullptr, size );
     54        fstream->read( const_cast<char*>( result.data() ), size, 1 );
     55        delete fstream;
     56        return result;
     57}
     58
    4759nv::string_buffer nv::program_manager::load_source( lua::table_guard& table, const string_view& append )
    4860{
     
    5163        if ( table.is_string( "files" ) )
    5264        {
    53                 out.append( fs.slurp( table.get_string( "files" ) ) );
     65                out.append( file_to_string( table.get_string( "files" ) ) );
    5466        }
    5567        else if ( table.is_table( "files" ) )
     
    6173                        const_string include( inctable.get<const_string,uint32>(i) );
    6274                        if ( i == count ) out.append( "#line 1\n" );
    63                         out.append( fs.slurp( include ) );
     75                        out.append( file_to_string( include ) );
    6476                }
    6577        }
     
    6779        if ( table.is_string( "file" ) )
    6880        {
    69                 const_string data = fs.slurp( table.get_string( "file" ) );
     81                const_string data = file_to_string( table.get_string( "file" ) );
    7082                out.append( "#line 1\n" + data );
    7183        }
  • trunk/src/gfx/image.cc

    r487 r505  
    9898        const uint8* data = idata->get_data();
    9999        size_t depth      = idata->get_depth();
     100        size_t cdepth     = m_depth > depth ? depth : m_depth;
    100101        uint32 dstride    = rsizex * depth;
    101102
     
    106107                {
    107108                        uint32 xy = pos + x * m_depth;
    108                         for( size_t e = 0; e < depth; ++e )
     109                        for( size_t e = 0; e < cdepth; ++e )
    109110                        {
    110111                                m_data[ xy + e ] = data[ y*dstride + x * depth + e ];
  • trunk/src/gl/gl_context.cc

    r503 r505  
    848848}
    849849
    850 
    851850nv::gl_context::~gl_context()
    852851{
  • trunk/src/gl/gl_device.cc

    r501 r505  
    145145{
    146146        unsigned glid = 0;
    147         unsigned glenum = buffer_type_to_enum( type );
    148147        glGenBuffers( 1, &glid );
    149148
  • trunk/src/gl/gl_window.cc

    r466 r505  
    99#include "nv/core/logging.hh"
    1010#include "nv/lib/gl.hh"
     11#include "nv/lib/sdl.hh"
    1112
    1213using namespace nv;
     
    3132        delete m_context;
    3233        m_context = nullptr;
    33         delete m_input;
    3434}
    3535
     
    4141
    4242        m_handle = handle;
     43        m_dc     = dc;
    4344
    4445        // TODO: error checking
     
    110111}
    111112
     113void nv::gl_window::make_current()
     114{
     115#if NV_PLATFORM == NV_WINDOWS
     116        HDC hdc = reinterpret_cast<HDC>( m_hwnd );
     117        dynwglMakeCurrent( hdc, reinterpret_cast<HGLRC>( m_context->get_native_handle() ) );
     118#endif
     119}
     120
     121nv::uint32 nv::gl_window::window_id()
     122{
     123        return SDL_GetWindowID( static_cast<SDL_Window*>( m_handle ) );
     124}
     125
  • trunk/src/lua/lua_state.cc

    r503 r505  
    201201}
    202202
    203 shash64 nv::lua::table_guard::get_string( string_view element, string_table& table, uint64 defval /*= 0 */ )
     203nv::shash64 nv::lua::table_guard::get_string( string_view element, string_table* table, uint64 defval /*= 0 */ )
    204204{
    205205        lua_getfield( m_state, -1, element.data() );
     
    210210        {
    211211                str = lua_tolstring( m_state, -1, &l );
    212                 result = table.insert( string_view( str, l ) );
    213         }
    214         lua_pop( m_state, 1 );
    215         return result;
    216 }
    217 
    218 nv::shash64 nv::lua::table_guard::get_string( string_view element, string_table* table, uint64 defval /*= 0 */ )
    219 {
    220         lua_getfield( m_state, -1, element.data() );
     212                string_view sv( str, l );
     213                result = table ? table->insert( sv ) : shash64( sv );
     214        }
     215        lua_pop( m_state, 1 );
     216        return result;
     217}
     218
     219shash64 nv::lua::table_guard::get_string_hash_64( int i, uint64 defval /*= 0 */ )
     220{
     221        lua_rawgeti( m_state, -1, i );
     222        size_t l = 0;
     223        const char* str = nullptr;
     224        uint64 result = defval;
     225        if ( lua_type( m_state, -1 ) == LUA_TSTRING )
     226        {
     227                str = lua_tolstring( m_state, -1, &l );
     228                result = hash_string< uint64 >( str, l );
     229                //NV_LOG_DEBUG( str );
     230        }
     231        lua_pop( m_state, 1 );
     232        return shash64( result );
     233}
     234
     235nv::string128 nv::lua::table_guard::get_string128( int i, string_view defval /*= string_view() */ )
     236{
     237        lua_rawgeti( m_state, -1, i );
     238        size_t l = 0;
     239        const char* str = nullptr;
     240        if ( lua_type( m_state, -1 ) == LUA_TSTRING )
     241        {
     242                str = lua_tolstring( m_state, -1, &l );
     243        }
     244        else
     245        {
     246                l = defval.size();
     247                str = defval.data();
     248        }
     249        string128 result( str, l );
     250        lua_pop( m_state, 1 );
     251        return result;
     252}
     253
     254const_string nv::lua::table_guard::get_string( int i, string_view defval /*= string_view() */ )
     255{
     256        lua_rawgeti( m_state, -1, i );
     257        size_t l = 0;
     258        const char* str = nullptr;
     259        if ( lua_type( m_state, -1 ) == LUA_TSTRING )
     260        {
     261                str = lua_tolstring( m_state, -1, &l );
     262        }
     263        else
     264        {
     265                l = defval.size();
     266                str = defval.data();
     267        }
     268        const_string result( str, l );
     269        lua_pop( m_state, 1 );
     270        return result;
     271}
     272
     273shash64 nv::lua::table_guard::get_string( int i, string_table* table, uint64 defval /*= 0 */ )
     274{
     275        lua_rawgeti( m_state, -1, i );
    221276        size_t l = 0;
    222277        const char* str = nullptr;
     
    302357}
    303358
     359char nv::lua::table_guard::get_char( int i, char defval /*= ' ' */ )
     360{
     361        lua_rawgeti( m_state, -1, i );
     362        char result = ( lua_type( m_state, -1 ) == LUA_TSTRING && nlua_rawlen( m_state, -1 ) > 0 ) ? lua_tostring( m_state, -1 )[0] : defval;
     363        lua_pop( m_state, 1 );
     364        return result;
     365}
     366
     367int nv::lua::table_guard::get_integer( int i, int defval /*= 0 */ )
     368{
     369        lua_rawgeti( m_state, -1, i );
     370        lua_Integer result = lua_type( m_state, -1 ) == LUA_TNUMBER ? lua_tointeger( m_state, -1 ) : defval;
     371        lua_pop( m_state, 1 );
     372        return static_cast<int>( result );
     373}
     374
     375unsigned nv::lua::table_guard::get_unsigned( int i, unsigned defval /*= 0 */ )
     376{
     377        lua_rawgeti( m_state, -1, i );
     378        unsigned result = lua_type( m_state, -1 ) == LUA_TNUMBER ? nlua_tounsigned( m_state, -1 ) : defval;
     379        lua_pop( m_state, 1 );
     380        return result;
     381}
     382
     383double nv::lua::table_guard::get_double( int i, double defval /*= 0.0 */ )
     384{
     385        lua_rawgeti( m_state, -1, i );
     386        double result = lua_type( m_state, -1 ) == LUA_TNUMBER ? lua_tonumber( m_state, -1 ) : defval;
     387        lua_pop( m_state, 1 );
     388        return result;
     389}
     390
     391float nv::lua::table_guard::get_float( int i, float defval /*= 0.0 */ )
     392{
     393        lua_rawgeti( m_state, -1, i );
     394        float result = lua_type( m_state, -1 ) == LUA_TNUMBER ? static_cast<float>( lua_tonumber( m_state, -1 ) ) : defval;
     395        lua_pop( m_state, 1 );
     396        return result;
     397}
     398
     399bool nv::lua::table_guard::get_boolean( int i, bool defval /*= false */ )
     400{
     401        lua_rawgeti( m_state, -1, i );
     402        bool result = lua_type( m_state, -1 ) == LUA_TBOOLEAN ? lua_toboolean( m_state, -1 ) != 0 : defval;
     403        lua_pop( m_state, 1 );
     404        return result;
     405}
     406
    304407float nv::lua::table_guard::get_float( string_view element, float defval /*= 0.0 */ )
    305408{
     
    326429}
    327430
     431bool nv::lua::table_guard::is_table( int i )
     432{
     433        lua_rawgeti( m_state, -1, i );
     434        bool result = lua_type( m_state, -1 ) == LUA_TTABLE;
     435        lua_pop( m_state, 1 );
     436        return result;
     437}
     438
     439bool nv::lua::table_guard::is_number( int i )
     440{
     441        lua_rawgeti( m_state, -1, i );
     442        bool result = lua_type( m_state, -1 ) == LUA_TNUMBER;
     443        lua_pop( m_state, 1 );
     444        return result;
     445}
     446
     447bool nv::lua::table_guard::is_boolean( int i )
     448{
     449        lua_rawgeti( m_state, -1, i );
     450        bool result = lua_type( m_state, -1 ) == LUA_TBOOLEAN;
     451        lua_pop( m_state, 1 );
     452        return result;
     453}
     454
     455bool nv::lua::table_guard::is_string( int i )
     456{
     457        lua_rawgeti( m_state, -1, i );
     458        bool result = lua_type( m_state, -1 ) == LUA_TSTRING;
     459        lua_pop( m_state, 1 );
     460        return result;
     461}
     462
    328463bool nv::lua::table_guard::is_number( string_view element )
    329464{
     
    349484        return result;
    350485}
    351 
    352486
    353487bool nv::lua::table_guard::read( const string_view& element, const type_entry* entry, void* object )
  • trunk/src/sdl/sdl_input.cc

    r406 r505  
    2020static bool sdl_key_event_to_io_event( const SDL_KeyboardEvent& ke, io_event& kevent )
    2121{
    22         kevent.type        = EV_KEY;
    23         kevent.key.pressed = ( ke.state != SDL_RELEASED );
    24         kevent.key.ascii   = 0;
    25         kevent.key.code    = KEY_NONE;
     22        kevent.type          = EV_KEY;
     23        kevent.key.window_id = ke.windowID;
     24        kevent.key.pressed   = ( ke.state != SDL_RELEASED );
     25        kevent.key.ascii     = 0;
     26        kevent.key.code      = KEY_NONE;
    2627
    2728        uint32 ucode = static_cast<uint32>( ke.keysym.sym );
     
    107108static bool sdl_mouse_button_to_io_event( const SDL_MouseButtonEvent& mb, io_event& mevent )
    108109{
    109         mevent.type            = EV_MOUSE_BUTTON;
    110         mevent.mbutton.button  = MOUSE_NONE;
    111         mevent.mbutton.pressed = (mb.state != SDL_RELEASED);
    112         mevent.mbutton.x       = static_cast< uint16 >( mb.x );
    113         mevent.mbutton.y       = static_cast< uint16 >( mb.y );
     110        mevent.type              = EV_MOUSE_BUTTON;
     111        mevent.mbutton.window_id = mb.windowID;
     112        mevent.mbutton.button    = MOUSE_NONE;
     113        mevent.mbutton.pressed   = (mb.state != SDL_RELEASED);
     114        mevent.mbutton.x         = static_cast< uint16 >( mb.x );
     115        mevent.mbutton.y         = static_cast< uint16 >( mb.y );
    114116
    115117        switch ( mb.button )
     
    126128static bool sdl_mouse_wheel_to_io_event( const SDL_MouseWheelEvent& mm, io_event& mevent )
    127129{
    128         mevent.type          = EV_MOUSE_WHEEL;
    129         mevent.mwheel.x      = static_cast< sint32 >( mm.x );
    130         mevent.mwheel.y      = static_cast< sint32 >( mm.y );
     130        mevent.type             = EV_MOUSE_WHEEL;
     131        mevent.mwheel.window_id = mm.windowID;
     132        mevent.mwheel.x         = static_cast< sint32 >( mm.x );
     133        mevent.mwheel.y         = static_cast< sint32 >( mm.y );
    131134        return true;
    132135}
     
    134137static bool sdl_mouse_motion_to_io_event( const SDL_MouseMotionEvent& mm, io_event& mevent )
    135138{
    136         mevent.type          = EV_MOUSE_MOVE;
    137         mevent.mmove.pressed = (mm.state != SDL_RELEASED);
    138         mevent.mmove.x       = static_cast< uint16 >( mm.x );
    139         mevent.mmove.y       = static_cast< uint16 >( mm.y );
    140         mevent.mmove.rx      = static_cast< sint16 >( mm.xrel );
    141         mevent.mmove.ry      = static_cast< sint16 >( mm.yrel );
     139        mevent.type            = EV_MOUSE_MOVE;
     140        mevent.mmove.window_id = mm.windowID;
     141        mevent.mmove.pressed   = (mm.state != SDL_RELEASED);
     142        mevent.mmove.x         = static_cast< uint16 >( mm.x );
     143        mevent.mmove.y         = static_cast< uint16 >( mm.y );
     144        mevent.mmove.rx        = static_cast< sint16 >( mm.xrel );
     145        mevent.mmove.ry        = static_cast< sint16 >( mm.yrel );
    142146        return true;
    143147}
     
    222226        case SDL_VIDEOEXPOSE     : return false;
    223227*/
     228        case SDL_WINDOWEVENT_ENTER: ioevent.type = EV_SYSTEM; ioevent.system.param1 = 1; ioevent.system.param1 = e.window.windowID; return true;
     229        case SDL_WINDOWEVENT_LEAVE: ioevent.type = EV_SYSTEM; ioevent.system.param1 = 0; ioevent.system.param1 = e.window.windowID; return true;
    224230        case SDL_SYSWMEVENT      : ioevent.type = EV_SYSTEM; return true;
    225231        case SDL_QUIT            : ioevent.type = EV_QUIT;   return true;
  • trunk/src/sdl/sdl_window.cc

    r492 r505  
    133133        SDL_GL_SetSwapInterval( enabled ? 1 : 0 );
    134134}
     135
     136void nv::sdl::window::make_current()
     137{
     138        SDL_GLContext native = static_cast<SDL_GLContext>( m_context->get_native_handle() );
     139        SDL_GL_MakeCurrent( static_cast<SDL_Window*>( m_handle ), native );
     140}
     141
     142nv::uint32 nv::sdl::window::window_id()
     143{
     144        return SDL_GetWindowID( static_cast<SDL_Window*>( m_handle ) );
     145}
  • trunk/src/sdl/sdl_window_manager.cc

    r395 r505  
    1717sdl::window_manager::window_manager()
    1818{
     19        primal_window = nullptr;
    1920        nv::load_sdl_library();
    2021
     
    2930{
    3031        if ( ! SDL_WasInit( SDL_INIT_VIDEO ) ) SDL_InitSubSystem( SDL_INIT_VIDEO );
    31         return new sdl::window( dev, width, height, fullscreen );
     32        sdl::window* result = new sdl::window( dev, width, height, fullscreen );
     33        primal_window = result->get_handle();
     34        return result;
    3235}
    3336
     
    3538{
    3639        if ( ! SDL_WasInit( SDL_INIT_VIDEO ) ) SDL_InitSubSystem( SDL_INIT_VIDEO );
    37         return SDL_CreateWindowFrom( sys_w_handle );
     40        if ( primal_window )
     41        {
     42                char buffer[128];
     43                sprintf( buffer, "%p", primal_window );
     44                NV_ASSERT( SDL_SetHint( "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT", buffer ) == SDL_TRUE );
     45        }
     46        primal_window = SDL_CreateWindowFrom( sys_w_handle );
     47        return primal_window;
    3848}
    3949
  • trunk/src/wx/wx_canvas.cc

    r470 r505  
    1313wxEND_EVENT_TABLE()
    1414
    15 nv::wx_gl_canvas::wx_gl_canvas( wxWindow *parent )
     15nv::wx_gl_canvas::wx_gl_canvas( wxWindow *parent, input* in )
    1616        : wxWindow( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
    1717        wxFULL_REPAINT_ON_RESIZE )
     
    1919        nv::load_gl_no_context();
    2020        wxClientDC dc( this );
     21        m_render  = true;
     22        m_wm      = new nv::sdl::window_manager;
     23        m_device  = new nv::gl_device();
     24        if ( !in ) in = new nv::sdl::input;
     25        m_window = new nv::gl_window( m_device, m_wm, in, GetHWND(), dc.GetHDC() );
     26        m_context = m_window->get_context();
     27        m_main    = true;
     28}
     29
     30nv::wx_gl_canvas::wx_gl_canvas( wxWindow *parent, wx_gl_canvas *sibling, input* in )
     31        : wxWindow( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
     32                wxFULL_REPAINT_ON_RESIZE )
     33{
     34        wxClientDC dc( this );
    2135        m_render = true;
    22         m_wm = new nv::sdl::window_manager;
     36        m_wm = sibling->m_wm;
    2337        m_device = new nv::gl_device();
    24         m_window = new nv::gl_window( m_device, m_wm, new nv::sdl::input(), GetHWND(), dc.GetHDC() );
     38        if ( !in ) in = new nv::sdl::input;
     39        m_window = new nv::gl_window( m_device, m_wm, in, GetHWND(), dc.GetHDC() );
    2540        m_context = m_window->get_context();
     41        make_current();
     42        m_main = false;
     43
    2644}
    2745
    2846nv::wx_gl_canvas::~wx_gl_canvas()
    2947{
     48        make_current();
    3049        delete m_window;
    3150        delete m_device;
     
    3453void nv::wx_gl_canvas::on_paint( wxPaintEvent& )
    3554{
     55        make_current();
    3656        const wxSize client_size = GetClientSize();
    3757        m_context->set_viewport( nv::ivec4( nv::ivec2(), client_size.x, client_size.y ) );
     
    5373void nv::wx_gl_canvas::on_idle( wxIdleEvent& evt )
    5474{
    55         nv::sleep( 10 );
     75        nv::sleep( 1 );
    5676        if ( m_render )
    5777        {
     78                make_current();
    5879                on_update();
    5980                evt.RequestMore(); // render continuously, not only once on idle
    6081        }
     82}
     83
     84void nv::wx_gl_canvas::make_current()
     85{
     86        m_window->make_current();
    6187}
    6288
Note: See TracChangeset for help on using the changeset viewer.