Changeset 469


Ignore:
Timestamp:
09/17/15 17:17:20 (10 years ago)
Author:
epyon
Message:
  • stl/short_string - minor fix
  • stl/utility - max for 3 arguments
  • stl/math length_sq
  • interface/context - proper handling of buffer ownage in va's
  • wx/canvas - sleep added
Location:
trunk
Files:
8 edited

Legend:

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

    r395 r469  
    4141                program             m_program;
    4242                vertex_array        m_va;
     43                buffer              m_vb;
     44                uint32              m_buffer_size;
    4345                vector< debug_vtx > m_data;
    4446        };
  • trunk/nv/interface/context.hh

    r463 r469  
    125125
    126126                template < typename VTX, slot SLOT >
    127                 void add_vertex_buffer_impl( vertex_array, buffer, const false_type& )
     127                void add_vertex_buffer_impl( vertex_array, buffer, bool, const false_type& )
    128128                {
    129129                }
    130130
    131131                template < typename VTX, slot SLOT >
    132                 void add_vertex_buffer_impl( vertex_array va, buffer vb, const true_type& )
     132                void add_vertex_buffer_impl( vertex_array va, buffer vb, bool owned, const true_type& )
    133133                {
    134134                        typedef slot_info< VTX, SLOT > vinfo;
    135135                        typedef datatype_traits< typename vinfo::value_type > dt_traits;
    136                         add_vertex_buffer( va, SLOT, vb, type_to_enum< typename dt_traits::base_type >::type, dt_traits::size, vinfo::offset, sizeof( VTX ), false );
     136                        add_vertex_buffer( va, SLOT, vb, type_to_enum< typename dt_traits::base_type >::type, dt_traits::size, vinfo::offset, sizeof( VTX ), owned );
    137137                }
    138138
    139139                template < typename VTX, slot SLOT >
    140                 void add_vertex_buffer( vertex_array va, buffer vb )
    141                 {
    142                         add_vertex_buffer_impl< VTX, SLOT >( va, vb, has_slot< VTX, SLOT >() );
     140                void add_vertex_buffer( vertex_array va, buffer vb, bool owned )
     141                {
     142                        add_vertex_buffer_impl< VTX, SLOT >( va, vb, owned, has_slot< VTX, SLOT >() );
    143143                }
    144144
    145145                template < typename VTX >
    146                 void add_vertex_buffers( vertex_array va, buffer vb )
    147                 {
    148                         add_vertex_buffer< VTX, slot::POSITION >  ( va, vb );
    149                         add_vertex_buffer< VTX, slot::TEXCOORD >  ( va, vb );
    150                         add_vertex_buffer< VTX, slot::NORMAL   >  ( va, vb );
    151                         add_vertex_buffer< VTX, slot::TANGENT >   ( va, vb );
    152                         add_vertex_buffer< VTX, slot::BONEINDEX > ( va, vb );
    153                         add_vertex_buffer< VTX, slot::BONEWEIGHT >( va, vb );
    154                         add_vertex_buffer< VTX, slot::COLOR >     ( va, vb );
     146                void add_vertex_buffers( vertex_array va, buffer vb, bool owned )
     147                {
     148                        add_vertex_buffer< VTX, slot::POSITION >  ( va, vb, owned );
     149                        add_vertex_buffer< VTX, slot::TEXCOORD >  ( va, vb, owned );
     150                        add_vertex_buffer< VTX, slot::NORMAL   >  ( va, vb, owned );
     151                        add_vertex_buffer< VTX, slot::TANGENT >   ( va, vb, owned );
     152                        add_vertex_buffer< VTX, slot::BONEINDEX > ( va, vb, owned );
     153                        add_vertex_buffer< VTX, slot::BONEWEIGHT >( va, vb, owned );
     154                        add_vertex_buffer< VTX, slot::COLOR >     ( va, vb, owned );
    155155                }
    156156
     
    182182                vertex_array create_vertex_array( const VTX* v, size_t count, buffer_hint hint )
    183183                {
    184                         // TODO: vb will not be owned or freed!
    185184                        vertex_array va = create_vertex_array();
    186185                        buffer       vb = m_device->create_buffer( VERTEX_BUFFER, hint, count * sizeof( VTX ), v );
    187                         add_vertex_buffers< VTX >( va, vb );
     186                        add_vertex_buffers< VTX >( va, vb, true );
    188187                        return va;
    189188                }
  • trunk/nv/stl/math/geometric.hh

    r454 r469  
    7070                {
    7171                        return sqrt( dot( v, v ) );
     72                }
     73
     74                template < typename T, typename enable_if< is_fp_vec<T>::value >::type* = nullptr >
     75                inline value_type_t<T> length_sq( const T& v )
     76                {
     77                        return dot( v, v );
    7278                }
    7379
  • trunk/nv/stl/string/short_string.hh

    r442 r469  
    9595                        char buffer[8];
    9696                        size_t result = sint32_to_buffer( array_ref< char >( buffer ), s );
    97                         return ( result > 0 ? append( buffer.data(), result ) : 0 );
     97                        return ( result > 0 ? append( buffer, result ) : 0 );
    9898                }
    9999
  • trunk/nv/stl/utility/common.hh

    r395 r469  
    3434
    3535        template < typename T >
     36        inline const T& max( const T& a, const T& b, const T& c )
     37        {
     38                return a < b ? (c < b ? b : c) : a;
     39        }
     40
     41        template < typename T >
    3642        inline const T& min( const T& a, const T& b )
    3743        {
    3844                return a > b ? b : a;
    3945        }
     46
     47        template < typename T >
     48        inline const T& min( const T& a, const T& b, const T& c )
     49        {
     50                return a > b ? ( c > b ? b : c ) : a;
     51        }
     52
    4053}
    4154
  • trunk/src/gfx/debug_draw.cc

    r395 r469  
    88
    99#include "nv/interface/device.hh"
     10#include "nv/core/logging.hh"
    1011
    1112static const char *nv_debug_draw_vertex_shader = R"(
     
    3435{
    3536        m_program = m_context->get_device()->create_program( nv_debug_draw_vertex_shader, nv_debug_draw_fragment_shader );
     37        m_buffer_size = 0;
    3638}
    3739
    3840void nv::debug_data::update()
    3941{
    40         m_context->release( m_va );
    41         m_va = m_context->create_vertex_array( m_data, nv::STATIC_DRAW );
     42        if ( !m_va.is_valid() || m_data.size() > m_buffer_size )
     43        {
     44                if ( m_va.is_valid() ) m_context->release( m_va );
     45                m_buffer_size = nv::max( m_data.size(), 4096U, m_buffer_size );
     46                m_va = m_context->create_vertex_array();
     47                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 );
     49        }
     50        else
     51        {
     52                m_context->update( m_vb, m_data.data(), 0, m_data.size()* sizeof( debug_vtx ) );
     53        }
    4254}
    4355
  • trunk/src/gl/gl_context.cc

    r466 r469  
    4848                for ( uint32 i = 0; i < info->count; ++i )
    4949                {
    50                         if ( info->attr[i].owner ) m_device->release( info->attr[i].vbuffer );
     50                        if ( info->attr[i].owner )
     51                                m_device->release( info->attr[i].vbuffer );
    5152                }
    5253                if ( info->index.is_valid() && info->index_owner) m_device->release( info->index );
  • trunk/src/gui/gui_gfx_renderer.cc

    r456 r469  
    160160        sr->varray = m_window->get_context()->create_vertex_array();
    161161        buffer vb = sr->buffer.get_buffer();
    162         m_window->get_context()->add_vertex_buffers< vertex >( sr->varray, vb );
     162        m_window->get_context()->add_vertex_buffers< vertex >( sr->varray, vb, false );
    163163
    164164        nv::sampler sampler( nv::sampler::LINEAR, nv::sampler::CLAMP_TO_EDGE );
Note: See TracChangeset for help on using the changeset viewer.