Ignore:
Timestamp:
05/17/14 02:35:19 (11 years ago)
Author:
epyon
Message:
  • massive update of mesh handling
  • universal mesh handling routines
  • removed a lot of legacy code
  • significantly streamlined MD5 loading
  • all tests updated to new features
File:
1 edited

Legend:

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

    r237 r239  
    1111
    1212
    13 nv::skeletal_mesh::skeletal_mesh( context* a_context, md5_loader* a_loader )
     13nv::skeletal_mesh::skeletal_mesh( context* a_context, md5_mesh_data* a_mesh_data )
    1414        : animated_mesh()
    15         , m_data( a_loader )
     15        , m_mesh_data( a_mesh_data )
    1616        , m_animation( nullptr )
    1717{
    18         nv::uint32 vcount = a_loader->get_vertex_count(0);
    19         m_va = a_context->get_device()->create_vertex_array();
     18        m_va = a_context->get_device()->create_vertex_array( a_mesh_data, nv::STREAM_DRAW );
     19}
    2020
    21         m_vb_position = a_context->get_device()->create_vertex_buffer( nv::STREAM_DRAW, vcount * sizeof( nv::vec3 ), (const void*)a_loader->get_positions(0).data() );
    22         m_va->add_vertex_buffer( nv::slot::POSITION, m_vb_position, nv::FLOAT, 3, 0, 0, false );
    23         m_vb_normal = a_context->get_device()->create_vertex_buffer( nv::STREAM_DRAW, vcount * sizeof( nv::vec3 ), (const void*)a_loader->get_normals(0).data()  );
    24         m_va->add_vertex_buffer( nv::slot::NORMAL,   m_vb_normal, nv::FLOAT, 3, 0, 0, false );
    25         m_vb_tangent = a_context->get_device()->create_vertex_buffer( nv::STREAM_DRAW, vcount * sizeof( nv::vec3 ), (const void*)a_loader->get_tangents(0).data() );
    26         m_va->add_vertex_buffer( nv::slot::TANGENT,  m_vb_tangent, nv::FLOAT, 3, 0, 0, false );
    27 
    28         nv::vertex_buffer* vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, vcount * sizeof( nv::vec2 ), (const void*)a_loader->get_texcoords(0).data() );
    29         m_va->add_vertex_buffer( nv::slot::TEXCOORD, vb, nv::FLOAT, 2 );
    30         nv::index_buffer* ib = a_context->get_device()->create_index_buffer( nv::STATIC_DRAW, a_loader->get_index_count(0) * sizeof( nv::uint32 ), (const void*)a_loader->get_indices(0).data() );
    31         m_va->set_index_buffer( ib, nv::UINT, true );
    32 }
    3321
    3422void nv::skeletal_mesh::setup_animation( md5_animation* a_anim )
     
    4533        {
    4634                m_animation->update( ms * 0.001f );
    47                 m_data->apply( *m_animation );
     35                m_mesh_data->apply( *m_animation );
     36                vertex_buffer* vb = m_va->find_buffer( nv::POSITION );
     37                const mesh_raw_channel* pch = m_mesh_data->get_channel_data()[0];
     38                vb->bind();
     39                vb->update( (const void*)pch->data, 0, pch->size );
     40                vb->unbind();
    4841        }
    49 
    50         nv::uint32 usize = m_data->get_vertex_count(0) * sizeof( nv::vec3 );
    51         m_vb_position->bind();
    52         m_vb_position->update( (const void*)m_data->get_positions(0).data(), 0, usize );
    53         m_vb_normal  ->bind();
    54         m_vb_normal  ->update( (const void*)m_data->get_normals(0).data(),   0, usize );
    55         m_vb_tangent ->bind();
    56         m_vb_tangent ->update( (const void*)m_data->get_tangents(0).data(),  0, usize );
    57 
    58         // Technically this is not needed, because the va is just a fake class,
    59         // but if it's real it will be needed?
    60 //      m_va->update_vertex_buffer( nv::slot::POSITION, m_vb_position, false );
    61 //      m_va->update_vertex_buffer( nv::slot::NORMAL,   m_vb_normal,   false );
    62 //      m_va->update_vertex_buffer( nv::slot::TANGENT,  m_vb_tangent,  false );
    63         // TODO: answer is - probably not
    6442}
    6543
     
    6745{
    6846        delete m_va;
     47        delete m_mesh_data;
    6948}
    7049
Note: See TracChangeset for help on using the changeset viewer.