Changeset 71


Ignore:
Timestamp:
06/01/13 00:24:46 (12 years ago)
Author:
epyon
Message:
  • mesh interface class with vertex_attribute, index, primitive and order support
Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/render_test/rl.cc

    r50 r71  
    1515#include <nv/string.hh>
    1616#include <nv/types.hh>
    17 
    18 typedef glm::detail::tvec3<char> byte3;
     17#include <nv/interface/mesh.hh>
    1918
    2019const nv::uint16 size_x  = 16;
     
    6261};
    6362
    64 struct world;
    65 struct being;
    66 
    6763class application
    6864{
     
    7066        application();
    7167        bool initialize();
    72         bool init_program( const std::string& name, nv::program*& p, nv::vertex_array*& va, int count, void* vertex, void* material );
     68        bool init_program( const std::string& name, nv::program*& p, nv::vertex_array*& va, nv::mesh* m );
    7369        bool run();
    7470        ~application();
     
    110106{
    111107        { // CHARACTER
    112                 byte3 vertex[6];
    113                 byte3 material[6];
     108                nv::mesh cmesh;
     109                nv::vertex_attribute<nv::i8vec3>::list& vtx = cmesh.add_attribute<nv::i8vec3>("coords")->get();
     110                nv::vertex_attribute<nv::i8vec3>::list& mat = cmesh.add_attribute<nv::i8vec3>("material")->get();
    114111                int m = 16;     int x = 0; int y = 0; int h = 0;
    115                 vertex[0] = byte3( x,   h, y );   material[0] = byte3( m, 1, 0 );
    116                 vertex[1] = byte3( x,   h, y+1 ); material[1] = byte3( m, 1, 0 );
    117                 vertex[2] = byte3( x+1, h, y+1 ); material[2] = byte3( m, 1, 0 );
    118                 vertex[3] = byte3( x+1, h, y+1 ); material[3] = byte3( m, 1, 0 );
    119                 vertex[4] = byte3( x+1, h, y );   material[4] = byte3( m, 1, 0 );
    120                 vertex[5] = byte3( x,   h, y );   material[5] = byte3( m, 1, 0 );
    121 
    122                 if (!init_program( "char", m_char_program, m_char_va, 6, vertex, material ) ) return false;
     112                vtx.emplace_back( x,   h, y ); 
     113                vtx.emplace_back( x,   h, y+1 );
     114                vtx.emplace_back( x+1, h, y+1 );
     115                vtx.emplace_back( x+1, h, y+1 );
     116                vtx.emplace_back( x+1, h, y ); 
     117                vtx.emplace_back( x,   h, y ); 
     118                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;
    123121        }
    124122
    125123        { // WORLD
    126                 byte3 vertex[size_x * size_y * 256];
    127                 byte3 material[size_x * size_y * 256];
    128                 m_count = 0;
    129                 int mcount = 0;
     124                nv::mesh wmesh;
     125                nv::vertex_attribute<nv::i8vec3>::list& vtx = wmesh.add_attribute<nv::i8vec3>("coords")->get();
     126                nv::vertex_attribute<nv::i8vec3>::list& mat = wmesh.add_attribute<nv::i8vec3>("material")->get();
     127
    130128                for (int i = 0; i < size_x * size_y; ++i )
    131129                {
     
    133131                        int y = i / size_x;
    134132
    135                         vertex[m_count++] = byte3( x,   height[i], y   ); material[mcount++] = byte3( map[i], 2, 0 );
    136                         vertex[m_count++] = byte3( x,   height[i], y+1 ); material[mcount++] = byte3( map[i], 2, 0 );
    137                         vertex[m_count++] = byte3( x+1, height[i], y+1 ); material[mcount++] = byte3( map[i], 2, 0 );
    138 
    139                         vertex[m_count++] = byte3( x+1, height[i], y+1 ); material[mcount++] = byte3( map[i], 2, 0 );
    140                         vertex[m_count++] = byte3( x+1, height[i], y );   material[mcount++] = byte3( map[i], 2, 0 );
    141                         vertex[m_count++] = byte3( x,   height[i], y );   material[mcount++] = byte3( map[i], 2, 0 );
     133                        vtx.emplace_back( x,   height[i], y   );
     134                        vtx.emplace_back( x,   height[i], y+1 );
     135                        vtx.emplace_back( x+1, height[i], y+1 );
     136                        vtx.emplace_back( x+1, height[i], y+1 );
     137                        vtx.emplace_back( x+1, height[i], y );   
     138                        vtx.emplace_back( x,   height[i], y );   
     139                        mat.insert( mat.end(), 6, nv::i8vec3( map[i], 2, 0 ) );
    142140
    143141                        if (i > 0 && height[i-1] != height[i])
     
    147145                                for ( int h = height[i-1]; h != height[i]; h = h + dir )
    148146                                {
    149                                         vertex[m_count++] = byte3( x, h,     y );   material[mcount++] = byte3( m, -dir, 0 );
    150                                         vertex[m_count++] = byte3( x, h,     y+1 ); material[mcount++] = byte3( m, -dir, 0 );
    151                                         vertex[m_count++] = byte3( x, h+dir, y+1 ); material[mcount++] = byte3( m, -dir, 0 );
    152 
    153                                         vertex[m_count++] = byte3( x, h+dir, y+1 ); material[mcount++] = byte3( m, -dir, 0 );
    154                                         vertex[m_count++] = byte3( x, h+dir, y );   material[mcount++] = byte3( m, -dir, 0 );
    155                                         vertex[m_count++] = byte3( x, h,     y );   material[mcount++] = byte3( m, -dir, 0 );
     147                                        m_count += 6;
     148                                        vtx.emplace_back( x, h,     y );   
     149                                        vtx.emplace_back( x, h,     y+1 );
     150                                        vtx.emplace_back( x, h+dir, y+1 );
     151                                        vtx.emplace_back( x, h+dir, y+1 );
     152                                        vtx.emplace_back( x, h+dir, y );   
     153                                        vtx.emplace_back( x, h,     y );   
     154                                        mat.insert( mat.end(), 6, nv::i8vec3( m, -dir, 0 ) );
    156155                                }
    157156                        }
     
    163162                                for ( int h = height[i-size_x]; h != height[i]; h = h + dir )
    164163                                {
    165                                         vertex[m_count++] = byte3( x,   h,     y ); material[mcount++] = byte3( m, -3*dir, 0 );
    166                                         vertex[m_count++] = byte3( x,   h+dir, y ); material[mcount++] = byte3( m, -3*dir, 0 );
    167                                         vertex[m_count++] = byte3( x+1, h+dir, y ); material[mcount++] = byte3( m, -3*dir, 0 );
    168 
    169                                         vertex[m_count++] = byte3( x+1, h+dir, y ); material[mcount++] = byte3( m, -3*dir, 0 );
    170                                         vertex[m_count++] = byte3( x+1, h,     y ); material[mcount++] = byte3( m, -3*dir, 0 );
    171                                         vertex[m_count++] = byte3( x,   h,     y ); material[mcount++] = byte3( m, -3*dir, 0 );
     164                                        vtx.emplace_back( x,   h,     y );
     165                                        vtx.emplace_back( x,   h+dir, y );
     166                                        vtx.emplace_back( x+1, h+dir, y );
     167
     168                                        vtx.emplace_back( x+1, h+dir, y );
     169                                        vtx.emplace_back( x+1, h,     y );
     170                                        vtx.emplace_back( x,   h,     y );
     171                                        mat.insert( mat.end(), 6, nv::i8vec3( m, -3*dir, 0 ) );
    172172                                }
    173173                        }
     
    175175                }
    176176
    177                 if (!init_program( "box",  m_box_program, m_box_va, m_count, vertex, material ) ) return false;
     177                m_count = vtx.size();
     178                if (!init_program( "box",  m_box_program, m_box_va, &wmesh ) ) return false;
    178179        }
    179180
     
    181182}
    182183
    183 bool application::init_program( const std::string& name, nv::program*& p, nv::vertex_array*& va, int count, void* vertex, void* material )
     184bool application::init_program( const std::string& name, nv::program*& p, nv::vertex_array*& va, nv::mesh* m )
    184185{
    185186        p  = m_device->create_program( nv::slurp( name+".vert" ), nv::slurp( name+".frag" ) );
    186187        va = m_device->create_vertex_array();
    187 
    188         nv::vertex_buffer* vbcoords   = m_device->create_vertex_buffer( nv::STATIC_DRAW, count*sizeof(byte3), vertex );
    189         va->add_vertex_buffer( p->get_attribute( "coords" )->get_location(), vbcoords, nv::BYTE, 3 );
    190         nv::vertex_buffer* vbmaterial = m_device->create_vertex_buffer( nv::STATIC_DRAW, count*sizeof(byte3), material );
    191         va->add_vertex_buffer( p->get_attribute( "material" )->get_location(), vbmaterial, nv::BYTE, 3 );
    192 
     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        }
    193195        return true;
    194196}
Note: See TracChangeset for help on using the changeset viewer.