Changeset 321 for trunk/tests/md5_test/nv_md5_test.cc
- Timestamp:
- 08/25/14 02:43:30 (11 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/md5_test/nv_md5_test.cc
r261 r321 1 #include <nv/co mmon.hh>1 #include <nv/core/common.hh> 2 2 #include <iomanip> 3 3 #include <nv/gfx/keyframed_mesh.hh> 4 #include <nv/interface/vertex_buffer.hh>5 4 #include <nv/gl/gl_device.hh> 6 5 #include <nv/gfx/image.hh> 7 6 #include <nv/interface/context.hh> 8 7 #include <nv/interface/window.hh> 9 #include <nv/interface/program.hh>10 #include <nv/interface/texture2d.hh>11 8 #include <nv/interface/mesh_loader.hh> 12 9 #include <nv/io/c_file_system.hh> 13 10 #include <nv/formats/md5_loader.hh> 14 #include <nv/ profiler.hh>15 #include <nv/ logging.hh>16 #include <nv/ logger.hh>17 #include <nv/ math.hh>18 #include <nv/ time.hh>19 #include <nv/ string.hh>11 #include <nv/core/profiler.hh> 12 #include <nv/core/logging.hh> 13 #include <nv/core/logger.hh> 14 #include <nv/core/math.hh> 15 #include <nv/core/time.hh> 16 #include <nv/core/string.hh> 20 17 #include <nv/gfx/skeletal_mesh.hh> 21 18 #include <glm/gtx/rotate_vector.hpp> … … 37 34 nv::device* m_device; 38 35 nv::window* m_window; 39 nv::texture2d* m_diffuse; 40 nv::texture2d* m_specular; 41 nv::texture2d* m_normal; 36 nv::context* m_context; 37 nv::texture m_diffuse; 38 nv::texture m_specular; 39 nv::texture m_normal; 42 40 nv::clear_state m_clear_state; 43 41 nv::render_state m_render_state; … … 45 43 46 44 nv::skeletal_mesh* m_mesh; 47 nv::program *m_program;48 nv::m d5_mesh_data*m_mesh_data;49 nv:: md5_animation* m_animation;45 nv::program m_program; 46 nv::mesh_data* m_mesh_data; 47 nv::animation_entry* m_animation; 50 48 51 49 }; … … 54 52 { 55 53 NV_PROFILE( "app_construct" ); 56 m_device = new nv::gl_device(); 57 m_window = m_device->create_window( 800, 600, false ); 54 m_device = new nv::gl_device(); 55 m_window = m_device->create_window( 800, 600, false ); 56 m_context = m_window->get_context(); 58 57 m_animation = nullptr; 59 58 60 59 nv::sampler sampler( nv::sampler::LINEAR, nv::sampler::REPEAT ); 61 60 nv::image_data* data = m_device->create_image_data( "data/qshambler_d.png" ); 62 m_diffuse = m_device->create_texture 2d( data->get_size(), nv::RGBA, nv::UBYTE, sampler, (void*)data->get_data());61 m_diffuse = m_device->create_texture( data, sampler ); 63 62 delete data; 64 63 data = m_device->create_image_data( "data/qshambler_s.png" ); 65 m_specular = m_device->create_texture 2d( data->get_size(), nv::RGBA, nv::UBYTE, sampler, (void*)data->get_data());64 m_specular = m_device->create_texture( data, sampler ); 66 65 delete data; 67 66 68 67 data = m_device->create_image_data( "data/qshambler_local.png" ); 69 m_normal = m_device->create_texture 2d( data->get_size(), nv::RGBA, nv::UBYTE, sampler, (void*)data->get_data());68 m_normal = m_device->create_texture( data, sampler ); 70 69 delete data; 71 70 … … 98 97 { 99 98 NV_PROFILE("create_mesh"); 100 m_mesh_data = (nv::md5_mesh_data*)loader->release_mesh_data();101 m_mesh = new nv::skeletal_mesh ( m_window->get_context(), m_mesh_data);99 m_mesh_data = loader->release_mesh_data(); 100 m_mesh = new nv::skeletal_mesh_cpu( m_context, m_mesh_data, loader->release_mesh_nodes_data() ); 102 101 delete loader; 103 102 } … … 125 124 last_ticks = ticks; 126 125 ticks = m_device->get_ticks(); 127 nv::uint32 elapsed = ticks - last_ticks; 128 m_mesh->update( elapsed ); 129 { 130 NV_PROFILE( "clear" ); 131 m_window->get_context()->clear( m_clear_state ); 132 } 126 m_mesh->update_animation( m_animation, ticks ); 127 m_context->clear( m_clear_state ); 133 128 134 129 { … … 141 136 m_scene_state.get_camera().set_perspective(60.0f, 1.0f*800.0f/600.0f, 0.1f, 1000.0f); 142 137 143 m_ diffuse ->bind( 0);144 m_ specular->bind( 1);145 m_ normal ->bind( 2);146 m_ program->set_opt_uniform("light_position", glm::vec3(180.0, 180.0, 0) );147 m_ program->set_opt_uniform("light_diffuse", glm::vec4(0.7,0.7,0.7,1.0) );148 m_ program->set_opt_uniform("light_specular", glm::vec4(1.0,1.0,1.0,1.0) );138 m_context->bind( m_diffuse, nv::TEX_DIFFUSE ); 139 m_context->bind( m_specular, nv::TEX_SPECULAR ); 140 m_context->bind( m_normal, nv::TEX_NORMAL ); 141 m_device->set_opt_uniform( m_program, "light_position", glm::vec3(180.0, 180.0, 0) ); 142 m_device->set_opt_uniform( m_program, "light_diffuse", glm::vec4(0.7,0.7,0.7,1.0) ); 143 m_device->set_opt_uniform( m_program, "light_specular", glm::vec4(1.0,1.0,1.0,1.0) ); 149 144 } 150 145 … … 158 153 ) ); 159 154 160 m_window->get_context()->draw( m_render_state, m_scene_state, m_program, m_mesh ); 155 m_mesh->update( m_program ); 156 m_context->draw( nv::TRIANGLES, m_render_state, m_scene_state, m_program, m_mesh->get_vertex_array(), m_mesh->get_index_count() ); 161 157 } 162 158 … … 206 202 if ( anim_file != nullptr ) 207 203 { 208 m_animation = new nv::md5_animation(); 209 if ( !m_animation->load_animation(*anim_file) ) 210 { 211 delete m_animation; 212 m_animation = nullptr; 213 } 214 m_mesh->setup_animation( m_animation ); 204 nv::md5_loader* loader = new nv::md5_loader(); 205 loader->load( *anim_file ); 215 206 delete anim_file; 207 m_animation = new nv::skeletal_animation_entry_cpu( "", loader->release_mesh_nodes_data(), true ); 208 m_mesh->run_animation( m_animation ); 209 delete loader; 216 210 } 217 211 } … … 220 214 application::~application() 221 215 { 222 delete m_program;216 m_device->release( m_program ); 223 217 delete m_mesh; 224 delete m_diffuse;218 m_device->release( m_diffuse ); 225 219 delete m_window; 226 220 delete m_device;
Note: See TracChangeset
for help on using the changeset viewer.