public void UnloadTexture(ModelTexture texture)
 {
     lock (_textures)
     {
         texture.RemoveRef();
         if (texture.RefCount == 0)
         {
             _textures.Remove(texture.TexturePath);
         }
     }
 }
        public ModelTexture LoadTexture(IPackageIndexer packageIndexer, string texturePath, Device device)
        {
            using (var stream = ModelTextureManager.OpenTexture(packageIndexer, texturePath))
            {
                var pos = stream.Position;

                lock (_textures)
                {
                    if (!_textures.TryGetValue(texturePath, out ModelTexture texture))
                    {
                        var info = ImageInformation.FromStream(stream);
                        stream.Seek(pos, SeekOrigin.Begin);
                        texture = new ModelTexture(texturePath, Texture.FromStream(device, stream), info);
                        _textures.Add(texturePath, texture);
                    }
                    else
                    {
                        texture.AddRef();
                    }
                    return(texture);
                }
            }
        }