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