Fixing some stuff
This commit is contained in:
Vendored
-2
@@ -1,6 +1,5 @@
|
||||
{
|
||||
"cmake.cmakePath": "cmake",
|
||||
"cmake.skipConfigureIfCachePresent": false,
|
||||
"cmake.configureArgs": [
|
||||
"-Wno-dev"
|
||||
],
|
||||
@@ -10,7 +9,6 @@
|
||||
"external/**": true
|
||||
},
|
||||
"git.ignoreSubmodules": true,
|
||||
"cmake.configureOnOpen": true,
|
||||
"cmake.parallelJobs": 0,
|
||||
"cmake.buildDirectory": "${workspaceFolder}/build",
|
||||
"C_Cpp.files.exclude": {
|
||||
|
||||
@@ -50,9 +50,6 @@ void closestHit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttribu
|
||||
result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf);
|
||||
}
|
||||
result += brdf.evaluateAmbient();
|
||||
// gamma correction
|
||||
result = result / (result + float3(1.0));
|
||||
result = pow(result, float3(1.0/2.2));
|
||||
|
||||
hitValue.color = result;
|
||||
hitValue.alpha = brdf.getAlpha();
|
||||
|
||||
@@ -72,15 +72,7 @@ void FontLoader::import(FontImportArgs args, PFontAsset asset) {
|
||||
FT_Done_FreeType(ft);
|
||||
asset->setUsedTextures(std::move(usedTextures));
|
||||
|
||||
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);
|
||||
AssetRegistry::saveAsset(asset, FontAsset::IDENTIFIER, asset->getFolderPath(), asset->getName());
|
||||
|
||||
asset->setStatus(Asset::Status::Ready);
|
||||
}
|
||||
@@ -24,7 +24,7 @@ MaterialLoader::MaterialLoader(Gfx::PGraphics graphics) : graphics(graphics) {
|
||||
.importPath = "",
|
||||
},
|
||||
placeholderAsset);
|
||||
AssetRegistry::get().assetRoot->materials[""] = std::move(placeholderAsset);
|
||||
AssetRegistry::get().registerMaterial(std::move(placeholderAsset));
|
||||
}
|
||||
|
||||
MaterialLoader::~MaterialLoader() {}
|
||||
@@ -213,16 +213,9 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto stream = AssetRegistry::createWriteStream((std::filesystem::path(asset->folderPath) / asset->getName()).string().append(".asset"),
|
||||
std::ios::binary);
|
||||
AssetRegistry::saveAsset(asset, MaterialAsset::IDENTIFIER, asset->getFolderPath(), asset->getName());
|
||||
|
||||
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;
|
||||
asset->setStatus(Asset::Status::Ready);
|
||||
}
|
||||
|
||||
PMaterialAsset MaterialLoader::getPlaceHolderMaterial() { return placeholderMaterial; }
|
||||
|
||||
@@ -592,16 +592,7 @@ void MeshLoader::import(MeshImportArgs args, PMeshAsset meshAsset) {
|
||||
meshAsset->meshes = std::move(meshes);
|
||||
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);
|
||||
|
||||
AssetRegistry::saveAsset(meshAsset, MeshAsset::IDENTIFIER, meshAsset->getFolderPath(), meshAsset->getName());
|
||||
|
||||
meshAsset->setStatus(Asset::Status::Ready);
|
||||
std::cout << "Finished loading " << args.filePath << std::endl;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ TextureLoader::TextureLoader(Gfx::PGraphics graphics) : graphics(graphics) {
|
||||
.importPath = "",
|
||||
},
|
||||
placeholderAsset);
|
||||
AssetRegistry::get().assetRoot->textures[""] = std::move(placeholder);
|
||||
AssetRegistry::get().registerTexture(std::move(placeholder));
|
||||
}
|
||||
|
||||
TextureLoader::~TextureLoader() {}
|
||||
@@ -138,25 +138,14 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) {
|
||||
return;
|
||||
}
|
||||
|
||||
//textureAsset->setTexture(std::move(serialized));
|
||||
|
||||
std::string path = (std::filesystem::path(args.importPath) / textureAsset->getName()).string().append(".asset");
|
||||
auto assetStream = AssetRegistry::createWriteStream(std::move(path), std::ios::binary);
|
||||
ArchiveBuffer buffer(graphics);
|
||||
// write identifier
|
||||
Serialization::save(buffer, TextureAsset::IDENTIFIER);
|
||||
// write name
|
||||
Serialization::save(buffer, textureAsset->getName());
|
||||
// write folder
|
||||
Serialization::save(buffer, textureAsset->getFolderPath());
|
||||
// write asset data
|
||||
//textureAsset->save(buffer);
|
||||
Serialization::save(buffer, serialized);
|
||||
|
||||
buffer.writeToStream(assetStream);
|
||||
|
||||
buffer.rewind();
|
||||
textureAsset->load(buffer);
|
||||
|
||||
std::unique_lock l(AssetRegistry::get().assetLock);
|
||||
AssetRegistry::get().loadAsset(buffer);
|
||||
textureAsset->setTexture(std::move(serialized));
|
||||
|
||||
AssetRegistry::saveAsset(textureAsset, TextureAsset::IDENTIFIER, textureAsset->getFolderPath(), textureAsset->getName());
|
||||
|
||||
textureAsset->setStatus(Asset::Status::Ready);
|
||||
}
|
||||
|
||||
+179
-160
@@ -11,7 +11,6 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
AssetRegistry* _instance = new AssetRegistry();
|
||||
@@ -21,6 +20,7 @@ AssetRegistry::~AssetRegistry() { delete assetRoot; }
|
||||
void AssetRegistry::init(std::filesystem::path rootFolder, Gfx::PGraphics graphics) { get().initialize(rootFolder, graphics); }
|
||||
|
||||
PMeshAsset AssetRegistry::findMesh(std::string_view folderPath, std::string_view filePath) {
|
||||
std::unique_lock l(get().assetLock);
|
||||
AssetFolder* folder = get().assetRoot;
|
||||
if (!folderPath.empty()) {
|
||||
folder = get().getOrCreateFolder(folderPath);
|
||||
@@ -29,6 +29,7 @@ PMeshAsset AssetRegistry::findMesh(std::string_view folderPath, std::string_view
|
||||
}
|
||||
|
||||
PTextureAsset AssetRegistry::findTexture(std::string_view folderPath, std::string_view filePath) {
|
||||
std::unique_lock l(get().assetLock);
|
||||
AssetFolder* folder = get().assetRoot;
|
||||
if (!folderPath.empty()) {
|
||||
folder = get().getOrCreateFolder(folderPath);
|
||||
@@ -37,6 +38,7 @@ PTextureAsset AssetRegistry::findTexture(std::string_view folderPath, std::strin
|
||||
}
|
||||
|
||||
PFontAsset AssetRegistry::findFont(std::string_view folderPath, std::string_view filePath) {
|
||||
std::unique_lock l(get().assetLock);
|
||||
AssetFolder* folder = get().assetRoot;
|
||||
if (!folderPath.empty()) {
|
||||
folder = get().getOrCreateFolder(folderPath);
|
||||
@@ -45,6 +47,7 @@ PFontAsset AssetRegistry::findFont(std::string_view folderPath, std::string_view
|
||||
}
|
||||
|
||||
PMaterialAsset AssetRegistry::findMaterial(std::string_view folderPath, std::string_view filePath) {
|
||||
std::unique_lock l(get().assetLock);
|
||||
AssetFolder* folder = get().assetRoot;
|
||||
if (!folderPath.empty()) {
|
||||
folder = get().getOrCreateFolder(folderPath);
|
||||
@@ -53,6 +56,7 @@ PMaterialAsset AssetRegistry::findMaterial(std::string_view folderPath, std::str
|
||||
}
|
||||
|
||||
PMaterialInstanceAsset AssetRegistry::findMaterialInstance(std::string_view folderPath, std::string_view filePath) {
|
||||
std::unique_lock l(get().assetLock);
|
||||
AssetFolder* folder = get().assetRoot;
|
||||
if (!folderPath.empty()) {
|
||||
folder = get().getOrCreateFolder(folderPath);
|
||||
@@ -60,6 +64,31 @@ PMaterialInstanceAsset AssetRegistry::findMaterialInstance(std::string_view fold
|
||||
return folder->instances.at(std::string(filePath));
|
||||
}
|
||||
|
||||
void AssetRegistry::registerMesh(OMeshAsset mesh) {
|
||||
std::unique_lock l(get().assetLock);
|
||||
get().registerMeshInternal(std::move(mesh));
|
||||
}
|
||||
|
||||
void AssetRegistry::registerTexture(OTextureAsset texture) {
|
||||
std::unique_lock l(get().assetLock);
|
||||
get().registerTextureInternal(std::move(texture));
|
||||
}
|
||||
|
||||
void AssetRegistry::registerFont(OFontAsset font) {
|
||||
std::unique_lock l(get().assetLock);
|
||||
get().registerFontInternal(std::move(font));
|
||||
}
|
||||
|
||||
void AssetRegistry::registerMaterial(OMaterialAsset material) {
|
||||
std::unique_lock l(get().assetLock);
|
||||
get().registerMaterialInternal(std::move(material));
|
||||
}
|
||||
|
||||
void AssetRegistry::registerMaterialInstance(OMaterialInstanceAsset instance) {
|
||||
std::unique_lock l(get().assetLock);
|
||||
get().registerMaterialInstanceInternal(std::move(instance));
|
||||
}
|
||||
|
||||
std::ofstream AssetRegistry::createWriteStream(const std::filesystem::path& relativePath, std::ios_base::openmode openmode) {
|
||||
return get().internalCreateWriteStream(relativePath, openmode);
|
||||
}
|
||||
@@ -68,135 +97,6 @@ std::ifstream AssetRegistry::createReadStream(const std::filesystem::path& relat
|
||||
return get().internalCreateReadStream(relativePath, openmode);
|
||||
}
|
||||
|
||||
AssetRegistry& AssetRegistry::get() { return *_instance; }
|
||||
|
||||
AssetRegistry::AssetRegistry() : assetRoot(nullptr) {}
|
||||
|
||||
AssetRegistry* AssetRegistry::getInstance() { return _instance; }
|
||||
|
||||
void AssetRegistry::loadRegistry() { get().loadRegistryInternal(); }
|
||||
|
||||
void AssetRegistry::saveRegistry() { get().saveRegistryInternal(); }
|
||||
|
||||
AssetRegistry::AssetFolder* AssetRegistry::getOrCreateFolder(std::string_view fullPath) {
|
||||
AssetFolder* result = assetRoot;
|
||||
std::string temp = std::string(fullPath);
|
||||
while (!temp.empty()) {
|
||||
size_t slashLoc = temp.find("/");
|
||||
if (slashLoc == std::string::npos) {
|
||||
if (!result->children.contains(temp)) {
|
||||
result->children[temp] = new AssetFolder(temp);
|
||||
}
|
||||
return result->children[temp];
|
||||
}
|
||||
std::string folderName = temp.substr(0, slashLoc);
|
||||
if (!result->children.contains(folderName)) {
|
||||
result->children[folderName] = new AssetFolder(fullPath);
|
||||
}
|
||||
result = result->children[folderName];
|
||||
temp = temp.substr(slashLoc + 1, temp.size());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void AssetRegistry::initialize(const std::filesystem::path& _rootFolder, Gfx::PGraphics _graphics) {
|
||||
std::unique_lock l(get().assetLock);
|
||||
this->graphics = _graphics;
|
||||
this->rootFolder = _rootFolder;
|
||||
this->assetRoot = new AssetFolder("");
|
||||
loadRegistryInternal();
|
||||
}
|
||||
|
||||
void AssetRegistry::loadRegistryInternal() {
|
||||
peekFolder(assetRoot);
|
||||
loadFolder(assetRoot);
|
||||
}
|
||||
|
||||
void AssetRegistry::peekFolder(AssetFolder* folder) {
|
||||
for (const auto& entry : std::filesystem::directory_iterator(rootFolder / folder->folderPath)) {
|
||||
const auto& stem = entry.path().stem().string();
|
||||
if (entry.is_directory()) {
|
||||
if (folder->folderPath.empty()) {
|
||||
folder->children[stem] = new AssetFolder(stem);
|
||||
} else {
|
||||
folder->children[stem] = new AssetFolder(folder->folderPath + "/" + stem);
|
||||
}
|
||||
peekFolder(folder->children[stem]);
|
||||
continue;
|
||||
}
|
||||
if (entry.path().filename().compare(".DS_Store") == 0) {
|
||||
continue;
|
||||
}
|
||||
auto stream = std::ifstream(entry.path(), std::ios::binary);
|
||||
|
||||
ArchiveBuffer buffer(graphics);
|
||||
buffer.readFromStream(stream);
|
||||
peekAsset(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
void AssetRegistry::loadFolder(AssetFolder* folder) {
|
||||
for (const auto& entry : std::filesystem::directory_iterator(rootFolder / folder->folderPath)) {
|
||||
const auto& path = entry.path();
|
||||
if (entry.is_directory()) {
|
||||
auto relative = path.stem().string();
|
||||
loadFolder(folder->children[relative]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entry.path().filename().compare(".DS_Store") == 0) {
|
||||
continue;
|
||||
}
|
||||
auto stream = std::ifstream(path, std::ios::binary);
|
||||
|
||||
ArchiveBuffer buffer(graphics);
|
||||
buffer.readFromStream(stream);
|
||||
loadAsset(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
void AssetRegistry::peekAsset(ArchiveBuffer& buffer) {
|
||||
// Read asset type
|
||||
uint64 identifier;
|
||||
Serialization::load(buffer, identifier);
|
||||
|
||||
// Read name
|
||||
std::string name;
|
||||
Serialization::load(buffer, name);
|
||||
|
||||
// Read folder
|
||||
std::string folderPath;
|
||||
Serialization::load(buffer, folderPath);
|
||||
|
||||
AssetFolder* folder = getOrCreateFolder(folderPath);
|
||||
|
||||
OAsset asset;
|
||||
switch (identifier) {
|
||||
case TextureAsset::IDENTIFIER:
|
||||
asset = new TextureAsset(folderPath, name);
|
||||
folder->textures[name] = std::move(asset);
|
||||
break;
|
||||
case MeshAsset::IDENTIFIER:
|
||||
asset = new MeshAsset(folderPath, name);
|
||||
folder->meshes[name] = std::move(asset);
|
||||
break;
|
||||
case MaterialAsset::IDENTIFIER:
|
||||
asset = new MaterialAsset(folderPath, name);
|
||||
folder->materials[name] = std::move(asset);
|
||||
break;
|
||||
case MaterialInstanceAsset::IDENTIFIER:
|
||||
asset = new MaterialInstanceAsset(folderPath, name);
|
||||
folder->instances[name] = std::move(asset);
|
||||
break;
|
||||
case FontAsset::IDENTIFIER:
|
||||
asset = new FontAsset(folderPath, name);
|
||||
folder->fonts[name] = std::move(asset);
|
||||
break;
|
||||
default:
|
||||
throw new std::logic_error("Unknown Identifier");
|
||||
}
|
||||
}
|
||||
|
||||
void AssetRegistry::loadAsset(ArchiveBuffer& buffer) {
|
||||
// Read asset type
|
||||
uint64 identifier;
|
||||
@@ -209,8 +109,7 @@ void AssetRegistry::loadAsset(ArchiveBuffer& buffer) {
|
||||
// Read folder
|
||||
std::string folderPath;
|
||||
Serialization::load(buffer, folderPath);
|
||||
|
||||
AssetFolder* folder = getOrCreateFolder(folderPath);
|
||||
AssetFolder* folder = get().getOrCreateFolder(folderPath);
|
||||
|
||||
PAsset asset;
|
||||
switch (identifier) {
|
||||
@@ -235,6 +134,149 @@ void AssetRegistry::loadAsset(ArchiveBuffer& buffer) {
|
||||
asset->load(buffer);
|
||||
}
|
||||
|
||||
void AssetRegistry::saveAsset(PAsset asset, uint64 identifier, const std::filesystem::path& folderPath, std::string name) {
|
||||
if (name.empty())
|
||||
return;
|
||||
|
||||
std::string path = (folderPath / name).string().append(".asset");
|
||||
auto assetStream = createWriteStream(std::move(path), std::ios::binary);
|
||||
ArchiveBuffer buffer(get().graphics);
|
||||
// write identifier
|
||||
Serialization::save(buffer, identifier);
|
||||
// write name
|
||||
Serialization::save(buffer, name);
|
||||
// write folder
|
||||
Serialization::save(buffer, folderPath.string());
|
||||
// write asset data
|
||||
asset->save(buffer);
|
||||
buffer.writeToStream(assetStream);
|
||||
}
|
||||
|
||||
AssetRegistry& AssetRegistry::get() { return *_instance; }
|
||||
|
||||
AssetRegistry::AssetRegistry() : assetRoot(nullptr) {}
|
||||
|
||||
AssetRegistry* AssetRegistry::getInstance() { return _instance; }
|
||||
|
||||
void AssetRegistry::loadRegistry() {
|
||||
get().loadRegistryInternal();
|
||||
}
|
||||
|
||||
void AssetRegistry::saveRegistry() {
|
||||
get().saveRegistryInternal();
|
||||
}
|
||||
|
||||
AssetRegistry::AssetFolder* AssetRegistry::getOrCreateFolder(std::string_view fullPath) {
|
||||
AssetFolder* result = assetRoot;
|
||||
std::string temp = std::string(fullPath);
|
||||
while (!temp.empty()) {
|
||||
size_t slashLoc = temp.find("/");
|
||||
if (slashLoc == std::string::npos) {
|
||||
if (!result->children.contains(temp)) {
|
||||
result->children[temp] = new AssetFolder(temp);
|
||||
}
|
||||
return result->children[temp];
|
||||
}
|
||||
std::string folderName = temp.substr(0, slashLoc);
|
||||
if (!result->children.contains(folderName)) {
|
||||
result->children[folderName] = new AssetFolder(fullPath);
|
||||
}
|
||||
result = result->children[folderName];
|
||||
temp = temp.substr(slashLoc + 1, temp.size());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void AssetRegistry::initialize(const std::filesystem::path& _rootFolder, Gfx::PGraphics _graphics) {
|
||||
this->graphics = _graphics;
|
||||
this->rootFolder = _rootFolder;
|
||||
this->assetRoot = new AssetFolder("");
|
||||
loadRegistryInternal();
|
||||
}
|
||||
|
||||
void AssetRegistry::loadRegistryInternal() {
|
||||
List<Pair<PAsset, ArchiveBuffer>> peeked;
|
||||
{
|
||||
std::unique_lock l(get().assetLock);
|
||||
peeked = peekFolder(assetRoot);
|
||||
}
|
||||
for (auto& [asset, buffer] : peeked) {
|
||||
asset->load(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
List<Pair<PAsset, ArchiveBuffer>> AssetRegistry::peekFolder(AssetFolder* folder) {
|
||||
List<Pair<PAsset, ArchiveBuffer>> peeked;
|
||||
for (const auto& entry : std::filesystem::directory_iterator(rootFolder / folder->folderPath)) {
|
||||
const auto& stem = entry.path().stem().string();
|
||||
if (entry.is_directory()) {
|
||||
if (folder->folderPath.empty()) {
|
||||
folder->children[stem] = new AssetFolder(stem);
|
||||
} else {
|
||||
folder->children[stem] = new AssetFolder(folder->folderPath + "/" + stem);
|
||||
}
|
||||
auto temp = peekFolder(folder->children[stem]);
|
||||
for (auto t : temp) {
|
||||
peeked.add(t);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (entry.path().filename().compare(".DS_Store") == 0) {
|
||||
continue;
|
||||
}
|
||||
auto stream = std::ifstream(entry.path(), std::ios::binary);
|
||||
|
||||
ArchiveBuffer buffer(graphics);
|
||||
buffer.readFromStream(stream);
|
||||
peeked.add(peekAsset(buffer));
|
||||
}
|
||||
return peeked;
|
||||
}
|
||||
|
||||
Pair<PAsset, ArchiveBuffer> AssetRegistry::peekAsset(ArchiveBuffer& buffer) {
|
||||
// Read asset type
|
||||
uint64 identifier;
|
||||
Serialization::load(buffer, identifier);
|
||||
|
||||
// Read name
|
||||
std::string name;
|
||||
Serialization::load(buffer, name);
|
||||
|
||||
// Read folder
|
||||
std::string folderPath;
|
||||
Serialization::load(buffer, folderPath);
|
||||
|
||||
AssetFolder* folder = getOrCreateFolder(folderPath);
|
||||
|
||||
PAsset asset;
|
||||
switch (identifier) {
|
||||
case TextureAsset::IDENTIFIER:
|
||||
folder->textures[name] = new TextureAsset(folderPath, name);
|
||||
asset = PTextureAsset(folder->textures[name]);
|
||||
break;
|
||||
case MeshAsset::IDENTIFIER:
|
||||
folder->meshes[name] = new MeshAsset(folderPath, name);
|
||||
asset = PMeshAsset(folder->meshes[name]);
|
||||
break;
|
||||
case MaterialAsset::IDENTIFIER:
|
||||
folder->materials[name] = new MaterialAsset(folderPath, name);
|
||||
asset = PMaterialAsset(folder->materials[name]);
|
||||
break;
|
||||
case MaterialInstanceAsset::IDENTIFIER:
|
||||
folder->instances[name] = new MaterialInstanceAsset(folderPath, name);
|
||||
asset = PMaterialInstanceAsset(folder->instances[name]);
|
||||
break;
|
||||
case FontAsset::IDENTIFIER:
|
||||
folder->fonts[name] = new FontAsset(folderPath, name);
|
||||
asset = PFontAsset(folder->fonts[name]);
|
||||
break;
|
||||
default:
|
||||
throw new std::logic_error("Unknown Identifier");
|
||||
}
|
||||
return {asset, buffer};
|
||||
}
|
||||
|
||||
|
||||
void AssetRegistry::saveRegistryInternal() { saveFolder("", assetRoot); }
|
||||
|
||||
void AssetRegistry::saveFolder(const std::filesystem::path& folderPath, AssetFolder* folder) {
|
||||
@@ -259,52 +301,29 @@ void AssetRegistry::saveFolder(const std::filesystem::path& folderPath, AssetFol
|
||||
}
|
||||
}
|
||||
|
||||
void AssetRegistry::saveAsset(PAsset asset, uint64 identifier, const std::filesystem::path& folderPath, std::string name) {
|
||||
if (name.empty())
|
||||
return;
|
||||
|
||||
std::string path = (folderPath / name).string().append(".asset");
|
||||
auto assetStream = createWriteStream(std::move(path), std::ios::binary);
|
||||
ArchiveBuffer buffer(graphics);
|
||||
// write identifier
|
||||
Serialization::save(buffer, identifier);
|
||||
// write name
|
||||
Serialization::save(buffer, name);
|
||||
// write folder
|
||||
Serialization::save(buffer, folderPath.string());
|
||||
// write asset data
|
||||
asset->save(buffer);
|
||||
buffer.writeToStream(assetStream);
|
||||
}
|
||||
|
||||
std::filesystem::path AssetRegistry::getRootFolder() { return get().rootFolder; }
|
||||
|
||||
void AssetRegistry::registerMesh(OMeshAsset mesh) {
|
||||
std::unique_lock l(assetLock);
|
||||
void AssetRegistry::registerMeshInternal(OMeshAsset mesh) {
|
||||
AssetFolder* folder = getOrCreateFolder(mesh->getFolderPath());
|
||||
folder->meshes[mesh->getName()] = std::move(mesh);
|
||||
}
|
||||
|
||||
void AssetRegistry::registerTexture(OTextureAsset texture) {
|
||||
std::unique_lock l(assetLock);
|
||||
void AssetRegistry::registerTextureInternal(OTextureAsset texture) {
|
||||
AssetFolder* folder = getOrCreateFolder(texture->getFolderPath());
|
||||
folder->textures[texture->getName()] = std::move(texture);
|
||||
}
|
||||
|
||||
void AssetRegistry::registerFont(OFontAsset font) {
|
||||
std::unique_lock l(assetLock);
|
||||
void AssetRegistry::registerFontInternal(OFontAsset font) {
|
||||
AssetFolder* folder = getOrCreateFolder(font->getFolderPath());
|
||||
folder->fonts[font->getName()] = std::move(font);
|
||||
}
|
||||
|
||||
void AssetRegistry::registerMaterial(OMaterialAsset material) {
|
||||
std::unique_lock l(assetLock);
|
||||
void AssetRegistry::registerMaterialInternal(OMaterialAsset material) {
|
||||
AssetFolder* folder = getOrCreateFolder(material->getFolderPath());
|
||||
folder->materials[material->getName()] = std::move(material);
|
||||
}
|
||||
|
||||
void AssetRegistry::registerMaterialInstance(OMaterialInstanceAsset material) {
|
||||
std::unique_lock l(assetLock);
|
||||
void AssetRegistry::registerMaterialInstanceInternal(OMaterialInstanceAsset material) {
|
||||
AssetFolder* folder = getOrCreateFolder(material->getFolderPath());
|
||||
folder->instances[material->getName()] = std::move(material);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#pragma once
|
||||
#include "Asset.h"
|
||||
#include "Containers/Map.h"
|
||||
#include "Containers/Pair.h"
|
||||
#include "Containers/List.h"
|
||||
#include "MinimalEngine.h"
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace Seele {
|
||||
DECLARE_REF(TextureAsset)
|
||||
DECLARE_REF(FontAsset)
|
||||
@@ -26,9 +27,18 @@ class AssetRegistry {
|
||||
static PMaterialAsset findMaterial(std::string_view folderPath, std::string_view filePath);
|
||||
static PMaterialInstanceAsset findMaterialInstance(std::string_view folderPath, std::string_view filePath);
|
||||
|
||||
static void registerMesh(OMeshAsset mesh);
|
||||
static void registerTexture(OTextureAsset texture);
|
||||
static void registerFont(OFontAsset font);
|
||||
static void registerMaterial(OMaterialAsset material);
|
||||
static void registerMaterialInstance(OMaterialInstanceAsset instance);
|
||||
|
||||
static std::ofstream createWriteStream(const std::filesystem::path& relativePath, std::ios_base::openmode openmode = std::ios::out);
|
||||
static std::ifstream createReadStream(const std::filesystem::path& relativePath, std::ios_base::openmode openmode = std::ios::in);
|
||||
|
||||
static void loadAsset(ArchiveBuffer& buffer);
|
||||
static void saveAsset(PAsset asset, uint64 identifier, const std::filesystem::path& folderPath, std::string name);
|
||||
|
||||
static void set(AssetRegistry registry);
|
||||
|
||||
static void loadRegistry();
|
||||
@@ -47,25 +57,21 @@ class AssetRegistry {
|
||||
AssetFolder* getOrCreateFolder(std::string_view foldername);
|
||||
AssetRegistry();
|
||||
static AssetRegistry* getInstance();
|
||||
|
||||
private:
|
||||
static AssetRegistry& get();
|
||||
|
||||
private:
|
||||
void initialize(const std::filesystem::path& rootFolder, Gfx::PGraphics graphics);
|
||||
void loadRegistryInternal();
|
||||
void peekFolder(AssetFolder* folder);
|
||||
void loadFolder(AssetFolder* folder);
|
||||
void peekAsset(ArchiveBuffer& buffer);
|
||||
void loadAsset(ArchiveBuffer& buffer);
|
||||
List<Pair<PAsset, ArchiveBuffer>> peekFolder(AssetFolder* folder);
|
||||
Pair<PAsset, ArchiveBuffer> peekAsset(ArchiveBuffer& buffer);
|
||||
void saveRegistryInternal();
|
||||
void saveFolder(const std::filesystem::path& folderPath, AssetFolder* folder);
|
||||
void saveAsset(PAsset asset, uint64 identifier, const std::filesystem::path& folderPath, std::string name);
|
||||
|
||||
void registerMesh(OMeshAsset mesh);
|
||||
void registerTexture(OTextureAsset texture);
|
||||
void registerFont(OFontAsset font);
|
||||
void registerMaterial(OMaterialAsset material);
|
||||
void registerMaterialInstance(OMaterialInstanceAsset instance);
|
||||
void registerMeshInternal(OMeshAsset mesh);
|
||||
void registerTextureInternal(OTextureAsset texture);
|
||||
void registerFontInternal(OFontAsset font);
|
||||
void registerMaterialInternal(OMaterialAsset material);
|
||||
void registerMaterialInstanceInternal(OMaterialInstanceAsset instance);
|
||||
|
||||
std::ofstream internalCreateWriteStream(const std::filesystem::path& relativePath, std::ios_base::openmode openmode = std::ios::out);
|
||||
std::ifstream internalCreateReadStream(const std::filesystem::path& relaitvePath, std::ios_base::openmode openmode = std::ios::in);
|
||||
@@ -75,10 +81,5 @@ class AssetRegistry {
|
||||
AssetFolder* assetRoot;
|
||||
Gfx::PGraphics graphics;
|
||||
bool release = false;
|
||||
friend class MaterialAsset;
|
||||
friend class TextureLoader;
|
||||
friend class FontLoader;
|
||||
friend class MaterialLoader;
|
||||
friend class MeshLoader;
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Material/Material.h"
|
||||
#include "MaterialInstanceAsset.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
@@ -28,7 +28,7 @@ PMaterialInstanceAsset MaterialAsset::instantiate(const InstantiationParameter&
|
||||
asset->setHandle(std::move(instance));
|
||||
asset->setBase(this);
|
||||
PMaterialInstanceAsset ref = asset;
|
||||
AssetRegistry::get().saveAsset(ref, MaterialInstanceAsset::IDENTIFIER, ref->getFolderPath(), ref->getName());
|
||||
AssetRegistry::get().registerMaterialInstance(std::move(asset));
|
||||
AssetRegistry::registerMaterialInstance(std::move(asset));
|
||||
AssetRegistry::saveAsset(ref, MaterialInstanceAsset::IDENTIFIER, ref->getFolderPath(), ref->getName());
|
||||
return ref;
|
||||
}
|
||||
|
||||
@@ -22,13 +22,12 @@ TextureAsset::TextureAsset(std::string_view folderPath, std::string_view name) :
|
||||
|
||||
TextureAsset::~TextureAsset() {}
|
||||
|
||||
void TextureAsset::save(ArchiveBuffer& buffer) const { /*
|
||||
Serialization::save(buffer, ktxData);*/
|
||||
void TextureAsset::save(ArchiveBuffer& buffer) const {
|
||||
Serialization::save(buffer, ktxData);
|
||||
}
|
||||
|
||||
void TextureAsset::load(ArchiveBuffer& buffer) {
|
||||
ktxTexture2* ktxHandle;
|
||||
Array<uint8> ktxData;
|
||||
Serialization::load(buffer, ktxData);
|
||||
KTX_ASSERT(
|
||||
ktxTexture_CreateFromMemory(ktxData.data(), ktxData.size(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, (ktxTexture**)&ktxHandle));
|
||||
|
||||
@@ -13,12 +13,13 @@ class TextureAsset : public Asset {
|
||||
virtual void save(ArchiveBuffer& buffer) const override;
|
||||
virtual void load(ArchiveBuffer& buffer) override;
|
||||
Gfx::PTexture getTexture() { return texture; }
|
||||
void setTexture(Array<uint8> data) { }
|
||||
void setTexture(Array<uint8> data) { ktxData = std::move(data); }
|
||||
uint32 getWidth();
|
||||
uint32 getHeight();
|
||||
|
||||
private:
|
||||
Gfx::OTexture texture;
|
||||
Array<uint8> ktxData;
|
||||
friend class TextureLoader;
|
||||
};
|
||||
DEFINE_REF(TextureAsset)
|
||||
|
||||
@@ -66,6 +66,7 @@ void VertexData::updateMesh(entt::entity id, uint32 meshIndex, PMesh mesh, Compo
|
||||
.worldPosition = Vector(inst.transformMatrix[3]),
|
||||
.instanceData = inst,
|
||||
.meshData = data,
|
||||
.cullingOffset = meshletOffset,
|
||||
.rayTracingScene = mesh->blas,
|
||||
});
|
||||
return;
|
||||
@@ -149,6 +150,7 @@ void VertexData::createDescriptors() {
|
||||
}
|
||||
for (uint32 i = 0; i < transparentData.size(); ++i) {
|
||||
transparentData[i].offsets.instanceOffset = instanceData.size();
|
||||
cullingOffsets.add(transparentData[i].cullingOffset);
|
||||
instanceData.add(transparentData[i].instanceData);
|
||||
instanceMeshData.add(transparentData[i].meshData);
|
||||
rayTracingScene.add(transparentData[i].rayTracingScene);
|
||||
|
||||
@@ -51,6 +51,7 @@ class VertexData {
|
||||
Vector worldPosition;
|
||||
InstanceData instanceData;
|
||||
MeshData meshData;
|
||||
uint32 cullingOffset;
|
||||
Gfx::PBottomLevelAS rayTracingScene;
|
||||
};
|
||||
void resetMeshData();
|
||||
|
||||
@@ -122,6 +122,8 @@ void BufferAllocation::updateContents(uint64 regionOffset, uint64 regionSize, vo
|
||||
cmd->bindResource(PBufferAllocation(this));
|
||||
cmd->bindResource(PBufferAllocation(staging));
|
||||
vkCmdCopyBuffer(cmd->getHandle(), staging->buffer, buffer, 1, ©);
|
||||
pipelineBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT);
|
||||
|
||||
// transferOwnership(prevOwner);
|
||||
graphics->getDestructionManager()->queueResourceForDestruction(std::move(staging));
|
||||
@@ -157,6 +159,8 @@ void BufferAllocation::readContents(uint64 regionOffset, uint64 regionSize, void
|
||||
cmd->bindResource(PBufferAllocation(this));
|
||||
cmd->bindResource(PBufferAllocation(staging));
|
||||
vkCmdCopyBuffer(cmd->getHandle(), buffer, staging->buffer, 1, ©);
|
||||
pipelineBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT);
|
||||
pool->submitCommands();
|
||||
cmd->getFence()->wait(1000000);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user