Changeset 491 for trunk


Ignore:
Timestamp:
04/29/16 12:42:28 (9 years ago)
Author:
epyon
Message:
  • mass update (will try to do atomic from now)
Location:
trunk
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/gfx/skeleton_instance.hh

    r487 r491  
    7070
    7171                uint32 size() const { return m_offsets.size(); }
     72//      protected:
     73                dynamic_array< value_type >   m_offsets;
    7274        protected:
    73                 dynamic_array< value_type >   m_offsets;
    7475
    7576                template < typename T >
     
    8687                uint32 size() const { return m_indices.size(); }
    8788                uint32 skeleton_size() const { return m_bone_count; }
     89//      protected:
     90                dynamic_array< sint16 > m_indices;
    8891        protected:
    89                 dynamic_array< sint16 > m_indices;
    9092                data_descriptor         m_key;
    9193                uint32                  m_bone_count;
     
    170172                        if ( bones.size() != m_matrix.size() ) m_matrix.resize( bones.size() );
    171173                }
     174
     175                void resize( uint32 new_size )
     176                {
     177                        m_matrix.resize( new_size );
     178                }
     179
     180                void assign( const skeleton_transforms& skeleton, const skeleton_binding& binding, const bone_transforms< value_type >& bones, uint32 offset )
     181                {
     182                        uint32 sz = bones.size();
     183                        if ( m_matrix.size() < offset + sz ) m_matrix.resize( offset + sz );
     184                        const transform* transforms = skeleton.xforms();
     185                        for ( uint32 n = 0; n < skeleton.size(); ++n )
     186                        {
     187                                sint16 bone_id = binding.m_indices[n];
     188                                if ( bone_id >= 0 )
     189                                {
     190                                        m_matrix[offset + bone_id] = ( transforms[n] * bones.m_offsets[bone_id] ).extract();
     191                                }
     192                        }
     193                }
     194
     195
    172196        protected:
    173197
  • trunk/nv/gfx/sliced_buffer.hh

    r437 r491  
    202202                void create_buffer( size_t size )
    203203                {
    204                         m_context->get_device()->release( m_buffer );
    205204                        m_capacity = size;
    206                         m_buffer   = m_context->get_device()->create_buffer( m_type, m_hint, size * value_type_size, nullptr );
     205                        if ( m_buffer )
     206                                m_context->get_device()->create_buffer( m_buffer, size * value_type_size, nullptr );
     207                        else
     208                                m_buffer = m_context->get_device()->create_buffer( m_type, m_hint, size * value_type_size, nullptr );
    207209                }
    208210        private:
  • trunk/nv/gl/gl_context.hh

    r485 r491  
    2424        };
    2525
     26        struct gl_vertex_array_info : public vertex_array_info
     27        {
     28                unsigned glid;
     29        };
     30
     31
    2632        class gl_context : public context
    2733        {
     
    3036                virtual ~gl_context();
    3137
    32                 virtual vertex_array create_vertex_array();
     38                virtual vertex_array create_vertex_array( const vertex_array_desc& desc );
    3339                virtual framebuffer create_framebuffer();
    3440                virtual void release( vertex_array va );
    3541                virtual void release( framebuffer f );
    36                 virtual const vertex_array_info* get_vertex_array_info( vertex_array va ) const;
    3742                virtual const framebuffer_info* get_framebuffer_info( framebuffer f ) const;
    3843
     
    4954                virtual void bind( texture t, texture_slot slot );
    5055                virtual void bind( buffer b, uint32 index, size_t offset = 0, size_t size = 0 );
     56                virtual void bind( buffer b, texture t );
     57
    5158
    5259                virtual void update( texture t, const void* data );
    5360                virtual void update( buffer b, const void* data, size_t offset, size_t size );
    54 //              virtual void update( buffer b, uint32 index, const void* data, size_t offset, size_t size );
     61                //              virtual void update( buffer b, uint32 index, const void* data, size_t offset, size_t size );
    5562
    5663                virtual void clear( const clear_state& cs );
     
    7582                void force_apply_render_state( const render_state& state );
    7683                void force_apply_stencil_face( unsigned face, const stencil_test_face& stencil );
    77                 // TODO: remove
    78                 virtual vertex_array_info* get_vertex_array_info_mutable( vertex_array );
    7984        private:
    8085                void apply_stencil_test( const stencil_test& stencil );
     
    95100                void* m_handle;
    96101
    97                 handle_store< vertex_array_info, vertex_array > m_vertex_arrays;
    98                 handle_store< gl_framebuffer_info, framebuffer > m_framebuffers;
     102                handle_store< gl_vertex_array_info, vertex_array > m_vertex_arrays;
     103                handle_store< gl_framebuffer_info, framebuffer >   m_framebuffers;
    99104        };
    100105
  • trunk/nv/gl/gl_device.hh

    r485 r491  
    4848                virtual texture create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, const void* data = nullptr );
    4949                virtual texture create_texture( texture_type type, ivec3 size, image_format aformat, sampler asampler, const void* data = nullptr );
     50                virtual texture create_texture( texture_type type, pixel_format format );
     51                virtual void create_buffer( buffer b, size_t size, const void* source = nullptr );
    5052
    5153                virtual void release( buffer b );
  • trunk/nv/gui/gui_environment.hh

    r440 r491  
    4040                        void destroy_element( handle e );
    4141                        bool process_io_event( const io_event& ev );
     42                        renderer* get_renderer() { return m_renderer; }
    4243                        string_view get_string( shash64 h );
    4344                        virtual ~environment();
  • trunk/nv/gui/gui_gfx_renderer.hh

    r444 r491  
    5252                        virtual void on_select_change( element* e );
    5353                        virtual rectangle get_area() const { return m_area; }
     54                        virtual void set_shader( program p );
    5455                        virtual ~gfx_renderer();
    5556                private:
  • trunk/nv/interface/context.hh

    r485 r491  
    4747        struct vertex_array_info
    4848        {
    49                 static const int MAX_ATTRIBUTES = 24;
     49                static const int MAX_ATTRIBUTES = 16;
    5050
    5151                uint32        count;
     
    6363        };
    6464
     65        class vertex_array_desc : private vertex_array_info
     66        {
     67        private:
     68                friend class context;
     69                friend class gl_context;
     70        public:
     71                vertex_array_desc()
     72                {
     73                        count = 0;
     74                        index = buffer();
     75                        index_owner = false;
     76                        index_type = USHORT;
     77                }
     78
     79                template < typename VTX, slot SLOT >
     80                void add_vertex_buffer( buffer vb, bool owned )
     81                {
     82                        add_vertex_buffer_impl< VTX, SLOT >( vb, owned, has_slot< VTX, SLOT >() );
     83                }
     84
     85                template < typename VTX >
     86                void add_vertex_buffers( buffer vb, bool owned )
     87                {
     88                        add_vertex_buffer< VTX, slot::POSITION >( vb, owned );
     89                        add_vertex_buffer< VTX, slot::TEXCOORD >( vb, owned );
     90                        add_vertex_buffer< VTX, slot::NORMAL   >( vb, owned );
     91                        add_vertex_buffer< VTX, slot::TANGENT >( vb, owned );
     92                        add_vertex_buffer< VTX, slot::BONEINDEX >( vb, owned );
     93                        add_vertex_buffer< VTX, slot::BONEWEIGHT >( vb, owned );
     94                        add_vertex_buffer< VTX, slot::COLOR >( vb, owned );
     95                }
     96
     97                void add_vertex_buffers( buffer buf, const data_descriptor& descriptor )
     98                {
     99                        for ( const auto& cslot : descriptor )
     100                        {
     101                                const datatype_info& info = get_datatype_info( cslot.etype );
     102                                add_vertex_buffer( cslot.vslot, buf, info.base, info.elements, cslot.offset, descriptor.element_size(), false );
     103                        }
     104                }
     105
     106
     107                // TODO: should be private
     108                void add_vertex_buffer( slot location, buffer buf, datatype datatype, size_t components, size_t offset = 0, size_t stride = 0, bool owner = true )
     109                {
     110                        NV_ASSERT( count < uint16( MAX_ATTRIBUTES ), "MAX_ATTRIBUTES reached!" );
     111                        vertex_buffer_attribute& p = attr[count];
     112                        p.vbuffer    = buf;
     113                        p.dtype      = datatype;
     114                        p.components = components;
     115                        p.offset     = offset;
     116                        p.stride     = stride;
     117                        p.owner      = owner;
     118                        p.location   = location;
     119                        count++;
     120                }
     121
     122                // TODO: should be private
     123                void set_index_buffer( buffer b, datatype datatype, bool owner )
     124                {
     125                        index = b;
     126                        index_owner = owner;
     127                        index_type = datatype;
     128                }
     129        private:
     130                template < typename VTX, slot SLOT >
     131                void add_vertex_buffer_impl( buffer, bool, const false_type& )
     132                {
     133                }
     134
     135                template < typename VTX, slot SLOT >
     136                void add_vertex_buffer_impl( buffer vb, bool owned, const true_type& )
     137                {
     138                        typedef slot_info< VTX, SLOT > vinfo;
     139                        typedef datatype_traits< typename vinfo::value_type > dt_traits;
     140                        add_vertex_buffer( SLOT, vb, type_to_enum< typename dt_traits::base_type >::type, dt_traits::size, vinfo::offset, sizeof( VTX ), owned );
     141                }
     142
     143        };
     144
    65145        class context
    66146        {
     
    71151                }
    72152
    73                 virtual vertex_array create_vertex_array() = 0;
     153                virtual vertex_array create_vertex_array( const vertex_array_desc& desc ) = 0;
    74154                virtual framebuffer create_framebuffer() = 0;
    75155                virtual void release( vertex_array ) = 0;
    76156                virtual void release( framebuffer ) = 0;
    77157
    78                 virtual const vertex_array_info* get_vertex_array_info( vertex_array ) const = 0;
    79158                virtual const framebuffer_info* get_framebuffer_info( framebuffer ) const = 0;
    80159
     
    92171                virtual void bind( texture, texture_slot ) = 0;
    93172                virtual void bind( buffer, uint32 /*index*/, size_t /*offset*/ = 0, size_t /*size */= 0 ) = 0;
     173                virtual void bind( buffer, texture ) = 0;
    94174
    95175                virtual void update( texture, const void* ) = 0;
    96176                virtual void update( buffer, const void*, size_t /*offset*/, size_t /*size*/ ) = 0;
     177
    97178//              virtual void update( buffer, uint32 /*index*/, const void* , size_t /*offset*/, size_t /*size*/ ) = 0;
    98179
     
    116197                }
    117198
    118                 template < typename VTX, slot SLOT >
    119                 void add_vertex_buffer_impl( vertex_array, buffer, bool, const false_type& )
    120                 {
    121                 }
    122 
    123                 template < typename VTX, slot SLOT >
    124                 void add_vertex_buffer_impl( vertex_array va, buffer vb, bool owned, const true_type& )
    125                 {
    126                         typedef slot_info< VTX, SLOT > vinfo;
    127                         typedef datatype_traits< typename vinfo::value_type > dt_traits;
    128                         add_vertex_buffer( va, SLOT, vb, type_to_enum< typename dt_traits::base_type >::type, dt_traits::size, vinfo::offset, sizeof( VTX ), owned );
    129                 }
    130 
    131                 template < typename VTX, slot SLOT >
    132                 void add_vertex_buffer( vertex_array va, buffer vb, bool owned )
    133                 {
    134                         add_vertex_buffer_impl< VTX, SLOT >( va, vb, owned, has_slot< VTX, SLOT >() );
    135                 }
    136 
    137                 template < typename VTX >
    138                 void add_vertex_buffers( vertex_array va, buffer vb, bool owned )
    139                 {
    140                         add_vertex_buffer< VTX, slot::POSITION >  ( va, vb, owned );
    141                         add_vertex_buffer< VTX, slot::TEXCOORD >  ( va, vb, owned );
    142                         add_vertex_buffer< VTX, slot::NORMAL   >  ( va, vb, owned );
    143                         add_vertex_buffer< VTX, slot::TANGENT >   ( va, vb, owned );
    144                         add_vertex_buffer< VTX, slot::BONEINDEX > ( va, vb, owned );
    145                         add_vertex_buffer< VTX, slot::BONEWEIGHT >( va, vb, owned );
    146                         add_vertex_buffer< VTX, slot::COLOR >     ( va, vb, owned );
    147                 }
    148 
    149                 void add_vertex_buffers( vertex_array va, buffer buf, const data_descriptor& descriptor )
    150                 {
    151                         for ( const auto& cslot : descriptor )
    152                         {
    153                                 const datatype_info& info = get_datatype_info( cslot.etype );
    154                                 add_vertex_buffer( va, cslot.vslot, buf, info.base, info.elements, cslot.offset, descriptor.element_size(), false );
    155                         }
    156                 }
    157 
    158 
    159199                template < typename VTXDATA >
    160200                enable_if_t< is_class< VTXDATA >::value, vertex_array >
     
    174214                vertex_array create_vertex_array( const VTX* v, size_t count, buffer_hint hint )
    175215                {
    176                         vertex_array va = create_vertex_array();
    177216                        buffer       vb = m_device->create_buffer( VERTEX_BUFFER, hint, count * sizeof( VTX ), v );
    178                         add_vertex_buffers< VTX >( va, vb, true );
    179                         return va;
     217                        vertex_array_desc desc;
     218                        desc.add_vertex_buffers< VTX >( vb, true );
     219                        return create_vertex_array( desc );
    180220                }
    181221
     
    183223                vertex_array create_vertex_array( const VTX* v, size_t vcount, const IDX* i, size_t icount, buffer_hint hint )
    184224                {
    185                         vertex_array va = create_vertex_array( v, vcount, hint );
     225                        buffer       vb = m_device->create_buffer( VERTEX_BUFFER, hint, count * sizeof( VTX ), v );
    186226                        buffer       ib = m_device->create_buffer( INDEX_BUFFER, hint, icount * sizeof( IDX ), i );
    187                         set_index_buffer( va, ib, type_to_enum< IDX >::type, true );
    188                         return va;
    189                 }
    190 
    191                 void replace_vertex_buffer( vertex_array va, buffer vb, bool owner )
    192                 {
    193                         vertex_array_info* info = get_vertex_array_info_mutable( va );
    194                         if ( info )
    195                         {
    196                                 for ( uint32 i = 0; i < info->count; ++i )
    197                                 {
    198                                         vertex_buffer_attribute& vba = info->attr[i];
    199                                         if ( vba.owner ) m_device->release( vba.vbuffer );
    200                                         vba.vbuffer = vb;
    201                                         vba.owner   = owner;
    202                                 }
    203                         }
    204                 }
    205 
    206                 void replace_vertex_buffer( vertex_array va, buffer vb, slot location, bool owner )
    207                 {
    208                         vertex_array_info* info = get_vertex_array_info_mutable( va );
    209                         if ( info )
    210                         {
    211                                 for ( uint32 i = 0; i < info->count; ++i )
    212                                 {
    213                                         if ( info->attr[i].location == location )
    214                                         {
    215                                                 vertex_buffer_attribute& vba = info->attr[i];
    216                                                 if ( vba.owner ) m_device->release( vba.vbuffer );
    217                                                 vba.vbuffer = vb;
    218                                                 vba.owner   = owner;
    219                                         }
    220                                 }
    221                         }
    222                 }
    223 
    224                 void update_attribute_offset( vertex_array va, slot location, size_t offset )
    225                 {
    226                         vertex_array_info* info = get_vertex_array_info_mutable( va );
    227                         if ( info )
    228                         {
    229                                 for ( uint32 i = 0; i < info->count; ++i )
    230                                 {
    231                                         if ( info->attr[i].location == location )
    232                                         {
    233                                                 info->attr[i].offset = offset;
    234                                         }
    235                                 }
    236                         }
    237                 }
    238 
    239                 void set_index_buffer( vertex_array va, buffer b, datatype datatype, bool owner )
    240                 {
    241                         vertex_array_info* info = get_vertex_array_info_mutable( va );
    242                         if ( info )
    243                         {
    244                                 if ( m_device->get_buffer_info( b )->type == INDEX_BUFFER )
    245                                 {
    246                                         if (info->index.is_valid() && info->index_owner) m_device->release( info->index );
    247 
    248                                         info->index       = b;
    249                                         info->index_owner = owner;
    250                                         info->index_type  = datatype;
    251                                 }
    252                         }
    253                 }
    254 
    255                 virtual void add_vertex_buffer( vertex_array va, slot location, buffer buf, datatype datatype, size_t components, size_t offset = 0, size_t stride = 0, bool owner = true )
    256                 {
    257                         vertex_array_info* info = get_vertex_array_info_mutable( va );
    258                         if ( info )
    259                         {
    260                                 NV_ASSERT( info->count < uint16( vertex_array_info::MAX_ATTRIBUTES ), "MAX_ATTRIBUTES reached!" );
    261                                 vertex_buffer_attribute& p = info->attr[ info->count ];
    262                                 p.vbuffer    = buf;
    263                                 p.dtype      = datatype;
    264                                 p.components = components;
    265                                 p.offset     = offset;
    266                                 p.stride     = stride;
    267                                 p.owner      = owner;
    268                                 p.location   = location;
    269                                 info->count++;
    270                         }
    271                 }
    272 
    273                 buffer find_buffer( vertex_array va, slot location )
    274                 {
    275                         const vertex_array_info* info = get_vertex_array_info( va );
    276                         if ( info )
    277                         {
    278                                 for ( uint32 i = 0; i < info->count; ++i )
    279                                 {
    280                                         if ( info->attr[i].location == location )
    281                                         {
    282                                                 return info->attr[i].vbuffer;
    283                                         }
    284                                 }
    285                         }
    286                         return buffer();
     227                        vertex_array_desc desc;
     228                        desc.add_vertex_buffers< VTX >( vb, true );
     229                        desc.set_index_buffer( ib, type_to_enum< IDX >::type, true );
     230                        return create_vertex_array( desc );
    287231                }
    288232
     
    290234                vertex_array create_vertex_array( const data_channel_set* data, buffer_hint hint )
    291235                {
    292                         vertex_array  va = create_vertex_array();
     236                        vertex_array_desc va_desc;
    293237                        for ( auto& channel : *data )
    294238                        {
     
    300244                                        {
    301245                                                buffer b = m_device->create_buffer( INDEX_BUFFER, hint, channel.raw_size(), channel.raw_data() );
    302                                                 set_index_buffer( va, b, desc[0].etype, true );
     246                                                va_desc.set_index_buffer( b, desc[0].etype, true );
    303247                                        }
    304248                                        else
    305249                                        {
    306250                                                buffer b = m_device->create_buffer( VERTEX_BUFFER, hint, channel.raw_size(), channel.raw_data() );
    307                                                 add_vertex_buffers( va, b, desc );
     251                                                va_desc.add_vertex_buffers( b, desc );
    308252                                        }
    309253                                }
    310254                        }
    311                         return va;
     255                        return create_vertex_array( va_desc );
    312256                }
    313257
    314258        protected:
    315                 // TODO: remove
    316                 virtual vertex_array_info* get_vertex_array_info_mutable( vertex_array ) = 0;
     259
    317260
    318261                device*      m_device;
  • trunk/nv/interface/device.hh

    r486 r491  
    5151                TEXTURE_1D_ARRAY,
    5252                TEXTURE_2D_ARRAY,
     53                TEXTURE_1D_BUFFER,
    5354        };
    5455
    5556        enum texture_slot
    5657        {
    57                 TEX_DIFFUSE  = 0,
    58                 TEX_SPECULAR = 1,
    59                 TEX_NORMAL   = 2,
    60                 TEX_GLOSS    = 3,
    61                 TEX_EMISSIVE = 4,
    62                 TEXTURE_0    = 0,
    63                 TEXTURE_1    = 1,
    64                 TEXTURE_2    = 2,
    65                 TEXTURE_3    = 3,
    66                 TEXTURE_4    = 4,
    67                 TEXTURE_5    = 5,
    68                 TEXTURE_6    = 6,
    69                 TEXTURE_7    = 7,
     58                TEX_DIFFUSE   = 0,
     59                TEX_NORMAL    = 1,
     60                TEX_METALLIC  = 2,
     61                TEX_SPECULAR  = 2, // obsolete
     62                TEX_ROUGHNESS = 3,
     63                TEX_GLOSS     = 3, // obsolete
     64                TEX_EMISSIVE  = 4,
     65                TEXTURE_0     = 0,
     66                TEXTURE_1     = 1,
     67                TEXTURE_2     = 2,
     68                TEXTURE_3     = 3,
     69                TEXTURE_4     = 4,
     70                TEXTURE_5     = 5,
     71                TEXTURE_6     = 6,
     72                TEXTURE_7     = 7,
     73                TEXTURE_8     = 8,
     74                TEXTURE_9     = 9,
     75                TEXTURE_10    = 10,
     76                TEXTURE_11    = 11,
     77                TEXTURE_12    = 12,
     78                TEXTURE_13    = 13,
     79                TEXTURE_14    = 14,
     80                TEXTURE_15    = 15,
    7081        };
    7182
     
    136147                INDEX_BUFFER,
    137148                UNIFORM_BUFFER,
     149                TEXTURE_BUFFER,
    138150        };
    139151
     
    184196                virtual texture create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, const void* data = nullptr ) = 0;
    185197                virtual texture create_texture( texture_type type, ivec3 size, image_format aformat, sampler asampler, const void* data = nullptr ) = 0;
     198                virtual texture create_texture( texture_type type, pixel_format format ) = 0;
     199
    186200                // TODO: remove?
    187201                virtual texture create_texture( ivec2 size, image_format aformat, sampler asampler, const void* data = nullptr ) { return create_texture( TEXTURE_2D, size, aformat, asampler, data ); }
     202
     203                virtual void create_buffer( buffer, size_t, const void* = nullptr ) = 0;
     204
     205
    188206                virtual image_data* create_image_data( string_view filename ) = 0; // temporary
    189207                virtual image_data* create_image_data( const uint8* data, uint32 size ) = 0; // temporary
     
    307325
    308326                        engine_link_uniform_factory_map& factory_link_map = get_link_uniform_factory();
    309                         factory_link_map[ "nv_texture_0" ] = new engine_link_uniform_int<0>();
    310                         factory_link_map[ "nv_texture_1" ] = new engine_link_uniform_int<1>();
    311                         factory_link_map[ "nv_texture_2" ] = new engine_link_uniform_int<2>();
    312                         factory_link_map[ "nv_texture_3" ] = new engine_link_uniform_int<3>();
    313                         factory_link_map[ "nv_texture_4" ] = new engine_link_uniform_int<4>();
    314                         factory_link_map[ "nv_texture_5" ] = new engine_link_uniform_int<5>();
    315                         factory_link_map[ "nv_texture_6" ] = new engine_link_uniform_int<6>();
    316                         factory_link_map[ "nv_texture_7" ] = new engine_link_uniform_int<7>();
    317                         factory_link_map[ "nv_t_diffuse" ] = new engine_link_uniform_int<0>();
    318                         factory_link_map[ "nv_t_specular"] = new engine_link_uniform_int<1>();
    319                         factory_link_map[ "nv_t_normal"  ] = new engine_link_uniform_int<2>();
    320                         factory_link_map[ "nv_t_gloss"   ] = new engine_link_uniform_int<3>();
    321                         factory_link_map[ "nv_t_emissive"] = new engine_link_uniform_int<4>();
     327                        factory_link_map[ "nv_texture_0"  ] = new engine_link_uniform_int<0>();
     328                        factory_link_map[ "nv_texture_1"  ] = new engine_link_uniform_int<1>();
     329                        factory_link_map[ "nv_texture_2"  ] = new engine_link_uniform_int<2>();
     330                        factory_link_map[ "nv_texture_3"  ] = new engine_link_uniform_int<3>();
     331                        factory_link_map[ "nv_texture_4"  ] = new engine_link_uniform_int<4>();
     332                        factory_link_map[ "nv_texture_5"  ] = new engine_link_uniform_int<5>();
     333                        factory_link_map[ "nv_texture_6"  ] = new engine_link_uniform_int<6>();
     334                        factory_link_map[ "nv_texture_7"  ] = new engine_link_uniform_int<7>();
     335                        factory_link_map[ "nv_t_diffuse"  ] = new engine_link_uniform_int<int( TEX_DIFFUSE )>();
     336                        factory_link_map[ "nv_t_normal"   ] = new engine_link_uniform_int<int( TEX_NORMAL )>();
     337                        factory_link_map[ "nv_t_metallic" ] = new engine_link_uniform_int<int( TEX_METALLIC )>();
     338                        factory_link_map[ "nv_t_specular" ] = new engine_link_uniform_int<int( TEX_METALLIC )>();
     339                        factory_link_map[ "nv_t_roughness"] = new engine_link_uniform_int<int( TEX_ROUGHNESS )>();
     340                        factory_link_map[ "nv_t_gloss"    ] = new engine_link_uniform_int<int( TEX_ROUGHNESS )>();
     341                        factory_link_map[ "nv_t_emissive" ] = new engine_link_uniform_int<int( TEX_EMISSIVE )>();
    322342                }
    323343                void destroy_engine_uniforms()
  • trunk/nv/interface/image_data.hh

    r486 r491  
    3636                DEPTH24,
    3737                DEPTH32,
     38                R8I,
     39                R8UI,
     40                R16I,
     41                R16UI,
     42                R32I,
     43                R32UI,
    3844        };
    3945       
  • trunk/nv/lib/gl.hh

    r465 r491  
    8989        };
    9090
    91         const char* get_gl_extension_name( gl_extensions extension );
    92         bool load_gl_extension( gl_extensions extension );
    93         gl_extensions load_gl_extensions( uint32 extensions );
    94         bool is_gl_extension_loaded( gl_extensions extensions );
    95         bool are_gl_extensions_loaded( uint32 extensions );
     91//      const char* get_gl_extension_name( gl_extensions extension );
     92//      bool load_gl_extension( gl_extensions extension );
     93//      gl_extensions load_gl_extensions( uint32 extensions );
     94//      bool is_gl_extension_loaded( gl_extensions extensions );
     95//      bool are_gl_extensions_loaded( uint32 extensions );
    9696        bool load_gl_no_context( const char* path = NV_GL_PATH );
    9797        /* Dynamic load support */
  • trunk/nv/lua/lua_values.hh

    r449 r491  
    140140
    141141                template <>
     142                struct pass_traits<float>
     143                {
     144                        static void push( lua_State *L, float s ) { detail::push_number( L, static_cast<double>( s ) ); }
     145                        static float to( lua_State *L, int index ) { return static_cast<float>( detail::to_number( L, index ) ); }
     146                        static float to( lua_State *L, int index, lnumber def ) { return static_cast<float>( detail::to_number( L, index, def ) ); }
     147                };
     148
     149                template <>
    142150                struct pass_traits<bool>
    143151                {
     
    202210                        struct lua_type_impl< T, enable_if_t< is_floating_point< T >::value > >
    203211                        {
    204                                 typedef lnumber type;
     212                                typedef T type;
    205213                        };
    206214
  • trunk/src/engine/material_manager.cc

    r486 r491  
    3939
    4040                // HACK
    41                 for ( uint32 i = 0; i < 5; ++i )
     41                for ( uint32 i = 0; i < 8; ++i )
    4242                        if ( result->textures[i].is_nil() )
    4343                                result->textures[i] = m_default;
     
    5959bool material_manager::load_resource( nv::lua::table_guard& table, nv::shash64 id )
    6060{
     61        c_file_system fs;
    6162        material* m = new material;
    62         m->paths[ TEX_DIFFUSE ]  = table.get_string128( "diffuse" );
    63         m->paths[ TEX_SPECULAR ] = table.get_string128( "specular" );
    64         m->paths[ TEX_NORMAL ]   = table.get_string128( "normal" );
    65         m->paths[ TEX_EMISSIVE ] = table.get_string128( "emissive" );
    66         m->paths[ TEX_GLOSS ]    = table.get_string128( "gloss" );
     63
     64        if ( table.is_string( "path" ) )
     65        {
     66                string128 path = table.get_string128( "path" );
     67                for ( uint32 i = 0; i < 5; ++i )
     68                        m->paths[i] = path;
     69                m->paths[TEX_DIFFUSE].append( "_diffuse.png" );
     70                m->paths[TEX_NORMAL].append( "_normal.png" );
     71                m->paths[TEX_METALLIC].append( "_metallic.png" );
     72                m->paths[TEX_ROUGHNESS].append( "_roughness.png" );
     73                m->paths[TEX_EMISSIVE].append( "_emissive.png" );
     74                for ( uint32 i = 0; i < 5; ++i )
     75                {
     76                        if ( !fs.exists( m->paths[i] ) )
     77                        {
     78                                if ( i != TEX_EMISSIVE )
     79                                        NV_LOG_ERROR( "Texture file not found! : ", m->paths[i] );
     80                                m->paths[i].clear();
     81                        }
     82                }
     83        }
     84        else
     85        {
     86                m->paths[ TEX_DIFFUSE ]  = table.get_string128( "diffuse" );
     87                m->paths[ TEX_NORMAL ]   = table.get_string128( "normal" );
     88                m->paths[ TEX_METALLIC]  = table.get_string128( "metallic" );
     89                m->paths[ TEX_ROUGHNESS] = table.get_string128( "roughness" );
     90                m->paths[ TEX_EMISSIVE ] = table.get_string128( "emissive" );
     91        }
    6792        add( id, m );
    6893        return true;
    6994}
     95
  • trunk/src/engine/particle_engine.cc

    r479 r491  
    497497        info->particles = new particle[ data->quota ];
    498498        info->quads     = new particle_quad[ data->quota ];
    499         info->vtx_array = m_context->create_vertex_array<particle_vtx>( info->quads[0].data, data->quota*6, STREAM_DRAW );
    500         info->vtx_buffer = m_context->find_buffer( info->vtx_array, slot::POSITION );
     499
     500        vertex_array_desc desc;
     501        info->vtx_buffer = m_device->create_buffer( VERTEX_BUFFER, STREAM_DRAW, data->quota * 6 * sizeof( particle_vtx ), info->quads[0].data );
     502        desc.add_vertex_buffers< particle_vtx >( info->vtx_buffer, true );
     503        info->vtx_array = m_context->create_vertex_array( desc );
    501504        info->last_update = m_last_update;
    502505        info->test = false;
  • trunk/src/formats/assimp_loader.cc

    r487 r491  
    188188
    189189        uint8*  cdata   = maccess.add_channel( desc, mesh->mNumVertices ).raw_data();
    190         uint16* indices = reinterpret_cast<uint16*>( maccess.add_channel< index_u16 >( mesh->mNumFaces * 3 ).raw_data() );
     190        uint32* indices = reinterpret_cast<uint32*>( maccess.add_channel< index_u32 >( mesh->mNumFaces * 3 ).raw_data() );
    191191
    192192        if ( mesh->mTangents && mesh->mBitangents )
     
    239239                for (unsigned int j=0; j<face->mNumIndices; j++)
    240240                {
    241                         indices[ i*3 + j ] = uint16( face->mIndices[j] );
     241                        indices[ i*3 + j ] = uint32( face->mIndices[j] );
    242242                }
    243243        }
  • trunk/src/gfx/debug_draw.cc

    r469 r491  
    2525#version 120
    2626varying vec3 v_color;
     27out vec4 o_frag_color;
    2728void main(void)
    2829{
    29         gl_FragColor = vec4( v_color, 1.0 );
     30        o_frag_color = vec4( v_color, 1.0 );
    3031}
    3132)";
     
    4445                if ( m_va.is_valid() ) m_context->release( m_va );
    4546                m_buffer_size = nv::max( m_data.size(), 4096U, m_buffer_size );
    46                 m_va = m_context->create_vertex_array();
    4747                m_vb = m_context->get_device()->create_buffer( VERTEX_BUFFER, nv::STREAM_DRAW, m_buffer_size * sizeof( debug_vtx ), m_data.data() );
    48                 m_context->add_vertex_buffers< debug_vtx >( m_va, m_vb, true );
     48                vertex_array_desc va_desc;
     49                va_desc.add_vertex_buffers< debug_vtx >( m_vb, true );
     50                m_va = m_context->create_vertex_array( va_desc );
    4951        }
    5052        else
  • trunk/src/gfx/mesh_creator.cc

    r487 r491  
    388388        {
    389389        case USHORT: swap_culling_impl< uint16 >( m_idx_channel ); break;
    390         case UINT: swap_culling_impl< uint16 >( m_idx_channel ); break;
     390        case UINT: swap_culling_impl< uint32 >( m_idx_channel ); break;
    391391        default: NV_ASSERT( false, "Swap culling supports only unsigned and unsigned short indices!" ); break;
    392392        }
  • trunk/src/gl/gl_context.cc

    r487 r491  
    1414using namespace nv;
    1515
    16 nv::vertex_array nv::gl_context::create_vertex_array()
     16nv::vertex_array nv::gl_context::create_vertex_array( const vertex_array_desc& desc )
    1717{
    1818        vertex_array result = m_vertex_arrays.create();
    19         vertex_array_info* info = m_vertex_arrays.get( result );
    20         info->count       = 0;
    21         info->index       = buffer();
    22         info->index_owner = false;
    23         info->index_type  = USHORT;
     19        gl_vertex_array_info* info = m_vertex_arrays.get( result );
     20
     21        glGenVertexArrays( 1, &info->glid );
     22        info->count       = desc.count;
     23        info->index       = desc.index;
     24        info->index_owner = desc.index_owner;
     25        info->index_type  = desc.index_type;
     26
     27        for ( uint32 i = 0; i < desc.count; ++i )
     28                info->attr[i] = desc.attr[i];
     29
     30        glBindVertexArray( info->glid );
     31
     32        for ( uint32 i = 0; i < info->count; ++i )
     33        {
     34                const vertex_buffer_attribute& vba = info->attr[i];
     35                uint32 location = static_cast<uint32>( vba.location );
     36                glEnableVertexAttribArray( location );
     37                const gl_buffer_info* vinfo = static_cast<const gl_buffer_info*>( m_device->get_buffer_info( vba.vbuffer ) );
     38                if ( vinfo && vinfo->type == VERTEX_BUFFER )
     39                        glBindBuffer( GL_ARRAY_BUFFER, vinfo->glid );
     40                else
     41                {
     42                        // TODO: report error
     43                }
     44
     45                glVertexAttribPointer(
     46                        location,
     47                        static_cast<GLint>( vba.components ),
     48                        nv::datatype_to_gl_enum( vba.dtype ),
     49                        GL_FALSE,
     50                        static_cast<GLsizei>( vba.stride ),
     51                        reinterpret_cast<void*>( vba.offset )
     52                        );
     53        }
     54        glBindBuffer( GL_ARRAY_BUFFER, 0 );
     55
     56        if ( info->index.is_valid() )
     57        {
     58                const gl_buffer_info* iinfo = static_cast<const gl_buffer_info*>( m_device->get_buffer_info( info->index ) );
     59                if ( iinfo && iinfo->type == INDEX_BUFFER )
     60                {
     61                        glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, iinfo->glid );
     62                }
     63                else
     64                {
     65                        // TODO: report error
     66                }
     67        }
     68        glBindBuffer( GL_ARRAY_BUFFER, 0 );
     69        glBindVertexArray( 0 );
     70
     71        if ( info->index.is_valid() )
     72        {
     73                glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
     74        }
     75
     76        for ( uint32 i = 0; i < info->count; ++i )
     77        {
     78                glDisableVertexAttribArray( static_cast<uint32>( info->attr[i].location ) );
     79        }
     80
     81
    2482        return result;
    2583}
     
    2785nv::framebuffer nv::gl_context::create_framebuffer()
    2886{
    29         if ( is_gl_extension_loaded( GL_EXT_FRAMEBUFFER_OBJECT ) && is_gl_extension_loaded( GL_EXT_FRAMEBUFFER_BLIT ) )
    30         {
    31                 unsigned glid   = 0;
    32                 glGenFramebuffers( 1, &glid );
    33                 framebuffer result = m_framebuffers.create();
    34                 gl_framebuffer_info* info = m_framebuffers.get( result );
    35                 info->glid = glid;
    36                 info->depth_rb_glid = 0;
    37                 info->color_attachment_count = 0;
    38                 return result;
    39         }
    40         else return framebuffer();
     87        unsigned glid   = 0;
     88        glGenFramebuffers( 1, &glid );
     89        framebuffer result = m_framebuffers.create();
     90        gl_framebuffer_info* info = m_framebuffers.get( result );
     91        info->glid = glid;
     92        info->depth_rb_glid = 0;
     93        info->color_attachment_count = 0;
     94        return result;
    4195}
    4296
    4397void nv::gl_context::release( vertex_array va )
    4498{
    45         vertex_array_info* info = m_vertex_arrays.get( va );
     99        gl_vertex_array_info* info = m_vertex_arrays.get( va );
    46100        if ( info )
    47101        {
     
    52106                }
    53107                if ( info->index.is_valid() && info->index_owner) m_device->release( info->index );
     108                glDeleteVertexArrays( 1, &info->glid );
    54109                m_vertex_arrays.destroy( va );
    55110        }
     
    71126}
    72127
    73 const vertex_array_info* nv::gl_context::get_vertex_array_info( vertex_array va ) const
    74 {
    75         return m_vertex_arrays.get( va );
    76 }
    77 
    78128const framebuffer_info* nv::gl_context::get_framebuffer_info( framebuffer f ) const
    79129{
    80130        return m_framebuffers.get( f );
    81 }
    82 
    83 vertex_array_info* nv::gl_context::get_vertex_array_info_mutable( vertex_array va )
    84 {
    85         return m_vertex_arrays.get( va );
    86131}
    87132
     
    170215        glDrawBuffer( 0 );
    171216        glReadBuffer( 0 );
    172         if ( is_gl_extension_loaded( GL_EXT_FRAMEBUFFER_OBJECT ) && is_gl_extension_loaded( GL_EXT_FRAMEBUFFER_BLIT ) )
    173         {
    174                 unsigned result = glCheckFramebufferStatus( framebuffer_slot_to_enum(ft) );
    175                 if ( result == GL_FRAMEBUFFER_COMPLETE ) return true;
    176                 switch ( result )
    177                 {
    178                 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT         : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete attachment!" ); break;
    179                 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT : NV_LOG_ERROR( "gl_context::check : Framebuffer missing attachment!" ); break;
     217
     218        unsigned result = glCheckFramebufferStatus( framebuffer_slot_to_enum(ft) );
     219        if ( result == GL_FRAMEBUFFER_COMPLETE ) return true;
     220        switch ( result )
     221        {
     222        case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT         : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete attachment!" ); break;
     223        case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT : NV_LOG_ERROR( "gl_context::check : Framebuffer missing attachment!" ); break;
    180224//              case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS         : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete dimensions!" ); break;
    181225//              case GL_FRAMEBUFFER_INCOMPLETE_FORMATS            : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete formats!" ); break;
    182                 case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER        : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete draw buffer!" ); break;
    183                 case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER        : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete read buffer!" ); break;
    184                 case GL_FRAMEBUFFER_UNSUPPORTED                   : NV_LOG_ERROR( "gl_context::check : Framebuffer format combination unsupported!" ); break;
    185                 default: NV_LOG_ERROR( "gl_context::check : Unknown Framebuffer error! (", result, ")" ); break;
    186                 }
    187         }
    188         else
    189         {
    190                 NV_LOG_ERROR( "gl_context::check : Framebuffer extensions not loaded!" );
     226        case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER        : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete draw buffer!" ); break;
     227        case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER        : NV_LOG_ERROR( "gl_context::check : Framebuffer incomplete read buffer!" ); break;
     228        case GL_FRAMEBUFFER_UNSUPPORTED                   : NV_LOG_ERROR( "gl_context::check : Framebuffer format combination unsupported!" ); break;
     229        default: NV_LOG_ERROR( "gl_context::check : Unknown Framebuffer error! (", result, ")" ); break;
    191230        }
    192231        glDrawBuffer( GL_BACK );
     
    205244        {
    206245                glBindFramebuffer( framebuffer_slot_to_enum(ft), 0 );
     246        }
     247}
     248
     249void nv::gl_context::bind( buffer b, texture t )
     250{
     251        const gl_buffer_info*  binfo = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( b ) );
     252        const gl_texture_info* tinfo = static_cast< const gl_texture_info* >( m_device->get_texture_info( t ) );
     253        NV_ASSERT( binfo && tinfo, "Bad buffer or texture passed to create_texture" );
     254        if ( binfo && tinfo )
     255        {
     256                NV_ASSERT_ALWAYS( binfo->type == TEXTURE_BUFFER && tinfo->type == TEXTURE_1D_BUFFER, "bad texture or buffer type!" );
     257                glActiveTexture( GL_TEXTURE0 );
     258                glBindTexture( GL_TEXTURE_BUFFER, tinfo->glid );
     259                glTexBuffer( GL_TEXTURE_BUFFER, image_format_to_internal_enum( tinfo->format.format ), binfo->glid );
     260                glBindTexture( GL_TEXTURE_BUFFER, 0 );
    207261        }
    208262}
     
    252306void nv::gl_context::bind( vertex_array va )
    253307{
    254         const vertex_array_info* info = m_vertex_arrays.get( va );
    255         if ( info )
    256         {
    257                 for ( uint32 i = 0; i < info->count; ++i )
    258                 {
    259                         const vertex_buffer_attribute& vba = info->attr[i];
    260                         uint32 location                    = static_cast<uint32>( vba.location );
    261                         glEnableVertexAttribArray( location );
    262                         const gl_buffer_info* vinfo = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( vba.vbuffer ) );
    263                         if ( vinfo && vinfo->type == VERTEX_BUFFER )
    264                                 glBindBuffer( GL_ARRAY_BUFFER, vinfo->glid );
    265                         else
    266                         {
    267                                 // TODO: report error
    268                         }
    269 
    270                         glVertexAttribPointer(
    271                                 location,
    272                                 static_cast<GLint>( vba.components ),
    273                                 nv::datatype_to_gl_enum( vba.dtype ),
    274                                 GL_FALSE,
    275                                 static_cast<GLsizei>( vba.stride ),
    276                                 reinterpret_cast<void*>( vba.offset )
    277                                 );
    278                 }
    279                 glBindBuffer( GL_ARRAY_BUFFER, 0 );
    280 
    281                 if ( info->index.is_valid() )
    282                 {
    283                         const gl_buffer_info* iinfo = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( info->index ) );
    284                         if ( iinfo && iinfo->type == INDEX_BUFFER )
    285                         {
    286                                 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, iinfo->glid );
    287                         }
    288                         else
    289                         {
    290                                 // TODO: report error
    291                         }
    292                 }
     308        gl_vertex_array_info* info = m_vertex_arrays.get( va );
     309        if ( info )
     310        {
     311                glBindVertexArray( info->glid );
    293312        }
    294313}
     
    313332        if ( info )
    314333        {
    315                 if ( info->index.is_valid() )
    316                 {
    317                         glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
    318                 }
    319 
    320                 for ( uint32 i = 0; i < info->count; ++i )
    321                 {
    322                         glDisableVertexAttribArray( static_cast<uint32>( info->attr[i].location ) );
    323                 }
     334                glBindVertexArray( 0 );
    324335        }
    325336}
     
    340351{
    341352        const gl_texture_info* info = static_cast< const gl_texture_info* >( m_device->get_texture_info( t ) );
     353        NV_ASSERT_ALWAYS( info->type != TEXTURE_1D_BUFFER, "Buffer texture passed to update!" );
    342354        if ( info )
    343355        {
     
    347359
    348360                glBindTexture( gl_type, info->glid );
     361                int this_should_be_subTexImage;
    349362                if ( info->type == TEXTURE_3D || info->type == TEXTURE_2D_ARRAY )
    350363                        glTexImage3D( gl_type, 0, static_cast<GLint>( nv::image_format_to_internal_enum( format.format ) ), size.x, size.y, size.z, 0, nv::image_format_to_enum( format.format ), nv::datatype_to_gl_enum( format.type ), data );
     
    722735{
    723736        // TODO: configurable:
    724         load_gl_extensions( GL_EXT_FRAMEBUFFER_BLIT | GL_EXT_FRAMEBUFFER_OBJECT | GL_EXT_TEXTURE_ARRAY );
     737//      load_gl_extensions( GL_EXT_FRAMEBUFFER_BLIT | GL_EXT_FRAMEBUFFER_OBJECT | GL_EXT_TEXTURE_ARRAY );
    725738        force_apply_render_state( m_render_state );
    726 
    727739}
    728740
  • trunk/src/gl/gl_device.cc

    r487 r491  
    1717gl_device::gl_device()
    1818{
    19         m_shader_header.append( "#version 330\n" );
     19        m_shader_header.append( "#version 330 core\n" );
    2020        for ( auto& i : get_uniform_factory() )
    2121                m_shader_header.append( "uniform "+datatype_to_glsl_type( i.second->get_datatype() )+" "+ i.first +";\n" );
     
    9595nv::texture nv::gl_device::create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, const void* data /*= nullptr */ )
    9696{
    97         NV_ASSERT_ALWAYS( type != TEXTURE_3D && type != TEXTURE_2D_ARRAY, "2D texture type expected!" );
     97        NV_ASSERT_ALWAYS( type != TEXTURE_1D_BUFFER && type != TEXTURE_3D && type != TEXTURE_2D_ARRAY, "2D texture type expected!" );
    9898        unsigned glid = 0;
    9999        unsigned gl_type = texture_type_to_enum( type );
     100        GLint gl_internal = GLint( nv::image_format_to_internal_enum( aformat.format ) );
     101        unsigned gl_enum = nv::image_format_to_enum( aformat.format );
    100102
    101103        bool is_depth = aformat.format == DEPTH16 || aformat.format == DEPTH24 || aformat.format == DEPTH32;
     
    106108
    107109        // Detect if mipmapping was requested
    108         if ( gl_type == GL_TEXTURE_2D && asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST )
     110        if ( gl_type == GL_TEXTURE_2D && gl_enum != GL_RED_INTEGER && asampler.filter_min != sampler::LINEAR && asampler.filter_min != sampler::NEAREST )
    109111        {
    110112                // TODO: This should not be done if we use framebuffers!
     
    119121        glTexParameteri( gl_type, GL_TEXTURE_MIN_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_min ) ) );
    120122        glTexParameteri( gl_type, GL_TEXTURE_MAG_FILTER, GLint( nv::sampler_filter_to_enum( asampler.filter_max ) ) );
    121         glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, GLint( nv::sampler_wrap_to_enum( asampler.wrap_s) ) );
    122         glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, GLint( nv::sampler_wrap_to_enum( asampler.wrap_t) ) );
     123       
     124        if ( gl_enum != GL_RED_INTEGER )
     125        {
     126                glTexParameteri( gl_type, GL_TEXTURE_WRAP_S, GLint( nv::sampler_wrap_to_enum( asampler.wrap_s ) ) );
     127                glTexParameteri( gl_type, GL_TEXTURE_WRAP_T, GLint( nv::sampler_wrap_to_enum( asampler.wrap_t ) ) );
     128        }
    123129
    124130        if ( is_depth )
     
    140146//      glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso );
    141147
    142         glTexImage2D( gl_type, 0, GLint( nv::image_format_to_internal_enum(aformat.format) ), size.x, size.y, 0, nv::image_format_to_enum(aformat.format), nv::datatype_to_gl_enum(aformat.type), data );
     148        glTexImage2D( gl_type, 0, gl_internal, size.x, size.y, 0, gl_enum, nv::datatype_to_gl_enum(aformat.type), data );
    143149
    144150        glBindTexture( gl_type, 0 );
     
    154160}
    155161
     162
     163nv::texture nv::gl_device::create_texture( texture_type type, pixel_format format )
     164{
     165        NV_ASSERT_ALWAYS( type == TEXTURE_1D_BUFFER );
     166        unsigned glid = 0;
     167        unsigned gl_type = texture_type_to_enum( type );
     168
     169        glGenTextures( 1, &glid );
     170
     171        texture result = m_textures.create();
     172        gl_texture_info* info = m_textures.get( result );
     173        info->type = type;
     174        info->format = format;
     175        info->tsampler = sampler();
     176        info->size = ivec3( 1, 1, 1 );
     177        info->glid = glid;
     178
     179        return result;
     180}
     181
    156182nv::texture nv::gl_device::create_texture( texture_type type, ivec3 size, image_format aformat, sampler asampler, const void* data /*= nullptr */ )
    157183{
     
    234260nv::buffer nv::gl_device::create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source /*= nullptr */ )
    235261{
    236         unsigned glid   = 0;
     262        unsigned glid = 0;
    237263        unsigned glenum = buffer_type_to_enum( type );
    238264        glGenBuffers( 1, &glid );
    239265
    240         glBindBuffer( glenum, glid );
    241         glBufferData( glenum, GLsizeiptr( size ), source, buffer_hint_to_enum( hint ) );
    242         glBindBuffer( glenum, 0 );
     266        if ( size > 0 )
     267        {
     268                glBindBuffer( glenum, glid );
     269                glBufferData( glenum, GLsizeiptr( size ), source, buffer_hint_to_enum( hint ) );
     270                glBindBuffer( glenum, 0 );
     271        }
    243272
    244273        buffer result = m_buffers.create();
     
    249278        info->glid = glid;
    250279        return result;
     280}
     281
     282void nv::gl_device::create_buffer( buffer b, size_t size, const void* source )
     283{
     284        gl_buffer_info* info = m_buffers.get( b );
     285        if ( info )
     286        {
     287                unsigned glenum = buffer_type_to_enum( info->type );
     288                glBindBuffer( glenum, info->glid );
     289                glBufferData( glenum, GLsizeiptr( size ), source, buffer_hint_to_enum( info->hint ) );
     290                glBindBuffer( glenum, 0 );
     291        }
    251292}
    252293
  • trunk/src/gl/gl_enum.cc

    r473 r491  
    1515        switch( type )
    1616        {
    17         case TEXTURE_1D      : return GL_TEXTURE_1D;
    18         case TEXTURE_2D      : return GL_TEXTURE_2D;
    19         case TEXTURE_RECT    : return GL_TEXTURE_RECTANGLE;
    20         case TEXTURE_3D      : return GL_TEXTURE_3D;
    21         case TEXTURE_CUBE    : return GL_TEXTURE_CUBE_MAP;
    22         case TEXTURE_1D_ARRAY: return GL_TEXTURE_1D_ARRAY;
    23         case TEXTURE_2D_ARRAY: return GL_TEXTURE_2D_ARRAY;
     17        case TEXTURE_1D       : return GL_TEXTURE_1D;
     18        case TEXTURE_2D       : return GL_TEXTURE_2D;
     19        case TEXTURE_RECT     : return GL_TEXTURE_RECTANGLE;
     20        case TEXTURE_3D       : return GL_TEXTURE_3D;
     21        case TEXTURE_CUBE     : return GL_TEXTURE_CUBE_MAP;
     22        case TEXTURE_1D_ARRAY : return GL_TEXTURE_1D_ARRAY;
     23        case TEXTURE_2D_ARRAY : return GL_TEXTURE_2D_ARRAY;
     24        case TEXTURE_1D_BUFFER: return GL_TEXTURE_BUFFER;
    2425        NV_RETURN_COVERED_DEFAULT( 0 );
    2526        }
     
    171172        case INDEX_BUFFER   : return GL_ELEMENT_ARRAY_BUFFER;
    172173        case UNIFORM_BUFFER : return GL_UNIFORM_BUFFER;
     174        case TEXTURE_BUFFER : return GL_TEXTURE_BUFFER;
    173175                NV_RETURN_COVERED_DEFAULT( 0 );
    174176        }
     
    193195        case DEPTH24 : return GL_DEPTH_COMPONENT;
    194196        case DEPTH32 : return GL_DEPTH_COMPONENT;
     197        case R8I     : return GL_RED_INTEGER;
     198        case R8UI    : return GL_RED_INTEGER;
     199        case R16I    : return GL_RED_INTEGER;
     200        case R16UI   : return GL_RED_INTEGER;
     201        case R32I    : return GL_RED_INTEGER;
     202        case R32UI   : return GL_RED_INTEGER;
    195203        NV_RETURN_COVERED_DEFAULT( 0 );
    196204        }
     
    215223        case DEPTH24 : return GL_DEPTH_COMPONENT24;
    216224        case DEPTH32:  return GL_DEPTH_COMPONENT32;
     225        case R8I     : return GL_R8I;
     226        case R8UI    : return GL_R8UI;
     227        case R16I    : return GL_R16I;
     228        case R16UI   : return GL_R16UI;
     229        case R32I    : return GL_R32I;
     230        case R32UI   : return GL_R32UI;
    217231        NV_RETURN_COVERED_DEFAULT( 0 );
    218232        }
     
    358372        case GL_SAMPLER_1D_ARRAY_SHADOW: return INT;
    359373        case GL_SAMPLER_2D_ARRAY_SHADOW: return INT;
     374        case GL_SAMPLER_BUFFER         : return INT;
     375
     376        case GL_INT_SAMPLER_1D                : return INT;
     377        case GL_INT_SAMPLER_2D                : return INT;
     378        case GL_INT_SAMPLER_3D                : return INT;
     379        case GL_INT_SAMPLER_2D_RECT           : return INT;
     380        case GL_INT_SAMPLER_CUBE              : return INT;
     381        case GL_INT_SAMPLER_1D_ARRAY          : return INT;
     382        case GL_INT_SAMPLER_2D_ARRAY          : return INT;
     383        case GL_INT_SAMPLER_BUFFER            : return INT;
     384        case GL_UNSIGNED_INT_SAMPLER_1D       : return INT;
     385        case GL_UNSIGNED_INT_SAMPLER_2D       : return INT;
     386        case GL_UNSIGNED_INT_SAMPLER_3D       : return INT;
     387        case GL_UNSIGNED_INT_SAMPLER_2D_RECT  : return INT;
     388        case GL_UNSIGNED_INT_SAMPLER_CUBE     : return INT;
     389        case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY : return INT;
     390        case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY : return INT;
     391        case GL_UNSIGNED_INT_SAMPLER_BUFFER   : return INT;
    360392                // TODO: implement?
    361393//      case GL_BOOL   
  • trunk/src/gui/gui_gfx_renderer.cc

    r487 r491  
    1212
    1313static const char *nv_gui_vertex_shader = R"(
    14 #version 130
     14#version 330
    1515in vec2 nv_position;
    1616in vec2 nv_texcoord;
     
    2828
    2929static const char *nv_gui_fragment_shader = R"(
    30 #version 130
     30#version 330
    3131in vec4 v_color;
    3232in vec2 v_texcoord;
    3333uniform sampler2D nv_t_diffuse;
     34out vec4 o_frag_color;
     35
    3436void main(void)
    3537{
    3638        vec4 tex_color = texture2D( nv_t_diffuse, v_texcoord );
    37         gl_FragColor   = v_color * tex_color;
     39        o_frag_color   = v_color * tex_color;
    3840}
    3941)";
     
    158160        m_scene_state.get_camera().set_ortho( 0.0f, float( m_window->get_width() ), float( m_window->get_height() ), 0.0f );
    159161
    160         sr->varray = m_window->get_context()->create_vertex_array();
    161162        buffer vb = sr->buffer.get_buffer();
    162         m_window->get_context()->add_vertex_buffers< vertex >( sr->varray, vb, false );
     163        vertex_array_desc va_desc;
     164        va_desc.add_vertex_buffers< vertex >( vb, true );
     165        sr->varray = m_window->get_context()->create_vertex_array( va_desc );
    163166
    164167        nv::sampler sampler( nv::sampler::LINEAR, nv::sampler::CLAMP_TO_EDGE );
     
    377380        if ( sr->buffer.commit() )
    378381        {
    379                 buffer vb = sr->buffer.get_buffer();
    380                 m_context->replace_vertex_buffer( sr->varray, vb, false );
     382//              buffer vb = sr->buffer.get_buffer();
     383//              m_context->replace_vertex_buffer( sr->varray, vb, false );
    381384        }
    382385        m_context->bind( sr->tex, TEX_DIFFUSE );
     
    401404        m_style.load_flags( e );
    402405}
     406
     407void nv::gui::gfx_renderer::set_shader( program p )
     408{
     409        static_cast<screen_render_data*>( m_render_data )->shader = p;
     410}
  • trunk/src/lib/gl.cc

    r487 r491  
    226226#endif
    227227}
    228 
     228/*
    229229const char* nv::get_gl_extension_name( gl_extensions extension )
    230230{
     
    311311        return true;
    312312}
    313 
     313*/
     314
     315
  • trunk/src/lua/lua_area.cc

    r490 r491  
    161161                }
    162162        }
    163         if (c->y != a->ul.y && c->y != a->lr.y && c->x == a->ul.x + 1 ) c->x = a->ul.x;
     163        if (c->y != a->ul.y && c->y != a->lr.y && c->x == a->ul.x + 1 ) c->x = a->lr.x;
    164164
    165165
     
    313313{
    314314        nv::ivec2 c = to_coord( L, 1 );
    315         int amount = static_cast< int >( lua_tointeger( L, 1 ) );
     315        int amount = static_cast< int >( lua_tointeger( L, 2 ) );
    316316        nv::ivec2 shift( amount, amount );
    317317        push_area( L, nv::rectangle( c - shift, c + shift ) );
  • trunk/src/sdl/sdl_window.cc

    r486 r491  
    3030        //      SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 4 );
    3131
    32         SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
    33         SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
     32        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
     33        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
     34
     35        SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
     36
    3437        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
    3538
Note: See TracChangeset for help on using the changeset viewer.