/// <summary>
        /// Renders the post processing stage and all linked stages.
        /// </summary>
        /// <returns>TargetTexture of the last linked post processing stage.</returns>
        public Texture2D Render(Texture2D sourceTexture)
        {
            OpenGL.ValidateThread();
            GL.Disable(EnableCap.Blend);
            GL.Disable(EnableCap.DepthTest);
            GL.Disable(EnableCap.CullFace);

            var stage = this;

            stage.SourceTexture = sourceTexture;

            FrameBuffer renderTarget = FrameBuffer.Current;

            this.tools.Value.vao.Bind();
            Viewport.Push();
            while (stage != null)
            {
                if (stage.Effect == null)
                {
                    throw new InvalidOperationException("One or more post processing stages are missing a shader.");
                }
                if (stage.TargetTexture == null)
                {
                    throw new InvalidOperationException("One or more post processing stages are missing a target texture.");
                }

                Viewport.Area = new Box2i(0, 0, stage.TargetTexture.Width, stage.TargetTexture.Height);
                this.tools.Value.frameBuffer.SetTextures(stage.TargetTexture);
                this.tools.Value.frameBuffer.Bind();

                stage.Effect.InvertY = true;

                var cs = stage.Effect.Select();
                cs.Bind();
                cs.BindUniform(stage);

                GL.DrawArrays(PrimitiveType.TriangleStrip, 0, 4);

                if (stage.Stage == null)
                {
                    break;
                }
                else
                {
                    stage.Stage.SourceTexture = stage.TargetTexture;
                    stage = stage.Stage;
                }
            }
            ;
            Viewport.Pop();
            VertexArray.Unbind();
            FrameBuffer.Current = renderTarget;

            return(stage.TargetTexture);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Pops a viewport from the stack and makes it current.
 /// </summary>
 public static void Pop()
 {
     OpenGL.ValidateThread();
     if (current.Value.stack.Count > 0)
     {
         Viewport.Area = current.Value.stack.Pop();
     }
     else
     {
         Viewport.Area = GetDefault();
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Pushes the current viewport settings on the stack.
 /// </summary>
 public static void Push()
 {
     OpenGL.ValidateThread();
     current.Value.stack.Push(current.Value.viewport);
 }