21 {
23
24 try {
25 root =
XFILE(asset->name_path.c_str()).getRoot();
26 }
27 catch (int e) {
28
29 return;
30 }
31
32 const auto& cse_mat = root->getChild("CSESHADER");
33 const auto& cse_shaders = cse_mat.children;
34 for (const auto& shader : cse_shaders) {
35 const auto& pass = shader.getAttribute("pass").value;
36 const auto& vert_path = shader.getAttribute("v").value;
37 const auto& frag_path = shader.getAttribute("f").value;
38
39 std::string&& vert = "";
40 std::string&& frag = "";
41
42 std::string hashes = "";
43
44 if (shader.hasAttribute("localPath")
45 && shader.getAttribute("localPath").value == "1") {
46 const auto vert_asset_path = asset->path + vert_path;
47 const auto frag_asset_path = asset->path + frag_path;
48 vert = AssetMgr::LoadAssetFile(vert_asset_path);
49 frag = AssetMgr::LoadAssetFile(frag_asset_path);
50 hashes = GetShaderHash(vert_asset_path, frag_asset_path);
51 } else {
52 const auto& resMgr = CORE->GetCore(
ResMgr);
53 const auto& vert_asset = resMgr->GetAssetReference(vert_path);
54 const auto& frag_asset = resMgr->GetAssetReference(frag_path);
55
56 vert = AssetMgr::LoadAssetFile(vert_asset->name_path);
57 frag = AssetMgr::LoadAssetFile(frag_asset->name_path);
58 hashes = vert_asset->hash + frag_asset->hash;
59 }
60
61 if (vert.empty() || frag.empty() || hashes.empty()) continue;
62
63 const auto& existHandle = SResource::Get<GLProgramHandle>(hashes);
65 if (existHandle == nullptr) {
67 handle->SetName(hashes);
68 } else {
69 handle = existHandle;
70 }
71 m_handles.insert(std::pair<std::string, GLProgramHandle*>(pass, handle));
72 if(pass == "geometry") m_geometryHandle = handle;
73 if(pass == "forward") m_forwardHandle = handle;
74 if(pass == "depthOnly") m_depthOnlyHandle = handle;
75 }
76
77 SAFE_DELETE(root);
78}
static GLProgramHandle * CreateProgramHandle(const GLchar *vertexSource, const GLchar *fragmentSource, GLProgramHandle *handle=nullptr)
Creates a program handle.