示例#1
0
        public override IObservable <Mat> Process(IObservable <Mat> source)
        {
            return(Observable.Defer(() =>
            {
                Mesh mesh = null;
                return source.CombineEither(
                    ShaderManager.ReserveMaterial(ShaderName),
                    (input, material) =>
                {
                    material.Update(() =>
                    {
                        if (mesh == null)
                        {
                            mesh = new Mesh();
                            VertexHelper.BindVertexAttributes(
                                mesh.VertexBuffer,
                                mesh.VertexArray,
                                input.Cols * input.ElementSize,
                                vertexAttributes);
                        }

                        mesh.DrawMode = DrawMode;
                        mesh.VertexCount = VertexHelper.UpdateVertexBuffer(mesh.VertexBuffer, input, Usage);
                        mesh.Draw();
                    });
                    return input;
                }).Finally(() =>
                {
                    if (mesh != null)
                    {
                        mesh.Dispose();
                    }
                });
            }));
        }
示例#2
0
 IObservable <Mesh> Process <TVertex, TIndex>(IObservable <Tuple <TVertex[], TIndex[]> > source, DrawElementsType elementType)
     where TVertex : struct
     where TIndex : struct
 {
     return(source.Select(input =>
     {
         var mesh = new Mesh();
         var indices = input.Item2;
         VertexHelper.BindVertexAttributes(
             mesh.VertexBuffer,
             mesh.VertexArray,
             BlittableValueType <TVertex> .Stride,
             vertexAttributes);
         mesh.EnsureElementArray();
         mesh.DrawMode = DrawMode;
         mesh.VertexCount = indices.Length;
         mesh.ElementArrayType = elementType;
         VertexHelper.UpdateVertexBuffer(mesh.VertexBuffer, input.Item1, Usage);
         GL.BindBuffer(BufferTarget.ElementArrayBuffer, mesh.ElementArray);
         GL.BufferData(BufferTarget.ElementArrayBuffer,
                       new IntPtr(indices.Length * BlittableValueType <TIndex> .Stride),
                       indices,
                       Usage);
         GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
         return mesh;
     }));
 }
示例#3
0
 public IObservable <TVertex[]> Process <TVertex>(IObservable <TVertex[]> source) where TVertex : struct
 {
     return(Observable.Defer(() =>
     {
         Mesh mesh = null;
         return source.CombineEither(
             ShaderManager.ReserveMaterial(ShaderName).Do(material =>
         {
             material.Update(() =>
             {
                 mesh = new Mesh();
                 VertexHelper.BindVertexAttributes(
                     mesh.VertexBuffer,
                     mesh.VertexArray,
                     BlittableValueType <TVertex> .Stride,
                     vertexAttributes);
             });
         }),
             (input, material) =>
         {
             material.Update(() =>
             {
                 mesh.DrawMode = DrawMode;
                 mesh.VertexCount = VertexHelper.UpdateVertexBuffer(mesh.VertexBuffer, input, Usage);
                 mesh.Draw();
             });
             return input;
         });
     }));
 }
示例#4
0
        IObservable <Tuple <TVertex[], TIndex[]> > Process <TVertex, TIndex>(IObservable <Tuple <TVertex[], TIndex[]> > source, DrawElementsType elementType)
            where TVertex : struct
            where TIndex : struct
        {
            return(Observable.Create <Tuple <TVertex[], TIndex[]> >(observer =>
            {
                var name = MeshName;
                if (string.IsNullOrEmpty(name))
                {
                    throw new InvalidOperationException("A mesh name must be specified.");
                }

                Mesh mesh = null;
                return source.CombineEither(
                    ShaderManager.WindowSource.Do(window =>
                {
                    window.Update(() =>
                    {
                        try
                        {
                            mesh = window.ResourceManager.Load <Mesh>(name);
                            VertexHelper.BindVertexAttributes(
                                mesh.VertexBuffer,
                                mesh.VertexArray,
                                BlittableValueType <TVertex> .Stride,
                                vertexAttributes);
                        }
                        catch (Exception ex) { observer.OnError(ex); }
                    });
                }),
                    (input, window) =>
                {
                    window.Update(() =>
                    {
                        var indices = input.Item2;
                        mesh.EnsureElementArray();
                        mesh.DrawMode = DrawMode;
                        mesh.VertexCount = indices.Length;
                        mesh.ElementArrayType = elementType;
                        VertexHelper.UpdateVertexBuffer(mesh.VertexBuffer, input.Item1, Usage);
                        GL.BindBuffer(BufferTarget.ElementArrayBuffer, mesh.ElementArray);
                        GL.BufferData(BufferTarget.ElementArrayBuffer,
                                      new IntPtr(indices.Length * BlittableValueType <TIndex> .Stride),
                                      indices,
                                      Usage);
                        GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
                    });
                    return input;
                }).SubscribeSafe(observer);
            }));
        }
