1 | |
---|
2 | #include "resource_texture.h" |
---|
3 | #include "substring.h" |
---|
4 | #include "multi_type.h" |
---|
5 | #include "debug.h" |
---|
6 | |
---|
7 | |
---|
8 | ResourceTexture::ResourceTexture(const std::string& imageName, GLenum target, const Resources::KeepLevel& keepLevel) |
---|
9 | : Resource(&ResourceTexture::type) |
---|
10 | { |
---|
11 | Resources::StorePointer* ptr = this->acquireResource(imageName + ',' + MultiType((int)target).getString()); |
---|
12 | |
---|
13 | if (ptr) |
---|
14 | { |
---|
15 | PRINTF(5)("FOUND TEXTURE: %s\n", imageName.c_str()); |
---|
16 | this->acquireData(static_cast<ResourceTexture::TextureResourcePointer*>(ptr)->ptr()); |
---|
17 | } |
---|
18 | else |
---|
19 | { |
---|
20 | PRINTF(5)("NOT FOUND TEXTURE: %s\n", imageName.c_str()); |
---|
21 | std::string fileName = this->Resource::locateFile(imageName); |
---|
22 | this->Texture::loadImage(fileName, target); |
---|
23 | this->Resource::addResource(new ResourceTexture::TextureResourcePointer(imageName + ',' + MultiType((int)target).getString(), keepLevel, this->Texture::dataPointer())); |
---|
24 | } |
---|
25 | } |
---|
26 | |
---|
27 | ResourceTexture ResourceTexture::createFromString(const std::string& loadString, const Resources::KeepLevel& keepLevel) |
---|
28 | { |
---|
29 | SubString loadValues(loadString, ','); |
---|
30 | std::string imageName; |
---|
31 | GLenum target = GL_TEXTURE_2D; |
---|
32 | if (loadValues.size() > 0) |
---|
33 | imageName = loadValues[0]; |
---|
34 | if (loadValues.size() > 1) |
---|
35 | target = (GLenum)MultiType(loadValues[2]).getInt(); |
---|
36 | |
---|
37 | return ResourceTexture(imageName, target, keepLevel); |
---|
38 | } |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | Resources::tType<ResourceTexture> ResourceTexture::type("Texture"); |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | ResourceTexture::TextureResourcePointer::TextureResourcePointer(const std::string& loadString, const Resources::KeepLevel& keepLevel, const TextureData::Pointer& data) |
---|
49 | : Resources::StorePointer(loadString, keepLevel) , pointer(data) |
---|
50 | {} |
---|
51 | |
---|
52 | |
---|