Пример #1
0
        public async Task LoadOverrideAsync([NotNull] IDeviceContextHolder holder, [CanBeNull] byte[] data)
        {
            var id = ++_overrideId;

            if (data == null)
            {
                Override = null;
                holder.RaiseTexturesUpdated();
                return;
            }

            try {
                var resource = await Task.Run(() => LoadSafe(holder.Device, data));

                if (id != _overrideId)
                {
                    return;
                }
                Override = resource;
                holder.RaiseTexturesUpdated();
            } catch (Exception) {
                if (id != _overrideId)
                {
                    return;
                }
                Override = null;
                holder.RaiseTexturesUpdated();
            }
        }
Пример #2
0
        public void LoadOverride([CanBeNull] IDeviceContextHolder holder, byte[] data)
        {
            var id = ++_overrideId;

            if (data == null)
            {
                Override = null;
                holder?.RaiseTexturesUpdated();
                return;
            }

            try {
                var resource = LoadSafe(holder?.Device, data);
                if (id != _overrideId)
                {
                    return;
                }
                Override = resource;
                holder?.RaiseTexturesUpdated();
            } catch (Exception) {
                if (id != _overrideId)
                {
                    return;
                }
                Override = null;
                holder?.RaiseTexturesUpdated();
            }
        }
Пример #3
0
        public async Task LoadOverrideAsync([CanBeNull] IDeviceContextHolder holder, string filename)
        {
            var id = ++_overrideId;

            if (filename == null || !File.Exists(filename))
            {
                Override = null;
                holder?.RaiseTexturesUpdated();
                return;
            }

            try {
                var resource = await Task.Run(() => LoadSafe(holder?.Device, filename));

                if (id != _overrideId)
                {
                    return;
                }
                Override = resource;
                holder?.RaiseTexturesUpdated();
            } catch (Exception) {
                if (id != _overrideId)
                {
                    return;
                }
                Override = null;
                holder?.RaiseTexturesUpdated();
            }
        }
Пример #4
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);
        }
Пример #5
0
        public async Task LoadOverrideAsync([CanBeNull] IDeviceContextHolder holder, [CanBeNull] byte[] data)
        {
            var id = ++_overrideId;

            if (data == null)
            {
                Override = null;
            }
            else
            {
                try {
                    var resource = await Task.Run(() => LoadSafe(holder?.Device, data));

                    if (id != _overrideId)
                    {
                        resource?.Dispose();
                        return;
                    }

                    Override = resource;
                } catch (Exception e) {
                    if (id != _overrideId)
                    {
                        return;
                    }
                    AcToolsLogging.Write(e);
                    Override = null;
                }
            }

            holder?.RaiseTexturesUpdated();
        }
Пример #6
0
        public void SetProceduralOverride(IDeviceContextHolder holder, byte[] textureBytes)
        {
            if (textureBytes == null)
            {
                ProceduralOverride = null;
                holder?.RaiseTexturesUpdated();
                return;
            }

            try {
                ProceduralOverride = LoadSafe(holder?.Device, textureBytes);
                holder?.RaiseTexturesUpdated();
            } catch (Exception) {
                ProceduralOverride = null;
                holder?.RaiseTexturesUpdated();
            }
        }
Пример #7
0
        public async Task LoadAsync([CanBeNull] IDeviceContextHolder holder, byte[] data)
        {
            var id       = ++_resourceId;
            var resource = await Task.Run(() => LoadSafe(holder?.Device, data));

            if (id != _resourceId)
            {
                return;
            }
            Resource = resource;
            holder?.RaiseTexturesUpdated();
        }
Пример #8
0
        public void Load([CanBeNull] IDeviceContextHolder holder, byte[] data)
        {
            var id       = ++_resourceId;
            var resource = LoadSafe(holder?.Device, data);

            if (id != _resourceId)
            {
                return;
            }
            Resource = resource;
            holder?.RaiseTexturesUpdated();
        }
Пример #9
0
        public async Task LoadAsync([CanBeNull] IDeviceContextHolder holder, string filename)
        {
            var id       = ++_resourceId;
            var resource = await Task.Run(() => LoadSafe(holder?.Device, filename));

            if (id != _resourceId)
            {
                resource?.Dispose();
                return;
            }

            Resource = resource;
            holder?.RaiseTexturesUpdated();
        }
Пример #10
0
        public void Load([CanBeNull] IDeviceContextHolder holder, string filename)
        {
            var id       = ++_resourceId;
            var resource = LoadSafe(holder?.Device, filename);

            if (id != _resourceId)
            {
                resource?.Dispose();
                return;
            }

            Resource = resource;
            holder?.RaiseTexturesUpdated();
        }
Пример #11
0
 public void RaiseTexturesUpdated()
 {
     _mainHolder.RaiseTexturesUpdated();
 }
Пример #12
0
 public void SetProceduralOverride(IDeviceContextHolder holder, ShaderResourceView textureView, bool disposeLater)
 {
     ProceduralOverride         = textureView;
     _disposeProceduralOverride = disposeLater;
     holder?.RaiseTexturesUpdated();
 }
Пример #13
0
 public void SetProceduralOverride(IDeviceContextHolder holder, byte[] textureBytes)
 {
     ProceduralOverride         = textureBytes == null ? null : LoadSafe(holder?.Device, textureBytes);
     _disposeProceduralOverride = true;
     holder?.RaiseTexturesUpdated();
 }