| 68 | } |
| 69 | |
| 70 | Shader* ShaderCache::load(String filename) { |
| 71 | auto filenameStr = filename.toString(); |
| 72 | auto items = filename.split(":"_slice); |
| 73 | if (!items.empty() && items.front() == "builtin"_slice) { |
| 74 | auto it = _shaders.find(filenameStr); |
| 75 | if (it != _shaders.end()) { |
| 76 | return it->second; |
| 77 | } |
| 78 | bgfx::RendererType::Enum type = bgfx::getRendererType(); |
| 79 | bgfx::ShaderHandle handle = bgfx::createEmbeddedShader(DoraShaders, type, items.back().c_str()); |
| 80 | if (!bgfx::isValid(handle)) { |
| 81 | Error("failed to load builtin shader named: \"{}\".", items.back().toString()); |
| 82 | return nullptr; |
| 83 | } |
| 84 | Shader* shader = Shader::create(handle); |
| 85 | _shaders[filenameStr] = shader; |
| 86 | return shader; |
| 87 | } |
| 88 | std::string shaderFile; |
| 89 | if (SharedContent.exist(filenameStr)) { |
| 90 | shaderFile = SharedContent.getFullPath(filenameStr); |
| 91 | } else { |
| 92 | auto path = Path::concat({getShaderPath(), filenameStr}); |
| 93 | if (SharedContent.exist(path)) { |
| 94 | shaderFile = SharedContent.getFullPath(path); |
| 95 | } |
| 96 | } |
| 97 | if (shaderFile.empty()) { |
| 98 | Error("shader file \"{}\" not exist.", filenameStr); |
| 99 | return nullptr; |
| 100 | } |
| 101 | auto it = _shaders.find(shaderFile); |
| 102 | if (it != _shaders.end()) { |
| 103 | return it->second; |
| 104 | } |
| 105 | const bgfx::Memory* mem = SharedContent.loadBX(shaderFile); |
| 106 | bgfx::ShaderHandle handle = bgfx::createShader(mem); |
| 107 | if (!bgfx::isValid(handle)) { |
| 108 | Error("failed to load shader \"{}\".", shaderFile); |
| 109 | return nullptr; |
| 110 | } |
| 111 | Shader* shader = Shader::create(handle); |
| 112 | _shaders[shaderFile] = shader; |
| 113 | return shader; |
| 114 | } |
| 115 | |
| 116 | Shader* ShaderCache::load(String filename, ShaderStage stage) { |
| 117 | auto ext = Path::getExt(filename); |
nothing calls this directly
no test coverage detected