1 | // Copyright (C) 2015-2015 ChaosForge Ltd
|
---|
2 | // http://chaosforge.org/
|
---|
3 | //
|
---|
4 | // This file is part of Nova libraries.
|
---|
5 | // For conditions of distribution and use, see copying.txt file in root folder.
|
---|
6 |
|
---|
7 | #include "nv/engine/mesh_manager.hh"
|
---|
8 |
|
---|
9 | using namespace nv;
|
---|
10 |
|
---|
11 | resource< gpu_mesh > gpu_mesh_manager::load_resource( resource< data_channel_set > mesh )
|
---|
12 | {
|
---|
13 | resource< gpu_mesh > result = get( mesh.id().value() );
|
---|
14 | if ( result ) return result;
|
---|
15 | if ( auto lmesh = mesh.lock() )
|
---|
16 | {
|
---|
17 | gpu_mesh* gm = new gpu_mesh;
|
---|
18 | gm->va = m_context->create_vertex_array( &*lmesh, STATIC_DRAW );
|
---|
19 | gm->count = lmesh->get_channel_size( slot::INDEX );
|
---|
20 | gm->shader = lmesh->get_channel( slot::BONEINDEX ) != nullptr ? BONE : NORMAL;
|
---|
21 | return add( mesh.id(), gm );
|
---|
22 | }
|
---|
23 | return resource< gpu_mesh >();
|
---|
24 | }
|
---|
25 |
|
---|
26 | bool nv::gpu_mesh_manager::load_resource( const string_view& id )
|
---|
27 | {
|
---|
28 | if ( auto lmesh = m_mesh_manager->get( id ).lock() )
|
---|
29 | {
|
---|
30 | gpu_mesh* gm = new gpu_mesh;
|
---|
31 | gm->va = m_context->create_vertex_array( &*lmesh, STATIC_DRAW );
|
---|
32 | gm->count = lmesh->get_channel_size( slot::INDEX );
|
---|
33 | gm->shader = lmesh->get_channel( slot::BONEINDEX ) != nullptr ? BONE : NORMAL;
|
---|
34 | add( id, gm );
|
---|
35 | return true;
|
---|
36 | }
|
---|
37 | return false;
|
---|
38 | }
|
---|
39 |
|
---|
40 | void gpu_mesh_manager::release( gpu_mesh* m )
|
---|
41 | {
|
---|
42 | m_context->release( m->va );
|
---|
43 | }
|
---|