MCPcopy Create free account
hub / github.com/Norbyte/bg3se / IncTextureRef

Method IncTextureRef

BG3Extender/Extender/Client/IMGUI/IMGUI.cpp:2207–2246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2205}
2206
2207std::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
2249bool IMGUITextureLoader::DecTextureRef(TextureOpaqueHandle id, FixedString const& textureGuid)

Callers 1

RegisterTextureMethod · 0.80

Calls 7

GetResourceMethod · 0.80
GetStringMethod · 0.80
RegisterTextureMethod · 0.80
try_getMethod · 0.45
setMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected