Changeset 73
- Timestamp:
- 06/01/13 01:26:51 (12 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/interface/device.hh
r70 r73 15 15 #include <nv/common.hh> 16 16 #include <nv/string.hh> 17 #include <nv/interface/mesh.hh> 17 18 #include <nv/interface/vertex_buffer.hh> 18 19 #include <nv/interface/texture2d.hh> … … 32 33 virtual vertex_array* create_vertex_array() = 0; 33 34 virtual texture2d* create_texture2d( ivec2 size, image_format aformat, datatype adatatype, sampler asampler, void* data = nullptr ) = 0; 35 36 virtual vertex_array* create_vertex_array( const mesh* m, const attribute_map* am, buffer_hint hint ) 37 { 38 vertex_array* result = create_vertex_array(); 39 for ( auto attr : m->get_attributes() ) 40 { 41 // TODO : error checking 42 vertex_buffer* vb = create_vertex_buffer( hint, attr.second->get_size(), attr.second->get_data() ); 43 result->add_vertex_buffer( am->at( attr.first )->get_location(), vb, attr.second->get_base_type(), attr.second->get_components() ); 44 } 45 if ( m->has_indices() ) 46 { 47 const vertex_attribute_base* i = m->get_indices(); 48 index_buffer* vb = create_index_buffer( hint, i->get_size(), i->get_data() ); 49 result->set_index_buffer( vb ); 50 } 51 return result; 52 } 34 53 }; 35 54 -
trunk/nv/interface/mesh.hh
r71 r73 17 17 #include <nv/string.hh> 18 18 #include <nv/types.hh> 19 #include <nv/interface/context.hh> 19 20 #include <unordered_map> 20 21 #include <vector> … … 100 101 } 101 102 103 const vertex_attribute_base* get_indices() const { return m_indices; } 102 104 vertex_attribute_base* get_indices() { return m_indices; } 103 105 104 106 template <typename T> 105 vertex_attribute<T>* get_indices( const string& attr )107 vertex_attribute<T>* get_indices() 106 108 { 107 109 return m_indices->get_type() == type_to_enum<T>() ? ((vertex_attribute<T>*)(m_indices)); : nullptr; -
trunk/nv/interface/program.hh
r70 r73 98 98 i != m_uniform_map.end(); ++i ) delete i->second; 99 99 } 100 101 const attribute_map& get_attributes() const { return m_attribute_map; } 102 const uniform_map& get_uniforms() const { return m_uniform_map; } 103 100 104 attribute* try_get_attribute( const string& name ) const 101 105 { -
trunk/tests/render_test/rl.cc
r71 r73 66 66 application(); 67 67 bool initialize(); 68 bool init_program( const std::string& name, nv::program*& p, nv::vertex_array*& va, nv::mesh* m );69 68 bool run(); 70 69 ~application(); … … 117 116 vtx.emplace_back( x, h, y ); 118 117 mat.insert( mat.end(), 6, nv::i8vec3( m, 1, 0 ) ); 119 120 if (!init_program( "char", m_char_program, m_char_va, &cmesh ) ) return false;118 m_char_program = m_device->create_program( nv::slurp( "char.vert" ), nv::slurp( "char.frag" ) ); 119 m_char_va = m_device->create_vertex_array( &cmesh, &(m_char_program->get_attributes()), nv::STATIC_DRAW ); 121 120 } 122 121 … … 175 174 } 176 175 177 m_count = vtx.size(); 178 if (!init_program( "box", m_box_program, m_box_va, &wmesh ) ) return false; 179 } 180 181 return true; 182 } 183 184 bool application::init_program( const std::string& name, nv::program*& p, nv::vertex_array*& va, nv::mesh* m ) 185 { 186 p = m_device->create_program( nv::slurp( name+".vert" ), nv::slurp( name+".frag" ) ); 187 va = m_device->create_vertex_array(); 188 const nv::mesh::map& attrs = m->get_attributes(); 189 190 for ( auto attr : attrs ) 191 { 192 nv::vertex_buffer* vb = m_device->create_vertex_buffer( nv::STATIC_DRAW, attr.second->get_size(), attr.second->get_data() ); 193 va->add_vertex_buffer( p->get_attribute( attr.first )->get_location(), vb, attr.second->get_base_type(), attr.second->get_components() ); 194 } 176 m_count = vtx.size(); 177 m_box_program = m_device->create_program( nv::slurp( "box.vert" ), nv::slurp( "box.frag" ) ); 178 m_box_va = m_device->create_vertex_array( &wmesh, &(m_box_program->get_attributes()), nv::STATIC_DRAW ); 179 } 180 195 181 return true; 196 182 }
Note: See TracChangeset
for help on using the changeset viewer.