From 1e056b03e2f91375fb8fdeabfc8c9788517b1452 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 24 Feb 2022 10:32:49 +0100 Subject: [PATCH] Fix textures with the PCM library. --- world/jobs/terrain_2d_terrain_job.cpp | 51 ++++++++++++++------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/world/jobs/terrain_2d_terrain_job.cpp b/world/jobs/terrain_2d_terrain_job.cpp index ea3ed7b..30e0724 100644 --- a/world/jobs/terrain_2d_terrain_job.cpp +++ b/world/jobs/terrain_2d_terrain_job.cpp @@ -78,42 +78,43 @@ void Terrain2DTerrain2DJob::phase_library_setup() { if (lib->supports_caching()) { if (!_chunk->material_cache_key_has()) { lib->material_cache_get_key(_chunk); - } else { - Ref cache = lib->material_cache_get(_chunk->material_cache_key_get()); + } - if (!cache.is_valid()) { - //Try a fallback texture - Ref cd = _chunk; - - if (cd.is_valid()) { - Ref tex = lib->texture_get(); - - if (tex.is_valid()) { - cd->mesh_rid_set(Terrain2DChunkDefault::MESH_INDEX_TERRAIN, Terrain2DChunkDefault::MESH_TYPE_INDEX_TEXTURE_RID, tex->get_rid()); - } - } - - next_phase(); - return; - } - - //Note: without threadpool and threading none of this can happen, as cache will get initialized the first time a thread requests it! - while (!cache->get_initialized()) { - //Means it's currently merging the atlases on a different thread. - //Let's just wait - OS::get_singleton()->delay_usec(100); - } + Ref cache = lib->material_cache_get(_chunk->material_cache_key_get()); + if (!cache.is_valid()) { + //Try a fallback texture Ref cd = _chunk; if (cd.is_valid()) { - Ref tex = cache->texture_get_merged(); + Ref tex = lib->texture_get(); if (tex.is_valid()) { cd->mesh_rid_set(Terrain2DChunkDefault::MESH_INDEX_TERRAIN, Terrain2DChunkDefault::MESH_TYPE_INDEX_TEXTURE_RID, tex->get_rid()); } } + + next_phase(); + return; } + + //Note: without threadpool and threading none of this can happen, as cache will get initialized the first time a thread requests it! + while (!cache->get_initialized()) { + //Means it's currently merging the atlases on a different thread. + //Let's just wait + OS::get_singleton()->delay_usec(100); + } + + Ref cd = _chunk; + + if (cd.is_valid()) { + Ref tex = cache->texture_get_merged(); + + if (tex.is_valid()) { + cd->mesh_rid_set(Terrain2DChunkDefault::MESH_INDEX_TERRAIN, Terrain2DChunkDefault::MESH_TYPE_INDEX_TEXTURE_RID, tex->get_rid()); + } + } + } else { Ref cd = _chunk;