[484] | 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/material_manager.hh"
|
---|
| 8 |
|
---|
| 9 | #include "nv/io/c_file_system.hh"
|
---|
| 10 | #include "nv/image/png_loader.hh"
|
---|
| 11 |
|
---|
| 12 | using namespace nv;
|
---|
| 13 |
|
---|
| 14 | bool gpu_material_manager::load_resource( const string_view& id )
|
---|
| 15 | {
|
---|
| 16 | if ( auto mat = m_material_manager->get( id ).lock() )
|
---|
| 17 | {
|
---|
| 18 | gpu_material* result = new gpu_material;
|
---|
| 19 | sampler smp( sampler::LINEAR, sampler::REPEAT );
|
---|
| 20 | for ( uint32 i = 0; i < size( mat->paths ); ++i )
|
---|
| 21 | if ( !mat->paths[i].empty() )
|
---|
| 22 | if ( auto data = m_image_manager->get( mat->paths[i] ).lock() )
|
---|
[485] | 23 | {
|
---|
[484] | 24 | result->textures[i] = m_context->get_device()->create_texture( &*data, smp );
|
---|
[485] | 25 | }
|
---|
[484] | 26 | add( id, result );
|
---|
| 27 | return true;
|
---|
| 28 | }
|
---|
| 29 | return false;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | void gpu_material_manager::release( gpu_material* m )
|
---|
| 33 | {
|
---|
| 34 | for ( const texture& t : m->textures )
|
---|
| 35 | {
|
---|
| 36 | m_context->get_device()->release( t );
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | bool material_manager::load_resource( nv::lua::table_guard& table, nv::shash64 id )
|
---|
| 41 | {
|
---|
| 42 | material* m = new material;
|
---|
| 43 | m->paths[ TEX_DIFFUSE ] = table.get_string128( "diffuse" );
|
---|
| 44 | m->paths[ TEX_SPECULAR ] = table.get_string128( "specular" );
|
---|
| 45 | m->paths[ TEX_NORMAL ] = table.get_string128( "normal" );
|
---|
| 46 | m->paths[ TEX_GLOSS ] = table.get_string128( "gloss" );
|
---|
| 47 | add( id, m );
|
---|
| 48 | return true;
|
---|
| 49 | }
|
---|