Example #1
0
        public void Run()
        {
            application.RunEvents();            // run this once before checking window
            while (!window.IsClosed())
            {
                device.BeginFrame();
                commandList.Start();
                commandList.BeginRenderPass(renderPass);
                var windowSize = window.GetSize(WindowSizeType.WorkingArea);
                commandList.SetViewPort(new ViewPort(new Rect2(0, 0, windowSize.width, windowSize.height)));
                commandList.SetRenderState(renderState);
                commandList.Draw();
                commandList.EndRenderPass();
                commandList.Finish();
                commandList.Execute();
                device.EndFrame();

                // update constant buffer
                constantBufferObject.offset = (float)Math.Sin(rot);
                rot += 0.1f;
                constantBuffer.Update(constantBufferObject);

                // run application events
                application.RunEvents();
            }
        }
        public void Run()
        {
            application.RunEvents();            // run this once before checking window
            while (!window.IsClosed())
            {
                // get window size and viewport
                var windowSize = window.GetSize(WindowSizeType.WorkingArea);
                var viewPort   = new ViewPort(new Rect2(0, 0, windowSize.width, windowSize.height));

                // update camera
                camera.position = new Vec3(MathF.Cos(rot), .5f, MathF.Sin(rot)) * 3;
                camera.aspect   = viewPort.GetAspect();
                camera.LookAt(Vec3.zero);

                // update constant buffer
                if (!constantBuffer.BeginUpdate(device.swapChain))
                {
                    throw new Exception("Failed to update ConstantBuffer");
                }
                constantBuffer.Update(MathF.Abs(MathF.Cos(rot * .5f)), shaderEffectVar_Constrast);
                constantBuffer.Update(camera.matrix, shaderEffectVar_Camera);
                constantBuffer.EndUpdate();
                rot += 0.01f;

                // render frame and present
                device.BeginFrame();

                commandList.Start(device.swapChain);                // RENDER INTO: RenderTexture
                commandList.BeginRenderPass(renderTextureTest.renderPass);
                commandList.SetViewPort(new ViewPort(0, 0, renderTextureTest.renderTexture.width, renderTextureTest.renderTexture.height));
                commandList.SetRenderState(renderTextureTest.renderState);
                commandList.Draw();
                commandList.EndRenderPass();
                commandList.Finish();
                commandList.Execute();

                // execute compute shader
                commandList_Compute.Start(device.swapChain);
                commandList_Compute.SetComputeState(computeState);
                commandList_Compute.ExecuteComputeShader(renderTextureTest.renderTexture.width / 8, renderTextureTest.renderTexture.height / 8, 1);
                commandList_Compute.Finish();
                commandList_Compute.Execute();

                commandList.Start(device.swapChain);                // RENDER INTO: SwapChain
                commandList.BeginRenderPass(renderPass);
                commandList.SetViewPort(viewPort);
                commandList.SetRenderState(renderState);
                commandList.Draw();
                commandList.EndRenderPass();
                commandList.Finish();
                commandList.Execute();

                // copy render-texture into swap-chain surface
                if (renderTextureMSAA.msaaLevel != MSAALevel.Disabled)
                {
                    device.swapChain.ResolveMSAA(renderTextureMSAA);
                }
                else
                {
                    device.swapChain.CopyTexture(renderTextureMSAA);
                }
                device.EndFrame();

                // run application events
                application.RunEvents();
            }
        }
