| 2205 | } |
| 2206 | |
| 2207 | std::optional<TextureLoadResult> IMGUITextureLoader::IncTextureRef(FixedString const& textureGuid) |
| 2208 | { |
| 2209 | if (!renderer_) { |
| 2210 | ERR("Loading texture with no rendering backend?"); |
| 2211 | return {}; |
| 2212 | } |
| 2213 | |
| 2214 | auto refs = refCounts_.try_get(textureGuid); |
| 2215 | if (refs) { |
| 2216 | refs->RefCount++; |
| 2217 | return refs->LoadResult; |
| 2218 | } |
| 2219 | |
| 2220 | auto tex = (resource::TextureResource*)GetStaticSymbols().GetCurrentResourceBank()->GetResource(ResourceBankType::Texture, textureGuid); |
| 2221 | if (!tex) { |
| 2222 | return {}; |
| 2223 | } |
| 2224 | |
| 2225 | if (tex->Type != TextureType::T1D // shouldn't be here, but tex type is set incorrectly for some atlases |
| 2226 | && tex->Type != TextureType::T2D) { |
| 2227 | ERR("Cannot render texture '%s': expected 2D texture, got %d", textureGuid.GetString(), tex->Type); |
| 2228 | return {}; |
| 2229 | } |
| 2230 | |
| 2231 | auto descriptor = (*GetStaticSymbols().ls__AppliedMaterial__LoadTexture)(nullptr, textureGuid); |
| 2232 | if (!descriptor) { |
| 2233 | return {}; |
| 2234 | } |
| 2235 | |
| 2236 | auto loadResult = renderer_->RegisterTexture(descriptor); |
| 2237 | if (!loadResult) { |
| 2238 | auto textureManager = (*GetStaticSymbols().ls__gGlobalResourceManager)->TextureManager; |
| 2239 | (*GetStaticSymbols().ls__TextureManager__UnloadTexture)(textureManager, textureGuid); |
| 2240 | return {}; |
| 2241 | } |
| 2242 | |
| 2243 | refCounts_.set(textureGuid, TextureRefCount{ descriptor, *loadResult, 1 }); |
| 2244 | pendingUnloads_.remove(textureGuid); |
| 2245 | return *loadResult; |
| 2246 | } |
| 2247 | |
| 2248 | |
| 2249 | bool IMGUITextureLoader::DecTextureRef(TextureOpaqueHandle id, FixedString const& textureGuid) |
no test coverage detected