static public void EnsureInstance() { if (instance == null) { var go = new GameObject("Water.RenderTexturesCache"); go.hideFlags = HideFlags.HideAndDontSave; if (Application.isPlaying) { DontDestroyOnLoad(go); } instance = go.AddComponent <RenderTexturesUpdater>(); } }
static public RenderTexturesCache GetCache(int width, int height, int depthBuffer, RenderTextureFormat format, bool linear, bool uav, bool mipMaps = false) { RenderTexturesUpdater.EnsureInstance(); ulong hash = 0; hash |= (uint)width; hash |= ((uint)height << 16); hash |= ((ulong)depthBuffer << 29); // >> 3 << 32 hash |= ((linear ? 1UL : 0UL) << 34); hash |= ((uav ? 1UL : 0UL) << 35); hash |= ((mipMaps ? 1UL : 0UL) << 36); hash |= ((ulong)format << 37); RenderTexturesCache renderTexturesCache; if (!cache.TryGetValue(hash, out renderTexturesCache)) { cache[hash] = renderTexturesCache = new RenderTexturesCache(hash, (int)width, (int)height, (int)depthBuffer, format, linear, uav, mipMaps); } return(renderTexturesCache); }