Changeset 302 for trunk/src


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

Legend:

Unmodified
Added
Removed
  • trunk/src/formats/assimp_loader.cc

    r294 r302  
    317317                        {
    318318                                mesh_raw_channel* channel = meshes[m].get_raw_channels()[0];
    319                                 NV_ASSERT( !channel->is_index(), "index channel in release_merged!" );
    320319                                assimp_skinned_vtx* va = (assimp_skinned_vtx*)channel->data;
    321320                                for ( unsigned v = 0; v < channel->count; ++v )
  • trunk/src/gfx/debug_draw.cc

    r237 r302  
    2929
    3030nv::debug_data::debug_data( device* a_device )
    31         : m_device( a_device ), m_program( nullptr ), m_va( nullptr )
     31        : m_device( a_device ), m_program( nullptr ), m_va()
    3232{
    3333        m_program = m_device->create_program( nv_debug_draw_vertex_shader, nv_debug_draw_fragment_shader );
     
    3636void nv::debug_data::update()
    3737{
    38         delete m_va;
     38        m_device->release( m_va );
    3939        m_va = m_device->create_vertex_array( m_data, nv::STATIC_DRAW );
    4040}
     
    7575nv::debug_data::~debug_data()
    7676{
    77         delete m_va;
     77        m_device->release( m_va );
    7878        delete m_program;
    7979}
  • trunk/src/gfx/keyframed_mesh.cc

    r299 r302  
    1515using namespace nv;
    1616
    17 nv::keyframed_mesh::keyframed_mesh( const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
     17nv::keyframed_mesh::keyframed_mesh( context* a_context, const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
    1818        : animated_mesh()
     19        , m_context( a_context )
    1920        , m_mesh_data( a_data )
    2021        , m_tag_map( a_tag_map )
     
    3637        }
    3738        m_frame_count  = m_vchannel->count / m_vertex_count;
     39        m_pbuffer      = buffer();
    3840}
    3941
     
    103105nv::keyframed_mesh::~keyframed_mesh()
    104106{
    105         delete m_va;
     107        m_context->get_device()->release( m_va );
    106108}
    107109
     
    122124
    123125nv::keyframed_mesh_gpu::keyframed_mesh_gpu( context* a_context, const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
    124         : keyframed_mesh( a_data, a_tag_map )
     126        : keyframed_mesh( a_context, a_data, a_tag_map )
    125127        , m_loc_next_position( -1 )
    126128        , m_loc_next_normal( -1 )
     
    129131        , m_gpu_next_frame( 0xFFFFFFFF )
    130132{
    131         m_va = a_context->get_device()->create_vertex_array( a_data, STATIC_DRAW );
     133        m_va      = a_context->get_device()->create_vertex_array( a_data, STATIC_DRAW );
     134        m_pbuffer = a_context->get_device()->find_buffer( m_va, slot::POSITION );
    132135}
    133136
     
    137140        if ( m_loc_next_position == -1 ) return;
    138141        animated_mesh::update( ms );
    139 
     142        device* dev = m_context->get_device();
    140143        if ( m_gpu_last_frame != m_last_frame )
    141144        {
    142                 m_va->update_vertex_buffer( slot::POSITION, m_last_frame * m_vertex_count * m_vsize );
    143                 m_va->update_vertex_buffer( slot::NORMAL,   m_last_frame * m_vertex_count * m_vsize + sizeof( vec3 ) );
     145                uint32 base_offset = m_last_frame * m_vertex_count * m_vsize;
     146                dev->update_attribute_offset( m_va, slot::POSITION, base_offset );
     147                dev->update_attribute_offset( m_va, slot::NORMAL,   base_offset + sizeof( vec3 ) );
    144148                if ( m_has_tangent && m_loc_next_tangent != -1 )
    145149                {
    146                         m_va->update_vertex_buffer( slot::TANGENT,   m_last_frame * m_vertex_count * m_vsize + 2*sizeof( vec3 ) );
     150                        dev->update_attribute_offset( m_va, slot::TANGENT, base_offset + 2*sizeof( vec3 ) );
    147151                }
    148152                m_gpu_last_frame = m_last_frame;
     
    150154        if ( m_loc_next_position != -1 && m_gpu_next_frame != m_next_frame )
    151155        {
    152                 m_va->update_vertex_buffer( m_loc_next_position, m_next_frame * m_vertex_count * m_vsize );
    153                 m_va->update_vertex_buffer( m_loc_next_normal,   m_next_frame * m_vertex_count * m_vsize + sizeof( vec3 ) );
    154                 m_va->update_vertex_buffer( m_loc_next_tangent,   m_next_frame * m_vertex_count * m_vsize + 2*sizeof( vec3 ) );
     156                uint32 base_offset = m_next_frame * m_vertex_count * m_vsize;
     157                dev->update_attribute_offset( m_va, (slot)m_loc_next_position, base_offset );
     158                dev->update_attribute_offset( m_va, (slot)m_loc_next_normal, base_offset + sizeof( vec3 ) );
     159                if ( m_has_tangent && m_loc_next_tangent != -1 )
     160                {
     161                        dev->update_attribute_offset( m_va, (slot)m_loc_next_tangent, base_offset + 2*sizeof( vec3 ) );
     162                }
    155163                m_gpu_next_frame = m_next_frame;
    156164        }
     
    166174                        m_loc_next_tangent  = a_program->get_attribute( "nv_next_tangent" )->get_location();
    167175
    168                 vertex_buffer* vb = m_va->find_buffer( slot::POSITION );
    169                 m_va->add_vertex_buffer( m_loc_next_position, vb, FLOAT, 3, 0, m_vsize, false );
    170                 m_va->add_vertex_buffer( m_loc_next_normal,   vb, FLOAT, 3, sizeof( vec3 ), m_vsize, false );
     176                device* dev = m_context->get_device();
     177                dev->add_vertex_buffer( m_va, (slot)m_loc_next_position, m_pbuffer, FLOAT, 3, 0, m_vsize, false );
     178                dev->add_vertex_buffer( m_va, (slot)m_loc_next_normal,   m_pbuffer, FLOAT, 3, sizeof( vec3 ), m_vsize, false );
    171179                if ( m_has_tangent )
    172                         m_va->add_vertex_buffer( m_loc_next_tangent, vb, FLOAT, 4, 2*sizeof( vec3 ), m_vsize, false );
     180                        dev->add_vertex_buffer( m_va, (slot)m_loc_next_tangent, m_pbuffer, FLOAT, 4, 2*sizeof( vec3 ), m_vsize, false );
    173181        }
    174182        keyframed_mesh::update( a_program );
     
    176184
    177185nv::keyframed_mesh_cpu::keyframed_mesh_cpu( context* a_context, const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
    178         : keyframed_mesh( a_data, a_tag_map )
    179         , m_context( a_context )
    180 {
    181         m_va = m_context->get_device()->create_vertex_array();
    182         m_vb = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * m_vsize, (void*)m_vchannel->data );
    183         m_va->add_vertex_buffers( m_vb, m_vchannel );
    184 
    185         nv::vertex_buffer* vb = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_vertex_count * sizeof( nv::vec2 ), (void*)m_mesh_data->get_channel<vertex_t>()->data );
    186         m_va->add_vertex_buffers( vb, m_mesh_data->get_channel<vertex_t>() );
    187 
    188         nv::index_buffer* ib = m_context->get_device()->create_index_buffer( nv::STATIC_DRAW, m_mesh_data->get_index_channel()->size(), (void*)m_mesh_data->get_index_channel()->data );
    189         m_va->set_index_buffer( ib, m_mesh_data->get_index_channel()->desc.slots[0].etype, true );
     186        : keyframed_mesh( a_context, a_data, a_tag_map )
     187{
     188        m_va      = m_context->get_device()->create_vertex_array();
     189        m_pbuffer = m_context->get_device()->create_buffer( VERTEX_BUFFER, STATIC_DRAW, m_vertex_count * m_vsize, (void*)m_vchannel->data );
     190        m_context->get_device()->add_vertex_buffers( m_va, m_pbuffer, m_vchannel );
     191
     192        buffer  vb = m_context->get_device()->create_buffer( VERTEX_BUFFER, STATIC_DRAW, m_vertex_count * sizeof( vec2 ), (void*)m_mesh_data->get_channel<vertex_t>()->data );
     193        m_context->get_device()->add_vertex_buffers( m_va, vb, m_mesh_data->get_channel<vertex_t>() );
     194
     195        buffer  ib = m_context->get_device()->create_buffer( INDEX_BUFFER, STATIC_DRAW, m_mesh_data->get_index_channel()->size(), (void*)m_mesh_data->get_index_channel()->data );
     196
     197        m_context->get_device()->set_index_buffer( m_va, ib, m_mesh_data->get_index_channel()->desc.slots[0].etype, true );
    190198
    191199        m_data = new uint8[ m_vertex_count * m_vsize ];
     
    224232        }
    225233
    226         m_context->update( m_vb, m_data, 0, m_vertex_count * m_vsize );
     234        m_context->update( m_pbuffer, m_data, 0, m_vertex_count * m_vsize );
    227235}
    228236
  • trunk/src/gfx/mesh_creator.cc

    r295 r302  
    430430        {
    431431                mesh_raw_channel* old = m_data->m_channels[c];
    432                 size_t frame_count = ( old->is_index() ? 1 : old->count / size );
     432                size_t frame_count = ( old->get_buffer_type() == INDEX_BUFFER ? 1 : old->count / size );
    433433                m_data->m_channels[c] = append_channels( old, other->m_channels[c], frame_count );
    434434                NV_ASSERT( m_data->m_channels[c], "Merge problem!" );
    435                 if ( old->is_index() )
     435                if ( old->get_buffer_type() == INDEX_BUFFER )
    436436                {
    437437                        switch ( old->desc.slots[0].etype )
  • trunk/src/gfx/skeletal_mesh.cc

    r299 r302  
    1212
    1313nv::skeletal_mesh_cpu::skeletal_mesh_cpu( context* a_context, const mesh_data* a_mesh_data, const mesh_nodes_data* bones )
    14         : skeletal_mesh()
    15         , m_context( a_context )
     14        : skeletal_mesh( a_context )
    1615        , m_data( a_mesh_data )
    1716{
     
    2726        m_vtx_data  = a_mesh_data->get_channel_data<md5_vtx_pntiw>();
    2827        m_indices   = a_mesh_data->get_count();
    29         m_va        = a_context->get_device()->create_vertex_array( a_mesh_data, nv::STREAM_DRAW );
     28        m_va        = a_context->get_device()->create_vertex_array( a_mesh_data,
     29STREAM_DRAW );
     30        m_pbuffer   = a_context->get_device()->find_buffer( m_va, slot::POSITION );
    3031}
    3132
     
    6364                }
    6465
    65                 vertex_buffer* vb = m_va->find_buffer( nv::slot::POSITION );
    66                 m_context->update( vb, m_pntdata.data(), 0, m_pntdata.raw_size() );
     66                m_context->update( m_pbuffer, m_pntdata.data(), 0, m_pntdata.raw_size() );
    6767        }
    6868}
     
    8080                skeleton[i] = m_node_data->get_node(i)->data->get_transform( frame_num );
    8181        }
    82 }
    83 
    84 
    85 
    86 nv::skeletal_mesh_cpu::~skeletal_mesh_cpu()
    87 {
    88         delete m_va;
    8982}
    9083
     
    200193
    201194nv::skeletal_mesh_gpu::skeletal_mesh_gpu( context* a_context, const mesh_data* a_mesh, const mesh_nodes_data* a_bone_data )
    202         : skeletal_mesh(), m_bone_data( a_bone_data ), m_transform( nullptr )
     195        : skeletal_mesh( a_context ), m_bone_data( a_bone_data ), m_transform( nullptr )
    203196{
    204197        m_va          = a_context->get_device()->create_vertex_array( a_mesh, nv::STATIC_DRAW );
  • trunk/src/gl/gl_context.cc

    r301 r302  
    1010#include "nv/gl/gl_device.hh"
    1111#include "nv/gl/gl_program.hh"
    12 #include "nv/gl/gl_vertex_buffer.hh"
    1312
    1413using namespace nv;
     
    3130}
    3231
    33 void nv::gl_context::bind( vertex_buffer* b )
    34 {
    35         GLuint id = static_cast< gl_vertex_buffer* >( b )->glid;
    36         glBindBuffer( GL_ARRAY_BUFFER, id );
    37 }
    38 
    39 void nv::gl_context::bind( index_buffer* b )
    40 {
    41         GLuint id = static_cast< gl_index_buffer* >( b )->glid;
    42         glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, id );
    43 }
    44 
    45 void nv::gl_context::bind( vertex_array* va )
    46 {
    47         for ( vertex_buffer_attribute_map::iterator i = va->m_map.begin();      i != va->m_map.end(); ++i )
    48         {
    49                 uint32 location             = static_cast<uint32>( i->first );
    50                 vertex_buffer_attribute* va = i->second;
    51                 vertex_buffer*           vb = va->get_buffer();
    52                 glEnableVertexAttribArray( location );
    53                 bind( vb );
    54                 glVertexAttribPointer(
    55                         location,
    56                         static_cast<GLint>( va->get_components() ),
    57                         nv::datatype_to_gl_enum( va->get_datatype() ),
    58                         GL_FALSE,
    59                         static_cast<GLsizei>( va->get_stride() ),
    60                         (void*)va->get_offset()
    61                         );
    62                 unbind( vb );
    63         }
    64 
    65         if ( va->m_index )
    66         {
    67                 bind( va->m_index );
     32void nv::gl_context::bind( buffer b )
     33{
     34        const gl_buffer_info* info = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( b ) );
     35        if ( info )
     36        {
     37                glBindBuffer( buffer_type_to_enum( info->type ), info->glid );
     38        }
     39}
     40
     41void nv::gl_context::bind( vertex_array va )
     42{
     43        vertex_array_info* info = get_vertex_array_info( va );
     44        if ( info )
     45        {
     46                for ( uint32 i = 0; i < info->count; ++i )
     47                {
     48                        const vertex_buffer_attribute& vba = info->attr[i];
     49                        uint32 location                    = static_cast<uint32>( vba.location );
     50                        glEnableVertexAttribArray( location );
     51                        bind( vba.vbuffer );
     52                        glVertexAttribPointer(
     53                                location,
     54                                static_cast<GLint>( vba.components ),
     55                                nv::datatype_to_gl_enum( vba.dtype ),
     56                                GL_FALSE,
     57                                static_cast<GLsizei>( vba.stride ),
     58                                (void*)vba.offset
     59                                );
     60                        unbind( vba.vbuffer );
     61                }
     62
     63                if ( info->index.is_valid() )
     64                {
     65                        bind( info->index );
     66                }
    6867        }
    6968}
     
    7473}
    7574
    76 void nv::gl_context::unbind( vertex_buffer* )
    77 {
    78         glBindBuffer( GL_ARRAY_BUFFER, 0 );
    79 }
    80 
    81 void nv::gl_context::unbind( index_buffer* )
    82 {
    83         glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
    84 }
    85 
    86 void nv::gl_context::unbind( vertex_array* va )
    87 {
    88         if ( va->m_index )
    89         {
    90                 unbind( va->m_index );
    91         }
    92 
    93         for ( vertex_buffer_attribute_map::iterator i = va->m_map.begin();      i != va->m_map.end(); ++i )
    94         {
    95                 glDisableVertexAttribArray( static_cast<uint32>( i->first ) );
     75void nv::gl_context::unbind( buffer b )
     76{
     77        const gl_buffer_info* info = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( b ) );
     78        if ( info )
     79        {
     80                glBindBuffer( buffer_type_to_enum( info->type ), 0 );
     81        }
     82}
     83
     84void nv::gl_context::unbind( vertex_array va )
     85{
     86        vertex_array_info* info = get_vertex_array_info( va );
     87        if ( info )
     88        {
     89                if ( info->index.is_valid() )
     90                {
     91                        unbind( info->index );
     92                }
     93
     94                for ( uint32 i = 0; i < info->count; ++i )
     95                {
     96                        glDisableVertexAttribArray( static_cast<uint32>( info->attr[i].location ) );
     97                }
    9698        }
    9799}
     
    110112}
    111113
    112 void gl_context::update( vertex_buffer* b, const void* data, size_t offset, size_t size )
    113 {
    114         bind( b );
    115         glBufferSubData( GL_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)size, data );
    116 }
    117 
    118 void gl_context::update( index_buffer* b, const void* data, size_t offset, size_t size )
    119 {
    120         bind( b );
    121         glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)size, data );
     114void gl_context::update( buffer b, const void* data, size_t offset, size_t size )
     115{
     116        const gl_buffer_info* info = static_cast< const gl_buffer_info* >( m_device->get_buffer_info( b ) );
     117        if ( info )
     118        {
     119                bind( b );
     120                glBufferSubData( buffer_type_to_enum( info->type ), (GLintptr)offset, (GLsizeiptr)size, data );
     121        }
    122122}
    123123
     
    483483}
    484484
    485 void gl_context::draw( primitive prim, const render_state& rs, program* p, vertex_array* va, size_t count )
     485void gl_context::draw( primitive prim, const render_state& rs, program* p, vertex_array va, size_t count )
    486486{
    487487        apply_render_state( rs );
    488         if ( count > 0 )
     488        vertex_array_info* info = get_vertex_array_info( va );
     489        if ( count > 0 && info )
    489490        {
    490491                bind( p );
    491492                bind( va );
    492                 if ( va->has_index_buffer() )
    493                 {
    494                         glDrawElements( primitive_to_enum(prim), static_cast<GLsizei>( count ), datatype_to_gl_enum( va->get_index_buffer_type() ), 0 );
     493                if ( info->index.is_valid() )
     494                {
     495                        glDrawElements( primitive_to_enum(prim), static_cast<GLsizei>( count ), datatype_to_gl_enum( info->index_type ), 0 );
    495496                }
    496497                else
  • trunk/src/gl/gl_device.cc

    r301 r302  
    77#include "nv/gl/gl_window.hh"
    88#include "nv/gl/gl_program.hh"
    9 #include "nv/gl/gl_vertex_buffer.hh"
    109#include "nv/logging.hh"
    1110#include "nv/lib/sdl.hh"
     
    5655}
    5756
    58 vertex_buffer* gl_device::create_vertex_buffer( buffer_hint hint, size_t size, const void* source /*= nullptr */ )
    59 {
    60         return new gl_vertex_buffer( hint, size, source );
    61 }
    62 
    63 index_buffer* gl_device::create_index_buffer( buffer_hint hint, size_t size, const void* source /*= nullptr */ )
    64 {
    65         return new gl_index_buffer( hint, size, source );
    66 }
    67 
    68 vertex_array* gl_device::create_vertex_array()
    69 {
    70         return new vertex_array();
    71 }
    72 
    7357// this is a temporary function that will be removed once we find a way to
    7458// pass binary file data around
     
    10185gl_device::~gl_device()
    10286{
    103         // TODO: better use release_texture
    104         for ( auto& t : m_textures ) glDeleteTextures( 1, &t.glid );
     87        while ( m_textures.size() > 0 )
     88                release( m_textures.get_handle(0) );
     89        while ( m_buffers.size() > 0 )
     90                release( m_buffers.get_handle(0) );
    10591
    10692        SDL_Quit();
     
    142128}
    143129
    144 void nv::gl_device::release_texture( texture t )
     130void nv::gl_device::release( texture t )
    145131{
    146132        gl_texture_info* info = m_textures.get( t );
    147133        if ( info )
    148134        {
    149                 glDeleteTextures( 1, &(info->glid) );
     135                if ( info->glid != 0 )
     136                {
     137                        glDeleteTextures( 1, &(info->glid) );
     138                }
    150139                m_textures.destroy( t );
     140        }
     141}
     142
     143void nv::gl_device::release( buffer b )
     144{
     145        gl_buffer_info* info = m_buffers.get( b );
     146        if ( info )
     147        {
     148                if ( info->glid != 0 )
     149                {
     150                        glDeleteBuffers( 1, &(info->glid) );
     151                }
     152                m_buffers.destroy( b );
    151153        }
    152154}
     
    157159}
    158160
     161nv::buffer nv::gl_device::create_buffer( buffer_type type, buffer_hint hint, size_t size, const void* source /*= nullptr */ )
     162{
     163        unsigned glid   = 0;
     164        unsigned glenum = buffer_type_to_enum( type );
     165        glGenBuffers( 1, &glid );
     166
     167        glBindBuffer( glenum, glid );
     168        glBufferData( glenum, (GLsizeiptr)size, source, buffer_hint_to_enum( hint ) );
     169        glBindBuffer( glenum, 0 );
     170
     171        buffer result = m_buffers.create();
     172        gl_buffer_info* info = m_buffers.get( result );
     173        info->type = type;
     174        info->hint = hint;
     175        info->size = size;
     176        info->glid = glid;
     177        return result;
     178}
     179
     180const buffer_info* nv::gl_device::get_buffer_info( buffer t )
     181{
     182        return m_buffers.get( t );
     183}
  • trunk/src/gl/gl_enum.cc

    r292 r302  
    144144        case DYNAMIC_DRAW  : return GL_DYNAMIC_DRAW;
    145145        NV_RETURN_COVERED_DEFAULT( 0 );
     146        }
     147}
     148
     149unsigned int nv::buffer_type_to_enum( buffer_type type )
     150{
     151        switch( type )
     152        {
     153        case VERTEX_BUFFER : return GL_ARRAY_BUFFER;
     154        case INDEX_BUFFER  : return GL_ELEMENT_ARRAY_BUFFER;
     155                NV_RETURN_COVERED_DEFAULT( 0 );
    146156        }
    147157}
  • 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.