Changeset 239 for trunk/src/gfx
- Timestamp:
- 05/17/14 02:35:19 (11 years ago)
- Location:
- trunk/src/gfx
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gfx/keyframed_mesh.cc
r236 r239 15 15 using namespace nv; 16 16 17 keyframed_mesh::keyframed_mesh( context* a_context, mesh_data_old* a_data)17 nv::keyframed_mesh::keyframed_mesh( context* a_context, mesh_data* a_data, tag_map* a_tag_map ) 18 18 : animated_mesh() 19 , m_data( a_data ) 19 , m_mesh_data( a_data ) 20 , m_tag_map( a_tag_map ) 20 21 , m_start_frame( false ) 21 22 , m_stop_frame( false ) … … 29 30 { 30 31 m_va = a_context->get_device()->create_vertex_array(); 32 33 m_index_count = m_mesh_data->get_index_channel()->count; 34 m_vertex_count = m_mesh_data->get_channel_data()[1]->count; 35 m_frame_count = m_mesh_data->get_channel_data()[0]->count / m_vertex_count; 31 36 } 32 37 33 38 size_t keyframed_mesh::get_max_frames() const 34 39 { 35 return m_ data->get_frame_count();40 return m_frame_count; 36 41 } 37 42 38 43 transform keyframed_mesh::get_tag( const std::string& tag ) const 39 44 { 40 const std::vector< transform >& transforms = m_data->get_tag_map().at( tag ); 41 return interpolate( transforms[ m_last_frame ], transforms[ m_next_frame ], m_interpolation ); 45 NV_ASSERT( m_tag_map, "TAGMAP FAIL" ); 46 const std::vector< transform >* transforms = m_tag_map->get_tag( tag ); 47 NV_ASSERT( transforms, "TAG FAIL" ); 48 return interpolate( (*transforms)[ m_last_frame ], (*transforms)[ m_next_frame ], m_interpolation ); 42 49 } 43 50 … … 115 122 } 116 123 117 keyframed_mesh_gpu::keyframed_mesh_gpu( context* a_context, mesh_data_old* a_data, program* a_program )118 : keyframed_mesh( a_context, a_data )124 nv::keyframed_mesh_gpu::keyframed_mesh_gpu( context* a_context, mesh_data* a_data, tag_map* a_tag_map, program* a_program ) 125 : keyframed_mesh( a_context, a_data, a_tag_map ) 119 126 , m_loc_next_position( 0 ) 120 127 , m_loc_next_normal( 0 ) … … 122 129 , m_gpu_next_frame( 0xFFFFFFFF ) 123 130 { 124 nv::vertex_buffer* vb;125 131 m_loc_next_position = a_program->get_attribute( "nv_next_position" )->get_location(); 126 132 m_loc_next_normal = a_program->get_attribute( "nv_next_normal" )->get_location(); 133 m_va = a_context->get_device()->create_vertex_array( a_data, nv::STATIC_DRAW ); 134 vertex_buffer* vb = m_va->find_buffer( nv::POSITION ); 135 m_va->add_vertex_buffer( m_loc_next_position, vb, nv::FLOAT, 3, 0, sizeof( vertex_pn ), false ); 136 m_va->add_vertex_buffer( m_loc_next_normal, vb, nv::FLOAT, 3, sizeof( vec3 ), sizeof( vertex_pn ), false ); 137 } 127 138 128 vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ) * m_data->get_frame_count(), (void*)m_data->get_positions().data() );129 m_va->add_vertex_buffer( m_loc_next_position, vb, nv::FLOAT, 3, 0, 0, false );130 m_va->add_vertex_buffer( nv::POSITION, vb, nv::FLOAT, 3 );131 132 vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ) * m_data->get_frame_count(), (void*)m_data->get_normals().data() );133 m_va->add_vertex_buffer( m_loc_next_normal, vb, nv::FLOAT, 3, 0, 0, false );134 m_va->add_vertex_buffer( nv::NORMAL, vb, nv::FLOAT, 3 );135 136 vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec2 ), (void*)m_data->get_texcoords().data() );137 m_va->add_vertex_buffer( nv::slot::TEXCOORD, vb, nv::FLOAT, 2 );138 nv::index_buffer* ib = a_context->get_device()->create_index_buffer( nv::STATIC_DRAW, m_data->get_index_count() * sizeof( nv::uint32 ), (void*)m_data->get_indices().data() );139 m_va->set_index_buffer( ib, nv::UINT, true );140 }141 139 142 140 void nv::keyframed_mesh_gpu::update( uint32 ms ) … … 144 142 keyframed_mesh::update( ms ); 145 143 146 size_t vtx_count = m_data->get_vertex_count();147 144 if ( m_gpu_last_frame != m_last_frame ) 148 145 { 149 m_va->update_vertex_buffer( slot::POSITION, m_last_frame * vtx_count * sizeof( nv::vec3) );150 m_va->update_vertex_buffer( slot::NORMAL, m_last_frame * vtx_count * sizeof( nv::vec3 ) );146 m_va->update_vertex_buffer( slot::POSITION, m_last_frame * m_vertex_count * sizeof( vertex_pn ) ); 147 m_va->update_vertex_buffer( slot::NORMAL, m_last_frame * m_vertex_count * sizeof( vertex_pn ) + sizeof( vec3 ) ); 151 148 m_gpu_last_frame = m_last_frame; 152 149 } 153 150 if ( m_gpu_next_frame != m_next_frame ) 154 151 { 155 m_va->update_vertex_buffer( m_loc_next_position, m_next_frame * vtx_count * sizeof( nv::vec3) );156 m_va->update_vertex_buffer( m_loc_next_normal, m_next_frame * vtx_count * sizeof( nv::vec3 ) );152 m_va->update_vertex_buffer( m_loc_next_position, m_next_frame * m_vertex_count * sizeof( vertex_pn ) ); 153 m_va->update_vertex_buffer( m_loc_next_normal, m_next_frame * m_vertex_count * sizeof( vertex_pn ) + sizeof( vec3 ) ); 157 154 m_gpu_next_frame = m_next_frame; 158 155 } 159 156 } 160 157 158 nv::keyframed_mesh_cpu::keyframed_mesh_cpu( context* a_context, mesh_data* a_data, tag_map* a_tag_map ) 159 : keyframed_mesh( a_context, a_data, a_tag_map ) 160 { 161 m_vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * sizeof( vertex_pn ), (void*)m_mesh_data->get_channel_data()[0]->data ); 162 m_va->add_vertex_buffers( m_vb, m_mesh_data->get_channel_data()[0] ); 161 163 162 nv::keyframed_mesh_cpu::keyframed_mesh_cpu( context* a_context, mesh_data_old* a_data ) 163 : keyframed_mesh( a_context, a_data ) 164 { 165 m_vb_position = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ), (void*)m_data->get_position_frame(0) ); 166 m_va->add_vertex_buffer( nv::slot::POSITION, m_vb_position, nv::FLOAT, 3 ); 164 nv::vertex_buffer* vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * sizeof( nv::vec2 ), (void*)m_mesh_data->get_channel_data()[1]->data ); 165 m_va->add_vertex_buffers( vb, m_mesh_data->get_channel_data()[1] ); 167 166 168 m_vb_normal = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ), (void*)m_data->get_normal_frame(0));169 m_va-> add_vertex_buffer( nv::slot::NORMAL, m_vb_normal, nv::FLOAT, 3);167 nv::index_buffer* ib = a_context->get_device()->create_index_buffer( nv::STATIC_DRAW, m_mesh_data->get_index_channel()->size, (void*)m_mesh_data->get_index_channel()->data ); 168 m_va->set_index_buffer( ib, m_mesh_data->get_index_channel()->etype, true ); 170 169 171 nv::vertex_buffer* vb; 172 vb = a_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec2 ), (void*)m_data->get_texcoords().data() ); 173 m_va->add_vertex_buffer( nv::slot::TEXCOORD, vb, nv::FLOAT, 2 ); 174 175 nv::index_buffer* ib = a_context->get_device()->create_index_buffer( nv::STATIC_DRAW, m_data->get_index_count() * sizeof( nv::uint32 ), (void*)m_data->get_indices().data() ); 176 m_va->set_index_buffer( ib, nv::UINT, true ); 177 178 m_position.resize( m_data->get_vertex_count() ); 179 m_normal.resize( m_data->get_vertex_count() ); 170 m_vertex.resize( m_vertex_count ); 180 171 } 181 172 … … 184 175 keyframed_mesh::update( ms ); 185 176 186 size_t vtx_count = m_data->get_vertex_count(); 187 const vec3* prev_position = m_data->get_position_frame( m_last_frame ); 188 const vec3* next_position = m_data->get_position_frame( m_next_frame ); 189 const vec3* prev_normal = m_data->get_normal_frame( m_last_frame ); 190 const vec3* next_normal = m_data->get_normal_frame( m_next_frame ); 177 const vertex_pn* data = (const vertex_pn*)(m_mesh_data->get_channel_data()[0]->data); 178 const vertex_pn* prev = data + m_vertex_count * m_last_frame; 179 const vertex_pn* next = data + m_vertex_count * m_next_frame; 191 180 192 for ( size_t i = 0; i < vtx_count; ++i )181 for ( size_t i = 0; i < m_vertex_count; ++i ) 193 182 { 194 m_ position[i] = glm::mix( prev_position[i], next_position[i], m_interpolation );195 m_ normal[i] = glm::mix( prev_normal[i], next_normal[i], m_interpolation );183 m_vertex[i].position = glm::mix( prev[i].position, next[i].position, m_interpolation ); 184 m_vertex[i].normal = glm::mix( prev[i].normal, next[i].normal, m_interpolation ); 196 185 } 197 186 198 m_vb_position->bind(); 199 m_vb_position->update( m_position.data(), 0, vtx_count * sizeof( nv::vec3 ) ); 200 m_vb_position->unbind(); 201 202 m_vb_normal->bind(); 203 m_vb_normal->update( m_normal.data(), 0, vtx_count * sizeof( nv::vec3 ) ); 204 m_vb_normal->unbind(); 187 m_vb->bind(); 188 m_vb->update( m_vertex.data(), 0, m_vertex_count * sizeof( vertex_pn ) ); 189 m_vb->unbind(); 205 190 } -
trunk/src/gfx/skeletal_mesh.cc
r237 r239 11 11 12 12 13 nv::skeletal_mesh::skeletal_mesh( context* a_context, md5_ loader* a_loader)13 nv::skeletal_mesh::skeletal_mesh( context* a_context, md5_mesh_data* a_mesh_data ) 14 14 : animated_mesh() 15 , m_ data( a_loader)15 , m_mesh_data( a_mesh_data ) 16 16 , m_animation( nullptr ) 17 17 { 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 } 20 20 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 }33 21 34 22 void nv::skeletal_mesh::setup_animation( md5_animation* a_anim ) … … 45 33 { 46 34 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(); 48 41 } 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 not64 42 } 65 43 … … 67 45 { 68 46 delete m_va; 47 delete m_mesh_data; 69 48 } 70 49
Note: See TracChangeset
for help on using the changeset viewer.