示例#5
0
 public IObservable <Mesh> Process <TVertex>(IObservable <TVertex[]> source) where TVertex : struct
 {
     return(source.Select(input =>
     {
         var mesh = new Mesh();
         VertexHelper.BindVertexAttributes(
             mesh.VertexBuffer,
             mesh.VertexArray,
             BlittableValueType <TVertex> .Stride,
             vertexAttributes);
         mesh.DrawMode = DrawMode;
         mesh.VertexCount = VertexHelper.UpdateVertexBuffer(mesh.VertexBuffer, input, Usage);
         return mesh;
     }));
 }
示例#6
0
 public IObservable <Mesh> Process(IObservable <Mat> source)
 {
     return(source.Select(input =>
     {
         var mesh = new Mesh();
         VertexHelper.BindVertexAttributes(
             mesh.VertexBuffer,
             mesh.VertexArray,
             input.Cols * input.ElementSize,
             vertexAttributes);
         mesh.DrawMode = DrawMode;
         mesh.VertexCount = VertexHelper.UpdateVertexBuffer(mesh.VertexBuffer, input, Usage);
         return mesh;
     }));
 }
示例#7
0
        public override IObservable <Mat> Process(IObservable <Mat> source)
        {
            return(Observable.Create <Mat>(observer =>
            {
                var name = MeshName;
                if (string.IsNullOrEmpty(name))
                {
                    throw new InvalidOperationException("A mesh name must be specified.");
                }

                Mesh mesh = null;
                return source.CombineEither(
                    ShaderManager.WindowSource,
                    (input, window) =>
                {
                    window.Update(() =>
                    {
                        if (mesh == null)
                        {
                            try
                            {
                                mesh = window.ResourceManager.Load <Mesh>(name);
                                VertexHelper.BindVertexAttributes(
                                    mesh.VertexBuffer,
                                    mesh.VertexArray,
                                    input.Cols * input.ElementSize,
                                    vertexAttributes);
                            }
                            catch (Exception ex)
                            {
                                observer.OnError(ex);
                                return;
                            }
                        }

                        mesh.DrawMode = DrawMode;
                        mesh.VertexCount = VertexHelper.UpdateVertexBuffer(mesh.VertexBuffer, input, Usage);
                    });
                    return input;
                }).SubscribeSafe(observer);
            }));
        }
示例#8
0
        public IObservable <TVertex[]> Process <TVertex>(IObservable <TVertex[]> source) where TVertex : struct
        {
            return(Observable.Create <TVertex[]>(observer =>
            {
                var name = MeshName;
                if (string.IsNullOrEmpty(name))
                {
                    throw new InvalidOperationException("A mesh name must be specified.");
                }

                Mesh mesh = null;
                return source.CombineEither(
                    ShaderManager.WindowSource.Do(window =>
                {
                    window.Update(() =>
                    {
                        try
                        {
                            mesh = window.ResourceManager.Load <Mesh>(name);
                            VertexHelper.BindVertexAttributes(
                                mesh.VertexBuffer,
                                mesh.VertexArray,
                                BlittableValueType <TVertex> .Stride,
                                vertexAttributes);
                        }
                        catch (Exception ex) { observer.OnError(ex); }
                    });
                }),
                    (input, window) =>
                {
                    window.Update(() =>
                    {
                        mesh.DrawMode = DrawMode;
                        mesh.VertexCount = VertexHelper.UpdateVertexBuffer(mesh.VertexBuffer, input, Usage);
                    });
                    return input;
                }).SubscribeSafe(observer);
            }));
        }