Changeset 161 for trunk


Ignore:
Timestamp:
07/15/13 02:48:06 (12 years ago)
Author:
epyon
Message:
  • unified naming of attributes in nv
  • predefined attribute bindings based on unified names
  • unified naming of attributes in all tests
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/gfx/keyframed_mesh.hh

    r159 r161  
    3333
    3434                int m_loc_next_position;
    35                 int m_loc_last_position;
    3635                int m_loc_next_normal;
    37                 int m_loc_last_normal;
    3836
    3937                uint32 m_last_frame;
  • trunk/nv/interface/program.hh

    r139 r161  
    2222namespace nv
    2323{
     24        enum slot
     25        {
     26                POSITION = 0,
     27                TEXCOORD = 1,
     28                NORMAL   = 2,
     29                COLOR    = 3,
     30                TANGENT  = 4,
     31        };
     32
    2433        class attribute
    2534        {
  • trunk/src/formats/md3_loader.cc

    r156 r161  
    313313        }
    314314
    315         vertex_attribute< vec3 >* position = m->add_attribute<vec3>("position");
    316         vertex_attribute< vec3 >* normal   = m->add_attribute<vec3>("normal");
    317         vertex_attribute< vec2 >* texcoord = m->add_attribute<vec2>("texcoord");
     315        vertex_attribute< vec3 >* position = m->add_attribute<vec3>("nv_position");
     316        vertex_attribute< vec3 >* normal   = m->add_attribute<vec3>("nv_normal");
     317        vertex_attribute< vec2 >* texcoord = m->add_attribute<vec2>("nv_texcoord");
    318318        vertex_attribute< uint16 >* indices  = m->add_indices<uint16>();
    319319
  • trunk/src/formats/obj_loader.cc

    r148 r161  
    140140        if ( m_position == nullptr )
    141141        {
    142                 m_position  = m_mesh->add_attribute< vec3 >( "position" );
     142                m_position  = m_mesh->add_attribute< vec3 >( "nv_position" );
    143143        }
    144144        if ( m_tex_coord == nullptr )
    145145        {
    146                 m_tex_coord = m_mesh->add_attribute< vec2 >( "texcoord" );
     146                m_tex_coord = m_mesh->add_attribute< vec2 >( "nv_texcoord" );
    147147        }
    148148        if ( m_normal == nullptr && ni != nullptr )
    149149        {
    150                 m_normal = m_mesh->add_attribute< vec3 >( "normal" );
     150                m_normal = m_mesh->add_attribute< vec3 >( "nv_normal" );
    151151        }
    152152
     
    174174void mesh_obj_reader::calculate_tangents()
    175175{
    176         m_tangent = m_mesh->add_attribute< vec4 >( "tangent" );
     176        m_tangent = m_mesh->add_attribute< vec4 >( "nv_tangent" );
    177177
    178178        std::vector< vec3 >& vp = m_position->get();
  • trunk/src/gfx/keyframed_mesh.cc

    r159 r161  
    2121        , m_va( nullptr )
    2222        , m_loc_next_position( 0 )
    23         , m_loc_last_position( 0 )
    2423        , m_loc_next_normal( 0 )
    25         , m_loc_last_normal( 0 )
    2624        , m_last_frame( 0 )
    2725        , m_next_frame( 0 )
     
    3735
    3836        nv::vertex_buffer* vb;
    39         m_loc_next_position = m_program->get_attribute( "next_position" )->get_location();
    40         m_loc_last_position = m_program->get_attribute( "last_position" )->get_location();
    41         m_loc_next_normal   = m_program->get_attribute( "next_normal" )->get_location();
    42         m_loc_last_normal   = m_program->get_attribute( "last_normal" )->get_location();
     37        m_loc_next_position = m_program->get_attribute( "nv_next_position" )->get_location();
     38        m_loc_next_normal   = m_program->get_attribute( "nv_next_normal" )->get_location();
    4339
    4440        vb = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ) * m_data->get_frame_count(), (void*)m_data->get_positions().data() );
    4541        m_va->add_vertex_buffer( m_loc_next_position, vb, nv::FLOAT, 3, 0, 0, false );
    46         m_va->add_vertex_buffer( m_loc_last_position, vb, nv::FLOAT, 3 );
     42        m_va->add_vertex_buffer( nv::POSITION, vb, nv::FLOAT, 3 );
    4743
    4844        vb = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ) * m_data->get_frame_count(), (void*)m_data->get_normals().data() );
    4945        m_va->add_vertex_buffer( m_loc_next_normal, vb, nv::FLOAT, 3, 0, 0, false );
    50         m_va->add_vertex_buffer( m_loc_last_normal, vb, nv::FLOAT, 3 );
     46        m_va->add_vertex_buffer( nv::NORMAL, vb, nv::FLOAT, 3 );
    5147
    5248        vb = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec2 ), (void*)m_data->get_texcoords().data() );
    53         m_va->add_vertex_buffer( m_program->get_attribute( "texcoord" )->get_location(), vb, nv::FLOAT, 2 );
     49        m_va->add_vertex_buffer( nv::slot::TEXCOORD, vb, nv::FLOAT, 2 );
    5450        nv::index_buffer* ib = m_context->get_device()->create_index_buffer( nv::STATIC_DRAW, m_data->get_index_count() * sizeof( nv::uint16 ), (void*)m_data->get_indices().data() );
    5551        m_va->set_index_buffer( ib, nv::USHORT, true );
     
    129125        if ( m_gpu_last_frame != m_last_frame )
    130126        {
    131                 m_va->update_vertex_buffer( m_loc_last_position, m_last_frame * vtx_count * sizeof( nv::vec3 ) );
    132                 m_va->update_vertex_buffer( m_loc_last_normal,   m_last_frame * vtx_count * sizeof( nv::vec3 ) );
     127                m_va->update_vertex_buffer( slot::POSITION, m_last_frame * vtx_count * sizeof( nv::vec3 ) );
     128                m_va->update_vertex_buffer( slot::NORMAL,   m_last_frame * vtx_count * sizeof( nv::vec3 ) );
    133129                m_gpu_last_frame = m_last_frame;
    134130        }
     
    139135                m_gpu_next_frame = m_next_frame;
    140136        }
    141         m_program->set_uniform( "interpolate", m_interpolation );
     137        m_program->set_uniform( "nv_interpolate", m_interpolation );
    142138        m_context->draw( nv::TRIANGLES, rstate, m_program, m_va, m_data->get_index_count() );
    143139}
  • trunk/src/gl/gl_device.cc

    r153 r161  
    4444        SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
    4545        SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
    46         SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
     46        SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
    4747        SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
     48
     49        SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
     50        SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 4 );
     51
    4852}
    4953
  • trunk/src/gl/gl_program.cc

    r121 r161  
    105105        if (!vertex_shader.compile( vertex_program )) { return false; }
    106106        if (!fragment_shader.compile( fragment_program )) { return false; }
     107
     108        glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::POSITION ), "nv_position" );
     109        glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::TEXCOORD ), "nv_texcoord" );
     110        glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::NORMAL   ), "nv_normal"   );
     111        glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::COLOR    ), "nv_color"    );
     112        glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::TANGENT  ), "nv_tangent"  );
    107113
    108114        glAttachShader( m_name.get_value(), fragment_shader.get_id() );
  • trunk/src/gui/gui_renderer.cc

    r152 r161  
    8181        nv::program*      shader;
    8282        nv::texture2d*    texture;
    83 
    84         int loc_coord;
    85         int loc_color;
    86         int loc_tcoord;
    8783};
    8884
     
    116112        sr->varray     = m_window->get_device()->create_vertex_array();
    117113        sr->shader     = m_window->get_device()->create_program( nv::slurp( "gui.vert" ), nv::slurp( "gui.frag" ) );
    118         sr->loc_coord  = sr->shader->get_attribute("coord")->get_location();
    119         sr->loc_tcoord = sr->shader->get_attribute("tcoord")->get_location();
    120         sr->loc_color  = sr->shader->get_attribute("color")->get_location();
    121114        sr->shader->set_uniform( "tex", 0 );
    122115        glm::mat4 projection = glm::ortho( 0.0f, float( m_window->get_width() ), float( m_window->get_height() ), 0.0f, -1.0f, 1.0f );
    123         sr->shader->set_uniform( "projection", projection );
     116        sr->shader->set_uniform( "nv_projection", projection );
    124117
    125118        vertex_buffer* vb = (vertex_buffer*)sr->buffer.get_buffer();
    126         sr->varray->add_vertex_buffer( sr->loc_coord, vb, nv::INT,   2, 0, sizeof( vertex ), false );
    127         sr->varray->add_vertex_buffer( sr->loc_tcoord, vb, nv::FLOAT, 2, offset_of( &vertex::tcoord ), sizeof( vertex ), false );
    128         sr->varray->add_vertex_buffer( sr->loc_color,  vb, nv::FLOAT, 4, offset_of( &vertex::color ), sizeof( vertex ), false );
     119        sr->varray->add_vertex_buffer( slot::POSITION, vb, nv::INT,   2, 0, sizeof( vertex ), false );
     120        sr->varray->add_vertex_buffer( slot::TEXCOORD, vb, nv::FLOAT, 2, offset_of( &vertex::tcoord ), sizeof( vertex ), false );
     121        sr->varray->add_vertex_buffer( slot::COLOR,    vb, nv::FLOAT, 4, offset_of( &vertex::color ), sizeof( vertex ), false );
    129122
    130123        nv::sampler sampler( nv::sampler::LINEAR, nv::sampler::CLAMP_TO_EDGE );
     
    277270        {
    278271                nv::vertex_buffer* vb = (nv::vertex_buffer*)sr->buffer.get_buffer();
    279                 sr->varray->update_vertex_buffer( sr->loc_coord, vb, false );
    280                 sr->varray->update_vertex_buffer( sr->loc_tcoord, vb, false );
    281                 sr->varray->update_vertex_buffer( sr->loc_color,  vb, false );
     272                sr->varray->update_vertex_buffer( nv::POSITION, vb, false );
     273                sr->varray->update_vertex_buffer( nv::TEXCOORD, vb, false );
     274                sr->varray->update_vertex_buffer( nv::COLOR,    vb, false );
    282275        }
    283276        sr->texture->bind( 0 );
  • trunk/tests/cachebuf_test/cachebuf.vert

    r102 r161  
    11#version 120
    2 attribute vec2 coord;
    3 attribute vec4 color;
    4 uniform mat4 projection;
     2attribute vec2 nv_position;
     3attribute vec4 nv_color;
     4uniform mat4 nv_projection;
    55varying vec4 f_color;
    66
    77void main(void) {
    8         f_color = color;
    9         gl_Position = projection * vec4( coord.x, coord.y, 0.0, 1.0 );
     8        f_color = nv_color;
     9        gl_Position = nv_projection * vec4( nv_position.x, nv_position.y, 0.0, 1.0 );
    1010}
  • trunk/tests/cachebuf_test/nv_cachebuf_test.cc

    r152 r161  
    234234        nv::vertex_array* m_va;
    235235        unsigned int m_count;
    236         int m_coord_loc;
    237         int m_color_loc;
    238236};
    239237
     
    257255        {
    258256                m_program   = m_device->create_program( nv::slurp( "cachebuf.vert" ), nv::slurp( "cachebuf.frag" ) );
    259                 m_coord_loc = m_program->get_attribute("coord")->get_location();
    260                 m_color_loc = m_program->get_attribute("color")->get_location();
    261257                m_va        = m_device->create_vertex_array();
    262258
     
    270266                #endif
    271267
    272                 m_va->add_vertex_buffer( m_coord_loc, buffer, nv::INT,   2, 0, sizeof( vertex ), false );
    273                 m_va->add_vertex_buffer( m_color_loc, buffer, nv::FLOAT, 4, offset_of( &vertex::color ), sizeof( vertex ), false );
     268                m_va->add_vertex_buffer( nv::slot::POSITION, buffer, nv::INT,   2, 0, sizeof( vertex ), false );
     269                m_va->add_vertex_buffer( nv::slot::COLOR,    buffer, nv::FLOAT, 4, offset_of( &vertex::color ), sizeof( vertex ), false );
    274270        }
    275271        return true;
     
    281277        m_program->bind();
    282278        glm::mat4 projection = glm::ortho( 0.0f, 800.0f, 600.0f, 0.0f, -1.0f, 1.0f );
    283         m_program->set_uniform( "projection", glm::mat4(projection) );
     279        m_program->set_uniform( "nv_projection", glm::mat4(projection) );
    284280
    285281        while(!keypress)
     
    297293                        nv::vertex_buffer* buffer = (nv::vertex_buffer*)m_quad_cache->get_buffer();
    298294                        #endif
    299                         m_va->update_vertex_buffer( m_coord_loc, buffer, false );
    300                         m_va->update_vertex_buffer( m_color_loc, buffer, false );
     295                        m_va->update_vertex_buffer( nv::slot::POSITION, buffer, false );
     296                        m_va->update_vertex_buffer( nv::slot::COLOR,    buffer, false );
    301297                }
    302298
  • trunk/tests/gui_test/gui.frag

    r127 r161  
    11#version 120
    2 varying vec4 f_color;
    3 varying vec2 f_tcoord;
     2varying vec4 v_color;
     3varying vec2 v_texcoord;
    44uniform sampler2D tex;
    55 
    66void main(void) {
    7         vec4 texture = texture2D(tex,f_tcoord);
    8         gl_FragColor = f_color * texture;
     7        vec4 texture = texture2D(tex,v_texcoord);
     8        gl_FragColor = v_color * texture;
    99}
  • trunk/tests/gui_test/gui.vert

    r127 r161  
    11#version 120
    2 attribute vec2 coord;
    3 attribute vec2 tcoord;
    4 attribute vec4 color;
    5 uniform mat4 projection;
    6 varying vec4 f_color;
    7 varying vec2 f_tcoord;
     2attribute vec2 nv_position;
     3attribute vec2 nv_texcoord;
     4attribute vec4 nv_color;
     5uniform mat4 nv_projection;
     6varying vec4 v_color;
     7varying vec2 v_texcoord;
    88
    99void main(void) {
    10         f_color  = color;
    11         f_tcoord = tcoord;
    12         gl_Position = projection * vec4( coord.x, coord.y, 0.0, 1.0 );
     10        v_color     = nv_color;
     11        v_texcoord  = nv_texcoord;
     12        gl_Position = nv_projection * vec4( nv_position.x, nv_position.y, 0.0, 1.0 );
    1313}
  • trunk/tests/objload_test/obj.vert

    r139 r161  
    11#version 120
    22
    3 attribute vec3 position;
    4 attribute vec2 texcoord;
    5 attribute vec3 normal;
     3attribute vec3 nv_position;
     4attribute vec2 nv_texcoord;
     5attribute vec3 nv_normal;
    66
    77varying vec3 v_normal;
     
    1717
    1818void main(void) {
    19         vec4 vertex     = vec4( position, 1.0 );
     19        vec4 vertex     = vec4( nv_position, 1.0 );
    2020        vec3 eye_pos    = vec3( nv_m_modelview * vertex );
    21         v_normal        = normalize( nv_m_normal * normal );
     21        v_normal        = normalize( nv_m_normal * nv_normal );
    2222        v_light_vector  = vec3( normalize( light_position - eye_pos ) );
    2323        v_view_vector   = vec3( normalize( -eye_pos ) );
    2424
    25         v_texcoord      = texcoord;
     25        v_texcoord      = nv_texcoord;
    2626        gl_Position     = matrix_mvp * vertex;
    2727}
Note: See TracChangeset for help on using the changeset viewer.