EtrediaEmpires/materials/compile_materials.cpp
legatt 389ed599c8 Pipeline factory and materials
- AssetManager uses static assets ID from path hash
- PipelineFactory creates Vulkan pipelines using PipelineConfig structure depending on AssetMaterial and creation flags
- AssetMaterial describes pipelines (e.g. used shaders)
- Materials are described with JSON in sources with path references to other assets
- AssetMaterial is parsed from binary file with asset IDs in references
- compile_config tool compiles material JSON file to binary file with path references replaced with asset IDs
- Allocator supports type's constructors with arguments
- NativeFileSystem: fixed empty bufferSize and buffer trash
2025-08-29 13:13:11 +03:00

59 lines
1.4 KiB
C++

#include <filesystem>
#include <fstream>
#include <iostream>
#include <nlohmann/json.hpp>
#include <xxhash.h>
#include <string>
#include "AssetData.hpp"
using json = nlohmann::json;
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(AssetMaterial, vertexShader, fragmentShader)
int main(int argc, char **argv)
{
try
{
std::filesystem::path in = argv[1];
std::filesystem::path out = argv[2];
std::ifstream fin(in);
std::ofstream fout(out);
if (!fin.is_open()) {
std::cout << "Error: Could not open input file." << std::endl;
return 1;
}
if (!fout.is_open()) {
std::cout << "Error: Could not open output file." << std::endl;
return 1;
}
json data = json::parse(fin);
for (const char *link : {
"vertexShader",
"fragmentShader"
})
{
std::filesystem::path linkPath = data[link];
auto linkPath8 = linkPath.generic_u8string();
uint32_t assetId = XXH32(linkPath8.data(), linkPath8.size(), 0);
data[link] = assetId;
}
AssetMaterial material = data.get<AssetMaterial>();
fout.write(reinterpret_cast<const char*>(&material), sizeof(material));
fin.close();
fout.close();
}
catch (const std::exception &e)
{
std::cerr << e.what() << std::endl;
}
return 0;
}