1 | |
---|
2 | #include "resource_shader.h" |
---|
3 | #include "debug.h" |
---|
4 | #include "substring.h" |
---|
5 | |
---|
6 | ResourceShader::ResourceShader(const std::string& vertexShaderName, const std::string& fragmentShaderName) |
---|
7 | : Resource(&ResourceShader::type) |
---|
8 | { |
---|
9 | Resources::StorePointer* ptr = this->acquireResource(vertexShaderName +','+fragmentShaderName); |
---|
10 | |
---|
11 | if (ptr) |
---|
12 | { |
---|
13 | PRINTF(5)("FOUND SHADER: %s\n", vertexShaderName.c_str()); |
---|
14 | this->acquireData(static_cast<ResourceShader::ShaderResourcePointer*>(ptr)->ptr()); |
---|
15 | } |
---|
16 | else |
---|
17 | { |
---|
18 | PRINTF(5)("NOT FOUND SHADER: %s\n", vertexShaderName.c_str()); |
---|
19 | std::string vertexFileName = this->Resource::locateFile(vertexShaderName); |
---|
20 | std::string fragmentFileName; |
---|
21 | if (!fragmentShaderName.empty()) |
---|
22 | fragmentFileName = this->Resource::locateFile(fragmentShaderName); |
---|
23 | |
---|
24 | this->Shader::load(vertexFileName, fragmentFileName); |
---|
25 | this->Resource::addResource(new ResourceShader::ShaderResourcePointer(vertexShaderName+','+fragmentShaderName, Resources::KeepLevel(0), this->Shader::dataPointer())); |
---|
26 | } |
---|
27 | } |
---|
28 | |
---|
29 | ResourceShader ResourceShader::createFromString(const std::string& loadString) |
---|
30 | { |
---|
31 | std::string vertexShaderName; |
---|
32 | std::string fragmentShaderName; |
---|
33 | |
---|
34 | SubString shaderNames(loadString, ','); |
---|
35 | if (shaderNames.size() > 0) |
---|
36 | vertexShaderName = shaderNames[0]; |
---|
37 | if (shaderNames.size() > 1) |
---|
38 | fragmentShaderName = shaderNames[1]; |
---|
39 | |
---|
40 | return ResourceShader(vertexShaderName, fragmentShaderName); |
---|
41 | } |
---|
42 | |
---|
43 | Resources::tType<ResourceShader> ResourceShader::type("Shader"); |
---|
44 | |
---|
45 | ResourceShader::ShaderResourcePointer::ShaderResourcePointer(const std::string& loadString, const Resources::KeepLevel& keepLevel, const ShaderData::Pointer& data) |
---|
46 | : Resources::StorePointer(loadString, keepLevel) , pointer(data) |
---|
47 | {} |
---|