// public int createdContainerCount; // public int releasedContainerCount; public void Get(ShadowRenderingRequest request, ref ShadowContainer container) { if (float.IsNaN(request.dimensions.x) || request.dimensions.x < 1 || float.IsNaN(request.dimensions.y) || request.dimensions.y < 1) { ReleaseContainer(container); return; } #if LETAI_TRUESHADOW_DEBUG RenderTexture.ReleaseTemporary(debugTexture); if (request.shadow.alwaysRender) { debugTexture = RenderShadow(request); } #endif // Each request need a coresponding shadow texture // Texture may be shared by multiple elements // Texture are released when no longer used by any element // ShadowContainer keep track of texture and their usage int requestHash = request.GetHashCode(); // Case: requester can keep the same texture if (container?.requestHash == requestHash) { return; } ReleaseContainer(container); if (shadowCache.TryGetValue(requestHash, out var existingContainer)) { // Case: requester got texture from someone else existingContainer.RefCount++; container = existingContainer; } else { // Case: requester got new unique texture container = shadowCache[requestHash] = new ShadowContainer(RenderShadow(request), request); // Debug.Log($"Created new container for request\t{requestHash}\tTotal Created: {++createdContainerCount}\t Alive: {createdContainerCount - releasedContainerCount}"); } }
public ShadowContainer(RenderTexture texture, ShadowRenderingRequest request) { Texture = texture; RefCount = 1; requestHash = request.GetHashCode(); }