gltfio: Better behavior for releaseSourceData()

This commit is contained in:
Philip Rideout
2022-08-30 15:53:56 -07:00
parent 7337a467b9
commit de7dfc2ea6
5 changed files with 35 additions and 22 deletions

View File

@@ -167,8 +167,7 @@ static void decodeDracoMeshes(FFilamentAsset* asset) {
};
// Go through every primitive and check if it has a Draco mesh.
for (auto& pair : asset->mPrimitives) {
const cgltf_primitive* prim = pair.first;
for (auto& [prim, vertexBuffer] : asset->mPrimitives) {
if (!prim->has_draco_mesh_compression) {
continue;
}
@@ -177,7 +176,6 @@ static void decodeDracoMeshes(FFilamentAsset* asset) {
// If an error occurs, we can simply set the primitive's associated VertexBuffer to null.
// This does not cause a leak because it is a weak reference.
auto& vertexBuffer = pair.second;
// Check if we have already decoded this mesh.
DracoMesh* mesh = dracoCache->findOrCreateMesh(draco.buffer_view);
@@ -494,6 +492,9 @@ bool ResourceLoader::loadResources(FFilamentAsset* asset, bool async) {
// we need to generate the contents of a GPU buffer by processing one or more CPU buffer(s).
pImpl->computeTangents(asset);
asset->mBufferSlots = {};
asset->mPrimitives = {};
// If any decoding jobs are still underway from a previous load, wait for them to finish.
for (const auto& iter : pImpl->mTextureProviders) {
iter.second->waitForCompletion();
@@ -674,11 +675,12 @@ void ResourceLoader::Impl::cancelTextureDecoding() {
void ResourceLoader::Impl::createTextures(FFilamentAsset* asset, bool async) {
// Create new texture objects if they are not cached and kick off decoding jobs.
mRemainingTextureDownloads = 0;
for (auto slot : asset->mTextureSlots) {
for (const TextureSlot& slot : asset->mTextureSlots) {
if (Texture* texture = getOrCreateTexture(asset, slot)) {
asset->bindTexture(slot, texture);
}
}
asset->mTextureSlots = {};
// Non-threaded systems are required to use the asynchronous API.
assert_invariant(UTILS_HAS_THREADING || async);
@@ -711,14 +713,13 @@ void ResourceLoader::Impl::computeTangents(FFilamentAsset* asset) {
// Create a job description for each triangle-based primitive.
using Params = TangentsJob::Params;
std::vector<Params> jobParams;
for (auto pair : asset->mPrimitives) {
if (UTILS_UNLIKELY(pair.first->type != cgltf_primitive_type_triangles)) {
for (auto [prim, vb] : asset->mPrimitives) {
if (UTILS_UNLIKELY(prim->type != cgltf_primitive_type_triangles)) {
continue;
}
VertexBuffer* vb = pair.second;
auto iter = baseTangents.find(vb);
if (iter != baseTangents.end()) {
jobParams.emplace_back(Params {{ pair.first }, {vb, nullptr, iter->second }});
jobParams.emplace_back(Params {{ prim }, {vb, nullptr, iter->second }});
}
}