Exemple #1
0
 public override IObservable <Texture> Process(IObservable <IplImage> source)
 {
     return(Observable.Defer(() =>
     {
         var texture = default(Texture);
         var textureSize = default(Size);
         return source.CombineEither(
             ShaderManager.WindowUpdate(window =>
         {
             texture = configuration.CreateResource(window.ResourceManager);
         }),
             (input, window) =>
         {
             window.Update(() =>
             {
                 GL.BindTexture(TextureTarget.Texture2D, texture.Id);
                 var internalFormat = textureSize != input.Size ? InternalFormat : (PixelInternalFormat?)null;
                 TextureHelper.UpdateTexture(TextureTarget.Texture2D, internalFormat, input);
                 textureSize = input.Size;
             });
             return texture;
         }).Finally(() =>
         {
             if (texture != null)
             {
                 texture.Dispose();
             }
         });
     }));
 }
Exemple #2
0
        public IEnumerator <ElementIndex <Texture> > GetEnumerator(bool loop)
        {
            try
            {
                this.loop = loop;
                while (preloaded != null)
                {
                    var result = preloaded.MoveNext();
                    if (!result)
                    {
                        yield break;
                    }

                    var current = preloaded.Current;
                    GL.BindTexture(TextureTarget.Texture2D, Id);
                    TextureHelper.UpdateTexture(TextureTarget.Texture2D, pixelFormat, current.Value);
                    yield return(new ElementIndex <Texture>(this, current.Index));
                }
            }
            finally
            {
                this.loop = false;
                if (preloaded != null)
                {
                    preloaded.Dispose();
                    queryFrame = queryFrame.ContinueWith(task =>
                    {
                        frames.Reset();
                        return(default(ElementIndex <IplImage>));
                    });
                }

                preloaded = GetPreloadedFrames(frames, capacity);
            }
        }
 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
     }));
 }
        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;
            })));
        }
Exemple #5
0
        public override IObservable <IplImage> Process(IObservable <IplImage> source)
        {
            return(Observable.Create <IplImage>(observer =>
            {
                var texture = 0;
                var name = TextureName;
                var textureSize = default(Size);
                if (string.IsNullOrEmpty(name))
                {
                    throw new InvalidOperationException("A texture name must be specified.");
                }

                return source.CombineEither(
                    ShaderManager.WindowSource.Do(window =>
                {
                    window.Update(() =>
                    {
                        try
                        {
                            var tex = window.ResourceManager.Load <Texture>(name);
                            texture = tex.Id;
                        }
                        catch (Exception ex) { observer.OnError(ex); }
                    });
                }),
                    (input, window) =>
                {
                    window.Update(() =>
                    {
                        var target = TextureTarget;
                        if (target > TextureTarget.TextureBindingCubeMap && target < TextureTarget.ProxyTextureCubeMap)
                        {
                            GL.BindTexture(TextureTarget.TextureCubeMap, texture);
                        }
                        else
                        {
                            GL.BindTexture(target, texture);
                        }
                        var internalFormat = textureSize != input.Size ? InternalFormat : (PixelInternalFormat?)null;
                        TextureHelper.UpdateTexture(target, internalFormat, input);
                        textureSize = input.Size;
                    });
                    return input;
                }).SubscribeSafe(observer);
            }));
        }