public override void Render()
        {
            var context = this.DeviceManager.Direct3DContext;

            var vs = this.vertexShader;

            // OutputMerger targets must be set for every frame in Windows Store apps
            context.OutputMerger.SetTargets(this.DepthStencilView, this.RenderTargetView);

            context.ClearDepthStencilView(this.DepthStencilView, SharpDX.Direct3D11.DepthStencilClearFlags.Depth | SharpDX.Direct3D11.DepthStencilClearFlags.Stencil, 1.0f, 0);
            context.ClearRenderTargetView(this.RenderTargetView, new SharpDX.Color(Color.R, Color.G, Color.B, 1));

            // Set the context pipeline state
            SetContextState(context);

            ViewMatrix = Matrix.LookAtRH(Camera.Position, Camera.Position + Camera.LookAtDir, Vector3.UnitY);

            var viewProjection = ViewMatrix * ProjectionMatrix;
            // Extract camera position from view
            var camPosition = Matrix.Transpose(Matrix.Invert(ViewMatrix)).Column4;
            Camera.Position = new Vector3(camPosition.X, camPosition.Y, camPosition.Z);

            var perFrame = new ConstantBuffers.PerFrame();
            perFrame.CameraPosition = Camera.Position;
            context.UpdateSubresource(ref perFrame, perFrameBuffer);

            var perMaterial = new ConstantBuffers.PerMaterial();
            perMaterial.Ambient = new Color4(0.2f);
            perMaterial.Diffuse = SharpDX.Color.White;
            perMaterial.Emissive = new Color4(0);
            perMaterial.Specular = SharpDX.Color.White;
            perMaterial.SpecularPower = 20f;
            context.UpdateSubresource(ref perMaterial, perMaterialBuffer);

            //var scale = this.SwapChainPanel.CompositionScaleX;
            var worldRotation = Matrix.Identity * Matrix.RotationAxis(Vector3.UnitY, clock.ElapsedMilliseconds / 1000.0f);
            var perObject = new ConstantBuffers.PerObject();
            perObject.World = cubeRenderer.World * WorldMatrix * worldRotation;
            perObject.WorldInverseTranspose = Matrix.Transpose(Matrix.Invert(perObject.World));
            perObject.WorldViewProjection = perObject.World * viewProjection;
            perObject.Transpose();
            context.UpdateSubresource(ref perObject, perObjectBuffer);

            cubeRenderer.Render();

            textRenderer.Text = "Hello SwapChainPanel!";
            textRenderer.Render();

            fpsRenderer.Render();

            //// Draw a circle.
            //var d2dContext = DeviceManager.Direct2DContext;
            //float radiusX = this.RenderTargetSize.Width / 3.0f;
            //float radiusY = this.RenderTargetSize.Height / 3.0f;

            //float strokeWidth = 10.0f *this.SwapChainPanel.CompositionScaleX;
            //var brush = new SharpDX.Direct2D1.SolidColorBrush(d2dContext, SharpDX.Color.Black);
            //d2dContext.BeginDraw();
            //using (var sc2 = SwapChain.QueryInterface<SwapChain2>())
            //{
            //    d2dContext.Transform = sc2.MatrixTransform;
            //}
            //d2dContext.DrawEllipse(new SharpDX.Direct2D1.Ellipse(new Vector2(this.RenderTargetSize.Width / 2.0f, this.RenderTargetSize.Height / 2.0f), radiusX, radiusY), brush, strokeWidth );
            //d2dContext.EndDraw();

            // Present the render result
            Present();
        }
        public override void Render()
        {
            var context = this.DeviceManager.Direct3DContext;

            var vs = this.vertexShader;

            // OutputMerger targets must be set for every frame in Windows Store apps
            context.OutputMerger.SetTargets(this.DepthStencilView, this.RenderTargetView);

            context.ClearDepthStencilView(this.DepthStencilView, SharpDX.Direct3D11.DepthStencilClearFlags.Depth | SharpDX.Direct3D11.DepthStencilClearFlags.Stencil, 1.0f, 0);
            context.ClearRenderTargetView(this.RenderTargetView, new SharpDX.Color(Color.R, Color.G, Color.B, 1));

            // Set the context pipeline state
            SetContextState(context);

            ViewMatrix = Matrix.LookAtRH(Camera.Position, Camera.Position + Camera.LookAtDir, Vector3.UnitY);

            var viewProjection = ViewMatrix * ProjectionMatrix;
            // Extract camera position from view
            var camPosition = Matrix.Transpose(Matrix.Invert(ViewMatrix)).Column4;

            Camera.Position = new Vector3(camPosition.X, camPosition.Y, camPosition.Z);

            var perFrame = new ConstantBuffers.PerFrame();

            perFrame.CameraPosition = Camera.Position;
            context.UpdateSubresource(ref perFrame, perFrameBuffer);

            var perMaterial = new ConstantBuffers.PerMaterial();

            perMaterial.Ambient       = new Color4(0.2f);
            perMaterial.Diffuse       = SharpDX.Color.White;
            perMaterial.Emissive      = new Color4(0);
            perMaterial.Specular      = SharpDX.Color.White;
            perMaterial.SpecularPower = 20f;
            context.UpdateSubresource(ref perMaterial, perMaterialBuffer);

            //var scale = this.SwapChainPanel.CompositionScaleX;
            var worldRotation = Matrix.Identity * Matrix.RotationAxis(Vector3.UnitY, clock.ElapsedMilliseconds / 1000.0f);
            var perObject     = new ConstantBuffers.PerObject();

            perObject.World = cubeRenderer.World * WorldMatrix * worldRotation;
            perObject.WorldInverseTranspose = Matrix.Transpose(Matrix.Invert(perObject.World));
            perObject.WorldViewProjection   = perObject.World * viewProjection;
            perObject.Transpose();
            context.UpdateSubresource(ref perObject, perObjectBuffer);

            cubeRenderer.Render();

            textRenderer.Text = "Hello SwapChainPanel!";
            textRenderer.Render();

            fpsRenderer.Render();

            //// Draw a circle.
            //var d2dContext = DeviceManager.Direct2DContext;
            //float radiusX = this.RenderTargetSize.Width / 3.0f;
            //float radiusY = this.RenderTargetSize.Height / 3.0f;

            //float strokeWidth = 10.0f *this.SwapChainPanel.CompositionScaleX;
            //var brush = new SharpDX.Direct2D1.SolidColorBrush(d2dContext, SharpDX.Color.Black);
            //d2dContext.BeginDraw();
            //using (var sc2 = SwapChain.QueryInterface<SwapChain2>())
            //{
            //    d2dContext.Transform = sc2.MatrixTransform;
            //}
            //d2dContext.DrawEllipse(new SharpDX.Direct2D1.Ellipse(new Vector2(this.RenderTargetSize.Width / 2.0f, this.RenderTargetSize.Height / 2.0f), radiusX, radiusY), brush, strokeWidth );
            //d2dContext.EndDraw();

            // Present the render result
            Present();
        }