Changeset 508 for trunk/src


Ignore:
Timestamp:
07/19/16 13:43:10 (9 years ago)
Author:
epyon
Message:
  • nv::engine upgrades
  • default_resource_manager implementation
Location:
trunk/src
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/engine/animation.cc

    r487 r508  
    4141                {
    4242                        nv::c_file_system fs;
    43                         nv::stream* poses_file = fs.open( poses_path );
     43                        nv::stream* poses_file = open_stream( fs, poses_path );
     44                        NV_ASSERT_ALWAYS( poses_file, "CANT FIND POSES FILE!" );
    4445                        nv::nmd_loader* ploader = new nv::nmd_loader( nullptr );
    4546                        ploader->load( *poses_file );
  • trunk/src/engine/material_manager.cc

    r505 r508  
    3939
    4040                // HACK
    41                 for ( uint32 i = 0; i < 8; ++i )
    42                         if ( result->textures[i].is_nil() )
    43                                 result->textures[i] = m_default;
     41                for ( uint32 i = 0; i < 5; ++i )
     42                        if ( result->textures[i].is_nil() )
     43                                result->textures[i] = m_default;
    4444
    4545                return add( id, result );
     
    7777                                if ( i != TEX_EMISSIVE )
    7878                                        NV_LOG_ERROR( "Texture file not found! : ", m->paths[i] );
    79                                 m->paths[i].clear();
     79                                //m->paths[i].clear();
    8080                        }
    8181                }
  • trunk/src/engine/mesh_manager.cc

    r505 r508  
    1818                gm->va = m_context->create_vertex_array( &*lmesh, STATIC_DRAW );
    1919                gm->count = lmesh->get_channel_size( slot::INDEX );
    20                 gm->shader = lmesh->get_channel( slot::BONEINDEX ) != nullptr ? BONE : NORMAL;
     20                gm->shader = lmesh->get_channel( slot::BONEINDEX ) != nullptr ? BONE : DIRECT;
    2121                return add( mesh.id(), gm );
    2222        }
  • trunk/src/engine/model_manager.cc

    r507 r508  
    6464                if ( table.is_number( "attach" ) )
    6565                {
    66                         attach_id = table.get_integer( "attach", -1 );
     66                        attach_id = sint16( table.get_integer( "attach", -1 ) );
    6767                        //                              parent_id = 0;
    6868                }
     
    7171                        auto it = m->node_names.find( table.get_string_hash_64( "attach" ) );
    7272                        if ( it != m->node_names.end() )
    73                                 attach_id = it->second + 1;
     73                                attach_id = sint16( it->second + 1 );
    7474                        int error; int hack;
    7575                }
  • trunk/src/engine/renderer.cc

    r507 r508  
    66
    77#include "nv/engine/renderer.hh"
     8
     9#include "nv/core/profiler.hh"
     10
     11using namespace nv;
     12
     13renderer::renderer( context* ctx )
     14        : m_context( ctx )
     15{
     16        for ( auto& i : m_statistics ) i = 0;
     17
     18        struct qvtx
     19        {
     20                nv::vec2 position;
     21                nv::vec2 texcoord;
     22        };
     23
     24        qvtx quad[] = {
     25                qvtx{ vec2( -1.0f,-1.0f ), vec2( 0.0f, 0.0f ) },
     26                qvtx{ vec2( 1.0f,-1.0f ),  vec2( 1.0f, 0.0f ) },
     27                qvtx{ vec2( 1.0f,1.0f ),   vec2( 1.0f, 1.0f ) },
     28                qvtx{ vec2( 1.0f,1.0f ),   vec2( 1.0f, 1.0f ) },
     29                qvtx{ vec2( -1.0f,1.0f ),  vec2( 0.0f, 1.0f ) },
     30                qvtx{ vec2( -1.0f,-1.0f ), vec2( 0.0f, 0.0f ) },
     31        };
     32        m_quad = m_context->create_vertex_array( quad, 6, STATIC_DRAW );
     33}
     34
     35void renderer::sort()
     36{
     37        stable_sort( m_elements.begin(), m_elements.end(), renderer_element_compare() );
     38}
     39
     40
     41void renderer::render( const scene_state& s, const render_pass& pass )
     42{
     43        scene_state ss( s );
     44        m_context->bind( pass.fbuffer, FRAMEBUFFER );
     45        m_context->set_draw_buffers( pass.output_count, pass.output );
     46        m_context->set_viewport( ss.get_viewport() );
     47
     48        if ( pass.cstate.buffers != buffer_mask::NO_BUFFER )
     49                m_context->clear( pass.cstate );
     50
     51        for ( uint32 i = 0; i < size( pass.binds ); ++i )
     52                if ( pass.binds[i] )
     53                        m_context->bind( pass.binds[i], texture_slot( i ) );
     54
     55        resource_id current_mat;
     56        mat4 model = ss.get_model();
     57        for ( const renderer_element& element : m_elements )
     58                if ( match( element.flags, pass ) )
     59                {
     60                        ss.set_model( model * element.model.extract() );
     61                        if ( auto mesh = element.mesh.lock() )
     62                                if ( mesh->count > 0 )
     63                                        if ( auto program = pass.programs[mesh->shader].lock() )
     64                                        {
     65                                                if ( element.mat.id() != current_mat )
     66                                                {
     67                                                        if ( auto mat = element.mat.lock() )
     68                                                        {
     69                                                                for ( uint32 i = 0; i < 8; ++i )
     70                                                                        if ( mat->textures[i] && !pass.binds[i] )
     71                                                                                m_context->bind( mat->textures[i], nv::texture_slot( i ) );
     72                                                                current_mat = element.mat.id();
     73                                                        }
     74                                                }
     75
     76                                                m_context->get_device()->set_opt_uniform( *program, "nv_bone_offset", element.bone_offset );
     77                                                m_context->get_device()->set_opt_uniform( *program, "nv_flags", unsigned( *element.flags.data() ) );
     78
     79                                                m_context->apply_engine_uniforms( *program, ss );
     80                                                m_context->draw( TRIANGLES, pass.rstate, *program, mesh->va, mesh->count );
     81
     82                                                m_statistics[TRIANGLE_COUNT] += mesh->count / 3;
     83                                                m_statistics[DRAW_CALL]++;
     84                                        }
     85                }
     86
     87        m_context->bind( pass.fbuffer, FRAMEBUFFER );
     88}
     89
     90void renderer::render( const scene_state& ss, const render_pass& pass, vertex_array va, uint32 va_count, uint32 program_idx )
     91{
     92        m_context->bind( pass.fbuffer, FRAMEBUFFER );
     93        m_context->set_draw_buffers( pass.output_count, pass.output );
     94        m_context->set_viewport( ss.get_viewport() );
     95
     96        if ( pass.cstate.buffers != buffer_mask::NO_BUFFER )
     97                m_context->clear( pass.cstate );
     98
     99        for ( uint32 i = 0; i < size( pass.binds ); ++i )
     100                if ( pass.binds[i] )
     101                        m_context->bind( pass.binds[i], texture_slot(i) );
     102
     103        if ( auto program = pass.programs[program_idx].lock() )
     104        {
     105                m_context->apply_engine_uniforms( *program, ss );
     106                m_context->draw( TRIANGLES, pass.rstate, *program, va, va_count );
     107                m_statistics[ TRIANGLE_COUNT ] += 2;
     108                m_statistics[ DRAW_CALL ]++;
     109        }
     110
     111        m_context->bind( pass.fbuffer, FRAMEBUFFER );
     112}
     113
     114void nv::renderer::render_direct( const scene_state& s, const render_pass& pass, const nv::array_view< renderer_direct_element >& elements, uint32 program_idx )
     115{
     116        if ( m_elements.size() == 0 ) return;
     117
     118        scene_state ss( s );
     119        m_context->bind( pass.fbuffer, FRAMEBUFFER );
     120        m_context->set_draw_buffers( pass.output_count, pass.output );
     121        m_context->set_viewport( ss.get_viewport() );
     122
     123        if ( pass.cstate.buffers != buffer_mask::NO_BUFFER )
     124                m_context->clear( pass.cstate );
     125
     126        for ( uint32 i = 0; i < size( pass.binds ); ++i )
     127                if ( pass.binds[i] )
     128                        m_context->bind( pass.binds[i], texture_slot( i ) );
     129
     130        resource_id current_mat;
     131        resource_id current_prog;
     132
     133        mat4 model = ss.get_model();
     134        for ( uint32 index = 0; index < elements.size(); ++index )
     135        {
     136                const renderer_direct_element& element = elements[index];
     137                if ( match( element.flags, pass ) )
     138                {
     139                        ss.set_model( model * element.model.extract() );
     140                        if ( element.count > 0 )
     141                        {
     142                                if ( auto program = element.programs[program_idx].lock() )
     143                                {
     144                                        if ( element.material.id() != current_mat )
     145                                        {
     146                                                if ( auto mat = element.material.lock() )
     147                                                {
     148                                                        for ( uint32 i = 0; i < 8; ++i )
     149                                                                if ( mat->textures[i] && !pass.binds[i] )
     150                                                                        m_context->bind( mat->textures[i], nv::texture_slot( i ) );
     151                                                        current_mat = element.material.id();
     152                                                }
     153                                        }
     154
     155                                        m_context->get_device()->set_opt_uniform( *program, "nv_flags", unsigned( *element.flags.data() ) );
     156                                        m_context->get_device()->set_opt_uniform( *program, "nv_index", unsigned( index ) );
     157                                        m_context->apply_engine_uniforms( *program, ss );
     158
     159                                        if ( element.instances > 0 )
     160                                                m_context->draw_instanced( TRIANGLES, pass.rstate, *program, element.instances, element.va, element.count, element.first );
     161                                        else
     162                                                m_context->draw( TRIANGLES, pass.rstate, *program, element.va, element.count, element.first );
     163
     164                                        m_statistics[TRIANGLE_COUNT] += ( element.count / 3 ) * max< uint32 >( element.instances, 1 );
     165                                        m_statistics[DRAW_CALL]++;
     166                                }
     167                        }
     168                }
     169        }
     170        m_context->bind( pass.fbuffer, FRAMEBUFFER );
     171}
  • trunk/src/io/c_stream.cc

    r487 r508  
    7575        {
    7676                struct stat fstat;
    77                 int result = stat(m_file_name, &fstat );
     77                int result = stat(m_file_name.data(), &fstat );
    7878                if ( result != 0 )
    7979                {
Note: See TracChangeset for help on using the changeset viewer.