Example #1
0
        private TextureWithRefCount createTextureWithRefCount([NotNull] string lookupKey, [CanBeNull] Texture baseTexture)
        {
            if (baseTexture == null)
            {
                return(null);
            }

            lock (referenceCountLock)
            {
                if (!referenceCounts.TryGetValue(lookupKey, out TextureWithRefCount.ReferenceCount count))
                {
                    referenceCounts[lookupKey] = count = new TextureWithRefCount.ReferenceCount(referenceCountLock, () => onAllReferencesLost(baseTexture));
                }

                return(new TextureWithRefCount(baseTexture.TextureGL, count));
            }
        }
        /// <summary>
        /// Retrieves a texture.
        /// This texture should only be assigned once, as reference counting is being used internally.
        /// If you wish to use the same texture multiple times, call this method an equal number of times.
        /// </summary>
        /// <param name="name">The name of the texture.</param>
        /// <returns>The texture.</returns>
        public override Texture Get(string name)
        {
            lock (referenceCountLock)
            {
                var tex = base.Get(name);

                if (tex?.TextureGL == null)
                {
                    return(null);
                }

                if (!referenceCounts.TryGetValue(name, out TextureWithRefCount.ReferenceCount count))
                {
                    referenceCounts[name] = count = new TextureWithRefCount.ReferenceCount(referenceCountLock, () => onAllReferencesLost(name));
                }

                return(new TextureWithRefCount(tex.TextureGL, count));
            }
        }
        /// <summary>
        /// Retrieves a texture.
        /// This texture should only be assigned once, as reference counting is being used internally.
        /// If you wish to use the same texture multiple times, call this method an equal number of times.
        /// </summary>
        /// <param name="name">The name of the texture.</param>
        /// <param name="wrapModeS">The horizontal wrap mode of the texture.</param>
        /// <param name="wrapModeT">The vertical wrap mode of the texture.</param>
        /// <returns>The texture.</returns>
        public override Texture Get(string name, WrapMode wrapModeS, WrapMode wrapModeT)
        {
            lock (referenceCountLock)
            {
                var tex = base.Get(name, wrapModeS, wrapModeT);

                if (tex?.TextureGL == null)
                {
                    return(null);
                }

                if (!referenceCounts.TryGetValue(tex.LookupKey, out TextureWithRefCount.ReferenceCount count))
                {
                    referenceCounts[tex.LookupKey] = count = new TextureWithRefCount.ReferenceCount(referenceCountLock, () => onAllReferencesLost(tex));
                }

                return(new TextureWithRefCount(tex.TextureGL, count));
            }
        }