- Timestamp:
- 08/07/14 19:06:34 (11 years ago)
- Location:
- trunk/src
- Files:
-
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/formats/assimp_loader.cc
r294 r302 317 317 { 318 318 mesh_raw_channel* channel = meshes[m].get_raw_channels()[0]; 319 NV_ASSERT( !channel->is_index(), "index channel in release_merged!" );320 319 assimp_skinned_vtx* va = (assimp_skinned_vtx*)channel->data; 321 320 for ( unsigned v = 0; v < channel->count; ++v ) -
trunk/src/gfx/debug_draw.cc
r237 r302 29 29 30 30 nv::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() 32 32 { 33 33 m_program = m_device->create_program( nv_debug_draw_vertex_shader, nv_debug_draw_fragment_shader ); … … 36 36 void nv::debug_data::update() 37 37 { 38 delete m_va;38 m_device->release( m_va ); 39 39 m_va = m_device->create_vertex_array( m_data, nv::STATIC_DRAW ); 40 40 } … … 75 75 nv::debug_data::~debug_data() 76 76 { 77 delete m_va;77 m_device->release( m_va ); 78 78 delete m_program; 79 79 } -
trunk/src/gfx/keyframed_mesh.cc
r299 r302 15 15 using namespace nv; 16 16 17 nv::keyframed_mesh::keyframed_mesh( con st mesh_data* a_data, const mesh_nodes_data* a_tag_map )17 nv::keyframed_mesh::keyframed_mesh( context* a_context, const mesh_data* a_data, const mesh_nodes_data* a_tag_map ) 18 18 : animated_mesh() 19 , m_context( a_context ) 19 20 , m_mesh_data( a_data ) 20 21 , m_tag_map( a_tag_map ) … … 36 37 } 37 38 m_frame_count = m_vchannel->count / m_vertex_count; 39 m_pbuffer = buffer(); 38 40 } 39 41 … … 103 105 nv::keyframed_mesh::~keyframed_mesh() 104 106 { 105 delete m_va;107 m_context->get_device()->release( m_va ); 106 108 } 107 109 … … 122 124 123 125 nv::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 ) 125 127 , m_loc_next_position( -1 ) 126 128 , m_loc_next_normal( -1 ) … … 129 131 , m_gpu_next_frame( 0xFFFFFFFF ) 130 132 { 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 ); 132 135 } 133 136 … … 137 140 if ( m_loc_next_position == -1 ) return; 138 141 animated_mesh::update( ms ); 139 142 device* dev = m_context->get_device(); 140 143 if ( m_gpu_last_frame != m_last_frame ) 141 144 { 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 ) ); 144 148 if ( m_has_tangent && m_loc_next_tangent != -1 ) 145 149 { 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 ) ); 147 151 } 148 152 m_gpu_last_frame = m_last_frame; … … 150 154 if ( m_loc_next_position != -1 && m_gpu_next_frame != m_next_frame ) 151 155 { 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 } 155 163 m_gpu_next_frame = m_next_frame; 156 164 } … … 166 174 m_loc_next_tangent = a_program->get_attribute( "nv_next_tangent" )->get_location(); 167 175 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 ); 171 179 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 ); 173 181 } 174 182 keyframed_mesh::update( a_program ); … … 176 184 177 185 nv::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 ); 190 198 191 199 m_data = new uint8[ m_vertex_count * m_vsize ]; … … 224 232 } 225 233 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 ); 227 235 } 228 236 -
trunk/src/gfx/mesh_creator.cc
r295 r302 430 430 { 431 431 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 ); 433 433 m_data->m_channels[c] = append_channels( old, other->m_channels[c], frame_count ); 434 434 NV_ASSERT( m_data->m_channels[c], "Merge problem!" ); 435 if ( old-> is_index())435 if ( old->get_buffer_type() == INDEX_BUFFER ) 436 436 { 437 437 switch ( old->desc.slots[0].etype ) -
trunk/src/gfx/skeletal_mesh.cc
r299 r302 12 12 13 13 nv::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 ) 16 15 , m_data( a_mesh_data ) 17 16 { … … 27 26 m_vtx_data = a_mesh_data->get_channel_data<md5_vtx_pntiw>(); 28 27 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, 29 STREAM_DRAW ); 30 m_pbuffer = a_context->get_device()->find_buffer( m_va, slot::POSITION ); 30 31 } 31 32 … … 63 64 } 64 65 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() ); 67 67 } 68 68 } … … 80 80 skeleton[i] = m_node_data->get_node(i)->data->get_transform( frame_num ); 81 81 } 82 }83 84 85 86 nv::skeletal_mesh_cpu::~skeletal_mesh_cpu()87 {88 delete m_va;89 82 } 90 83 … … 200 193 201 194 nv::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 ) 203 196 { 204 197 m_va = a_context->get_device()->create_vertex_array( a_mesh, nv::STATIC_DRAW ); -
trunk/src/gl/gl_context.cc
r301 r302 10 10 #include "nv/gl/gl_device.hh" 11 11 #include "nv/gl/gl_program.hh" 12 #include "nv/gl/gl_vertex_buffer.hh"13 12 14 13 using namespace nv; … … 31 30 } 32 31 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 );32 void 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 41 void 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 } 68 67 } 69 68 } … … 74 73 } 75 74 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 ) ); 75 void 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 84 void 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 } 96 98 } 97 99 } … … 110 112 } 111 113 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 ); 114 void 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 } 122 122 } 123 123 … … 483 483 } 484 484 485 void gl_context::draw( primitive prim, const render_state& rs, program* p, vertex_array *va, size_t count )485 void gl_context::draw( primitive prim, const render_state& rs, program* p, vertex_array va, size_t count ) 486 486 { 487 487 apply_render_state( rs ); 488 if ( count > 0 ) 488 vertex_array_info* info = get_vertex_array_info( va ); 489 if ( count > 0 && info ) 489 490 { 490 491 bind( p ); 491 492 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 ); 495 496 } 496 497 else -
trunk/src/gl/gl_device.cc
r301 r302 7 7 #include "nv/gl/gl_window.hh" 8 8 #include "nv/gl/gl_program.hh" 9 #include "nv/gl/gl_vertex_buffer.hh"10 9 #include "nv/logging.hh" 11 10 #include "nv/lib/sdl.hh" … … 56 55 } 57 56 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 73 57 // this is a temporary function that will be removed once we find a way to 74 58 // pass binary file data around … … 101 85 gl_device::~gl_device() 102 86 { 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) ); 105 91 106 92 SDL_Quit(); … … 142 128 } 143 129 144 void nv::gl_device::release _texture( texture t )130 void nv::gl_device::release( texture t ) 145 131 { 146 132 gl_texture_info* info = m_textures.get( t ); 147 133 if ( info ) 148 134 { 149 glDeleteTextures( 1, &(info->glid) ); 135 if ( info->glid != 0 ) 136 { 137 glDeleteTextures( 1, &(info->glid) ); 138 } 150 139 m_textures.destroy( t ); 140 } 141 } 142 143 void 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 ); 151 153 } 152 154 } … … 157 159 } 158 160 161 nv::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 180 const 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 144 144 case DYNAMIC_DRAW : return GL_DYNAMIC_DRAW; 145 145 NV_RETURN_COVERED_DEFAULT( 0 ); 146 } 147 } 148 149 unsigned 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 ); 146 156 } 147 157 } -
trunk/src/gui/gui_renderer.cc
r301 r302 21 21 { 22 22 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; 29 29 } 30 30 gui_quad( const nv::ivec2& coorda, const nv::ivec2& coordb, const nv::vec4& color, const nv::vec2& tcoorda, const nv::vec2& tcoordb ) 31 31 { 32 32 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].t coord = tcoorda;40 vtx[1].t coord = nv::vec2( tcoorda.x, tcoordb.y );41 vtx[2].t coord = tcoordb;42 vtx[3].t coord = tcoordb;43 vtx[4].t coord = nv::vec2( tcoordb.x, tcoorda.y );44 vtx[5].t coord = 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; 45 45 } 46 46 gui_quad( const nv::ivec2& coorda, const nv::ivec2& coordb, const nv::ivec2& coordc, const nv::ivec2& coordd, const nv::vec4& color ) 47 47 { 48 48 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; 55 55 } 56 56 inline void set_color( const nv::vec4& color ) … … 66 66 public: 67 67 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) 69 69 { 70 70 … … 73 73 { 74 74 delete shader; 75 delete varray;75 ctx->get_device()->release( varray ); 76 76 } 77 77 78 78 nv::sliced_buffer<gui_quad> buffer; 79 nv::context* ctx; 79 80 nv::texture tex; 80 nv::vertex_array *varray;81 nv::vertex_array varray; 81 82 nv::program* shader; 82 83 }; … … 110 111 m_render_data = sr; 111 112 // ** EXTREMELY TEMPORARY! 112 sr->varray = m_window->get_device()->create_vertex_array();113 113 sr->shader = m_window->get_device()->create_program( nv::slurp( shader_path + ".vert" ), nv::slurp( shader_path + ".frag" ) ); 114 114 m_scene_state.get_camera().set_ortho( 0.0f, float( m_window->get_width() ), float( m_window->get_height() ), 0.0f ); 115 115 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 ); 120 119 121 120 nv::sampler sampler( nv::sampler::LINEAR, nv::sampler::CLAMP_TO_EDGE ); … … 267 266 if ( sr->buffer.commit() ) 268 267 { 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 ); 273 270 } 274 271 m_context->bind( sr->tex, TEX_DIFFUSE ); … … 284 281 if ( m_render_data ) 285 282 { 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 ); 287 284 delete m_render_data; 288 285 }
Note: See TracChangeset
for help on using the changeset viewer.