예제 #1
0
        public void Render(Pipeline.Pipeline pipeline, Pipeline.PipelineAssets pipelineAssets)
        {
            PopulateCommandList(pipeline, pipelineAssets);
            pipeline.CommandQueue.ExecuteCommandList(pipelineAssets.CommandList);

            var brush = new SharpDX.Direct2D1.SolidColorBrush(pipeline.D2DRenderTargets[0], SharpDX.Color4.White);

            pipeline.D3D11On12Device.AcquireWrappedResources(new SharpDX.Direct3D11.Resource[] { pipeline.WrappedBackBuffers[pipeline.FrameIndex] }, 1);
            pipeline.D2DRenderTargets[pipeline.FrameIndex].BeginDraw();
            pipeline.D2DRenderTargets[pipeline.FrameIndex].FillRectangle(new SharpDX.Mathematics.Interop.RawRectangleF(5f, 5f, 100f, 100f), brush);
            // textBrush.Color = Color4.Lerp(colors[t], colors[t + 1], f);
            // pipeline.D2DRenderTargets[pipeline.FrameIndex].DrawText("Hello Text", textFormat, new SharpDX.Mathematics.Interop.RawRectangleF((float)Math.Sin(Environment.TickCount / 1000.0F) * 200 + 400, 10, 2000, 500), textBrush);
            pipeline.D2DRenderTargets[pipeline.FrameIndex].EndDraw();
            pipeline.D3D11On12Device.ReleaseWrappedResources(new SharpDX.Direct3D11.Resource[] { pipeline.WrappedBackBuffers[pipeline.FrameIndex] }, 1);
            pipeline.D3D11Device.ImmediateContext.Flush();
            brush.Dispose();

            pipeline.SwapChain3.Present(1, 0);
            pipeline.MoveToNextFrame();
        }
예제 #2
0
        static void Main()
        {
            System.Windows.Forms.Application.SetHighDpiMode(System.Windows.Forms.HighDpiMode.SystemAware);
            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);

            var form           = new Form(800, 600);
            var pipeline       = new Pipeline.Pipeline(2, form.GraphicsPanel.ClientSize, form.GraphicsPanel.Handle);
            var pipelineAssets = new Pipeline.PipelineAssets(pipeline);
            var fpsCounter     = new FpsCounter();
            var engine         = new Engine.Engine();
            var bridge         = new UI.Bridge(engine, fpsCounter);

            form.GraphicsPanel.KeyDown += (object sender, System.Windows.Forms.KeyEventArgs e) =>
            {
                switch (e.KeyData)
                {
                case System.Windows.Forms.Keys.W:
                    engine.Camera.IsMovingForward = true;
                    break;

                case System.Windows.Forms.Keys.A:
                    engine.Camera.IsMovingLeft = true;
                    break;

                case System.Windows.Forms.Keys.S:
                    engine.Camera.IsMovingBackward = true;
                    break;

                case System.Windows.Forms.Keys.D:
                    engine.Camera.IsMovingRight = true;
                    break;
                }
            };

            form.GraphicsPanel.KeyUp += (object sender, System.Windows.Forms.KeyEventArgs e) =>
            {
                switch (e.KeyData)
                {
                case System.Windows.Forms.Keys.W:
                    engine.Camera.IsMovingForward = false;
                    break;

                case System.Windows.Forms.Keys.A:
                    engine.Camera.IsMovingLeft = false;
                    break;

                case System.Windows.Forms.Keys.S:
                    engine.Camera.IsMovingBackward = false;
                    break;

                case System.Windows.Forms.Keys.D:
                    engine.Camera.IsMovingRight = false;
                    break;
                }
            };

            form.GraphicsPanel.MouseMove += (object sender, System.Windows.Forms.MouseEventArgs e) =>
            {
            };

            form.WebView.CoreWebView2InitializationCompleted += (object sender, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e) =>
            {
                bridge.SetCoreWebView2(form.WebView.CoreWebView2);
            };

            form.GraphicsPanel.SizeChanged += (object sender, System.EventArgs e) =>
            {
                pipeline.WaitForGpu();
                pipeline.Resize(form.GraphicsPanel.ClientSize);
            };

            form.Show();
            fpsCounter.Initialize();
            var start = System.Diagnostics.Stopwatch.GetTimestamp();
            var last  = start;

            while (form.Created)
            {
                fpsCounter.OnFrame();

                var now   = System.Diagnostics.Stopwatch.GetTimestamp();
                var total = System.TimeSpan.FromTicks(now - start);
                var delta = System.TimeSpan.FromTicks(now - last);
                last = now;

                engine.Update(pipeline, pipelineAssets, total, delta);
                engine.Render(pipeline, pipelineAssets);
                pipeline.MoveToNextFrame();

                System.Windows.Forms.Application.DoEvents();
            }
        }