Decent asset loading
This commit is contained in:
@@ -72,5 +72,15 @@ void FontLoader::import(FontImportArgs args, PFontAsset asset)
|
||||
}
|
||||
FT_Done_Face(face);
|
||||
FT_Done_FreeType(ft);
|
||||
|
||||
auto stream = AssetRegistry::createWriteStream((std::filesystem::path(asset->getFolderPath()) / asset->getName()).replace_extension("asset").string(), std::ios::binary);
|
||||
|
||||
ArchiveBuffer archive;
|
||||
Serialization::save(archive, FontAsset::IDENTIFIER);
|
||||
Serialization::save(archive, asset->getName());
|
||||
Serialization::save(archive, asset->getFolderPath());
|
||||
asset->save(archive);
|
||||
archive.writeToStream(stream);
|
||||
|
||||
asset->setStatus(Asset::Status::Ready);
|
||||
}
|
||||
@@ -38,9 +38,9 @@ void MaterialLoader::importAsset(MaterialImportArgs args)
|
||||
|
||||
void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
||||
{
|
||||
auto stream = std::ifstream(args.filePath.c_str());
|
||||
auto jsonstream = std::ifstream(args.filePath.c_str());
|
||||
json j;
|
||||
stream >> j;
|
||||
jsonstream >> j;
|
||||
std::string materialName = j["name"].get<std::string>() + "Material";
|
||||
Gfx::PDescriptorLayout layout = graphics->createDescriptorLayout(materialName + "Layout");
|
||||
//Shader file needs to conform to the slang standard, which prohibits _
|
||||
@@ -221,9 +221,24 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
||||
std::move(codeExp),
|
||||
std::move(mat)
|
||||
);
|
||||
|
||||
asset->material->compile();
|
||||
graphics->getShaderCompiler()->registerMaterial(asset->material);
|
||||
asset->setStatus(Asset::Status::Ready);
|
||||
|
||||
if (asset->getName().empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto stream = AssetRegistry::createWriteStream((std::filesystem::path(asset->folderPath) / asset->getName()).string().append(".asset"), std::ios::binary);
|
||||
|
||||
ArchiveBuffer archive;
|
||||
Serialization::save(archive, MaterialAsset::IDENTIFIER);
|
||||
Serialization::save(archive, asset->getName());
|
||||
Serialization::save(archive, asset->getFolderPath());
|
||||
asset->save(archive);
|
||||
archive.writeToStream(stream);
|
||||
////co_return;
|
||||
}
|
||||
|
||||
|
||||
@@ -323,6 +323,17 @@ void MeshLoader::import(MeshImportArgs args, PMeshAsset meshAsset)
|
||||
}
|
||||
}
|
||||
meshAsset->physicsMesh = std::move(collider);
|
||||
|
||||
|
||||
auto stream = AssetRegistry::createWriteStream((std::filesystem::path(meshAsset->getFolderPath()) / meshAsset->getName()).replace_extension("asset").string(), std::ios::binary);
|
||||
|
||||
ArchiveBuffer archive;
|
||||
Serialization::save(archive, MeshAsset::IDENTIFIER);
|
||||
Serialization::save(archive, meshAsset->getName());
|
||||
Serialization::save(archive, meshAsset->getFolderPath());
|
||||
meshAsset->save(archive);
|
||||
archive.writeToStream(stream);
|
||||
|
||||
meshAsset->setStatus(Asset::Status::Ready);
|
||||
std::cout << "Finished loading " << args.filePath<< std::endl;
|
||||
std::cout << "Finished loading " << args.filePath << std::endl;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ PTextureAsset TextureLoader::getPlaceholderTexture()
|
||||
|
||||
void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset)
|
||||
{
|
||||
|
||||
int totalWidth, totalHeight, n;
|
||||
unsigned char* data = stbi_load(args.filePath.string().c_str(), &totalWidth, &totalHeight, &n, 4);
|
||||
ktxTexture2* kTexture;
|
||||
@@ -109,28 +110,45 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset)
|
||||
0, 0, 0, data, totalWidth * totalHeight * 4 * sizeof(unsigned char));
|
||||
}
|
||||
std::cout << "starting compression of " << textureAsset->getAssetIdentifier() << std::endl;
|
||||
ktxBasisParams params = {
|
||||
|
||||
ktxBasisParams params2 = {
|
||||
.structSize = sizeof(ktxBasisParams),
|
||||
.uastc = KTX_TRUE,
|
||||
.uastc = false,
|
||||
.threadCount = std::thread::hardware_concurrency(),
|
||||
.compressionLevel = 5,
|
||||
.qualityLevel = 0,
|
||||
};
|
||||
ktx_error_code_e error = ktxTexture2_CompressBasisEx(kTexture, ¶ms);
|
||||
|
||||
ktx_error_code_e error = ktxTexture2_CompressBasisEx(kTexture, ¶ms2);
|
||||
assert(error == KTX_SUCCESS);
|
||||
|
||||
//error = ktxTexture2_TranscodeBasis(kTexture, KTX_TTF_BC7_RGBA, 0);
|
||||
//assert(error == KTX_SUCCESS);
|
||||
|
||||
ktx_uint8_t* dest;
|
||||
ktx_size_t size;
|
||||
ktxTexture_WriteToMemory(ktxTexture(kTexture), &dest, &size);
|
||||
|
||||
Array<uint8> memory(size);
|
||||
std::memcpy(memory.data(), dest, size);
|
||||
|
||||
textureAsset->createFromMemory(std::move(memory), graphics);
|
||||
|
||||
free(dest);
|
||||
|
||||
stbi_image_free(data);
|
||||
|
||||
ArchiveBuffer temp(graphics);
|
||||
Serialization::save(temp, memory);
|
||||
temp.rewind();
|
||||
textureAsset->load(temp);
|
||||
if (textureAsset->getName().empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
auto stream = AssetRegistry::createWriteStream((std::filesystem::path(textureAsset->folderPath) / textureAsset->getName()).replace_extension("asset").string(), std::ios::binary);
|
||||
|
||||
ArchiveBuffer archive;
|
||||
Serialization::save(archive, TextureAsset::IDENTIFIER);
|
||||
Serialization::save(archive, textureAsset->getName());
|
||||
Serialization::save(archive, textureAsset->getFolderPath());
|
||||
Serialization::save(archive, memory);
|
||||
archive.writeToStream(stream);
|
||||
|
||||
|
||||
////co_return;
|
||||
}
|
||||
Reference in New Issue
Block a user