bool TextureStore::TileSwapper::unload(const TileKey& key, TileRecord& record) { // Cannot unload tiles that are still in use. if (boost_atomic::atomic_read32(&record.m_owners) > 0) return false; // Track the amount of memory used by the tile cache. const size_t tile_memory_size = dynamic_sizeof(*record.m_tile); assert(m_memory_size >= tile_memory_size); m_memory_size -= tile_memory_size; // Fetch the texture container. const TextureContainer& textures = key.m_assembly_uid == ~0 ? m_scene.textures() : m_scene.assemblies().get_by_uid(key.m_assembly_uid)->textures(); // Fetch the texture. const size_t texture_index = key.get_texture_index(); assert(texture_index < textures.size()); Texture* texture = textures.get_by_index(texture_index); #ifdef TRACK_TILE_UNLOADING RENDERER_LOG_DEBUG( "unloading tile (" FMT_SIZE_T ", " FMT_SIZE_T ") " "from texture \"%s\"...", key.get_tile_x(), key.get_tile_y(), texture->get_name()); #endif // Unload the tile. texture->unload_tile(key.get_tile_x(), key.get_tile_y(), record.m_tile); // Successfully unloaded the tile. return true; }
void TextureStore::TileSwapper::load(const TileKey& key, TileRecord& record) { // Fetch the texture container. const TextureContainer& textures = key.m_assembly_uid == ~0 ? m_scene.textures() : m_scene.assemblies().get_by_uid(key.m_assembly_uid)->textures(); // Fetch the texture. const size_t texture_index = key.get_texture_index(); assert(texture_index < textures.size()); Texture* texture = textures.get_by_index(texture_index); #ifdef TRACK_TILE_LOADING RENDERER_LOG_DEBUG( "loading tile (" FMT_SIZE_T ", " FMT_SIZE_T ") " "from texture \"%s\"...", key.get_tile_x(), key.get_tile_y(), texture->get_name()); #endif // Load the tile. record.m_tile = texture->load_tile(key.get_tile_x(), key.get_tile_y()); record.m_owners = 0; // Convert the tile to the linear RGB color space. switch (texture->get_color_space()) { case ColorSpaceLinearRGB: break; case ColorSpaceSRGB: convert_tile_srgb_to_linear_rgb(*record.m_tile); break; case ColorSpaceCIEXYZ: convert_tile_ciexyz_to_linear_rgb(*record.m_tile); break; assert_otherwise; } // Track the amount of memory used by the tile cache. m_memory_size += dynamic_sizeof(*record.m_tile); m_max_memory_size = max(m_max_memory_size, m_memory_size); #ifdef TRACK_CACHE_SIZE if (m_memory_size > m_memory_limit) { RENDERER_LOG_DEBUG( "texture store size is %s, exceeding capacity %s by %s", pretty_size(m_memory_size).c_str(), pretty_size(m_memory_limit).c_str(), pretty_size(m_memory_size - m_memory_limit).c_str()); } else { RENDERER_LOG_DEBUG( "texture store size is %s, below capacity %s by %s", pretty_size(m_memory_size).c_str(), pretty_size(m_memory_limit).c_str(), pretty_size(m_memory_size - m_memory_limit).c_str()); } #endif }