-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaterial.cpp
50 lines (38 loc) · 1.48 KB
/
Material.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "Material.h"
#include <string>
#include <memory>
#include "Filesystem.h"
#include "Log.h"
using namespace std;
Material::~Material()
{
}
shared_ptr<Texture> Material :: allocateTex(string filename, string ext, ResourceCache<Texture>& rcache)
{
shared_ptr<Texture> tex;
size_t split_point;
string fn = "";
if((split_point = filename.find_last_of(".")) != string::npos)
fn = filename.substr(0,split_point) + "_" + ext + filename.substr(split_point);
assert(!fn.empty());
fn = FS::getFileName(fn);
tex = rcache.cache(fn, ResourceCache<Texture>::F_PASS_NAME);
if(!tex)
Log::get().write("Failed to load material texture \"" + filename + "\"");
//assert(tex.get() && tex->good());
return tex;
}
shared_ptr<Material> Material :: allocate(string fn, ResourceCache<Texture>& rcache)
{
// is the texture 'fn' already loaded? (Don't load textures twice)
fn = FS::getFileName(fn);
shared_ptr<Texture> tex = rcache.cache(fn, ResourceCache<Texture>::F_PASS_NAME);
assert(tex.get() && tex->good());
assert(!fn.empty());
Log::get().write("Loaded Material " + fn);
shared_ptr<Texture> bump = allocateTex(fn, "NRM", rcache);
shared_ptr<Texture> disp = allocateTex(fn, "DISP", rcache);
shared_ptr<Texture> spec = allocateTex(fn, "SPEC", rcache);
shared_ptr<Texture> occ = allocateTex(fn, "OCC", rcache);
return shared_ptr<Material>(new Material(tex, bump, disp, spec, occ));
}