Ignore:
Timestamp:
08/07/14 19:06:34 (11 years ago)
Author:
epyon
Message:
  • buffers and vertex_arrays are now handle based
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gfx/keyframed_mesh.cc

    r299 r302  
    1515using namespace nv;
    1616
    17 nv::keyframed_mesh::keyframed_mesh( const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
     17nv::keyframed_mesh::keyframed_mesh( context* a_context, const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
    1818        : animated_mesh()
     19        , m_context( a_context )
    1920        , m_mesh_data( a_data )
    2021        , m_tag_map( a_tag_map )
     
    3637        }
    3738        m_frame_count  = m_vchannel->count / m_vertex_count;
     39        m_pbuffer      = buffer();
    3840}
    3941
     
    103105nv::keyframed_mesh::~keyframed_mesh()
    104106{
    105         delete m_va;
     107        m_context->get_device()->release( m_va );
    106108}
    107109
     
    122124
    123125nv::keyframed_mesh_gpu::keyframed_mesh_gpu( context* a_context, const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
    124         : keyframed_mesh( a_data, a_tag_map )
     126        : keyframed_mesh( a_context, a_data, a_tag_map )
    125127        , m_loc_next_position( -1 )
    126128        , m_loc_next_normal( -1 )
     
    129131        , m_gpu_next_frame( 0xFFFFFFFF )
    130132{
    131         m_va = a_context->get_device()->create_vertex_array( a_data, STATIC_DRAW );
     133        m_va      = a_context->get_device()->create_vertex_array( a_data, STATIC_DRAW );
     134        m_pbuffer = a_context->get_device()->find_buffer( m_va, slot::POSITION );
    132135}
    133136
     
    137140        if ( m_loc_next_position == -1 ) return;
    138141        animated_mesh::update( ms );
    139 
     142        device* dev = m_context->get_device();
    140143        if ( m_gpu_last_frame != m_last_frame )
    141144        {
    142                 m_va->update_vertex_buffer( slot::POSITION, m_last_frame * m_vertex_count * m_vsize );
    143                 m_va->update_vertex_buffer( slot::NORMAL,   m_last_frame * m_vertex_count * m_vsize + sizeof( vec3 ) );
     145                uint32 base_offset = m_last_frame * m_vertex_count * m_vsize;
     146                dev->update_attribute_offset( m_va, slot::POSITION, base_offset );
     147                dev->update_attribute_offset( m_va, slot::NORMAL,   base_offset + sizeof( vec3 ) );
    144148                if ( m_has_tangent && m_loc_next_tangent != -1 )
    145149                {
    146                         m_va->update_vertex_buffer( slot::TANGENT,   m_last_frame * m_vertex_count * m_vsize + 2*sizeof( vec3 ) );
     150                        dev->update_attribute_offset( m_va, slot::TANGENT, base_offset + 2*sizeof( vec3 ) );
    147151                }
    148152                m_gpu_last_frame = m_last_frame;
     
    150154        if ( m_loc_next_position != -1 && m_gpu_next_frame != m_next_frame )
    151155        {
    152                 m_va->update_vertex_buffer( m_loc_next_position, m_next_frame * m_vertex_count * m_vsize );
    153                 m_va->update_vertex_buffer( m_loc_next_normal,   m_next_frame * m_vertex_count * m_vsize + sizeof( vec3 ) );
    154                 m_va->update_vertex_buffer( m_loc_next_tangent,   m_next_frame * m_vertex_count * m_vsize + 2*sizeof( vec3 ) );
     156                uint32 base_offset = m_next_frame * m_vertex_count * m_vsize;
     157                dev->update_attribute_offset( m_va, (slot)m_loc_next_position, base_offset );
     158                dev->update_attribute_offset( m_va, (slot)m_loc_next_normal, base_offset + sizeof( vec3 ) );
     159                if ( m_has_tangent && m_loc_next_tangent != -1 )
     160                {
     161                        dev->update_attribute_offset( m_va, (slot)m_loc_next_tangent, base_offset + 2*sizeof( vec3 ) );
     162                }
    155163                m_gpu_next_frame = m_next_frame;
    156164        }
     
    166174                        m_loc_next_tangent  = a_program->get_attribute( "nv_next_tangent" )->get_location();
    167175
    168                 vertex_buffer* vb = m_va->find_buffer( slot::POSITION );
    169                 m_va->add_vertex_buffer( m_loc_next_position, vb, FLOAT, 3, 0, m_vsize, false );
    170                 m_va->add_vertex_buffer( m_loc_next_normal,   vb, FLOAT, 3, sizeof( vec3 ), m_vsize, false );
     176                device* dev = m_context->get_device();
     177                dev->add_vertex_buffer( m_va, (slot)m_loc_next_position, m_pbuffer, FLOAT, 3, 0, m_vsize, false );
     178                dev->add_vertex_buffer( m_va, (slot)m_loc_next_normal,   m_pbuffer, FLOAT, 3, sizeof( vec3 ), m_vsize, false );
    171179                if ( m_has_tangent )
    172                         m_va->add_vertex_buffer( m_loc_next_tangent, vb, FLOAT, 4, 2*sizeof( vec3 ), m_vsize, false );
     180                        dev->add_vertex_buffer( m_va, (slot)m_loc_next_tangent, m_pbuffer, FLOAT, 4, 2*sizeof( vec3 ), m_vsize, false );
    173181        }
    174182        keyframed_mesh::update( a_program );
     
    176184
    177185nv::keyframed_mesh_cpu::keyframed_mesh_cpu( context* a_context, const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
    178         : keyframed_mesh( a_data, a_tag_map )
    179         , m_context( a_context )
    180 {
    181         m_va = m_context->get_device()->create_vertex_array();
    182         m_vb = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * m_vsize, (void*)m_vchannel->data );
    183         m_va->add_vertex_buffers( m_vb, m_vchannel );
    184 
    185         nv::vertex_buffer* vb = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * sizeof( nv::vec2 ), (void*)m_mesh_data->get_channel<vertex_t>()->data );
    186         m_va->add_vertex_buffers( vb, m_mesh_data->get_channel<vertex_t>() );
    187 
    188         nv::index_buffer* ib = m_context->get_device()->create_index_buffer( nv::STATIC_DRAW, m_mesh_data->get_index_channel()->size(), (void*)m_mesh_data->get_index_channel()->data );
    189         m_va->set_index_buffer( ib, m_mesh_data->get_index_channel()->desc.slots[0].etype, true );
     186        : keyframed_mesh( a_context, a_data, a_tag_map )
     187{
     188        m_va      = m_context->get_device()->create_vertex_array();
     189        m_pbuffer = m_context->get_device()->create_buffer( VERTEX_BUFFER, STATIC_DRAW, m_vertex_count * m_vsize, (void*)m_vchannel->data );
     190        m_context->get_device()->add_vertex_buffers( m_va, m_pbuffer, m_vchannel );
     191
     192        buffer  vb = m_context->get_device()->create_buffer( VERTEX_BUFFER, STATIC_DRAW, m_vertex_count * sizeof( vec2 ), (void*)m_mesh_data->get_channel<vertex_t>()->data );
     193        m_context->get_device()->add_vertex_buffers( m_va, vb, m_mesh_data->get_channel<vertex_t>() );
     194
     195        buffer  ib = m_context->get_device()->create_buffer( INDEX_BUFFER, STATIC_DRAW, m_mesh_data->get_index_channel()->size(), (void*)m_mesh_data->get_index_channel()->data );
     196
     197        m_context->get_device()->set_index_buffer( m_va, ib, m_mesh_data->get_index_channel()->desc.slots[0].etype, true );
    190198
    191199        m_data = new uint8[ m_vertex_count * m_vsize ];
     
    224232        }
    225233
    226         m_context->update( m_vb, m_data, 0, m_vertex_count * m_vsize );
     234        m_context->update( m_pbuffer, m_data, 0, m_vertex_count * m_vsize );
    227235}
    228236
Note: See TracChangeset for help on using the changeset viewer.