Example #3
0
        public void Run()
        {
            application.RunEvents();            // run this once before checking window
            while (!window.IsClosed())
            {
                instance.Update();

                // print raw device input

                /*foreach (var device in instance.devices)
                 * {
                 *      if (!device.connected) continue;
                 *
                 *      // buttons
                 *      for (int i = 0; i != device.buttons.Length; ++i)
                 *      {
                 *              var button = device.buttons[i];
                 *              if (button.down) Console.WriteLine("Button: " + i.ToString());
                 *      }
                 *
                 *      // POV
                 *      for (int i = 0; i != device.povDirections.Length; ++i)
                 *      {
                 *              uint pov = device.povDirections[i];
                 *              if (pov != uint.MaxValue) Console.WriteLine("POV: " + i.ToString() + " " + pov.ToString());
                 *      }
                 *
                 *      // axes 1D
                 *      for (int i = 0; i != device.axes1D.Length; ++i)
                 *      {
                 *              var axis = device.axes1D[i];
                 *              if (axis.value != 0) Console.WriteLine("Axis1D: " + i.ToString() + " " + axis.value.ToString());
                 *      }
                 *
                 *      // axes 2D
                 *      for (int i = 0; i != device.axes2D.Length; ++i)
                 *      {
                 *              var axis = device.axes2D[i];
                 *              if (axis.value.Length() > 0) Console.WriteLine("Axis2D: " + i.ToString() + " " + axis.value.ToString());
                 *      }
                 *
                 *      // axes 3D
                 *      for (int i = 0; i != device.axes3D.Length; ++i)
                 *      {
                 *              var axis = device.axes3D[i];
                 *              if (axis.value.Length() > 0) Console.WriteLine("Axis3D: " + i.ToString() + " " + axis.value.ToString());
                 *      }
                 *
                 *      // sliders
                 *      for (int i = 0; i != device.sliders.Length; ++i)
                 *      {
                 *              var slider = device.sliders[i];
                 *              if (slider.value != 0) Console.WriteLine("Slider: " + i.ToString() + " " + slider.value.ToString());
                 *      }
                 * }*/

                // print gamepad input
                foreach (var gamepad in instance.gamepads)
                {
                    if (!gamepad.connected)
                    {
                        continue;
                    }

                    // rumble
                    gamepad.SetRumble(gamepad.triggerLeft.value, gamepad.triggerRight.value);

                    // buttons
                    if (gamepad.button1.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.button1));
                    }
                    if (gamepad.button2.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.button2));
                    }
                    if (gamepad.button3.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.button3));
                    }
                    if (gamepad.button4.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.button4));
                    }
                    if (gamepad.button5.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.button5));
                    }
                    if (gamepad.button6.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.button6));
                    }

                    if (gamepad.special1.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.special1));
                    }
                    if (gamepad.special2.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.special2));
                    }

                    if (gamepad.dpadLeft.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.dpadLeft));
                    }
                    if (gamepad.dpadRight.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.dpadRight));
                    }
                    if (gamepad.dpadDown.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.dpadDown));
                    }
                    if (gamepad.dpadUp.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.dpadUp));
                    }

                    if (gamepad.home.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.home));
                    }
                    if (gamepad.menu.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.menu));
                    }
                    if (gamepad.back.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.back));
                    }

                    if (gamepad.bumperLeft.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.bumperLeft));
                    }
                    if (gamepad.bumperRight.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.bumperRight));
                    }

                    if (gamepad.triggerButtonLeft.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.triggerButtonLeft));
                    }
                    if (gamepad.triggerButtonRight.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.triggerButtonRight));
                    }

                    if (gamepad.joystickButtonLeft.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.joystickButtonLeft));
                    }
                    if (gamepad.joystickButtonRight.down)
                    {
                        Console.WriteLine(gamepad.GetButtonName(gamepad.joystickButtonRight));
                    }

                    // triggers
                    if (gamepad.triggerLeft.value != 0)
                    {
                        Console.WriteLine(gamepad.GetTriggerName(gamepad.triggerLeft) + " " + gamepad.triggerLeft.value.ToString());
                    }
                    if (gamepad.triggerRight.value != 0)
                    {
                        Console.WriteLine(gamepad.GetTriggerName(gamepad.triggerRight) + " " + gamepad.triggerRight.value.ToString());
                    }

                    // joysticks
                    if (gamepad.joystickLeft.value.Length() != 0)
                    {
                        Console.WriteLine(gamepad.GetJoystickName(gamepad.joystickLeft) + " " + gamepad.joystickLeft.value.ToString());
                    }
                    if (gamepad.joystickRight.value.Length() != 0)
                    {
                        Console.WriteLine(gamepad.GetJoystickName(gamepad.joystickRight) + " " + gamepad.joystickRight.value.ToString());
                    }
                }

                // keep within 60fps
                System.Threading.Thread.Sleep(1000 / 60);

                // run application events
                application.RunEvents();
            }
        }