Changeset 238 for trunk/tests


Ignore:
Timestamp:
05/16/14 05:48:01 (11 years ago)
Author:
epyon
Message:
  • mesh data interface and usage
  • new wavefront importer (old pending removal)
  • updates to test projects
Location:
trunk/tests
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/objload_test/objload_test.cc

    r237 r238  
    3232        nv::vertex_array* m_va;
    3333        nv::program*      m_program;
    34         nv::mesh_data_old* m_mesh;
    35         nv::uint32        m_count;
     34        nv::mesh_data*    m_mesh;
    3635};
    3736
     
    6463        nv::c_file_system fs;
    6564        nv::stream* mesh_file = fs.open( "mesh.obj" );
    66         nv::mesh_loader* loader = new nv::obj_loader();
     65
     66//              nv::mesh_loader* loader = new nv::obj_loader();
     67//              loader->load( *mesh_file );
     68//              nv::mesh_data_old* mesh = loader->release_mesh_data();
     69//              m_count = loader->get_size();
     70//              delete mesh_file;
     71//              delete loader;
     72
     73        nv::wavefront_loader* loader = new nv::wavefront_loader();
    6774        loader->load( *mesh_file );
    6875        m_mesh = loader->release_mesh_data();
    69         m_count = loader->get_size();
    7076        delete mesh_file;
    7177        delete loader;
     
    7379        m_program = m_device->create_program( nv::slurp( "obj.vert" ), nv::slurp( "obj.frag" ) );
    7480
    75         nv::vertex_buffer* vb = nullptr;
    76         m_va = m_device->create_vertex_array();
    77         vb = m_device->create_vertex_buffer( nv::STATIC_DRAW, m_mesh->get_vertex_count() * sizeof( nv::vec3 ), m_mesh->get_positions().data() );
    78         m_va->add_vertex_buffer( nv::slot::POSITION, vb, nv::FLOAT, 3 );
    79         vb = m_device->create_vertex_buffer( nv::STATIC_DRAW, m_mesh->get_vertex_count() * sizeof( nv::vec3 ), m_mesh->get_normals().data() );
    80         m_va->add_vertex_buffer( nv::slot::NORMAL, vb, nv::FLOAT, 3 );
    81         vb = m_device->create_vertex_buffer( nv::STATIC_DRAW, m_mesh->get_vertex_count() * sizeof( nv::vec2 ), m_mesh->get_texcoords().data() );
    82         m_va->add_vertex_buffer( nv::slot::TEXCOORD, vb, nv::FLOAT, 2 );
     81//      nv::vertex_buffer* vb = nullptr;
     82        m_va = m_device->create_vertex_array( m_mesh, nv::STATIC_DRAW );
     83
    8384        return true;
    8485}
     
    113114                m_program->set_uniform( "diffuse", 0 );
    114115                m_program->set_uniform( "specular", 1 );
    115                 m_window->get_context()->draw( nv::TRIANGLES, m_render_state, m_program, m_va, m_count * 3 );
     116                m_window->get_context()->draw( nv::TRIANGLES, m_render_state, m_program, m_va, m_mesh->get_count() );
    116117                m_window->swap_buffers();
    117118
     
    147148application::~application()
    148149{
     150        delete m_mesh;
    149151        delete m_program;
    150         delete m_mesh;
    151152        delete m_diffuse;
    152153        delete m_specular;
  • trunk/tests/render_test/box.frag

    r46 r238  
    44varying vec3 f_material;
    55varying float f_diffuse_value;
    6 uniform sampler2D tex;
     6uniform sampler2D nv_t_diffuse;
    77uniform vec3 light;
    88 
     
    1616
    1717        if (secondary)
    18                 gl_FragColor = texture2D(tex, vec2((fract(f_coord.z - f_coord.x) + modulus ), ( fract(-f_coord.y) + remmod) )  / 16.0);
     18                gl_FragColor = texture2D(nv_t_diffuse, vec2((fract(f_coord.z - f_coord.x) + modulus ), ( fract(-f_coord.y) + remmod) )  / 16.0);
    1919        else
    20                 gl_FragColor = texture2D(tex, vec2((fract(f_coord.z) + modulus ), ( fract(f_coord.x) + remmod) )  / 16.0);
     20                gl_FragColor = texture2D(nv_t_diffuse, vec2((fract(f_coord.z) + modulus ), ( fract(f_coord.x) + remmod) )  / 16.0);
    2121        gl_FragColor = vec4( gl_FragColor.xyz * (f_diffuse_value + 0.4), 1.0 );
    2222}
  • trunk/tests/render_test/box.vert

    r46 r238  
    11#version 120
    2 attribute vec3 coords;
    3 attribute vec3 material;
     2attribute vec3 nv_position;
     3attribute vec3 nv_color;
     4uniform mat4 nv_m_mvp;
     5
    46varying vec3 f_coord;
    57varying vec3 f_normal;
    68varying vec3 f_material;
    79varying float f_diffuse_value;
    8 uniform mat4 matrix_mvp;
    910uniform vec3 light;
    1011
    1112void main(void) {
    1213        f_normal = vec3(0,0,0);
    13         f_normal[int(abs(material.y)-1)] = sign( material.y );
     14        f_normal[int(abs(nv_color.y)-1)] = sign( nv_color.y );
    1415        vec3 vnormal  = normalize(f_normal);
    15         vec3 vlight   = normalize(light - coords);
     16        vec3 vlight   = normalize(light - nv_position);
    1617        float diffuse = max(dot(vlight, vnormal), 0.0);
    1718        f_diffuse_value = diffuse;
    18         f_coord = coords;
    19         f_material = material;
    20         gl_Position = matrix_mvp * vec4(coords, 1.0);
     19        f_coord = nv_position;
     20        f_material = nv_color;
     21        gl_Position = nv_m_mvp * vec4(nv_position, 1.0);
    2122}
  • trunk/tests/render_test/char.frag

    r46 r238  
    22varying vec3 f_coord;
    33varying vec3 f_material;
    4 uniform sampler2D tex;
     4uniform sampler2D nv_t_diffuse;
    55 
    66void main(void) {
     
    99        float modulus = w - remmod * 16;
    1010
    11         gl_FragColor = texture2D(tex, vec2((fract(f_coord.x) + modulus ), ( fract(f_coord.z) + remmod) )  / 16.0);
     11        gl_FragColor = texture2D(nv_t_diffuse, vec2((fract(f_coord.x) + modulus ), ( fract(f_coord.z) + remmod) )  / 16.0);
    1212
    13 //      gl_FragColor = texture2D(tex, vec2((fract(f_coord.z - f_coord.x) + modulus ), ( fract(-f_coord.y) + remmod) )  / 16.0);
     13//      gl_FragColor = texture2D(nv_t_diffuse, vec2((fract(f_coord.z - f_coord.x) + modulus ), ( fract(-f_coord.y) + remmod) )  / 16.0);
    1414}
  • trunk/tests/render_test/char.vert

    r46 r238  
    11#version 120
    2 attribute vec3 coords;
    3 attribute vec3 material;
     2attribute vec3 nv_position;
     3attribute vec3 nv_color;
     4uniform mat4 nv_m_mvp;
     5
    46varying vec3 f_coord;
    57varying vec3 f_material;
    6 uniform mat4 matrix_mvp;
    78uniform vec3 pos;
    89
    910void main(void) {
    10         f_coord = coords;
    11         f_material = material;
    12         gl_Position = matrix_mvp * vec4(coords + pos, 1.0);
     11        f_coord = nv_position;
     12        f_material = nv_color;
     13        gl_Position = nv_m_mvp * vec4(nv_position + pos, 1.0);
    1314}
  • trunk/tests/render_test/rl.cc

    r231 r238  
    6767        nv::window* m_window;
    6868        nv::texture2d* m_texture;
    69         nv::clear_state m_clear_state;
     69
     70        nv::clear_state  m_clear_state;
    7071        nv::render_state m_render_state;
     72        nv::scene_state  m_scene_state;
    7173
    7274        nv::program* m_char_program;
     
    7577        nv::vertex_array* m_box_va;
    7678        unsigned int m_count;
     79};
     80
     81struct vtx
     82{
     83        nv::i8vec3 position;
     84        nv::i8vec3 color;
     85
     86        vtx( const nv::i8vec3& a_position, const nv::i8vec3& a_color )
     87                : position( a_position ), color( a_color ) {}
    7788};
    7889
     
    99110{
    100111        { // CHARACTER
    101                 nv::mesh cmesh;
    102                 nv::vertex_attribute<nv::i8vec3>::list& vtx = cmesh.add_attribute<nv::i8vec3>("coords")->get();
    103                 nv::vertex_attribute<nv::i8vec3>::list& mat = cmesh.add_attribute<nv::i8vec3>("material")->get();
     112                std::vector< vtx > v;
    104113                int m = 16;     int x = 0; int y = 0; int h = 0;
    105                 vtx.emplace_back( x,   h, y ); 
    106                 vtx.emplace_back( x,   h, y+1 );
    107                 vtx.emplace_back( x+1, h, y+1 );
    108                 vtx.emplace_back( x+1, h, y+1 );
    109                 vtx.emplace_back( x+1, h, y ); 
    110                 vtx.emplace_back( x,   h, y ); 
    111                 mat.insert( mat.end(), 6, nv::i8vec3( m, 1, 0 ) );
     114                nv::i8vec3 mt( m, 1, 0 );
     115                v.emplace_back( nv::i8vec3( x,   h, y ), mt ); 
     116                v.emplace_back( nv::i8vec3( x,   h, y+1 ), mt );
     117                v.emplace_back( nv::i8vec3( x+1, h, y+1 ), mt );
     118                v.emplace_back( nv::i8vec3( x+1, h, y+1 ), mt );
     119                v.emplace_back( nv::i8vec3( x+1, h, y ), mt ); 
     120                v.emplace_back( nv::i8vec3( x,   h, y ), mt ); 
    112121                m_char_program = m_device->create_program( nv::slurp( "char.vert" ), nv::slurp( "char.frag" ) );
    113                 m_char_va      = m_device->create_vertex_array( &cmesh, &(m_char_program->get_attributes()), nv::STATIC_DRAW );
     122                m_char_va      = m_device->create_vertex_array( v, nv::STATIC_DRAW );
    114123        }
    115124
    116125        { // WORLD
    117                 nv::mesh wmesh;
    118                 nv::vertex_attribute<nv::i8vec3>::list& vtx = wmesh.add_attribute<nv::i8vec3>("coords")->get();
    119                 nv::vertex_attribute<nv::i8vec3>::list& mat = wmesh.add_attribute<nv::i8vec3>("material")->get();
    120 
     126                std::vector< vtx > v;
     127                nv::i8vec3 mt;
    121128                for (int i = 0; i < size_x * size_y; ++i )
    122129                {
     
    124131                        int y = i / size_x;
    125132
    126                         vtx.emplace_back( x,   height[i], y   );
    127                         vtx.emplace_back( x,   height[i], y+1 );
    128                         vtx.emplace_back( x+1, height[i], y+1 );
    129                         vtx.emplace_back( x+1, height[i], y+1 );
    130                         vtx.emplace_back( x+1, height[i], y );   
    131                         vtx.emplace_back( x,   height[i], y );   
    132                         mat.insert( mat.end(), 6, nv::i8vec3( map[i], 2, 0 ) );
     133                        mt = nv::i8vec3( map[i], 2, 0 );
     134                        v.emplace_back( nv::i8vec3( x,   height[i], y   ), mt );
     135                        v.emplace_back( nv::i8vec3( x,   height[i], y+1 ), mt );
     136                        v.emplace_back( nv::i8vec3( x+1, height[i], y+1 ), mt );
     137                        v.emplace_back( nv::i8vec3( x+1, height[i], y+1 ), mt );
     138                        v.emplace_back( nv::i8vec3( x+1, height[i], y ), mt );
     139                        v.emplace_back( nv::i8vec3( x,   height[i], y ), mt );
    133140
    134141                        if (i > 0 && height[i-1] != height[i])
     
    139146                                {
    140147                                        m_count += 6;
    141                                         vtx.emplace_back( x, h,     y );   
    142                                         vtx.emplace_back( x, h,     y+1 );
    143                                         vtx.emplace_back( x, h+dir, y+1 );
    144                                         vtx.emplace_back( x, h+dir, y+1 );
    145                                         vtx.emplace_back( x, h+dir, y );   
    146                                         vtx.emplace_back( x, h,     y );   
    147                                         mat.insert( mat.end(), 6, nv::i8vec3( m, -dir, 0 ) );
     148                                        mt = nv::i8vec3( m, -dir, 0 );
     149                                        v.emplace_back( nv::i8vec3( x, h,     y ), mt );
     150                                        v.emplace_back( nv::i8vec3( x, h,     y+1 ), mt );
     151                                        v.emplace_back( nv::i8vec3( x, h+dir, y+1 ), mt );
     152                                        v.emplace_back( nv::i8vec3( x, h+dir, y+1 ), mt );
     153                                        v.emplace_back( nv::i8vec3( x, h+dir, y ), mt );
     154                                        v.emplace_back( nv::i8vec3( x, h,     y ), mt );
    148155                                }
    149156                        }
     
    155162                                for ( int h = height[i-size_x]; h != height[i]; h = h + dir )
    156163                                {
    157                                         vtx.emplace_back( x,   h,     y );
    158                                         vtx.emplace_back( x,   h+dir, y );
    159                                         vtx.emplace_back( x+1, h+dir, y );
    160 
    161                                         vtx.emplace_back( x+1, h+dir, y );
    162                                         vtx.emplace_back( x+1, h,     y );
    163                                         vtx.emplace_back( x,   h,     y );
    164                                         mat.insert( mat.end(), 6, nv::i8vec3( m, -3*dir, 0 ) );
     164                                        mt = nv::i8vec3( m, -3*dir, 0 );
     165                                        v.emplace_back( nv::i8vec3( x,   h,     y ), mt );
     166                                        v.emplace_back( nv::i8vec3( x,   h+dir, y ), mt );
     167                                        v.emplace_back( nv::i8vec3( x+1, h+dir, y ), mt );
     168
     169                                        v.emplace_back( nv::i8vec3( x+1, h+dir, y ), mt );
     170                                        v.emplace_back( nv::i8vec3( x+1, h,     y ), mt );
     171                                        v.emplace_back( nv::i8vec3( x,   h,     y ), mt );
    165172                                }
    166173                        }
     
    168175                }
    169176
    170                 m_count       = vtx.size();
     177                m_count       = v.size();
    171178                m_box_program = m_device->create_program( nv::slurp( "box.vert" ), nv::slurp( "box.frag" ) );
    172                 m_box_va      = m_device->create_vertex_array( &wmesh, &(m_box_program->get_attributes()), nv::STATIC_DRAW );
     179                m_box_va      = m_device->create_vertex_array( v, nv::STATIC_DRAW );
    173180        }
    174181
     
    181188
    182189        glm::vec3 move( 0, 0, 0 );
     190        m_scene_state.get_camera().set_perspective(25.0f, 1.0f*800.0f/600.0f, 0.1f, 100.0f);
    183191
    184192        while(!keypress)
    185193        {
     194                m_scene_state.set_model( glm::translate(glm::mat4(1.0f), glm::vec3(-8.5, 0.0, -8.0)) );
     195                m_scene_state.get_camera().set_lookat(glm::vec3(0.0, 20.0, 5.0) + move, glm::vec3(0.0, 4.0, 0.0) + move, glm::vec3(0.0, 1.0, 0.0));
     196
    186197                m_window->get_context()->clear( m_clear_state );
    187 
    188                 glm::mat4 model = glm::translate(glm::mat4(1.0f), glm::vec3(-8.5, 0.0, -8.0));
    189                 glm::mat4 view  = glm::lookAt(glm::vec3(0.0, 20.0, 5.0) + move, glm::vec3(0.0, 4.0, 0.0) + move, glm::vec3(0.0, 1.0, 0.0));
    190                 glm::mat4 projection = glm::perspective(25.0f, 1.0f*800.0f/600.0f, 0.1f, 100.0f);
    191                 glm::mat4 mv         = view * model;
    192 
    193198                m_texture->bind( 0 );
    194                 m_box_program->set_uniform( "matrix_mvp", projection * mv );
    195199                m_box_program->set_uniform( "light", glm::vec3(8.5, 4.5, 6.5) + move );
    196                 m_box_program->set_uniform( "tex", 0 );
    197                 m_window->get_context()->draw( nv::TRIANGLES, m_render_state, m_box_program, m_box_va, m_count );
    198 
    199                 m_char_program->set_uniform( "matrix_mvp", projection * mv );
     200                m_window->get_context()->draw( nv::TRIANGLES, m_render_state, m_scene_state, m_box_program, m_box_va, m_count );
     201
    200202                m_char_program->set_uniform( "pos", move + glm::vec3( 8, 4.1, 6 ) );
    201                 m_char_program->set_uniform( "tex", 0 );
    202                 m_window->get_context()->draw( nv::TRIANGLES, m_render_state, m_char_program, m_char_va, 6 );
     203                m_window->get_context()->draw( nv::TRIANGLES, m_render_state, m_scene_state, m_char_program, m_char_va, 6 );
    203204                m_window->swap_buffers();
    204205
Note: See TracChangeset for help on using the changeset viewer.