source: trunk/src/engine/material_manager.cc @ 485

Last change on this file since 485 was 485, checked in by epyon, 9 years ago
  • massive update (need to start doing atomics again) :/
File size: 1.4 KB
Line 
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
12using namespace nv;
13
14bool 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() )
23                                {
24                                        result->textures[i] = m_context->get_device()->create_texture( &*data, smp );
25                                }
26                add( id, result );
27                return true;
28        }
29        return false;
30}
31
32void 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
40bool 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}
Note: See TracBrowser for help on using the repository browser.