summaryrefslogtreecommitdiffstats
path: root/src/AssetManager.cpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2019-01-26 08:58:51 +0100
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2019-01-26 08:58:51 +0100
commit9c575f056ef47ef7e8da581164041985749c1676 (patch)
tree6bfec2ad24801c59f516dde644d4afeacf1503d4 /src/AssetManager.cpp
parentAdded Framebuffer class (diff)
downloadAltCraft-9c575f056ef47ef7e8da581164041985749c1676.tar
AltCraft-9c575f056ef47ef7e8da581164041985749c1676.tar.gz
AltCraft-9c575f056ef47ef7e8da581164041985749c1676.tar.bz2
AltCraft-9c575f056ef47ef7e8da581164041985749c1676.tar.lz
AltCraft-9c575f056ef47ef7e8da581164041985749c1676.tar.xz
AltCraft-9c575f056ef47ef7e8da581164041985749c1676.tar.zst
AltCraft-9c575f056ef47ef7e8da581164041985749c1676.zip
Diffstat (limited to 'src/AssetManager.cpp')
-rw-r--r--src/AssetManager.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp
index 03a672e..5f2a160 100644
--- a/src/AssetManager.cpp
+++ b/src/AssetManager.cpp
@@ -34,6 +34,7 @@ void ParseAsset(AssetTreeNode &node);
void ParseAssetTexture(AssetTreeNode &node);
void ParseAssetBlockModel(AssetTreeNode &node);
void ParseAssetBlockState(AssetTreeNode &node);
+void ParseAssetShader(AssetTreeNode &node);
void ParseBlockModels();
@@ -132,6 +133,11 @@ void ParseAsset(AssetTreeNode &node) {
ParseAssetTexture(node);
return;
}
+
+ if (node.parent->name == "shaders") {
+ ParseAssetShader(node);
+ return;
+ }
}
void ParseAssetTexture(AssetTreeNode &node) {
@@ -339,6 +345,32 @@ void ParseAssetBlockState(AssetTreeNode &node) {
node.data.shrink_to_fit();
}
+void ParseAssetShader(AssetTreeNode &node) {
+ try {
+ nlohmann::json j = nlohmann::json::parse(node.data);
+
+ std::string vertPath = j["vert"].get<std::string>();
+ std::string fragPath = j["frag"].get<std::string>();
+
+ AssetTreeNode *vertAsset = AssetManager::GetAssetByAssetName(vertPath);
+ AssetTreeNode *fragAsset = AssetManager::GetAssetByAssetName(fragPath);
+ std::string vertSource((char*)vertAsset->data.data(), (char*)vertAsset->data.data() + vertAsset->data.size());
+ std::string fragSource((char*)fragAsset->data.data(), (char*)fragAsset->data.data() + fragAsset->data.size());
+
+ std::vector<std::string> uniforms;
+
+ for (auto &it : j["uniforms"]) {
+ uniforms.push_back(it.get<std::string>());
+ }
+
+ node.asset = std::make_unique<AssetShader>();
+ AssetShader *asset = dynamic_cast<AssetShader*>(node.asset.get());
+ asset->shader = std::make_unique<NewShader>(vertSource, fragSource, uniforms);
+ } catch (...) {
+ return;
+ }
+}
+
void ParseBlockModels() {
std::string textureName;