MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / load

Method load

Source/Cache/ShaderCache.cpp:70–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70Shader* 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
116Shader* ShaderCache::load(String filename, ShaderStage stage) {
117 auto ext = Path::getExt(filename);

Callers

nothing calls this directly

Calls 15

getRendererTypeFunction · 0.85
createEmbeddedShaderFunction · 0.85
createShaderFunction · 0.85
getFullPathMethod · 0.80
loadBXMethod · 0.80
loadStrMethod · 0.80
loadFunction · 0.70
toStringMethod · 0.65
splitMethod · 0.65
findMethod · 0.65
existMethod · 0.65
compileMethod · 0.65

Tested by

no test coverage detected