Changeset 302 for trunk/src/gui


Ignore:
Timestamp:
08/07/14 19:06:34 (11 years ago)
Author:
epyon
Message:
  • buffers and vertex_arrays are now handle based
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/gui_renderer.cc

    r301 r302  
    2121        {
    2222                set_color( color );
    23                 vtx[0].coord = coorda;
    24                 vtx[1].coord = nv::ivec2( coorda.x, coordb.y );
    25                 vtx[2].coord = coordb;
    26                 vtx[3].coord = coordb;
    27                 vtx[4].coord = nv::ivec2( coordb.x, coorda.y );
    28                 vtx[5].coord = coorda;
     23                vtx[0].position = coorda;
     24                vtx[1].position = nv::ivec2( coorda.x, coordb.y );
     25                vtx[2].position = coordb;
     26                vtx[3].position = coordb;
     27                vtx[4].position = nv::ivec2( coordb.x, coorda.y );
     28                vtx[5].position = coorda;
    2929        }
    3030        gui_quad( const nv::ivec2& coorda, const nv::ivec2& coordb, const nv::vec4& color, const nv::vec2& tcoorda, const nv::vec2& tcoordb )
    3131        {
    3232                set_color( color );
    33                 vtx[0].coord = coorda;
    34                 vtx[1].coord = nv::ivec2( coorda.x, coordb.y );
    35                 vtx[2].coord = coordb;
    36                 vtx[3].coord = coordb;
    37                 vtx[4].coord = nv::ivec2( coordb.x, coorda.y );
    38                 vtx[5].coord = coorda;
    39                 vtx[0].tcoord = tcoorda;
    40                 vtx[1].tcoord = nv::vec2( tcoorda.x, tcoordb.y );
    41                 vtx[2].tcoord = tcoordb;
    42                 vtx[3].tcoord = tcoordb;
    43                 vtx[4].tcoord = nv::vec2( tcoordb.x, tcoorda.y );
    44                 vtx[5].tcoord = tcoorda;
     33                vtx[0].position = coorda;
     34                vtx[1].position = nv::ivec2( coorda.x, coordb.y );
     35                vtx[2].position = coordb;
     36                vtx[3].position = coordb;
     37                vtx[4].position = nv::ivec2( coordb.x, coorda.y );
     38                vtx[5].position = coorda;
     39                vtx[0].texcoord = tcoorda;
     40                vtx[1].texcoord = nv::vec2( tcoorda.x, tcoordb.y );
     41                vtx[2].texcoord = tcoordb;
     42                vtx[3].texcoord = tcoordb;
     43                vtx[4].texcoord = nv::vec2( tcoordb.x, tcoorda.y );
     44                vtx[5].texcoord = tcoorda;
    4545        }
    4646        gui_quad( const nv::ivec2& coorda, const nv::ivec2& coordb, const nv::ivec2& coordc, const nv::ivec2& coordd, const nv::vec4& color )
    4747        {
    4848                set_color( color );
    49                 vtx[0].coord = coorda;
    50                 vtx[1].coord = coordb;
    51                 vtx[2].coord = coordc;
    52                 vtx[3].coord = coordc;
    53                 vtx[4].coord = coordd;
    54                 vtx[5].coord = coorda;
     49                vtx[0].position = coorda;
     50                vtx[1].position = coordb;
     51                vtx[2].position = coordc;
     52                vtx[3].position = coordc;
     53                vtx[4].position = coordd;
     54                vtx[5].position = coorda;
    5555        }
    5656        inline void set_color( const nv::vec4& color )
     
    6666public:
    6767        screen_render_data( context* actx, size_t initial_size )
    68                 : buffer( actx, nv::DYNAMIC_DRAW, initial_size ), varray( nullptr ), shader(nullptr)
     68                : buffer( actx, VERTEX_BUFFER, DYNAMIC_DRAW, initial_size ), ctx( actx ), varray(), shader(nullptr)
    6969        {
    7070
     
    7373        {
    7474                delete shader;
    75                 delete varray;
     75                ctx->get_device()->release( varray );
    7676        }
    7777
    7878        nv::sliced_buffer<gui_quad> buffer;
     79        nv::context*      ctx;
    7980        nv::texture       tex;
    80         nv::vertex_array* varray;
     81        nv::vertex_array  varray;
    8182        nv::program*      shader;
    8283};
     
    110111        m_render_data = sr;
    111112        // ** EXTREMELY TEMPORARY!
    112         sr->varray     = m_window->get_device()->create_vertex_array();
    113113        sr->shader     = m_window->get_device()->create_program( nv::slurp( shader_path + ".vert" ), nv::slurp( shader_path + ".frag" ) );
    114114        m_scene_state.get_camera().set_ortho( 0.0f, float( m_window->get_width() ), float( m_window->get_height() ), 0.0f );
    115115
    116         vertex_buffer* vb = (vertex_buffer*)sr->buffer.get_buffer();
    117         sr->varray->add_vertex_buffer( slot::POSITION, vb, nv::INT,   2, 0, sizeof( vertex ), false );
    118         sr->varray->add_vertex_buffer( slot::TEXCOORD, vb, nv::FLOAT, 2, offset_of( &vertex::tcoord ), sizeof( vertex ), false );
    119         sr->varray->add_vertex_buffer( slot::COLOR,    vb, nv::FLOAT, 4, offset_of( &vertex::color ), sizeof( vertex ), false );
     116        sr->varray     = m_window->get_device()->create_vertex_array();
     117        buffer vb      = sr->buffer.get_buffer();
     118        m_window->get_device()->add_vertex_buffers< vertex >( sr->varray, vb );
    120119
    121120        nv::sampler sampler( nv::sampler::LINEAR, nv::sampler::CLAMP_TO_EDGE );
     
    267266        if ( sr->buffer.commit() )
    268267        {
    269                 nv::vertex_buffer* vb = (nv::vertex_buffer*)sr->buffer.get_buffer();
    270                 sr->varray->update_vertex_buffer( nv::slot::POSITION, vb, false );
    271                 sr->varray->update_vertex_buffer( nv::slot::TEXCOORD, vb, false );
    272                 sr->varray->update_vertex_buffer( nv::slot::COLOR,    vb, false );
     268                buffer vb = sr->buffer.get_buffer();
     269                m_context->get_device()->replace_vertex_buffer( sr->varray, vb, false );
    273270        }
    274271        m_context->bind( sr->tex, TEX_DIFFUSE );
     
    284281        if ( m_render_data )
    285282        {
    286                 m_context->get_device()->release_texture( ((screen_render_data*)m_render_data)->tex );
     283                m_context->get_device()->release( ((screen_render_data*)m_render_data)->tex );
    287284                delete m_render_data;
    288285        }
Note: See TracChangeset for help on using the changeset viewer.