using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework.Graphics;

using EVE.EVEShaders;

namespace EVE.EVEGpgpu
{
    abstract public class EVEGpTask
    {
        protected EVEGpKernel computeKernel;

        abstract public void Perform();
        abstract public void Initialize();
    }

    public class EVEGpTask_Blur : EVEGpTask
    {
        Texture2D initialTexture;

        GraphicsDevice currentProcessor;

        private static readonly EVEGpTask_Blur instance = new EVEGpTask_Blur();

        public static EVEGpTask_Blur Instance
        {
            get { return instance; }
        }

        override public void Perform()
        {
            RTData A_RT = RTManager.Instance.requestRT(SurfaceFormat.Color, 800, 600);
            RTData B_RT = RTManager.Instance.requestRT(SurfaceFormat.Color, 800, 600);

            computeKernel = EVEShaderManager.GetShader("GPGPU_Blur") as EVEGpKernel;
            computeKernel.myEffect.Parameters["fullTexel"].SetValue((1.0f/(float)(256)));

            computeKernel.PerformCopy(currentProcessor, initialTexture, A_RT.RT);
 
            computeKernel.CalculateSingleKernel(currentProcessor, "BoxBlur3x3", B_RT.RT, A_RT.RT);
            //computeKernel.CalculateSingleKernel(currentProcessor, "BoxBlur3x3", B_RT.RT, A_RT.RT);
            //computeKernel.CalculateSingleKernel(currentProcessor, "BoxBlur3x3", B_RT.RT, A_RT.RT);
            //computeKernel.CalculateSingleKernel(currentProcessor, "BoxBlur3x3", B_RT.RT, A_RT.RT);
            //computeKernel.CalculateSingleKernel(currentProcessor, "BoxBlur3x3", B_RT.RT, A_RT.RT);

            computeKernel.PerformDebugDraw(currentProcessor, "CopyArray", A_RT.RT);
            A_RT.Lock = false;
            B_RT.Lock = false;
        }

        override public void Initialize()
        {
            computeKernel = new EVEGpKernel(@"Content/Shaders/GPGPU/GPGPU_Blur");
            EVEShaderManager.AddKernel("GPGPU_Blur", computeKernel);
            currentProcessor = EVEGpuSupport.Instance.currentProcessor;

            initialTexture = EVEGpuSupport.Instance.cManager.Load<Texture2D>(@"Content/Textures/TW_SHOT") as Texture2D;          
        }
    }
}
