source: trunk/src/engine/image_manager.cc @ 504

Last change on this file since 504 was 504, checked in by epyon, 9 years ago
  • temporary add_base_path for image manager
  • random - warning fix
  • debug_draw - shader upgrade
File size: 1.1 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/image_manager.hh"
8
9#include "nv/image/png_loader.hh"
10#include "nv/io/c_file_system.hh"
11
12using namespace nv;
13
14void nv::image_manager::add_base_path( const string_view& path )
15{
16        m_paths.emplace_back( path );
17}
18
19bool image_manager::load_resource( const string_view& filename )
20{
21        png_loader loader;
22        c_file_system fs;
23        image_data* result = nullptr;
24        if ( fs.exists( filename ) )
25        {
26                stream* file = fs.open( filename );
27                result = loader.load( *file );
28                delete file;
29        }
30        else if ( m_paths.size() > 0 )
31        {
32                for ( const auto& path : m_paths )
33                {
34                        string128 fpath = path;
35                        fpath.append( filename );
36                        if ( fs.exists( fpath ) )
37                        {
38                                stream* file = fs.open( fpath );
39                                result = loader.load( *file );
40                                delete file;
41                                break;
42                        }
43                }
44        }
45        if ( result )
46                add( filename, result );
47        return result != nullptr;
48}
49
Note: See TracBrowser for help on using the repository browser.