Changeset 73


Ignore:
Timestamp:
06/01/13 01:26:51 (12 years ago)
Author:
epyon
Message:
  • shortcut create_vertex_array based on program and mesh
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/interface/device.hh

    r70 r73  
    1515#include <nv/common.hh>
    1616#include <nv/string.hh>
     17#include <nv/interface/mesh.hh>
    1718#include <nv/interface/vertex_buffer.hh>
    1819#include <nv/interface/texture2d.hh>
     
    3233                virtual vertex_array* create_vertex_array() = 0;
    3334                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                }
    3453        };
    3554
  • trunk/nv/interface/mesh.hh

    r71 r73  
    1717#include <nv/string.hh>
    1818#include <nv/types.hh>
     19#include <nv/interface/context.hh>
    1920#include <unordered_map>
    2021#include <vector>
     
    100101                }
    101102
     103                const vertex_attribute_base* get_indices() const { return m_indices; }
    102104                vertex_attribute_base* get_indices() { return m_indices; }
    103105
    104106                template <typename T>
    105                 vertex_attribute<T>* get_indices( const string& attr )
     107                vertex_attribute<T>* get_indices()
    106108                {
    107109                        return m_indices->get_type() == type_to_enum<T>() ? ((vertex_attribute<T>*)(m_indices)); : nullptr;
  • trunk/nv/interface/program.hh

    r70 r73  
    9898                                        i != m_uniform_map.end(); ++i ) delete i->second;
    9999                }
     100
     101                const attribute_map& get_attributes() const { return m_attribute_map; }
     102                const uniform_map& get_uniforms() const { return m_uniform_map; }
     103
    100104                attribute* try_get_attribute( const string& name ) const
    101105                {
  • trunk/tests/render_test/rl.cc

    r71 r73  
    6666        application();
    6767        bool initialize();
    68         bool init_program( const std::string& name, nv::program*& p, nv::vertex_array*& va, nv::mesh* m );
    6968        bool run();
    7069        ~application();
     
    117116                vtx.emplace_back( x,   h, y ); 
    118117                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 );
    121120        }
    122121
     
    175174                }
    176175
    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
    195181        return true;
    196182}
Note: See TracChangeset for help on using the changeset viewer.