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