Inheritance: IRenderableTexture
Beispiel #1
0
        protected override IRenderableTexture CreateTexture(IDeviceContextHolder contextHolder, string key)
        {
            var result = new RenderableTexture(key)
            {
                Resource = null
            };

            byte[] data;
            if (Kn5.TexturesData.TryGetValue(key, out data))
            {
                if (AsyncLoading)
                {
                    result.LoadAsync(contextHolder, data).Forget();
                }
                else
                {
                    result.Load(contextHolder, data);
                }
            }

            if (CurrentDirectory != null)
            {
                if (AsyncLoading)
                {
                    LoadOverrideAsync(contextHolder, result, key).Forget();
                }
                else
                {
                    LoadOverride(contextHolder, result, key);
                }
            }

            return(result);
        }
Beispiel #2
0
        protected override IRenderableTexture CreateTexture(IDeviceContextHolder contextHolder, string key)
        {
            var result = new RenderableTexture();

            if (_directory == null)
            {
                return(result);
            }
            var filename = Path.Combine(_directory, key);

            if (File.Exists(filename))
            {
                result.Exists = true;
                if (_asyncLoading)
                {
                    TaskExtension.Forget(result.LoadAsync(contextHolder, filename));
                }
                else
                {
                    result.Load(contextHolder, filename);
                }
            }

            return(Textures[filename] = result);
        }
Beispiel #3
0
        protected override IRenderableTexture CreateTexture(IDeviceContextHolder contextHolder, string key)
        {
            var result = new RenderableTexture(key)
            {
                Resource = null
            };

            foreach (var kn5 in Kn5)
            {
                if (kn5.TexturesData.TryGetValue(key, out var data))
                {
                    result.Exists = true;
                    if (AsyncLoading)
                    {
                        result.LoadAsync(contextHolder, data).ContinueWith(t => {
                            contextHolder.RaiseTexturesUpdated();
                        });
                    }
                    else
                    {
                        result.Load(contextHolder, data);
                    }
                    return(result);
                }
            }

            return(result);
        }
        protected override IRenderableTexture CreateTexture(IDeviceContextHolder contextHolder, string key)
        {
            if (_directory == null)
            {
                return(null);
            }
            var filename = Path.Combine(_directory, key);

            var result = new RenderableTexture {
                Resource = null
            };

            if (File.Exists(filename))
            {
                if (_asyncLoading)
                {
                    result.LoadAsync(contextHolder, filename).Forget();
                }
                else
                {
                    result.Load(contextHolder, filename);
                }
            }

            return(Textures[filename] = result);
        }
Beispiel #5
0
        private bool LoadOverride(IDeviceContextHolder contextHolder, RenderableTexture texture, string textureName)
        {
            var overrided = GetOverridedData(textureName);

            if (overrided == null)
            {
                return(false);
            }
            texture.LoadOverride(contextHolder, overrided);
            return(true);
        }
Beispiel #6
0
        private async Task <bool> LoadOverrideAsync(IDeviceContextHolder contextHolder, RenderableTexture texture, string textureName)
        {
            var overrided = await GetOverridedDataAsync(textureName);

            if (overrided == null)
            {
                return(false);
            }
            texture.LoadOverrideAsync(contextHolder, overrided).Forget();
            return(true);
        }
Beispiel #7
0
        public IRenderableTexture GetTexture(string filename, DeviceContextHolder contextHolder) {
            IRenderableTexture cached;
            if (_textures.TryGetValue(filename, out cached) && !cached.IsDisposed) return cached;
            if (!File.Exists(filename)) return null;

            var result = new RenderableTexture { Resource = null };
            result.LoadAsync(filename, contextHolder.Device).Forget();
            return _textures[filename] = result;
        }
Beispiel #8
0
 private async void LoadOverrideAsync(RenderableTexture texture, string textureName, IOverridedTextureProvider provider,
         DeviceContextHolder contextHolder) {
     var overrided = await provider.GetOverridedDataAsync(textureName);
     if (overrided != null) {
         texture.LoadOverrideAsync(overrided, contextHolder.Device).Forget();
     }
 }
Beispiel #9
0
        public IRenderableTexture GetTexture([NotNull] string kn5Filename, string textureName, DeviceContextHolder contextHolder) {
            if (kn5Filename == null) throw new ArgumentNullException(nameof(kn5Filename));

            var key = kn5Filename + "//" + textureName;
            IRenderableTexture texture;
            if (_textures.TryGetValue(key, out texture)) return texture;

            var result = new RenderableTexture(textureName) { Resource = null };
            IOverridedTextureProvider provider;
            if (_overridedProviders.TryGetValue(kn5Filename, out provider)) {
                LoadOverrideAsync(result, textureName, provider, contextHolder);
            }

            var kn5 = _kn5Entries.Where(x => string.Equals(x.Filename, kn5Filename, StringComparison.OrdinalIgnoreCase))
                          .Select(x => x.Kn5).FirstOrDefault(x => x.TexturesData.ContainsKey(textureName));
            if (kn5 == null) return result;
            
            result.LoadAsync(kn5.TexturesData[textureName], contextHolder.Device).Forget();
            return _textures[key] = result;
        }