Esempio n. 1
0
 public IObservable <Texture> Process(IObservable <IplImage> source)
 {
     return(source.SelectMany(input => ShaderManager.WindowUpdate().Select(window =>
     {
         using var texture = new Texture();
         configuration.ConfigureTexture(texture, input.Width, input.Height);
         TextureHelper.UpdateTexture(TextureTarget.Texture2D, InternalFormat, input);
         GL.BindTexture(TextureTarget.Texture2D, 0);
         var id = texture.Id;
         texture.Id = 0;
         return id;
     })).ToArray().Select(textures => new TextureSequence(textures)
     {
         PlaybackRate = PlaybackRate
     }));
 }
Esempio n. 2
0
        public override IObservable <Texture> Process(IObservable <IplImage[]> source)
        {
            return(source.SelectMany(input => ShaderManager.WindowUpdate().Select(window =>
            {
                var sequence = new TextureSequence(input.Length);
                using var enumerator = sequence.GetEnumerator(false);
                for (int i = 0; i < input.Length && enumerator.MoveNext(); i++)
                {
                    configuration.ConfigureTexture(sequence, input[i].Width, input[i].Height);
                    TextureHelper.UpdateTexture(TextureTarget.Texture2D, InternalFormat, input[i]);
                }

                GL.BindTexture(TextureTarget.Texture2D, 0);
                sequence.PlaybackRate = PlaybackRate;
                return sequence;
            })));
        }
Esempio n. 3
0
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            var values = base.GetStandardValues(context);
            var configurationResources = ShaderManager.LoadConfiguration().Shaders;

            if (configurationResources.Count > 0)
            {
                var shaderNames = configurationResources.Where(IsResourceSupported).Select(configuration => configuration.Name);
                if (values != null)
                {
                    shaderNames = shaderNames.Concat(values.Cast <string>());
                }
                values = new StandardValuesCollection(shaderNames.ToArray());
            }

            return(values);
        }
Esempio n. 4
0
        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            var values = base.GetStandardValues(context);
            var configurationResources = ShaderManager.LoadConfiguration().Textures;

            if (configurationResources.Count > 0)
            {
                var textureNames = configurationResources.Select(configuration => configuration.Name);
                if (values != null)
                {
                    textureNames = textureNames.Concat(values.Cast <string>());
                }
                values = new StandardValuesCollection(textureNames.ToArray());
            }

            return(values);
        }
Esempio n. 5
0
        public override IObservable <TSource> Process <TSource>(IObservable <TSource> source)
        {
            return(Observable.Create <TSource>(observer =>
            {
                if (meshNames.Count == 0)
                {
                    throw new InvalidOperationException("A mesh name must be specified.");
                }

                MeshAggregate mesh = null;
                return source.CombineEither(
                    ShaderManager.ReserveMaterial(ShaderName).Do(material =>
                {
                    material.Update(() =>
                    {
                        try
                        {
                            var meshAttributes = meshNames.Select(meshName => new MeshAttributeMapping(
                                                                      material.Window.ResourceManager.Load <Mesh>(meshName.Name),
                                                                      meshName.Divisor));
                            mesh = new MeshAggregate(meshAttributes);
                        }
                        catch (Exception ex) { observer.OnError(ex); }
                    });
                }),
                    (input, material) =>
                {
                    material.Update(() =>
                    {
                        mesh.Draw();
                    });
                    return input;
                }).Finally(() =>
                {
                    if (mesh != null)
                    {
                        mesh.Dispose();
                    }
                }).SubscribeSafe(observer);
            }));
        }
Esempio n. 6
0
        public IObservable <Mesh> Process(IObservable <Mesh> source)
        {
            return(Observable.Defer(() =>
            {
                var drawMesh = default(Action);
                var meshName = default(string);
                return source.CombineEither(
                    ShaderManager.ReserveShader(ShaderName),
                    (input, shader) =>
                {
                    if (meshName != MeshName)
                    {
                        meshName = MeshName;
                        drawMesh = CreateDrawAction(shader, meshName);
                    }

                    shader.Update(drawMesh ?? (() => input.Draw()));
                    return input;
                });
            }));
        }
Esempio n. 7
0
        IObservable <TSource> Process <TSource>(IObservable <TSource> source, Action <TSource> update)
        {
            return(Observable.Defer(() =>
            {
                var texture = default(Texture);
                var textureName = default(string);
                return source.CombineEither(
                    ShaderManager.ReserveShader(ShaderName),
                    (input, shader) =>
                {
                    if (textureName != TextureName)
                    {
                        textureName = TextureName;
                        texture = !string.IsNullOrEmpty(textureName)
                                ? shader.Window.ResourceManager.Load <Texture>(textureName)
                                : null;
                    }

                    if (texture != null)
                    {
                        var index = Index;
                        var textureId = index.HasValue ? ((TextureSequence)texture).Textures[index.Value] : texture.Id;
                        shader.Update(() =>
                        {
                            GL.ActiveTexture(TextureSlot);
                            GL.BindTexture(TextureTarget, textureId);
                        });
                    }
                    else if (update != null)
                    {
                        shader.Update(() => update(input));
                    }
                    return input;
                });
            }));
        }
Esempio n. 8
0
        IObservable <TSource> Process <TSource>(IObservable <TSource> source, Action <int, TSource> update)
        {
            return(Observable.Defer(() =>
            {
                var textureId = 0;
                var textureName = default(string);
                return source.CombineEither(
                    ShaderManager.ReserveShader(ShaderName),
                    (input, shader) =>
                {
                    if (textureName != TextureName)
                    {
                        textureName = TextureName;
                        var texture = !string.IsNullOrEmpty(textureName)
                                ? shader.Window.ResourceManager.Load <Texture>(textureName)
                                : null;
                        textureId = texture != null ? texture.Id : 0;
                    }

                    shader.Update(() => update(textureId, input));
                    return input;
                });
            }));
        }