using SharpDX;
using SharpDX.Toolkit;
using SharpDX.Toolkit.Graphics;
using System;

namespace Shader
{
    class ShaderDemo : Game
    {
        private GraphicsDeviceManager m_graphicsDeviceManager;

//        DepthStencilState m_depthStencilStateState;

        private SharpDX.Toolkit.Graphics.Effect m_Shader1;

        /// <summary>
        /// Entry point create and starts the game
        /// </summary>
        static void Main()
        {
            var program = new ShaderDemo();
            program.Run();
        }

        ShaderDemo()
        {
            // Creates a graphics manager. This is mandatory.
            m_graphicsDeviceManager = new GraphicsDeviceManager(this);
            m_graphicsDeviceManager.PreferredDepthStencilFormat = DepthFormat.Depth32;
            m_graphicsDeviceManager.PreferredBackBufferWidth = 700;
            m_graphicsDeviceManager.PreferredBackBufferHeight = 700;
            m_graphicsDeviceManager.SetPreferredGraphicsProfile(SharpDX.Direct3D.FeatureLevel.Level_10_1);

            // Setup the relative directory to the executable directory
            // for loading contents with the ContentManager
            Content.RootDirectory = "content";
        }

        protected override void Initialize()
        {
            base.Initialize();

            Window.Title = "Shader Demo";

            /*var depthStencilStateDesc = SharpDX.Direct3D11.DepthStencilStateDescription.Default();
            depthStencilStateDesc.IsDepthEnabled = false;
            m_depthStencilStateState = DepthStencilState.New(GraphicsDevice, "NoZ", depthStencilStateDesc);
            GraphicsDevice.SetDepthStencilState(m_depthStencilStateState);*/

            // Load Shaders
            m_Shader1 = Helpers.LoadEffect(GraphicsDevice, "shader1.fx");
        }


        protected override void Draw(GameTime gameTime)
        {
            // Clears the screen
            GraphicsDevice.Clear(new Color(255, 144, 1));

            var constants = m_Shader1.ConstantBuffers["Special"];
            constants.Parameters["c_time"].SetValue( (float)gameTime.TotalGameTime.TotalSeconds );
            Vector3 rAxis = new Vector3(12.0f, -6.0f, -8.0f);
            rAxis.Normalize();
            constants.Parameters["c_rotation"].SetValue(Matrix.RotationAxis(rAxis, 0.03f * (float)gameTime.TotalGameTime.TotalSeconds));
            m_Shader1.CurrentTechnique.Passes[0].Apply();
            GraphicsDevice.Draw(PrimitiveType.PointList, 1);

            base.Draw(gameTime);
        }
    }
}
