using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

using EVE.EVEObjects;
using EVE.EVECameras;

namespace EVE.EVEShaders
{
    public class EVEPostProc : EVEShader
    {
        private VertexPositionTexture[] verts;
        private VertexDeclaration declaration;
        private ResolveTexture2D resolved;

        //internal EVEPostProc() : base("BasicPost") { }
        public EVEPostProc(string asset) : base(asset) { }

        internal override void LoadContent(GraphicsDevice myDevice, ContentManager myLoader)
        {
            base.LoadContent(myDevice, myLoader);

            verts = new VertexPositionTexture[] {
                new VertexPositionTexture(new Vector3(-1, -1, 0), new Vector2(0, 1)),
                new VertexPositionTexture(new Vector3(-1, 1, 0), new Vector2(0, 0)),
                new VertexPositionTexture(new Vector3(1, -1, 0), new Vector2(1, 1)),
                new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(1, 0))
            };

            declaration = new VertexDeclaration(myDevice, VertexPositionTexture.VertexElements);

            resolved = new ResolveTexture2D(
                myDevice, myDevice.Viewport.Width,
                myDevice.Viewport.Height, 1,
                myDevice.DisplayMode.Format
            );
        }

        internal void Draw(GraphicsDevice myDevice)
        {
            myDevice.ResolveBackBuffer(resolved);
            myDevice.Textures[0] = resolved;

            SetParameters(null);
            myEffect.Begin();
            foreach (EffectPass pass in myEffect.CurrentTechnique.Passes)
            {
                pass.Begin();
                myDevice.VertexDeclaration = declaration;
                myDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, verts, 0, 2);
                pass.End();
            }
            myEffect.End();
        }
    }
}